summaryrefslogtreecommitdiff
path: root/server/.yarn/unplugged/node-gyp-npm-9.3.1-43540bab9c/node_modules/node-gyp/lib/create-config-gypi.js
diff options
context:
space:
mode:
authorrohan09-raj <rajrohan1914@gmail.com>2023-01-29 19:54:07 +0530
committerrohan09-raj <rajrohan1914@gmail.com>2023-01-29 19:54:07 +0530
commit54d26f03666dd8dc457bd66403d9badd42509296 (patch)
tree9fdca2caf4b624b95fbaf0153a6e0f3ac435280e /server/.yarn/unplugged/node-gyp-npm-9.3.1-43540bab9c/node_modules/node-gyp/lib/create-config-gypi.js
parentec8bb132218c1295f1a599c88454f682aba2409f (diff)
update the repo
Diffstat (limited to 'server/.yarn/unplugged/node-gyp-npm-9.3.1-43540bab9c/node_modules/node-gyp/lib/create-config-gypi.js')
-rw-r--r--server/.yarn/unplugged/node-gyp-npm-9.3.1-43540bab9c/node_modules/node-gyp/lib/create-config-gypi.js147
1 files changed, 147 insertions, 0 deletions
diff --git a/server/.yarn/unplugged/node-gyp-npm-9.3.1-43540bab9c/node_modules/node-gyp/lib/create-config-gypi.js b/server/.yarn/unplugged/node-gyp-npm-9.3.1-43540bab9c/node_modules/node-gyp/lib/create-config-gypi.js
new file mode 100644
index 0000000..ced4911
--- /dev/null
+++ b/server/.yarn/unplugged/node-gyp-npm-9.3.1-43540bab9c/node_modules/node-gyp/lib/create-config-gypi.js
@@ -0,0 +1,147 @@
+'use strict'
+
+const fs = require('graceful-fs')
+const log = require('npmlog')
+const path = require('path')
+
+function parseConfigGypi (config) {
+ // translated from tools/js2c.py of Node.js
+ // 1. string comments
+ config = config.replace(/#.*/g, '')
+ // 2. join multiline strings
+ config = config.replace(/'$\s+'/mg, '')
+ // 3. normalize string literals from ' into "
+ config = config.replace(/'/g, '"')
+ return JSON.parse(config)
+}
+
+async function getBaseConfigGypi ({ gyp, nodeDir }) {
+ // try reading $nodeDir/include/node/config.gypi first when:
+ // 1. --dist-url or --nodedir is specified
+ // 2. and --force-process-config is not specified
+ const useCustomHeaders = gyp.opts.nodedir || gyp.opts.disturl || gyp.opts['dist-url']
+ const shouldReadConfigGypi = useCustomHeaders && !gyp.opts['force-process-config']
+ if (shouldReadConfigGypi && nodeDir) {
+ try {
+ const baseConfigGypiPath = path.resolve(nodeDir, 'include/node/config.gypi')
+ const baseConfigGypi = await fs.promises.readFile(baseConfigGypiPath)
+ return parseConfigGypi(baseConfigGypi.toString())
+ } catch (err) {
+ log.warn('read config.gypi', err.message)
+ }
+ }
+
+ // fallback to process.config if it is invalid
+ return JSON.parse(JSON.stringify(process.config))
+}
+
+async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo }) {
+ const config = await getBaseConfigGypi({ gyp, nodeDir })
+ if (!config.target_defaults) {
+ config.target_defaults = {}
+ }
+ if (!config.variables) {
+ config.variables = {}
+ }
+
+ const defaults = config.target_defaults
+ const variables = config.variables
+
+ // don't inherit the "defaults" from the base config.gypi.
+ // doing so could cause problems in cases where the `node` executable was
+ // compiled on a different machine (with different lib/include paths) than
+ // the machine where the addon is being built to
+ defaults.cflags = []
+ defaults.defines = []
+ defaults.include_dirs = []
+ defaults.libraries = []
+
+ // set the default_configuration prop
+ if ('debug' in gyp.opts) {
+ defaults.default_configuration = gyp.opts.debug ? 'Debug' : 'Release'
+ }
+
+ if (!defaults.default_configuration) {
+ defaults.default_configuration = 'Release'
+ }
+
+ // set the target_arch variable
+ variables.target_arch = gyp.opts.arch || process.arch || 'ia32'
+ if (variables.target_arch === 'arm64') {
+ defaults.msvs_configuration_platform = 'ARM64'
+ defaults.xcode_configuration_platform = 'arm64'
+ }
+
+ // set the node development directory
+ variables.nodedir = nodeDir
+
+ // disable -T "thin" static archives by default
+ variables.standalone_static_library = gyp.opts.thin ? 0 : 1
+
+ if (process.platform === 'win32') {
+ defaults.msbuild_toolset = vsInfo.toolset
+ if (vsInfo.sdk) {
+ defaults.msvs_windows_target_platform_version = vsInfo.sdk
+ }
+ if (variables.target_arch === 'arm64') {
+ if (vsInfo.versionMajor > 15 ||
+ (vsInfo.versionMajor === 15 && vsInfo.versionMajor >= 9)) {
+ defaults.msvs_enable_marmasm = 1
+ } else {
+ log.warn('Compiling ARM64 assembly is only available in\n' +
+ 'Visual Studio 2017 version 15.9 and above')
+ }
+ }
+ variables.msbuild_path = vsInfo.msBuild
+ }
+
+ // loop through the rest of the opts and add the unknown ones as variables.
+ // this allows for module-specific configure flags like:
+ //
+ // $ node-gyp configure --shared-libxml2
+ Object.keys(gyp.opts).forEach(function (opt) {
+ if (opt === 'argv') {
+ return
+ }
+ if (opt in gyp.configDefs) {
+ return
+ }
+ variables[opt.replace(/-/g, '_')] = gyp.opts[opt]
+ })
+
+ return config
+}
+
+async function createConfigGypi ({ gyp, buildDir, nodeDir, vsInfo }) {
+ const configFilename = 'config.gypi'
+ const configPath = path.resolve(buildDir, configFilename)
+
+ log.verbose('build/' + configFilename, 'creating config file')
+
+ const config = await getCurrentConfigGypi({ gyp, nodeDir, vsInfo })
+
+ // ensures that any boolean values in config.gypi get stringified
+ function boolsToString (k, v) {
+ if (typeof v === 'boolean') {
+ return String(v)
+ }
+ return v
+ }
+
+ log.silly('build/' + configFilename, config)
+
+ // now write out the config.gypi file to the build/ dir
+ const prefix = '# Do not edit. File was generated by node-gyp\'s "configure" step'
+
+ const json = JSON.stringify(config, boolsToString, 2)
+ log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
+ await fs.promises.writeFile(configPath, [prefix, json, ''].join('\n'))
+
+ return configPath
+}
+
+module.exports = createConfigGypi
+module.exports.test = {
+ parseConfigGypi: parseConfigGypi,
+ getCurrentConfigGypi: getCurrentConfigGypi
+}