From d9b24552f40b327d119be2d83c696b31f57ad20f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Apr 2023 05:11:22 +0900 Subject: [PATCH] tools: make `js2c.py` usable for other build systems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/46930 Reviewed-By: Richard Lau Reviewed-By: Joyee Cheung Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- tools/js2c.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/js2c.py b/tools/js2c.py index f9c202e861b986..54c7dfce363100 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -209,12 +209,20 @@ def main(): '--directory', default=None, help='input file directory') + parser.add_argument( + '--root', + default=None, + help='root directory containing the sources') parser.add_argument('--verbose', action='store_true', help='output file') parser.add_argument('sources', nargs='*', help='input files') options = parser.parse_args() global is_verbose is_verbose = options.verbose sources = options.sources + + if options.root is not None: + os.chdir(options.root) + if options.directory is not None: js_files = utils.SearchFiles(options.directory, 'js') mjs_files = utils.SearchFiles(options.directory, 'mjs') @@ -225,7 +233,8 @@ def main(): # Should have exactly 3 types: `.js`, `.mjs` and `.gypi` assert len(source_files) == 3 # Currently config.gypi is the only `.gypi` file allowed - assert source_files['.gypi'] == ['config.gypi'] + assert len(source_files['.gypi']) == 1 + assert os.path.basename(source_files['.gypi'][0]) == 'config.gypi' source_files['config.gypi'] = source_files.pop('.gypi')[0] JS2C(source_files, options.target)