@@ -7,6 +7,7 @@ const os = require('os') |
7 | 7 | const processRelease = require('./process-release') |
8 | 8 | const win = process.platform === 'win32' |
9 | 9 | const findNodeDirectory = require('./find-node-directory') |
| 10 | +const createConfigGypi = require('./create-config-gypi') |
10 | 11 | const msgFormat = require('util').format |
11 | 12 | var findPython = require('./find-python') |
12 | 13 | if (win) { |
@@ -92,107 +93,14 @@ function configure (gyp, argv, callback) { |
92 | 93 | if (err) { |
93 | 94 | return callback(err) |
94 | 95 | } |
95 | | - |
96 | | - var configFilename = 'config.gypi' |
97 | | - var configPath = path.resolve(buildDir, configFilename) |
98 | | - |
99 | | - log.verbose('build/' + configFilename, 'creating config file') |
100 | | - |
101 | | - var config = process.config ? JSON.parse(JSON.stringify(process.config)) : {} |
102 | | - var defaults = config.target_defaults |
103 | | - var variables = config.variables |
104 | | - |
105 | | - // default "config.variables" |
106 | | - if (!variables) { |
107 | | - variables = config.variables = {} |
108 | | - } |
109 | | - |
110 | | - // default "config.defaults" |
111 | | - if (!defaults) { |
112 | | - defaults = config.target_defaults = {} |
113 | | - } |
114 | | - |
115 | | - // don't inherit the "defaults" from node's `process.config` object. |
116 | | - // doing so could cause problems in cases where the `node` executable was |
117 | | - // compiled on a different machine (with different lib/include paths) than |
118 | | - // the machine where the addon is being built to |
119 | | - defaults.cflags = [] |
120 | | - defaults.defines = [] |
121 | | - defaults.include_dirs = [] |
122 | | - defaults.libraries = [] |
123 | | - |
124 | | - // set the default_configuration prop |
125 | | - if ('debug' in gyp.opts) { |
126 | | - defaults.default_configuration = gyp.opts.debug ? 'Debug' : 'Release' |
127 | | - } |
128 | | - |
129 | | - if (!defaults.default_configuration) { |
130 | | - defaults.default_configuration = 'Release' |
131 | | - } |
132 | | - |
133 | | - // set the target_arch variable |
134 | | - variables.target_arch = gyp.opts.arch || process.arch || 'ia32' |
135 | | - if (variables.target_arch === 'arm64') { |
136 | | - defaults.msvs_configuration_platform = 'ARM64' |
137 | | - defaults.xcode_configuration_platform = 'arm64' |
138 | | - } |
139 | | - |
140 | | - // set the node development directory |
141 | | - variables.nodedir = nodeDir |
142 | | - |
143 | | - // disable -T "thin" static archives by default |
144 | | - variables.standalone_static_library = gyp.opts.thin ? 0 : 1 |
145 | | - |
146 | | - if (win) { |
| 96 | + if (process.platform === 'win32') { |
147 | 97 | process.env.GYP_MSVS_VERSION = Math.min(vsInfo.versionYear, 2015) |
148 | 98 | process.env.GYP_MSVS_OVERRIDE_PATH = vsInfo.path |
149 | | - defaults.msbuild_toolset = vsInfo.toolset |
150 | | - if (vsInfo.sdk) { |
151 | | - defaults.msvs_windows_target_platform_version = vsInfo.sdk |
152 | | - } |
153 | | - if (variables.target_arch === 'arm64') { |
154 | | - if (vsInfo.versionMajor > 15 || |
155 | | - (vsInfo.versionMajor === 15 && vsInfo.versionMajor >= 9)) { |
156 | | - defaults.msvs_enable_marmasm = 1 |
157 | | - } else { |
158 | | - log.warn('Compiling ARM64 assembly is only available in\n' + |
159 | | - 'Visual Studio 2017 version 15.9 and above') |
160 | | - } |
161 | | - } |
162 | | - variables.msbuild_path = vsInfo.msBuild |
163 | 99 | } |
164 | | - |
165 | | - // loop through the rest of the opts and add the unknown ones as variables. |
166 | | - // this allows for module-specific configure flags like: |
167 | | - // |
168 | | - // $ node-gyp configure --shared-libxml2 |
169 | | - Object.keys(gyp.opts).forEach(function (opt) { |
170 | | - if (opt === 'argv') { |
171 | | - return |
172 | | - } |
173 | | - if (opt in gyp.configDefs) { |
174 | | - return |
175 | | - } |
176 | | - variables[opt.replace(/-/g, '_')] = gyp.opts[opt] |
| 100 | + createConfigGypi({ gyp, buildDir, nodeDir, vsInfo }, (err, configPath) => { |
| 101 | + configs.push(configPath) |
| 102 | + findConfigs(err) |
177 | 103 | }) |
178 | | - |
179 | | - // ensures that any boolean values from `process.config` get stringified |
180 | | - function boolsToString (k, v) { |
181 | | - if (typeof v === 'boolean') { |
182 | | - return String(v) |
183 | | - } |
184 | | - return v |
185 | | - } |
186 | | - |
187 | | - log.silly('build/' + configFilename, config) |
188 | | - |
189 | | - // now write out the config.gypi file to the build/ dir |
190 | | - var prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step' |
191 | | - |
192 | | - var json = JSON.stringify(config, boolsToString, 2) |
193 | | - log.verbose('build/' + configFilename, 'writing out config file: %s', configPath) |
194 | | - configs.push(configPath) |
195 | | - fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs) |
196 | 104 | } |
197 | 105 |
|
198 | 106 | function findConfigs (err) { |
|