From 0f085706ed2a7401b7be18a4f7da913782122dc0 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 30 Jan 2025 17:05:18 -0800 Subject: [PATCH] Move gen_struct_info.py from tools/maint to tools Also update the extra_struct_info test to that it actually uses gen_struct_info to generated the struct_info json file. Fixes: #23436 --- src/modules.mjs | 4 ++-- system/include/webgpu/README.md | 4 ++-- test/other/test_extra_struct_info.h | 2 ++ test/other/test_extra_struct_info.js | 2 +- test/other/test_extra_struct_info.json | 11 +++++++---- test/test_other.py | 11 ++++++----- tools/{maint => }/gen_struct_info.py | 2 +- 7 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 test/other/test_extra_struct_info.h rename tools/{maint => }/gen_struct_info.py (99%) diff --git a/src/modules.mjs b/src/modules.mjs index 9f818d29391ea..b7ffbeaf8ebaa 100644 --- a/src/modules.mjs +++ b/src/modules.mjs @@ -337,7 +337,7 @@ const C_STRUCTS = new Proxy(structs, { get(target, prop) { if (!(prop in target)) { throw new Error( - `Missing C struct ${prop}! If you just added it to struct_info.json, you need to run ./tools/maint/gen_struct_info.py (then run a second time with --wasm64)`, + `Missing C struct ${prop}! If you just added it to struct_info.json, you need to run ./tools/gen_struct_info.py (then run a second time with --wasm64)`, ); } return target[prop]; @@ -348,7 +348,7 @@ const C_DEFINES = new Proxy(defines, { get(target, prop) { if (!(prop in target)) { throw new Error( - `Missing C define ${prop}! If you just added it to struct_info.json, you need to run ./tools/maint/gen_struct_info.py (then run a second time with --wasm64)`, + `Missing C define ${prop}! If you just added it to struct_info.json, you need to run ./tools/gen_struct_info.py (then run a second time with --wasm64)`, ); } return target[prop]; diff --git a/system/include/webgpu/README.md b/system/include/webgpu/README.md index b376899718d8c..d19bf43d5b8c3 100644 --- a/system/include/webgpu/README.md +++ b/system/include/webgpu/README.md @@ -46,8 +46,8 @@ To update these bindings from Dawn: ``` emcc --clear-cache - ./tools/maint/gen_struct_info.py - ./tools/maint/gen_struct_info.py --wasm64 + ./tools/gen_struct_info.py + ./tools/gen_struct_info.py --wasm64 ./tools/maint/gen_sig_info.py ``` diff --git a/test/other/test_extra_struct_info.h b/test/other/test_extra_struct_info.h new file mode 100644 index 0000000000000..c018e23a12467 --- /dev/null +++ b/test/other/test_extra_struct_info.h @@ -0,0 +1,2 @@ +#define AF_INET 42 + diff --git a/test/other/test_extra_struct_info.js b/test/other/test_extra_struct_info.js index dd81b9892d7fe..92131f4e968e5 100644 --- a/test/other/test_extra_struct_info.js +++ b/test/other/test_extra_struct_info.js @@ -1,6 +1,6 @@ console.error("(before) AF_INET=" + {{{ cDefs.AF_INET }}}); /* Loading this struct info file will override the default AF_INET value */ -{{{ loadStructInfo(__dirname + '/test_extra_struct_info.json'), null }}} +{{{ loadStructInfo('generated.json'), null }}} console.error("(after) AF_INET=" + {{{ cDefs.AF_INET }}}); diff --git a/test/other/test_extra_struct_info.json b/test/other/test_extra_struct_info.json index 7edabc62f3d9a..9681269f849e1 100644 --- a/test/other/test_extra_struct_info.json +++ b/test/other/test_extra_struct_info.json @@ -1,5 +1,8 @@ -{ - "defines": { - "AF_INET": 42 +[ + { + "file": "test_extra_struct_info.h", + "defines": [ + "AF_INET" + ] } -} +] diff --git a/test/test_other.py b/test/test_other.py index 0fa3207dd47b1..e1c1cf8cea1d8 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -13205,13 +13205,13 @@ def test_split_main_module(self): def test_gen_struct_info(self): # This test will start failing whenever the struct info changes (e.g. offset or defines # change). However it's easy to rebaseline with --rebaseline. - self.run_process([PYTHON, path_from_root('tools/maint/gen_struct_info.py'), '-o', 'out.json']) + self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '-o', 'out.json']) self.assertFileContents(path_from_root('src/struct_info_generated.json'), read_file('out.json')) # Same again for wasm64 node_version = shared.get_node_version(self.get_nodejs()) if node_version and node_version >= (14, 0, 0): - self.run_process([PYTHON, path_from_root('tools/maint/gen_struct_info.py'), '--wasm64', '-o', 'out.json']) + self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '--wasm64', '-o', 'out.json']) self.assertFileContents(path_from_root('src/struct_info_generated_wasm64.json'), read_file('out.json')) @crossplatform @@ -13228,7 +13228,7 @@ def test_gen_struct_info_env(self): # linking) to effect the internal building and running of this code. # For example -O2 causes printf -> iprintf which will fail with undefined symbol iprintf. with env_modify({'EMCC_CFLAGS': '-O2 BAD_ARG', 'EMCC_FORCE_STDLIBS': '1', 'EMCC_ONLY_FORCED_STDLIBS': '1'}): - self.run_process([PYTHON, path_from_root('tools/maint/gen_struct_info.py'), '-o', 'out.json']) + self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '-o', 'out.json']) def test_relocatable_limited_exports(self): # Building with RELOCATABLE should *not* automatically export all sybmols. @@ -14724,13 +14724,13 @@ def test_missing_struct_info(self): {{{ C_STRUCTS.Foo }}} ''') err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js']) - self.assertContained('Error: Missing C struct Foo! If you just added it to struct_info.json, you need to run ./tools/maint/gen_struct_info.py (then run a second time with --wasm64)', err) + self.assertContained('Error: Missing C struct Foo! If you just added it to struct_info.json, you need to run ./tools/gen_struct_info.py (then run a second time with --wasm64)', err) create_file('lib.js', ''' {{{ C_DEFINES.Foo }}} ''') err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js']) - self.assertContained('Error: Missing C define Foo! If you just added it to struct_info.json, you need to run ./tools/maint/gen_struct_info.py (then run a second time with --wasm64)', err) + self.assertContained('Error: Missing C define Foo! If you just added it to struct_info.json, you need to run ./tools/gen_struct_info.py (then run a second time with --wasm64)', err) def run_wasi_test_suite_test(self, name): if not os.path.exists(path_from_root('test/third_party/wasi-test-suite')): @@ -15432,6 +15432,7 @@ def test_save_temp(self): self.assertExists('hello_world.o') def test_extra_struct_info(self): + self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), test_file('other/test_extra_struct_info.json'), '-o', 'generated.json', '-I', test_file('other')]) stderr = self.run_process([EMCC, test_file('hello_world.c'), '--js-library', test_file('other/test_extra_struct_info.js')], stderr=PIPE).stderr self.assertContained('(before) AF_INET=2', stderr) self.assertContained('(after) AF_INET=42', stderr) diff --git a/tools/maint/gen_struct_info.py b/tools/gen_struct_info.py similarity index 99% rename from tools/maint/gen_struct_info.py rename to tools/gen_struct_info.py index 70754f35d1b9d..41511988f58ef 100755 --- a/tools/maint/gen_struct_info.py +++ b/tools/gen_struct_info.py @@ -64,7 +64,7 @@ import subprocess __scriptdir__ = os.path.dirname(os.path.abspath(__file__)) -__rootdir__ = os.path.dirname(os.path.dirname(__scriptdir__)) +__rootdir__ = os.path.dirname(__scriptdir__) sys.path.insert(0, __rootdir__) from tools import building