1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 12:42:30 +04:00

[FL-3629] fbt: reworked assets & resources handling (#3160)

* fbt: reworking targets & assets handling WIP
* fbt: dist fixes
* fbt: moved SD card resources to owning apps
* unit_tests: moved resources to app folder
* github: updated unit_tests paths
* github: packaging fixes
* unit_tests: fixes
* fbt: assets: internal cleanup
* fbt: reworked assets handling
* github: unit_tests: reintroducing fixes
* minor cleanup
* fbt: naming changes to reflect private nature of scons tools
* fbt: resources: fixed dist archive paths
* docs: updated paths
* docs: updated more paths
* docs: included "resources" parameter in app manifest docs; updated assets readme
* updated gitignore for assets
* github: updated action versions
* unit_tests: restored timeout; scripts: assets: logging changes
* gh: don't upload desktop animations for unit test run

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
hedger
2023-10-30 19:17:30 +04:00
committed by GitHub
parent 176fb21f5f
commit 917410a0a8
345 changed files with 466 additions and 394 deletions

View File

@@ -1,7 +1,5 @@
import itertools
import os
import pathlib
import shutil
from dataclasses import dataclass, field
from typing import Dict, List, Optional
@@ -290,7 +288,7 @@ def prepare_app_metadata(target, source, env):
)
def validate_app_imports(target, source, env):
def _validate_app_imports(target, source, env):
sdk_cache = SdkCache(env["SDK_DEFINITION"].path, load_version_only=False)
app_syms = set()
with open(target[0].path, "rt") as f:
@@ -342,35 +340,7 @@ def GetExtAppByIdOrPath(env, app_dir):
return app_artifacts
def resources_fap_dist_emitter(target, source, env):
# Initially we have a single target - target dir
# Here we inject pairs of (target, source) for each file
resources_root = target[0]
target = []
for app_artifacts in env["EXT_APPS"].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))
assert len(target) == len(source)
return (target, source)
def resources_fap_dist_action(target, source, env):
# FIXME: find a proper way to remove stale files
target_dir = env.Dir("${RESOURCES_ROOT}/apps")
shutil.rmtree(target_dir.path, ignore_errors=True)
# Iterate over pairs generated in emitter
for src, target in zip(source, target):
os.makedirs(os.path.dirname(target.path), exist_ok=True)
shutil.copy(src.path, target.path)
def embed_app_metadata_emitter(target, source, env):
def _embed_app_metadata_emitter(target, source, env):
app = env["APP"]
# Hack: change extension for fap libs
@@ -407,33 +377,52 @@ def generate_embed_app_metadata_actions(source, target, env, for_signature):
Action(prepare_app_metadata, "$APPMETA_COMSTR"),
]
objcopy_str = (
"${OBJCOPY} "
"--remove-section .ARM.attributes "
"--add-section ${_FAP_META_SECTION}=${APP._section_fapmeta} "
)
objcopy_args = [
"${OBJCOPY}",
"--remove-section",
".ARM.attributes",
"--add-section",
"${_FAP_META_SECTION}=${APP._section_fapmeta}",
"--set-section-flags",
"${_FAP_META_SECTION}=contents,noload,readonly,data",
]
if app._section_fapfileassets:
actions.append(Action(prepare_app_file_assets, "$APPFILE_COMSTR"))
objcopy_str += (
"--add-section ${_FAP_FILEASSETS_SECTION}=${APP._section_fapfileassets} "
objcopy_args.extend(
(
"--add-section",
"${_FAP_FILEASSETS_SECTION}=${APP._section_fapfileassets}",
"--set-section-flags",
"${_FAP_FILEASSETS_SECTION}=contents,noload,readonly,data",
)
)
objcopy_str += (
"--set-section-flags ${_FAP_META_SECTION}=contents,noload,readonly,data "
"--strip-debug --strip-unneeded "
"--add-gnu-debuglink=${SOURCE} "
"${SOURCES} ${TARGET}"
objcopy_args.extend(
(
"--strip-debug",
"--strip-unneeded",
"--add-gnu-debuglink=${SOURCE}",
"${SOURCES}",
"${TARGET}",
)
)
actions.extend(
(
Action(
objcopy_str,
[objcopy_args],
"$APPMETAEMBED_COMSTR",
),
Action(
"${PYTHON3} ${FBT_SCRIPT_DIR}/fastfap.py ${TARGET} ${OBJCOPY}",
[
[
"${PYTHON3}",
"${FBT_SCRIPT_DIR}/fastfap.py",
"${TARGET}",
"${OBJCOPY}",
]
],
"$FASTFAP_COMSTR",
),
)
@@ -511,7 +500,6 @@ def generate(env, **kw):
)
if not env["VERBOSE"]:
env.SetDefault(
FAPDISTCOMSTR="\tFAPDIST\t${TARGET}",
APPMETA_COMSTR="\tAPPMETA\t${TARGET}",
APPFILE_COMSTR="\tAPPFILE\t${TARGET}",
APPMETAEMBED_COMSTR="\tFAP\t${TARGET}",
@@ -534,18 +522,11 @@ def generate(env, **kw):
env.Append(
BUILDERS={
"FapDist": Builder(
action=Action(
resources_fap_dist_action,
"$FAPDISTCOMSTR",
),
emitter=resources_fap_dist_emitter,
),
"EmbedAppMetadata": Builder(
generator=generate_embed_app_metadata_actions,
suffix=".fap",
src_suffix=".elf",
emitter=embed_app_metadata_emitter,
emitter=_embed_app_metadata_emitter,
),
"ValidateAppImports": Builder(
action=[
@@ -554,7 +535,7 @@ def generate(env, **kw):
None, # "$APPDUMP_COMSTR",
),
Action(
validate_app_imports,
_validate_app_imports,
"$APPCHECK_COMSTR",
),
],