tools: dump config.gypi as json

This helps js2c processing the node.gypi correctly when a string
contains a quote.

PR-URL: https://github.com/nodejs/node/pull/60794
Refs: https://github.com/nodejs/node/pull/60703
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Chengzhong Wu
2025-11-23 01:37:32 +09:00
committed by GitHub
parent fb6b83c9ef
commit 7fd36886b4
3 changed files with 7 additions and 17 deletions

View File

@@ -2446,8 +2446,9 @@ if make_global_settings:
print_verbose(output) print_verbose(output)
# Dump as JSON to allow js2c.cc read it as a simple json file.
write('config.gypi', do_not_edit + write('config.gypi', do_not_edit +
pprint.pformat(output, indent=2, width=128) + '\n') json.dumps(output, indent=2) + '\n')
write('config.status', '#!/bin/sh\nset -x\nexec ./configure ' + write('config.status', '#!/bin/sh\nset -x\nexec ./configure ' +
' '.join([shlex.quote(arg) for arg in original_argv]) + '\n') ' '.join([shlex.quote(arg) for arg in original_argv]) + '\n')

View File

@@ -49,8 +49,7 @@ let config = fs.readFileSync(configPath, 'utf8');
// Clean up comment at the first line. // Clean up comment at the first line.
config = config.split('\n').slice(1).join('\n'); config = config.split('\n').slice(1).join('\n');
config = config.replace(/"/g, '\\"'); // Turn pseudo-booleans strings into booleans.
config = config.replace(/'/g, '"');
config = JSON.parse(config, (key, value) => { config = JSON.parse(config, (key, value) => {
if (value === 'true') return true; if (value === 'true') return true;
if (value === 'false') return false; if (value === 'false') return false;

View File

@@ -796,21 +796,11 @@ std::vector<char> JSONify(const std::vector<char>& code) {
// 1. Remove string comments // 1. Remove string comments
std::vector<char> stripped = StripComments(code); std::vector<char> stripped = StripComments(code);
// 2. join multiline strings // 2. turn pseudo-booleans strings into Booleans
std::vector<char> joined = JoinMultilineString(stripped); std::vector<char> result1 = ReplaceAll(stripped, R"("true")", "true");
std::vector<char> result2 = ReplaceAll(result1, R"("false")", "false");
// 3. normalize string literals from ' into " return result2;
for (size_t i = 0; i < joined.size(); ++i) {
if (joined[i] == '\'') {
joined[i] = '"';
}
}
// 4. turn pseudo-booleans strings into Booleans
std::vector<char> result3 = ReplaceAll(joined, R"("true")", "true");
std::vector<char> result4 = ReplaceAll(result3, R"("false")", "false");
return result4;
} }
int AddGypi(const std::string& var, int AddGypi(const std::string& var,