Skip to content

Commit a7bb974

Browse files
legendecasaduh95
authored andcommitted
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 <richard.lau@ibm.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 2d1efc7 commit a7bb974

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
@@ -2351,8 +2351,9 @@ def make_bin_override():
23512351

23522352
print_verbose(output)
23532353

2354+
# Dump as JSON to allow js2c.cc read it as a simple json file.
23542355
write('config.gypi', do_not_edit +
2355-
pprint.pformat(output, indent=2, width=128) + '\n')
2356+
json.dumps(output, indent=2) + '\n')
23562357

23572358
write('config.status', '#!/bin/sh\nset -x\nexec ./configure ' +
23582359
' '.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
@@ -784,21 +784,11 @@ std::vector<char> JSONify(const std::vector<char>& code) {
784784
// 1. Remove string comments
785785
std::vector<char> stripped = StripComments(code);
786786

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

790-
// 3. normalize string literals from ' into "
791-
for (size_t i = 0; i < joined.size(); ++i) {
792-
if (joined[i] == '\'') {
793-
joined[i] = '"';
794-
}
795-
}
796-
797-
// 4. turn pseudo-booleans strings into Booleans
798-
std::vector<char> result3 = ReplaceAll(joined, R"("true")", "true");
799-
std::vector<char> result4 = ReplaceAll(result3, R"("false")", "false");
800-
801-
return result4;
791+
return result2;
802792
}
803793

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

0 commit comments

Comments
 (0)