From def014dff3b183902599a36bed056e6811e067cf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 7 Sep 2023 18:20:38 +0900 Subject: [PATCH] tools: allow passing absolute path of config.gypi in js2c PR-URL: https://github.com/nodejs/node/pull/49162 Reviewed-By: Joyee Cheung Reviewed-By: Jiawen Geng --- tools/js2c.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/js2c.cc b/tools/js2c.cc index 83dbca135db628..904fb6fa44d4f5 100644 --- a/tools/js2c.cc +++ b/tools/js2c.cc @@ -89,6 +89,10 @@ bool StartsWith(const std::string& str, std::string_view prefix) { return str.compare(0, prefix_len, prefix) == 0; } +bool FilenameIsConfigGypi(const std::string& path) { + return path == "config.gypi" || EndsWith(path, "/config.gypi"); +} + typedef std::vector FileList; typedef std::map FileMap; @@ -707,7 +711,7 @@ int JS2C(const FileList& js_files, } } - assert(config == "config.gypi"); + assert(FilenameIsConfigGypi(config)); // "config.gypi" -> config_raw. int r = AddGypi("config", config, &definitions); if (r != 0) { @@ -789,10 +793,9 @@ int Main(int argc, char* argv[]) { // Should have exactly 3 types: `.js`, `.mjs` and `.gypi`. assert(file_map.size() == 3); auto gypi_it = file_map.find(".gypi"); - std::string config = "config.gypi"; // Currently config.gypi is the only `.gypi` file allowed if (gypi_it == file_map.end() || gypi_it->second.size() != 1 || - gypi_it->second[0] != config) { + !FilenameIsConfigGypi(gypi_it->second[0])) { fprintf( stderr, "Arguments should contain one and only one .gypi file: config.gypi\n"); @@ -805,7 +808,7 @@ int Main(int argc, char* argv[]) { std::sort(js_it->second.begin(), js_it->second.end()); std::sort(mjs_it->second.begin(), mjs_it->second.end()); - return JS2C(js_it->second, mjs_it->second, config, output); + return JS2C(js_it->second, mjs_it->second, gypi_it->second[0], output); } } // namespace js2c } // namespace node