Skip to content

Commit b31dd92

Browse files
authored
Move gen_struct_info.py from tools/maint to tools (#23551)
Also update the extra_struct_info test to that it actually uses gen_struct_info to generated the struct_info json file. Fixes: #23436
1 parent 91643e8 commit b31dd92

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

src/modules.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ const C_STRUCTS = new Proxy(structs, {
337337
get(target, prop) {
338338
if (!(prop in target)) {
339339
throw new Error(
340-
`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)`,
340+
`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)`,
341341
);
342342
}
343343
return target[prop];
@@ -348,7 +348,7 @@ const C_DEFINES = new Proxy(defines, {
348348
get(target, prop) {
349349
if (!(prop in target)) {
350350
throw new Error(
351-
`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)`,
351+
`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)`,
352352
);
353353
}
354354
return target[prop];

system/include/webgpu/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ To update these bindings from Dawn:
4646

4747
```
4848
emcc --clear-cache
49-
./tools/maint/gen_struct_info.py
50-
./tools/maint/gen_struct_info.py --wasm64
49+
./tools/gen_struct_info.py
50+
./tools/gen_struct_info.py --wasm64
5151
./tools/maint/gen_sig_info.py
5252
```
5353

test/other/test_extra_struct_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define AF_INET 42
2+

test/other/test_extra_struct_info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
console.error("(before) AF_INET=" + {{{ cDefs.AF_INET }}});
22

33
/* Loading this struct info file will override the default AF_INET value */
4-
{{{ loadStructInfo(__dirname + '/test_extra_struct_info.json'), null }}}
4+
{{{ loadStructInfo('generated.json'), null }}}
55

66
console.error("(after) AF_INET=" + {{{ cDefs.AF_INET }}});
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{
2-
"defines": {
3-
"AF_INET": 42
1+
[
2+
{
3+
"file": "test_extra_struct_info.h",
4+
"defines": [
5+
"AF_INET"
6+
]
47
}
5-
}
8+
]

test/test_other.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13208,13 +13208,13 @@ def test_split_main_module(self):
1320813208
def test_gen_struct_info(self):
1320913209
# This test will start failing whenever the struct info changes (e.g. offset or defines
1321013210
# change). However it's easy to rebaseline with --rebaseline.
13211-
self.run_process([PYTHON, path_from_root('tools/maint/gen_struct_info.py'), '-o', 'out.json'])
13211+
self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '-o', 'out.json'])
1321213212
self.assertFileContents(path_from_root('src/struct_info_generated.json'), read_file('out.json'))
1321313213

1321413214
# Same again for wasm64
1321513215
node_version = shared.get_node_version(self.get_nodejs())
1321613216
if node_version and node_version >= (14, 0, 0):
13217-
self.run_process([PYTHON, path_from_root('tools/maint/gen_struct_info.py'), '--wasm64', '-o', 'out.json'])
13217+
self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '--wasm64', '-o', 'out.json'])
1321813218
self.assertFileContents(path_from_root('src/struct_info_generated_wasm64.json'), read_file('out.json'))
1321913219

1322013220
@crossplatform
@@ -13231,7 +13231,7 @@ def test_gen_struct_info_env(self):
1323113231
# linking) to effect the internal building and running of this code.
1323213232
# For example -O2 causes printf -> iprintf which will fail with undefined symbol iprintf.
1323313233
with env_modify({'EMCC_CFLAGS': '-O2 BAD_ARG', 'EMCC_FORCE_STDLIBS': '1', 'EMCC_ONLY_FORCED_STDLIBS': '1'}):
13234-
self.run_process([PYTHON, path_from_root('tools/maint/gen_struct_info.py'), '-o', 'out.json'])
13234+
self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '-o', 'out.json'])
1323513235

1323613236
def test_relocatable_limited_exports(self):
1323713237
# Building with RELOCATABLE should *not* automatically export all sybmols.
@@ -14727,13 +14727,13 @@ def test_missing_struct_info(self):
1472714727
{{{ C_STRUCTS.Foo }}}
1472814728
''')
1472914729
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js'])
14730-
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)
14730+
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)
1473114731

1473214732
create_file('lib.js', '''
1473314733
{{{ C_DEFINES.Foo }}}
1473414734
''')
1473514735
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--js-library=lib.js'])
14736-
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)
14736+
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)
1473714737

1473814738
def run_wasi_test_suite_test(self, name):
1473914739
if not os.path.exists(path_from_root('test/third_party/wasi-test-suite')):
@@ -15435,6 +15435,7 @@ def test_save_temp(self):
1543515435
self.assertExists('hello_world.o')
1543615436

1543715437
def test_extra_struct_info(self):
15438+
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')])
1543815439
stderr = self.run_process([EMCC, test_file('hello_world.c'), '--js-library', test_file('other/test_extra_struct_info.js')], stderr=PIPE).stderr
1543915440
self.assertContained('(before) AF_INET=2', stderr)
1544015441
self.assertContained('(after) AF_INET=42', stderr)

tools/maint/gen_struct_info.py renamed to tools/gen_struct_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import subprocess
6565

6666
__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
67-
__rootdir__ = os.path.dirname(os.path.dirname(__scriptdir__))
67+
__rootdir__ = os.path.dirname(__scriptdir__)
6868
sys.path.insert(0, __rootdir__)
6969

7070
from tools import building

0 commit comments

Comments
 (0)