Skip to content

Commit 7fd3688

Browse files
authored
tools: dump config.gypi as json
This helps js2c processing the node.gypi correctly when a string contains a quote. PR-URL: #60794 Refs: #60703 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent fb6b83c commit 7fd3688

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

configure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2446,8 +2446,9 @@ def make_bin_override():
24462446

24472447
print_verbose(output)
24482448

2449+
# Dump as JSON to allow js2c.cc read it as a simple json file.
24492450
write('config.gypi', do_not_edit +
2450-
pprint.pformat(output, indent=2, width=128) + '\n')
2451+
json.dumps(output, indent=2) + '\n')
24512452

24522453
write('config.status', '#!/bin/sh\nset -x\nexec ./configure ' +
24532454
' '.join([shlex.quote(arg) for arg in original_argv]) + '\n')

test/parallel/test-process-config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ let config = fs.readFileSync(configPath, 'utf8');
4949

5050
// Clean up comment at the first line.
5151
config = config.split('\n').slice(1).join('\n');
52-
config = config.replace(/"/g, '\\"');
53-
config = config.replace(/'/g, '"');
52+
// Turn pseudo-booleans strings into booleans.
5453
config = JSON.parse(config, (key, value) => {
5554
if (value === 'true') return true;
5655
if (value === 'false') return false;

tools/js2c.cc

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -796,21 +796,11 @@ std::vector<char> JSONify(const std::vector<char>& code) {
796796
// 1. Remove string comments
797797
std::vector<char> stripped = StripComments(code);
798798

799-
// 2. join multiline strings
800-
std::vector<char> joined = JoinMultilineString(stripped);
799+
// 2. turn pseudo-booleans strings into Booleans
800+
std::vector<char> result1 = ReplaceAll(stripped, R"("true")", "true");
801+
std::vector<char> result2 = ReplaceAll(result1, R"("false")", "false");
801802

802-
// 3. normalize string literals from ' into "
803-
for (size_t i = 0; i < joined.size(); ++i) {
804-
if (joined[i] == '\'') {
805-
joined[i] = '"';
806-
}
807-
}
808-
809-
// 4. turn pseudo-booleans strings into Booleans
810-
std::vector<char> result3 = ReplaceAll(joined, R"("true")", "true");
811-
std::vector<char> result4 = ReplaceAll(result3, R"("false")", "false");
812-
813-
return result4;
803+
return result2;
814804
}
815805

816806
int AddGypi(const std::string& var,

0 commit comments

Comments
 (0)