1313WASM_EXEC = os .path .join (INTERPRETER_DIR , 'wasm' )
1414
1515WAST_TESTS_DIR = os .path .join (SCRIPT_DIR , 'core' )
16+ WAST_TEST_SUBDIRS = [os .path .basename (d ) for d in
17+ filter (os .path .isdir ,
18+ glob .glob (os .path .join (WAST_TESTS_DIR , '*' )))]
1619HARNESS_DIR = os .path .join (SCRIPT_DIR , 'harness' )
1720
1821HARNESS_FILES = ['testharness.js' , 'testharnessreport.js' , 'testharness.css' ]
@@ -67,13 +70,17 @@ def convert_wast_to_js(out_js_dir):
6770
6871 inputs = []
6972
70- for wast_file in glob .glob (os .path .join (WAST_TESTS_DIR , '*.wast' )):
73+ for wast_file in glob .glob (os .path .join (WAST_TESTS_DIR , '**/*.wast' ),
74+ recursive = True ):
7175 # Don't try to compile tests that are supposed to fail.
7276 if '.fail.' in wast_file :
7377 continue
7478
79+ js_subdir = os .path .basename (os .path .dirname (wast_file ))
80+ if js_subdir == 'core' :
81+ js_subdir = ''
7582 js_filename = os .path .basename (wast_file ) + '.js'
76- js_file = os .path .join (out_js_dir , js_filename )
83+ js_file = os .path .join (out_js_dir , js_subdir , js_filename )
7784 inputs .append ((wast_file , js_file ))
7885
7986 pool = mp .Pool (processes = 8 )
@@ -112,9 +119,9 @@ def build_js(out_js_dir):
112119 </head>
113120 <body>
114121
115- <script src={WPT_PREFIX}/testharness.js></script>
116- <script src={WPT_PREFIX}/testharnessreport.js></script>
117- <script src={PREFIX}/{JS_HARNESS}></script>
122+ <script src=" {WPT_PREFIX}/testharness.js" ></script>
123+ <script src=" {WPT_PREFIX}/testharnessreport.js" ></script>
124+ <script src=" {PREFIX}/{JS_HARNESS}" ></script>
118125
119126 <div id=log></div>
120127"""
@@ -137,6 +144,8 @@ def wrap_single_test(js_file):
137144
138145def build_html_js (out_dir ):
139146 ensure_empty_dir (out_dir )
147+ for d in WAST_TEST_SUBDIRS :
148+ ensure_empty_dir (os .path .join (out_dir , d ))
140149 copy_harness_files (out_dir , True )
141150
142151 tests = convert_wast_to_js (out_dir )
@@ -146,19 +155,25 @@ def build_html_js(out_dir):
146155
147156def build_html_from_js (tests , html_dir , use_sync ):
148157 for js_file in tests :
149- js_filename = os .path .basename (js_file )
150- html_filename = js_filename + '.html'
151- html_file = os .path .join (html_dir , html_filename )
158+ subdir = os .path .basename (os .path .dirname (js_file ))
159+ js_prefix = '../js'
160+ if subdir == 'js' :
161+ subdir = ''
162+ js_prefix = './js'
163+ js_filename = os .path .join (js_prefix , subdir , os .path .basename (js_file ))
164+ html_filename = os .path .basename (js_file ) + '.html'
165+ html_file = os .path .join (html_dir , subdir , html_filename )
152166 js_harness = "sync_index.js" if use_sync else "async_index.js"
167+ harness_dir = os .path .join (js_prefix , 'harness' )
153168 with open (html_file , 'w+' ) as f :
154- content = HTML_HEADER .replace ('{PREFIX}' , './js/harness' ) \
155- .replace ('{WPT_PREFIX}' , './js/harness' ) \
169+ content = HTML_HEADER .replace ('{PREFIX}' , harness_dir ) \
170+ .replace ('{WPT_PREFIX}' , harness_dir ) \
156171 .replace ('{JS_HARNESS}' , js_harness )
157- content += " <script src=./js/{SCRIPT} ></script>" . replace ( '{SCRIPT}' , js_filename )
172+ content += ' <script src="' + js_filename + '" ></script>'
158173 content += HTML_BOTTOM
159174 f .write (content )
160175
161- def build_html (html_dir , js_dir , use_sync ):
176+ def build_html (html_dir , use_sync ):
162177 print ("Building HTML tests..." )
163178
164179 js_html_dir = os .path .join (html_dir , 'js' )
@@ -248,11 +263,15 @@ def process_args():
248263
249264 if js_dir is not None :
250265 ensure_empty_dir (js_dir )
266+ for d in WAST_TEST_SUBDIRS :
267+ ensure_empty_dir (os .path .join (js_dir , d ))
251268 build_js (js_dir )
252269
253270 if html_dir is not None :
254271 ensure_empty_dir (html_dir )
255- build_html (html_dir , js_dir , args .use_sync )
272+ for d in WAST_TEST_SUBDIRS :
273+ ensure_empty_dir (os .path .join (html_dir , d ))
274+ build_html (html_dir , args .use_sync )
256275
257276 if front_dir is not None :
258277 ensure_empty_dir (front_dir )
0 commit comments