mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-13 05:06:30 +04:00
[FL-3629] fbt: SD card resource handling speedup (#3178)
* fbt: reduced size of resources dependency graphs, resulting in faster build task evaluation * lib: flipper_app: fixed error message & error handling for plugins
This commit is contained in:
@@ -7,16 +7,21 @@ from SCons.Errors import StopError
|
||||
from SCons.Node.FS import Dir, File
|
||||
|
||||
|
||||
def _resources_dist_emitter(target, source, env):
|
||||
def __generate_resources_dist_entries(env):
|
||||
src_target_entries = []
|
||||
|
||||
resources_root = env.Dir(env["RESOURCES_ROOT"])
|
||||
|
||||
target = []
|
||||
for app_artifacts in env["FW_EXTAPPS"].application_map.values():
|
||||
for _, dist_path in filter(
|
||||
lambda dist_entry: dist_entry[0], app_artifacts.dist_entries
|
||||
):
|
||||
source.append(app_artifacts.compact)
|
||||
target.append(resources_root.File(dist_path))
|
||||
src_target_entries.append(
|
||||
(
|
||||
app_artifacts.compact,
|
||||
resources_root.File(dist_path),
|
||||
)
|
||||
)
|
||||
|
||||
# Deploy apps' resources too
|
||||
for app in env["APPBUILD"].apps:
|
||||
@@ -26,34 +31,48 @@ def _resources_dist_emitter(target, source, env):
|
||||
for res_file in env.GlobRecursive("*", apps_resource_dir):
|
||||
if not isinstance(res_file, File):
|
||||
continue
|
||||
source.append(res_file)
|
||||
target.append(resources_root.File(res_file.get_path(apps_resource_dir)))
|
||||
src_target_entries.append(
|
||||
(
|
||||
res_file,
|
||||
resources_root.File(
|
||||
res_file.get_path(apps_resource_dir),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
# Deploy other stuff from _EXTRA_DIST
|
||||
for extra_dist in env["_EXTRA_DIST"]:
|
||||
if isinstance(extra_dist, Dir):
|
||||
for extra_file in env.GlobRecursive("*", extra_dist):
|
||||
if not isinstance(extra_file, File):
|
||||
continue
|
||||
source.append(extra_file)
|
||||
target.append(
|
||||
# Preserve dir name from original node
|
||||
resources_root.Dir(extra_dist.name).File(
|
||||
extra_file.get_path(extra_dist)
|
||||
)
|
||||
src_target_entries.append(
|
||||
(
|
||||
extra_dist,
|
||||
resources_root.Dir(extra_dist.name),
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise StopError(f"Unsupported extra dist type: {type(extra_dist)}")
|
||||
|
||||
assert len(target) == len(source)
|
||||
return src_target_entries
|
||||
|
||||
|
||||
def _resources_dist_emitter(target, source, env):
|
||||
src_target_entries = __generate_resources_dist_entries(env)
|
||||
source = list(map(lambda entry: entry[0], src_target_entries))
|
||||
return (target, source)
|
||||
|
||||
|
||||
def _resources_dist_action(target, source, env):
|
||||
dist_entries = __generate_resources_dist_entries(env)
|
||||
assert len(dist_entries) == len(source)
|
||||
shutil.rmtree(env.Dir(env["RESOURCES_ROOT"]).abspath, ignore_errors=True)
|
||||
for src, target in zip(source, target):
|
||||
os.makedirs(os.path.dirname(target.path), exist_ok=True)
|
||||
shutil.copy(src.path, target.path)
|
||||
for src, target in dist_entries:
|
||||
if isinstance(src, File):
|
||||
os.makedirs(os.path.dirname(target.path), exist_ok=True)
|
||||
shutil.copy(src.path, target.path)
|
||||
elif isinstance(src, Dir):
|
||||
shutil.copytree(src.path, target.path)
|
||||
else:
|
||||
raise StopError(f"Unsupported dist entry type: {type(src)}")
|
||||
|
||||
|
||||
def generate(env, **kw):
|
||||
@@ -69,26 +88,26 @@ def generate(env, **kw):
|
||||
|
||||
env.Append(
|
||||
BUILDERS={
|
||||
"ResourcesDist": Builder(
|
||||
action=Action(
|
||||
_resources_dist_action,
|
||||
"${RESOURCEDISTCOMSTR}",
|
||||
),
|
||||
emitter=_resources_dist_emitter,
|
||||
),
|
||||
"ManifestBuilder": Builder(
|
||||
action=Action(
|
||||
[
|
||||
action=[
|
||||
Action(
|
||||
_resources_dist_action,
|
||||
"${RESOURCEDISTCOMSTR}",
|
||||
),
|
||||
Action(
|
||||
[
|
||||
"${PYTHON3}",
|
||||
"${ASSETS_COMPILER}",
|
||||
"manifest",
|
||||
"${TARGET.dir.posix}",
|
||||
"--timestamp=${GIT_UNIX_TIMESTAMP}",
|
||||
]
|
||||
],
|
||||
"${RESMANIFESTCOMSTR}",
|
||||
)
|
||||
[
|
||||
"${PYTHON3}",
|
||||
"${ASSETS_COMPILER}",
|
||||
"manifest",
|
||||
"${TARGET.dir.posix}",
|
||||
"--timestamp=${GIT_UNIX_TIMESTAMP}",
|
||||
]
|
||||
],
|
||||
"${RESMANIFESTCOMSTR}",
|
||||
),
|
||||
],
|
||||
emitter=_resources_dist_emitter,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user