mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-05 06:53:18 +08:00
Fixed some efrocache logic my recent changes broke.
warm_start_cache functionality should now work again which means a lot less time spent in "Refreshing from cache" when the .efrocache map changes.
This commit is contained in:
parent
c93d3f9359
commit
ebf6ca5be1
@ -98,6 +98,7 @@ def lazybuild(target: str, category: LazyBuildCategory, command: str) -> None:
|
|||||||
'Makefile',
|
'Makefile',
|
||||||
'src/meta',
|
'src/meta',
|
||||||
'src/ballistica/shared/foundation/types.h',
|
'src/ballistica/shared/foundation/types.h',
|
||||||
|
'.efrocachemap',
|
||||||
],
|
],
|
||||||
# Our meta Makefile targets generally don't list tools
|
# Our meta Makefile targets generally don't list tools
|
||||||
# scripts that can affect their creation as sources, so
|
# scripts that can affect their creation as sources, so
|
||||||
@ -105,8 +106,8 @@ def lazybuild(target: str, category: LazyBuildCategory, command: str) -> None:
|
|||||||
# changes we'll blow away all existing meta builds.
|
# changes we'll blow away all existing meta builds.
|
||||||
#
|
#
|
||||||
# Update: also including featureset-defs here; any time
|
# Update: also including featureset-defs here; any time
|
||||||
# we're mucking with those it's good to start fresh to be
|
# we're mucking with those it's good to start things fresh
|
||||||
# sure.
|
# to be safe.
|
||||||
srcpaths_fullclean=[
|
srcpaths_fullclean=[
|
||||||
'tools/efrotools',
|
'tools/efrotools',
|
||||||
'tools/efrotoolsinternal',
|
'tools/efrotoolsinternal',
|
||||||
@ -135,6 +136,7 @@ def lazybuild(target: str, category: LazyBuildCategory, command: str) -> None:
|
|||||||
'Makefile',
|
'Makefile',
|
||||||
'src',
|
'src',
|
||||||
'ballisticakit-cmake/CMakeLists.txt',
|
'ballisticakit-cmake/CMakeLists.txt',
|
||||||
|
'.efrocachemap',
|
||||||
],
|
],
|
||||||
dirfilter=(
|
dirfilter=(
|
||||||
lambda root, dirname: not (
|
lambda root, dirname: not (
|
||||||
@ -166,6 +168,7 @@ def lazybuild(target: str, category: LazyBuildCategory, command: str) -> None:
|
|||||||
'Makefile',
|
'Makefile',
|
||||||
'src',
|
'src',
|
||||||
'ballisticakit-windows',
|
'ballisticakit-windows',
|
||||||
|
'.efrocachemap',
|
||||||
],
|
],
|
||||||
dirfilter=_win_dirfilter,
|
dirfilter=_win_dirfilter,
|
||||||
command=command,
|
command=command,
|
||||||
@ -183,6 +186,7 @@ def lazybuild(target: str, category: LazyBuildCategory, command: str) -> None:
|
|||||||
'Makefile',
|
'Makefile',
|
||||||
'tools/pcommand',
|
'tools/pcommand',
|
||||||
'src/resources',
|
'src/resources',
|
||||||
|
'.efrocachemap',
|
||||||
],
|
],
|
||||||
command=command,
|
command=command,
|
||||||
).run()
|
).run()
|
||||||
@ -208,6 +212,7 @@ def lazybuild(target: str, category: LazyBuildCategory, command: str) -> None:
|
|||||||
'Makefile',
|
'Makefile',
|
||||||
'tools',
|
'tools',
|
||||||
'src/assets',
|
'src/assets',
|
||||||
|
'.efrocachemap',
|
||||||
],
|
],
|
||||||
command=command,
|
command=command,
|
||||||
filefilter=_filefilter,
|
filefilter=_filefilter,
|
||||||
@ -234,6 +239,7 @@ def lazybuild(target: str, category: LazyBuildCategory, command: str) -> None:
|
|||||||
'config/featuresets',
|
'config/featuresets',
|
||||||
'tools/batools/dummymodule.py',
|
'tools/batools/dummymodule.py',
|
||||||
'src/ballistica',
|
'src/ballistica',
|
||||||
|
'.efrocachemap',
|
||||||
],
|
],
|
||||||
command=command,
|
command=command,
|
||||||
filefilter=_filefilter,
|
filefilter=_filefilter,
|
||||||
|
|||||||
@ -143,9 +143,9 @@ def get_target(path: str) -> None:
|
|||||||
|
|
||||||
local_cache_path = os.path.join(local_cache_dir, subpath)
|
local_cache_path = os.path.join(local_cache_dir, subpath)
|
||||||
|
|
||||||
# First off: if there's already a cache file in place, check its
|
# First off: if there's already a file in place, check its hash. If
|
||||||
# hash. If its calced hash matches its path, we can just update its
|
# its calced hash matches the hash-map's value for it, we can just
|
||||||
# timestamp and call it a day.
|
# update its timestamp and call it a day.
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
existing_hash = get_existing_file_hash(path)
|
existing_hash = get_existing_file_hash(path)
|
||||||
if existing_hash == hashval:
|
if existing_hash == hashval:
|
||||||
@ -492,6 +492,10 @@ def _write_cache_files(
|
|||||||
outfile.write(json.dumps(mapping, indent=2, sort_keys=True))
|
outfile.write(json.dumps(mapping, indent=2, sort_keys=True))
|
||||||
|
|
||||||
|
|
||||||
|
def _path_from_hash(hashstr: str) -> str:
|
||||||
|
return os.path.join(hashstr[:2], hashstr[2:4], hashstr[4:])
|
||||||
|
|
||||||
|
|
||||||
def _write_cache_file(staging_dir: str, fname: str) -> tuple[str, str, str]:
|
def _write_cache_file(staging_dir: str, fname: str) -> tuple[str, str, str]:
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
@ -511,7 +515,7 @@ def _write_cache_file(staging_dir: str, fname: str) -> tuple[str, str, str]:
|
|||||||
md5 = hashlib.md5()
|
md5 = hashlib.md5()
|
||||||
md5.update(prefix + fdataraw)
|
md5.update(prefix + fdataraw)
|
||||||
finalhash = md5.hexdigest()
|
finalhash = md5.hexdigest()
|
||||||
hashpath = os.path.join(finalhash[:2], finalhash[2:4], finalhash[4:])
|
hashpath = _path_from_hash(finalhash)
|
||||||
path = os.path.join(staging_dir, hashpath)
|
path = os.path.join(staging_dir, hashpath)
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
|
|
||||||
@ -623,13 +627,19 @@ def warm_start_cache() -> None:
|
|||||||
# per file, it adds up when done for thousands of files each time
|
# per file, it adds up when done for thousands of files each time
|
||||||
# the cache map changes. It is much more efficient to do it all in
|
# the cache map changes. It is much more efficient to do it all in
|
||||||
# one go here.
|
# one go here.
|
||||||
|
#
|
||||||
|
# Note to self: it could be nice to put together a lightweight build
|
||||||
|
# server system of some sort so we don't have to spin up a full
|
||||||
|
# Python process for each and every file we need to touch. In that
|
||||||
|
# case, this optimization would probably be unnecessary.
|
||||||
cachemap: dict[str, str]
|
cachemap: dict[str, str]
|
||||||
with open(CACHE_MAP_NAME, encoding='utf-8') as infile:
|
with open(CACHE_MAP_NAME, encoding='utf-8') as infile:
|
||||||
cachemap = json.loads(infile.read())
|
cachemap = json.loads(infile.read())
|
||||||
assert isinstance(cachemap, dict)
|
assert isinstance(cachemap, dict)
|
||||||
cachemap_mtime = os.path.getmtime(CACHE_MAP_NAME)
|
cachemap_mtime = os.path.getmtime(CACHE_MAP_NAME)
|
||||||
entries: list[tuple[str, str]] = []
|
entries: list[tuple[str, str]] = []
|
||||||
for fname, url in cachemap.items():
|
for fname, filehash in cachemap.items():
|
||||||
|
|
||||||
# File hasn't been pulled from cache yet = ignore.
|
# File hasn't been pulled from cache yet = ignore.
|
||||||
if not os.path.exists(fname):
|
if not os.path.exists(fname):
|
||||||
continue
|
continue
|
||||||
@ -638,14 +648,15 @@ def warm_start_cache() -> None:
|
|||||||
if cachemap_mtime < os.path.getmtime(fname):
|
if cachemap_mtime < os.path.getmtime(fname):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Don't have the cache source file for this guy = ignore.
|
# Don't have the cache source file for this guy = ignore. This
|
||||||
cachefile = local_cache_dir + '/' + '/'.join(url.split('/')[-3:])
|
# can happen if cache files have been blown away since the last
|
||||||
|
# time this was built.
|
||||||
|
cachefile = os.path.join(local_cache_dir, _path_from_hash(filehash))
|
||||||
if not os.path.exists(cachefile):
|
if not os.path.exists(cachefile):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Ok, add it to the list of files we can potentially update
|
# Ok, add it to the list of files we can potentially update
|
||||||
# timestamps on once we check its hash.
|
# timestamps on once we check its hash.
|
||||||
filehash = ''.join(url.split('/')[-3:])
|
|
||||||
entries.append((fname, filehash))
|
entries.append((fname, filehash))
|
||||||
|
|
||||||
if entries:
|
if entries:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user