31
31
import jsrun
32
32
from tools .shared import TEMP_DIR , EMCC , EMXX , DEBUG , EMCONFIGURE , EMCMAKE
33
33
from tools .shared import EMSCRIPTEN_TEMP_DIR
34
- from tools .shared import get_canonical_temp_dir , path_from_root
34
+ from tools .shared import get_canonical_temp_dir , try_delete , path_from_root
35
35
from tools .utils import MACOS , WINDOWS , read_file , read_binary , write_file , write_binary , exit_with_error
36
- from tools import shared , line_endings , building , config , utils
36
+ from tools import shared , line_endings , building , config
37
37
38
38
logger = logging .getLogger ('common' )
39
39
84
84
PYTHON = sys .executable
85
85
86
86
87
+ def delete_contents (pathname ):
88
+ for entry in os .listdir (pathname ):
89
+ try_delete (os .path .join (pathname , entry ))
90
+ # TODO(sbc): Should we make try_delete have a stronger guarantee?
91
+ assert not os .path .exists (os .path .join (pathname , entry ))
92
+
93
+
87
94
def test_file (* path_components ):
88
95
"""Construct a path relative to the emscripten "tests" directory."""
89
96
return str (Path (TEST_ROOT , * path_components ))
@@ -301,35 +308,6 @@ def make_executable(name):
301
308
Path (name ).chmod (stat .S_IREAD | stat .S_IWRITE | stat .S_IEXEC )
302
309
303
310
304
- def make_dir_writeable (dirname ):
305
- # Ensure all files are readable and writable by the current user.
306
- permission_bits = stat .S_IWRITE | stat .S_IREAD
307
-
308
- def is_writable (path ):
309
- return (os .stat (path ).st_mode & permission_bits ) != permission_bits
310
-
311
- def make_writable (path ):
312
- new_mode = os .stat (path ).st_mode | permission_bits
313
- os .chmod (path , new_mode )
314
-
315
- # Some tests make files and subdirectories read-only, so rmtree/unlink will not delete
316
- # them. Force-make everything writable in the subdirectory to make it
317
- # removable and re-attempt.
318
- if not is_writable (dirname ):
319
- make_writable (dirname )
320
-
321
- for directory , subdirs , files in os .walk (dirname ):
322
- for item in files + subdirs :
323
- i = os .path .join (directory , item )
324
- if not os .path .islink (i ):
325
- make_writable (i )
326
-
327
-
328
- def force_delete_dir (dirname ):
329
- make_dir_writeable (dirname )
330
- utils .delete_dir (dirname )
331
-
332
-
333
311
def parameterized (parameters ):
334
312
"""
335
313
Mark a test as parameterized.
@@ -531,7 +509,7 @@ def setUp(self):
531
509
# expect this. --no-clean can be used to keep the old contents for the new test
532
510
# run. This can be useful when iterating on a given test with extra files you want to keep
533
511
# around in the output directory.
534
- utils . delete_contents (self .working_dir )
512
+ delete_contents (self .working_dir )
535
513
else :
536
514
print ('Creating new test output directory' )
537
515
ensure_dir (self .working_dir )
@@ -549,7 +527,7 @@ def tearDown(self):
549
527
if not EMTEST_SAVE_DIR :
550
528
# rmtree() fails on Windows if the current working directory is inside the tree.
551
529
os .chdir (os .path .dirname (self .get_dir ()))
552
- force_delete_dir (self .get_dir ())
530
+ try_delete (self .get_dir ())
553
531
554
532
if EMTEST_DETECT_TEMPFILE_LEAKS and not DEBUG :
555
533
temp_files_after_run = []
@@ -973,9 +951,9 @@ def get_library(self, name, generated_libs, configure=['sh', './configure'], #
973
951
cache_name , env_init = env_init , native = native )
974
952
975
953
def clear (self ):
976
- utils . delete_contents (self .get_dir ())
954
+ delete_contents (self .get_dir ())
977
955
if EMSCRIPTEN_TEMP_DIR :
978
- utils . delete_contents (EMSCRIPTEN_TEMP_DIR )
956
+ delete_contents (EMSCRIPTEN_TEMP_DIR )
979
957
980
958
def run_process (self , cmd , check = True , ** args ):
981
959
# Wrapper around shared.run_process. This is desirable so that the tests
@@ -1741,7 +1719,7 @@ def btest(self, filename, expected=None, reference=None,
1741
1719
outfile = 'test.html'
1742
1720
args += [filename , '-o' , outfile ]
1743
1721
# print('all args:', args)
1744
- utils . delete_file (outfile )
1722
+ try_delete (outfile )
1745
1723
self .compile_btest (args , reporting = reporting )
1746
1724
self .assertExists (outfile )
1747
1725
if post_build :
0 commit comments