@@ -114,7 +114,7 @@ def get_num_cores():
114
114
115
115
116
116
def mp_run_process (command_tuple ):
117
- temp_files = configuration . get_temp_files ()
117
+ temp_files = get_temp_files ()
118
118
cmd , env , route_stdout_to_temp_files_suffix , pipe_stdout , check , cwd = command_tuple
119
119
std_out = temp_files .get (route_stdout_to_temp_files_suffix ) if route_stdout_to_temp_files_suffix else (subprocess .PIPE if pipe_stdout else None )
120
120
ret = std_out .name if route_stdout_to_temp_files_suffix else None
@@ -163,7 +163,7 @@ def run_multiple_processes(commands, env=os.environ.copy(), route_stdout_to_temp
163
163
with ToolchainProfiler .profile_block ('run_multiple_processes' ):
164
164
processes = []
165
165
num_parallel_processes = get_num_cores ()
166
- temp_files = configuration . get_temp_files ()
166
+ temp_files = get_temp_files ()
167
167
i = 0
168
168
num_completed = 0
169
169
@@ -466,9 +466,9 @@ def replace_or_append_suffix(filename, new_suffix):
466
466
# temp directory (TEMP_DIR/emscripten_temp).
467
467
def get_emscripten_temp_dir ():
468
468
"""Returns a path to EMSCRIPTEN_TEMP_DIR, creating one if it didn't exist."""
469
- global configuration , EMSCRIPTEN_TEMP_DIR
469
+ global EMSCRIPTEN_TEMP_DIR
470
470
if not EMSCRIPTEN_TEMP_DIR :
471
- EMSCRIPTEN_TEMP_DIR = tempfile .mkdtemp (prefix = 'emscripten_temp_' , dir = configuration . TEMP_DIR )
471
+ EMSCRIPTEN_TEMP_DIR = tempfile .mkdtemp (prefix = 'emscripten_temp_' , dir = TEMP_DIR )
472
472
473
473
if not DEBUG_SAVE :
474
474
def prepare_to_clean_temp (d ):
@@ -485,54 +485,47 @@ def get_canonical_temp_dir(temp_dir):
485
485
return os .path .join (temp_dir , 'emscripten_temp' )
486
486
487
487
488
- class Configuration :
489
- def __init__ (self ):
490
- self .EMSCRIPTEN_TEMP_DIR = None
491
-
492
- self .TEMP_DIR = os .environ .get ("EMCC_TEMP_DIR" , tempfile .gettempdir ())
493
- if not os .path .isdir (self .TEMP_DIR ):
494
- exit_with_error (f'The temporary directory `{ self .TEMP_DIR } ` does not exist! Please make sure that the path is correct.' )
495
-
496
- self .CANONICAL_TEMP_DIR = get_canonical_temp_dir (self .TEMP_DIR )
497
-
498
- if DEBUG :
499
- self .EMSCRIPTEN_TEMP_DIR = self .CANONICAL_TEMP_DIR
500
- try :
501
- safe_ensure_dirs (self .EMSCRIPTEN_TEMP_DIR )
502
- except Exception as e :
503
- exit_with_error (str (e ) + f'Could not create canonical temp dir. Check definition of TEMP_DIR in { config .EM_CONFIG } ' )
504
-
505
- # Since the canonical temp directory is, by definition, the same
506
- # between all processes that run in DEBUG mode we need to use a multi
507
- # process lock to prevent more than one process from writing to it.
508
- # This is because emcc assumes that it can use non-unique names inside
509
- # the temp directory.
510
- # Sadly we need to allow child processes to access this directory
511
- # though, since emcc can recursively call itself when building
512
- # libraries and ports.
513
- if 'EM_HAVE_TEMP_DIR_LOCK' not in os .environ :
514
- filelock_name = os .path .join (self .EMSCRIPTEN_TEMP_DIR , 'emscripten.lock' )
515
- lock = filelock .FileLock (filelock_name )
516
- os .environ ['EM_HAVE_TEMP_DIR_LOCK' ] = '1'
517
- lock .acquire ()
518
- atexit .register (lock .release )
519
-
520
- def get_temp_files (self ):
521
- if DEBUG_SAVE :
522
- # In debug mode store all temp files in the emscripten-specific temp dir
523
- # and don't worry about cleaning them up.
524
- return tempfiles .TempFiles (get_emscripten_temp_dir (), save_debug_files = True )
525
- else :
526
- # Otherwise use the system tempdir and try to clean up after ourselves.
527
- return tempfiles .TempFiles (self .TEMP_DIR , save_debug_files = False )
488
+ def setup_temp_dirs ():
489
+ global EMSCRIPTEN_TEMP_DIR , CANONICAL_TEMP_DIR , TEMP_DIR
490
+ EMSCRIPTEN_TEMP_DIR = None
491
+
492
+ TEMP_DIR = os .environ .get ("EMCC_TEMP_DIR" , tempfile .gettempdir ())
493
+ if not os .path .isdir (TEMP_DIR ):
494
+ exit_with_error (f'The temporary directory `{ TEMP_DIR } ` does not exist! Please make sure that the path is correct.' )
528
495
496
+ CANONICAL_TEMP_DIR = get_canonical_temp_dir (TEMP_DIR )
529
497
530
- def apply_configuration ():
531
- global configuration , EMSCRIPTEN_TEMP_DIR , CANONICAL_TEMP_DIR , TEMP_DIR
532
- configuration = Configuration ()
533
- EMSCRIPTEN_TEMP_DIR = configuration .EMSCRIPTEN_TEMP_DIR
534
- CANONICAL_TEMP_DIR = configuration .CANONICAL_TEMP_DIR
535
- TEMP_DIR = configuration .TEMP_DIR
498
+ if DEBUG :
499
+ EMSCRIPTEN_TEMP_DIR = CANONICAL_TEMP_DIR
500
+ try :
501
+ safe_ensure_dirs (EMSCRIPTEN_TEMP_DIR )
502
+ except Exception as e :
503
+ exit_with_error (str (e ) + f'Could not create canonical temp dir. Check definition of TEMP_DIR in { config .EM_CONFIG } ' )
504
+
505
+ # Since the canonical temp directory is, by definition, the same
506
+ # between all processes that run in DEBUG mode we need to use a multi
507
+ # process lock to prevent more than one process from writing to it.
508
+ # This is because emcc assumes that it can use non-unique names inside
509
+ # the temp directory.
510
+ # Sadly we need to allow child processes to access this directory
511
+ # though, since emcc can recursively call itself when building
512
+ # libraries and ports.
513
+ if 'EM_HAVE_TEMP_DIR_LOCK' not in os .environ :
514
+ filelock_name = os .path .join (EMSCRIPTEN_TEMP_DIR , 'emscripten.lock' )
515
+ lock = filelock .FileLock (filelock_name )
516
+ os .environ ['EM_HAVE_TEMP_DIR_LOCK' ] = '1'
517
+ lock .acquire ()
518
+ atexit .register (lock .release )
519
+
520
+
521
+ def get_temp_files ():
522
+ if DEBUG_SAVE :
523
+ # In debug mode store all temp files in the emscripten-specific temp dir
524
+ # and don't worry about cleaning them up.
525
+ return tempfiles .TempFiles (get_emscripten_temp_dir (), save_debug_files = True )
526
+ else :
527
+ # Otherwise use the system tempdir and try to clean up after ourselves.
528
+ return tempfiles .TempFiles (TEMP_DIR , save_debug_files = False )
536
529
537
530
538
531
def target_environment_may_be (environment ):
@@ -716,7 +709,7 @@ def get_llvm_target():
716
709
EM_NM = bat_suffix (path_from_root ('emnm' ))
717
710
FILE_PACKAGER = bat_suffix (path_from_root ('tools/file_packager' ))
718
711
719
- apply_configuration ()
712
+ setup_temp_dirs ()
720
713
721
714
Cache = cache .Cache (config .CACHE )
722
715
0 commit comments