Skip to content

Commit 34b0309

Browse files
authored
Setup the emscripten cache directory lazily (#19500)
This allows tools/scripts that don't use the cache at all to avoid setting one up. See: #19490
1 parent 8d6fd04 commit 34b0309

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

embuilder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def main():
188188
# Check sanity so that if settings file has changed, the cache is cleared here.
189189
# Otherwise, the cache will clear in an emcc process, which is invoked while building
190190
# a system library into the cache, causing trouble.
191+
cache.setup()
191192
shared.check_sanity()
192193

193194
if args.lto:

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3513,7 +3513,7 @@ def consume_arg_file():
35133513
logger.error('jcache is no longer supported')
35143514
elif check_arg('--cache'):
35153515
config.CACHE = os.path.normpath(consume_arg())
3516-
cache.setup(config.CACHE)
3516+
cache.setup()
35173517
# Ensure child processes share the same cache (e.g. when using emcc to compiler system
35183518
# libraries)
35193519
os.environ['EM_CACHE'] = config.CACHE

test/test_other.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ def verify_includes(stderr):
960960
end = stderr.index('End of search list.')
961961
includes = stderr[start:end]
962962
includes = [i.strip() for i in includes.splitlines()[1:]]
963+
cache.ensure_setup()
963964
cachedir = os.path.normpath(cache.cachedir)
964965
llvmroot = os.path.normpath(os.path.dirname(config.LLVM_ROOT))
965966
for i in includes:

tools/building.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def remove_quotes(arg):
6060

6161

6262
def get_building_env():
63+
cache.ensure()
6364
env = os.environ.copy()
6465
# point CC etc. to the em* tools.
6566
env['CC'] = EMCC

tools/cache.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,24 @@ def lock(reason):
6666

6767

6868
def ensure():
69+
ensure_setup()
6970
utils.safe_ensure_dirs(cachedir)
7071

7172

7273
def erase():
74+
ensure_setup()
7375
with lock('erase'):
7476
# Delete everything except the lockfile itself
7577
utils.delete_contents(cachedir, exclude=[os.path.basename(cachelock_name)])
7678

7779

7880
def get_path(name):
81+
ensure_setup()
7982
return Path(cachedir, name)
8083

8184

8285
def get_sysroot(absolute):
86+
ensure_setup()
8387
if absolute:
8488
return os.path.join(cachedir, 'sysroot')
8589
return 'sysroot'
@@ -94,6 +98,7 @@ def get_sysroot_dir(*parts):
9498

9599

96100
def get_lib_dir(absolute):
101+
ensure_setup()
97102
path = Path(get_sysroot(absolute=absolute), 'lib')
98103
if settings.MEMORY64:
99104
path = Path(path, 'wasm64-emscripten')
@@ -137,6 +142,7 @@ def get_lib(libname, *args, **kwargs):
137142
# Request a cached file. If it isn't in the cache, it will be created with
138143
# the given creator function
139144
def get(shortname, creator, what=None, force=False, quiet=False, deferred=False):
145+
ensure_setup()
140146
cachename = Path(cachedir, shortname)
141147
# Check for existence before taking the lock in case we can avoid the
142148
# lock completely.
@@ -168,13 +174,18 @@ def get(shortname, creator, what=None, force=False, quiet=False, deferred=False)
168174
return str(cachename)
169175

170176

171-
def setup(dirname):
177+
def setup():
172178
global cachedir, cachelock, cachelock_name
173179
# figure out the root directory for all caching
174-
cachedir = Path(dirname).resolve()
180+
cachedir = Path(config.CACHE).resolve()
175181

176182
# since the lock itself lives inside the cache directory we need to ensure it
177183
# exists.
178184
ensure()
179185
cachelock_name = Path(cachedir, 'cache.lock')
180186
cachelock = filelock.FileLock(cachelock_name)
187+
188+
189+
def ensure_setup():
190+
if not cachedir:
191+
setup()

tools/shared.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ def get_llvm_target():
748748
def init():
749749
set_version_globals()
750750
setup_temp_dirs()
751-
cache.setup(config.CACHE)
752751

753752

754753
# ============================================================================

0 commit comments

Comments
 (0)