2023-03-14 14:29:28 +00:00
|
|
|
import itertools
|
|
|
|
import pathlib
|
2022-11-05 11:47:59 +00:00
|
|
|
from dataclasses import dataclass, field
|
2023-09-21 12:56:00 +00:00
|
|
|
from typing import Dict, List, Optional
|
2023-03-14 14:29:28 +00:00
|
|
|
|
|
|
|
import SCons.Warnings
|
2023-05-03 05:48:49 +00:00
|
|
|
from ansi.color import fg
|
2023-03-14 14:29:28 +00:00
|
|
|
from fbt.appmanifest import FlipperApplication, FlipperAppType, FlipperManifestException
|
2022-09-14 16:11:38 +00:00
|
|
|
from fbt.elfmanifest import assemble_manifest_data
|
2023-03-14 14:29:28 +00:00
|
|
|
from fbt.fapassets import FileBundler
|
2022-10-28 15:32:06 +00:00
|
|
|
from fbt.sdk.cache import SdkCache
|
2023-08-10 16:21:56 +00:00
|
|
|
from fbt.util import resolve_real_dir_node
|
2023-05-03 05:48:49 +00:00
|
|
|
from SCons.Action import Action
|
|
|
|
from SCons.Builder import Builder
|
|
|
|
from SCons.Errors import UserError
|
|
|
|
from SCons.Node.FS import Entry, File
|
2022-06-26 12:00:03 +00:00
|
|
|
|
2023-04-06 02:44:37 +00:00
|
|
|
_FAP_META_SECTION = ".fapmeta"
|
|
|
|
_FAP_FILEASSETS_SECTION = ".fapassets"
|
|
|
|
|
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
@dataclass
|
|
|
|
class FlipperExternalAppInfo:
|
|
|
|
app: FlipperApplication
|
2023-03-14 14:29:28 +00:00
|
|
|
compact: Optional[File] = None
|
|
|
|
debug: Optional[File] = None
|
|
|
|
validator: Optional[Entry] = None
|
|
|
|
# List of tuples (dist_to_sd, path)
|
|
|
|
dist_entries: list[tuple[bool, str]] = field(default_factory=list)
|
|
|
|
|
|
|
|
|
|
|
|
class AppBuilder:
|
2023-09-21 12:56:00 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_app_work_dir(env, app):
|
|
|
|
return env["EXT_APPS_WORK_DIR"].Dir(app.appid)
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def __init__(self, env, app):
|
|
|
|
self.fw_env = env
|
|
|
|
self.app = app
|
2023-09-21 12:56:00 +00:00
|
|
|
self.ext_apps_work_dir = env["EXT_APPS_WORK_DIR"]
|
|
|
|
self.app_work_dir = self.get_app_work_dir(env, app)
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_alias = f"fap_{self.app.appid}"
|
2023-10-23 09:55:36 +00:00
|
|
|
self.icons_src = None
|
2023-03-14 14:29:28 +00:00
|
|
|
self.externally_built_files = []
|
|
|
|
self.private_libs = []
|
|
|
|
|
|
|
|
def build(self):
|
|
|
|
self._setup_app_env()
|
|
|
|
self._build_external_files()
|
|
|
|
self._compile_assets()
|
|
|
|
self._build_private_libs()
|
|
|
|
return self._build_app()
|
|
|
|
|
|
|
|
def _setup_app_env(self):
|
|
|
|
self.app_env = self.fw_env.Clone(
|
2023-08-10 16:21:56 +00:00
|
|
|
FAP_SRC_DIR=self.app._appdir,
|
|
|
|
FAP_WORK_DIR=self.app_work_dir,
|
2023-03-14 14:29:28 +00:00
|
|
|
)
|
2023-08-22 18:33:10 +00:00
|
|
|
self.app_env.Append(
|
|
|
|
CPPDEFINES=[
|
2023-11-15 16:27:35 +00:00
|
|
|
("FAP_VERSION", f'\\"{".".join(map(str, self.app.fap_version))}\\"'),
|
|
|
|
*self.app.cdefines,
|
2023-08-22 18:33:10 +00:00
|
|
|
],
|
|
|
|
)
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.VariantDir(self.app_work_dir, self.app._appdir, duplicate=False)
|
2022-10-06 13:55:57 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def _build_external_files(self):
|
|
|
|
if not self.app.fap_extbuild:
|
|
|
|
return
|
2022-10-06 13:55:57 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
for external_file_def in self.app.fap_extbuild:
|
|
|
|
self.externally_built_files.append(external_file_def.path)
|
|
|
|
self.app_env.Alias(self.app_alias, external_file_def.path)
|
|
|
|
self.app_env.AlwaysBuild(
|
|
|
|
self.app_env.Command(
|
2022-10-06 13:55:57 +00:00
|
|
|
external_file_def.path,
|
|
|
|
None,
|
|
|
|
Action(
|
|
|
|
external_file_def.command,
|
2023-03-14 14:29:28 +00:00
|
|
|
"" if self.app_env["VERBOSE"] else "\tEXTCMD\t${TARGET}",
|
2022-10-06 13:55:57 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def _compile_assets(self):
|
|
|
|
if not self.app.fap_icon_assets:
|
|
|
|
return
|
|
|
|
|
|
|
|
fap_icons = self.app_env.CompileIcons(
|
2023-09-21 12:56:00 +00:00
|
|
|
self.app_work_dir,
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app._appdir.Dir(self.app.fap_icon_assets),
|
2023-09-21 12:56:00 +00:00
|
|
|
icon_bundle_name=f"{self.app.fap_icon_assets_symbol or self.app.appid }_icons",
|
2022-10-06 13:55:57 +00:00
|
|
|
)
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.Alias("_fap_icons", fap_icons)
|
|
|
|
self.fw_env.Append(_APP_ICONS=[fap_icons])
|
2023-10-23 09:55:36 +00:00
|
|
|
self.icons_src = next(filter(lambda n: n.path.endswith(".c"), fap_icons))
|
2022-10-06 13:55:57 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def _build_private_libs(self):
|
|
|
|
for lib_def in self.app.fap_private_libs:
|
|
|
|
self.private_libs.append(self._build_private_lib(lib_def))
|
2022-10-06 13:55:57 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def _build_private_lib(self, lib_def):
|
2023-09-21 12:56:00 +00:00
|
|
|
lib_src_root_path = self.app_work_dir.Dir("lib").Dir(lib_def.name)
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.AppendUnique(
|
2022-10-06 13:55:57 +00:00
|
|
|
CPPPATH=list(
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.Dir(lib_src_root_path)
|
|
|
|
.Dir(incpath)
|
|
|
|
.srcnode()
|
|
|
|
.rfile()
|
|
|
|
.abspath
|
2022-10-06 13:55:57 +00:00
|
|
|
for incpath in lib_def.fap_include_paths
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
lib_sources = list(
|
|
|
|
itertools.chain.from_iterable(
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.GlobRecursive(source_type, lib_src_root_path)
|
2022-10-06 13:55:57 +00:00
|
|
|
for source_type in lib_def.sources
|
|
|
|
)
|
|
|
|
)
|
2023-03-14 14:29:28 +00:00
|
|
|
|
2022-10-06 13:55:57 +00:00
|
|
|
if len(lib_sources) == 0:
|
|
|
|
raise UserError(f"No sources gathered for private library {lib_def}")
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
private_lib_env = self.app_env.Clone()
|
2022-10-06 13:55:57 +00:00
|
|
|
private_lib_env.AppendUnique(
|
2023-09-21 12:56:00 +00:00
|
|
|
CCFLAGS=lib_def.cflags,
|
2022-10-06 13:55:57 +00:00
|
|
|
CPPDEFINES=lib_def.cdefines,
|
2022-11-02 15:15:40 +00:00
|
|
|
CPPPATH=list(
|
|
|
|
map(
|
2023-08-10 16:21:56 +00:00
|
|
|
lambda cpath: resolve_real_dir_node(self.app._appdir.Dir(cpath)),
|
2022-11-02 15:15:40 +00:00
|
|
|
lib_def.cincludes,
|
|
|
|
)
|
|
|
|
),
|
2022-10-06 13:55:57 +00:00
|
|
|
)
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
return private_lib_env.StaticLibrary(
|
2023-09-21 12:56:00 +00:00
|
|
|
self.app_work_dir.File(lib_def.name),
|
2022-10-06 13:55:57 +00:00
|
|
|
lib_sources,
|
|
|
|
)
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def _build_app(self):
|
2023-09-21 12:56:00 +00:00
|
|
|
if self.app.fap_file_assets:
|
|
|
|
self.app._assets_dirs = [self.app._appdir.Dir(self.app.fap_file_assets)]
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.Append(
|
2023-11-15 16:27:35 +00:00
|
|
|
LIBS=[*self.app.fap_libs, *self.private_libs, *self.app.fap_libs],
|
|
|
|
CPPPATH=[self.app_env.Dir(self.app_work_dir), self.app._appdir],
|
2023-03-14 14:29:28 +00:00
|
|
|
)
|
2022-10-06 13:55:57 +00:00
|
|
|
|
2023-11-01 04:21:31 +00:00
|
|
|
app_sources = self.app_env.GatherSources(
|
|
|
|
[self.app.sources, "!lib"], self.app_work_dir
|
2023-03-14 14:29:28 +00:00
|
|
|
)
|
2023-11-01 04:21:31 +00:00
|
|
|
|
2023-10-06 07:11:02 +00:00
|
|
|
if not app_sources:
|
|
|
|
raise UserError(f"No source files found for {self.app.appid}")
|
|
|
|
|
2023-10-23 09:55:36 +00:00
|
|
|
# Ensure that icons are included in the build, regardless of user-configured sources
|
|
|
|
if self.icons_src and not self.icons_src in app_sources:
|
|
|
|
app_sources.append(self.icons_src)
|
|
|
|
|
2023-10-06 07:11:02 +00:00
|
|
|
## Uncomment for debug
|
|
|
|
# print(f"App sources for {self.app.appid}: {list(f.path for f in app_sources)}")
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
app_artifacts = FlipperExternalAppInfo(self.app)
|
|
|
|
app_artifacts.debug = self.app_env.Program(
|
2023-09-21 12:56:00 +00:00
|
|
|
self.ext_apps_work_dir.File(f"{self.app.appid}_d.elf"),
|
2023-03-14 14:29:28 +00:00
|
|
|
app_sources,
|
|
|
|
APP_ENTRY=self.app.entry_point,
|
|
|
|
)[0]
|
|
|
|
|
|
|
|
app_artifacts.compact = self.app_env.EmbedAppMetadata(
|
2023-09-21 12:56:00 +00:00
|
|
|
self.ext_apps_work_dir.File(f"{self.app.appid}.fap"),
|
2023-03-14 14:29:28 +00:00
|
|
|
app_artifacts.debug,
|
|
|
|
APP=self.app,
|
|
|
|
)[0]
|
|
|
|
|
2023-09-21 12:56:00 +00:00
|
|
|
if self.app.embeds_plugins:
|
|
|
|
self.app._assets_dirs.append(self.app_work_dir.Dir("assets"))
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
app_artifacts.validator = self.app_env.ValidateAppImports(
|
2023-10-23 09:55:36 +00:00
|
|
|
app_artifacts.compact,
|
|
|
|
_CHECK_APP=self.app.do_strict_import_checks
|
|
|
|
and self.app_env.get("STRICT_FAP_IMPORT_CHECK"),
|
2023-03-14 14:29:28 +00:00
|
|
|
)[0]
|
|
|
|
|
|
|
|
if self.app.apptype == FlipperAppType.PLUGIN:
|
|
|
|
for parent_app_id in self.app.requires:
|
2023-09-21 12:56:00 +00:00
|
|
|
if self.app.fal_embedded:
|
|
|
|
parent_app = self.app._appmanager.get(parent_app_id)
|
|
|
|
if not parent_app:
|
|
|
|
raise UserError(
|
|
|
|
f"Embedded plugin {self.app.appid} requires unknown app {parent_app_id}"
|
|
|
|
)
|
|
|
|
self.app_env.Install(
|
|
|
|
target=self.get_app_work_dir(self.app_env, parent_app)
|
|
|
|
.Dir("assets")
|
|
|
|
.Dir("plugins"),
|
|
|
|
source=app_artifacts.compact,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
fal_path = f"apps_data/{parent_app_id}/plugins/{app_artifacts.compact.name}"
|
|
|
|
deployable = True
|
|
|
|
# If it's a plugin for a non-deployable app, don't include it in the resources
|
|
|
|
if parent_app := self.app._appmanager.get(parent_app_id):
|
|
|
|
if not parent_app.is_default_deployable:
|
|
|
|
deployable = False
|
|
|
|
app_artifacts.dist_entries.append((deployable, fal_path))
|
2023-03-14 14:29:28 +00:00
|
|
|
else:
|
|
|
|
fap_path = f"apps/{self.app.fap_category}/{app_artifacts.compact.name}"
|
|
|
|
app_artifacts.dist_entries.append(
|
|
|
|
(self.app.is_default_deployable, fap_path)
|
|
|
|
)
|
2022-10-06 13:55:57 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
self._configure_deps_and_aliases(app_artifacts)
|
|
|
|
return app_artifacts
|
2022-06-26 12:00:03 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def _configure_deps_and_aliases(self, app_artifacts: FlipperExternalAppInfo):
|
|
|
|
# Extra things to clean up along with the app
|
|
|
|
self.app_env.Clean(
|
|
|
|
app_artifacts.debug,
|
2023-09-21 12:56:00 +00:00
|
|
|
[*self.externally_built_files, self.app_work_dir],
|
2023-03-14 14:29:28 +00:00
|
|
|
)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
# Create listing of the app
|
|
|
|
app_elf_dump = self.app_env.ObjDump(app_artifacts.debug)
|
|
|
|
self.app_env.Alias(f"{self.app_alias}_list", app_elf_dump)
|
2022-09-29 11:00:22 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
# Extra dependencies for the app - manifest values, icon file
|
|
|
|
manifest_vals = {
|
|
|
|
k: v
|
|
|
|
for k, v in vars(self.app).items()
|
|
|
|
if not k.startswith(FlipperApplication.PRIVATE_FIELD_PREFIX)
|
|
|
|
}
|
2023-03-09 15:01:53 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.Depends(
|
2022-11-05 11:47:59 +00:00
|
|
|
app_artifacts.compact,
|
2023-03-14 14:29:28 +00:00
|
|
|
[self.app_env["SDK_DEFINITION"], self.app_env.Value(manifest_vals)],
|
2022-09-14 16:11:38 +00:00
|
|
|
)
|
2023-03-14 14:29:28 +00:00
|
|
|
if self.app.fap_icon:
|
|
|
|
self.app_env.Depends(
|
|
|
|
app_artifacts.compact,
|
|
|
|
self.app_env.File(f"{self.app._apppath}/{self.app.fap_icon}"),
|
|
|
|
)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
# Add dependencies on file assets
|
2023-09-21 12:56:00 +00:00
|
|
|
for assets_dir in self.app._assets_dirs:
|
2023-10-06 07:11:02 +00:00
|
|
|
glob_res = self.app_env.GlobRecursive("*", assets_dir)
|
2023-03-14 14:29:28 +00:00
|
|
|
self.app_env.Depends(
|
|
|
|
app_artifacts.compact,
|
2023-10-06 07:11:02 +00:00
|
|
|
(*glob_res, assets_dir),
|
2023-03-14 14:29:28 +00:00
|
|
|
)
|
2023-03-09 15:01:53 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
# Always run the validator for the app's binary when building the app
|
|
|
|
self.app_env.AlwaysBuild(app_artifacts.validator)
|
|
|
|
self.app_env.Alias(self.app_alias, app_artifacts.validator)
|
2022-11-05 11:47:59 +00:00
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
|
|
|
|
def BuildAppElf(env, app):
|
|
|
|
app_builder = AppBuilder(env, app)
|
|
|
|
env["EXT_APPS"][app.appid] = app_artifacts = app_builder.build()
|
2022-11-05 11:47:59 +00:00
|
|
|
return app_artifacts
|
2022-09-14 16:11:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def prepare_app_metadata(target, source, env):
|
2023-04-06 02:44:37 +00:00
|
|
|
metadata_node = next(filter(lambda t: t.name.endswith(_FAP_META_SECTION), target))
|
|
|
|
|
2022-10-19 14:28:48 +00:00
|
|
|
sdk_cache = SdkCache(env["SDK_DEFINITION"].path, load_version_only=True)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
|
|
|
if not sdk_cache.is_buildable():
|
|
|
|
raise UserError(
|
2023-03-14 14:29:28 +00:00
|
|
|
"SDK version is not finalized, please review changes and re-run operation. See AppsOnSDCard.md for more details."
|
2022-09-14 16:11:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
app = env["APP"]
|
2023-04-06 02:44:37 +00:00
|
|
|
with open(metadata_node.abspath, "wb") as f:
|
2022-09-14 16:11:38 +00:00
|
|
|
f.write(
|
|
|
|
assemble_manifest_data(
|
|
|
|
app_manifest=app,
|
|
|
|
hardware_target=int(env.subst("$TARGET_HW")),
|
|
|
|
sdk_version=sdk_cache.version.as_int(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
def _validate_app_imports(target, source, env):
|
2022-10-19 14:28:48 +00:00
|
|
|
sdk_cache = SdkCache(env["SDK_DEFINITION"].path, load_version_only=False)
|
2022-09-14 16:11:38 +00:00
|
|
|
app_syms = set()
|
|
|
|
with open(target[0].path, "rt") as f:
|
|
|
|
for line in f:
|
|
|
|
app_syms.add(line.split()[0])
|
|
|
|
unresolved_syms = app_syms - sdk_cache.get_valid_names()
|
|
|
|
if unresolved_syms:
|
2022-11-05 11:47:59 +00:00
|
|
|
warning_msg = fg.brightyellow(
|
2023-03-14 14:29:28 +00:00
|
|
|
f"{source[0].path}: app may not be runnable. Symbols not resolved using firmware's API: "
|
2022-11-05 11:47:59 +00:00
|
|
|
) + fg.brightmagenta(f"{unresolved_syms}")
|
|
|
|
disabled_api_syms = unresolved_syms.intersection(sdk_cache.get_disabled_names())
|
|
|
|
if disabled_api_syms:
|
|
|
|
warning_msg += (
|
|
|
|
fg.brightyellow(" (in API, but disabled: ")
|
|
|
|
+ fg.brightmagenta(f"{disabled_api_syms}")
|
|
|
|
+ fg.brightyellow(")")
|
|
|
|
)
|
2023-10-23 09:55:36 +00:00
|
|
|
if env.get("_CHECK_APP"):
|
|
|
|
raise UserError(warning_msg)
|
|
|
|
else:
|
|
|
|
SCons.Warnings.warn(SCons.Warnings.LinkWarning, warning_msg),
|
2022-09-14 16:11:38 +00:00
|
|
|
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
def GetExtAppByIdOrPath(env, app_dir):
|
2022-09-14 16:11:38 +00:00
|
|
|
if not app_dir:
|
|
|
|
raise UserError("APPSRC= not set")
|
|
|
|
|
|
|
|
appmgr = env["APPMGR"]
|
|
|
|
|
|
|
|
app = None
|
2022-10-06 13:55:57 +00:00
|
|
|
try:
|
2023-03-14 14:29:28 +00:00
|
|
|
# Maybe user passed an appid?
|
2022-10-06 13:55:57 +00:00
|
|
|
app = appmgr.get(app_dir)
|
2023-05-03 05:48:49 +00:00
|
|
|
except FlipperManifestException:
|
2023-03-14 14:29:28 +00:00
|
|
|
# Look up path components in known app dirs
|
2022-10-06 13:55:57 +00:00
|
|
|
for dir_part in reversed(pathlib.Path(app_dir).parts):
|
|
|
|
if app := appmgr.find_by_appdir(dir_part):
|
|
|
|
break
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
if not app:
|
|
|
|
raise UserError(f"Failed to resolve application for given APPSRC={app_dir}")
|
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
app_artifacts = env["EXT_APPS"].get(app.appid, None)
|
|
|
|
if not app_artifacts:
|
2022-09-29 11:00:22 +00:00
|
|
|
raise UserError(
|
2023-03-14 14:29:28 +00:00
|
|
|
f"Application {app.appid} is not configured to be built as external"
|
2022-09-29 11:00:22 +00:00
|
|
|
)
|
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
return app_artifacts
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
def _embed_app_metadata_emitter(target, source, env):
|
2023-03-09 15:01:53 +00:00
|
|
|
app = env["APP"]
|
|
|
|
|
2023-03-14 14:29:28 +00:00
|
|
|
# Hack: change extension for fap libs
|
|
|
|
if app.apptype == FlipperAppType.PLUGIN:
|
|
|
|
target[0].name = target[0].name.replace(".fap", ".fal")
|
|
|
|
|
2023-09-21 12:56:00 +00:00
|
|
|
app_work_dir = AppBuilder.get_app_work_dir(env, app)
|
|
|
|
app._section_fapmeta = app_work_dir.File(_FAP_META_SECTION)
|
|
|
|
target.append(app._section_fapmeta)
|
2023-03-09 15:01:53 +00:00
|
|
|
|
2023-09-21 12:56:00 +00:00
|
|
|
# At this point, we haven't added dir with embedded plugins to _assets_dirs yet
|
|
|
|
if app._assets_dirs or app.embeds_plugins:
|
|
|
|
app._section_fapfileassets = app_work_dir.File(_FAP_FILEASSETS_SECTION)
|
|
|
|
target.append(app._section_fapfileassets)
|
2023-03-09 15:01:53 +00:00
|
|
|
|
|
|
|
return (target, source)
|
|
|
|
|
|
|
|
|
2023-09-21 12:56:00 +00:00
|
|
|
def prepare_app_file_assets(target, source, env):
|
2023-04-06 02:44:37 +00:00
|
|
|
files_section_node = next(
|
|
|
|
filter(lambda t: t.name.endswith(_FAP_FILEASSETS_SECTION), target)
|
|
|
|
)
|
|
|
|
|
2023-09-21 12:56:00 +00:00
|
|
|
bundler = FileBundler(
|
|
|
|
list(env.Dir(asset_dir).abspath for asset_dir in env["APP"]._assets_dirs)
|
|
|
|
)
|
2023-04-06 02:44:37 +00:00
|
|
|
bundler.export(files_section_node.abspath)
|
2023-03-09 15:01:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate_embed_app_metadata_actions(source, target, env, for_signature):
|
|
|
|
app = env["APP"]
|
|
|
|
|
|
|
|
actions = [
|
|
|
|
Action(prepare_app_metadata, "$APPMETA_COMSTR"),
|
|
|
|
]
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
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",
|
|
|
|
]
|
2023-03-09 15:01:53 +00:00
|
|
|
|
2023-09-21 12:56:00 +00:00
|
|
|
if app._section_fapfileassets:
|
|
|
|
actions.append(Action(prepare_app_file_assets, "$APPFILE_COMSTR"))
|
2023-10-30 15:17:30 +00:00
|
|
|
objcopy_args.extend(
|
|
|
|
(
|
|
|
|
"--add-section",
|
|
|
|
"${_FAP_FILEASSETS_SECTION}=${APP._section_fapfileassets}",
|
|
|
|
"--set-section-flags",
|
|
|
|
"${_FAP_FILEASSETS_SECTION}=contents,noload,readonly,data",
|
|
|
|
)
|
2023-09-21 12:56:00 +00:00
|
|
|
)
|
2023-03-09 15:01:53 +00:00
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
objcopy_args.extend(
|
|
|
|
(
|
|
|
|
"--strip-debug",
|
|
|
|
"--strip-unneeded",
|
|
|
|
"--add-gnu-debuglink=${SOURCE}",
|
|
|
|
"${SOURCES}",
|
|
|
|
"${TARGET}",
|
|
|
|
)
|
2023-03-09 15:01:53 +00:00
|
|
|
)
|
|
|
|
|
2023-06-28 08:19:10 +00:00
|
|
|
actions.extend(
|
|
|
|
(
|
|
|
|
Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
[objcopy_args],
|
2023-06-28 08:19:10 +00:00
|
|
|
"$APPMETAEMBED_COMSTR",
|
|
|
|
),
|
|
|
|
Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${FBT_SCRIPT_DIR}/fastfap.py",
|
|
|
|
"${TARGET}",
|
|
|
|
"${OBJCOPY}",
|
|
|
|
]
|
|
|
|
],
|
2023-06-28 08:19:10 +00:00
|
|
|
"$FASTFAP_COMSTR",
|
|
|
|
),
|
2023-03-09 15:01:53 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return Action(actions)
|
|
|
|
|
|
|
|
|
2023-07-18 09:39:30 +00:00
|
|
|
@dataclass
|
|
|
|
class AppDeploymentComponents:
|
|
|
|
deploy_sources: Dict[str, object] = field(default_factory=dict)
|
|
|
|
validators: List[object] = field(default_factory=list)
|
|
|
|
extra_launch_args: str = ""
|
2023-04-06 02:44:37 +00:00
|
|
|
|
2023-07-18 09:39:30 +00:00
|
|
|
def add_app(self, app_artifacts):
|
2023-04-06 02:44:37 +00:00
|
|
|
for _, ext_path in app_artifacts.dist_entries:
|
2023-07-18 09:39:30 +00:00
|
|
|
self.deploy_sources[f"/ext/{ext_path}"] = app_artifacts.compact
|
|
|
|
self.validators.append(app_artifacts.validator)
|
|
|
|
|
|
|
|
|
|
|
|
def _gather_app_components(env, appname) -> AppDeploymentComponents:
|
|
|
|
components = AppDeploymentComponents()
|
2023-04-06 02:44:37 +00:00
|
|
|
|
|
|
|
def _add_host_app_to_targets(host_app):
|
|
|
|
artifacts_app_to_run = env["EXT_APPS"].get(host_app.appid, None)
|
2023-07-18 09:39:30 +00:00
|
|
|
components.add_app(artifacts_app_to_run)
|
2023-04-06 02:44:37 +00:00
|
|
|
for plugin in host_app._plugins:
|
2023-07-18 09:39:30 +00:00
|
|
|
components.add_app(env["EXT_APPS"].get(plugin.appid, None))
|
2023-04-06 02:44:37 +00:00
|
|
|
|
|
|
|
artifacts_app_to_run = env.GetExtAppByIdOrPath(appname)
|
|
|
|
if artifacts_app_to_run.app.apptype == FlipperAppType.PLUGIN:
|
|
|
|
# We deploy host app instead
|
|
|
|
host_app = env["APPMGR"].get(artifacts_app_to_run.app.requires[0])
|
|
|
|
|
|
|
|
if host_app:
|
2023-07-10 08:03:41 +00:00
|
|
|
if host_app.apptype in [
|
|
|
|
FlipperAppType.EXTERNAL,
|
|
|
|
FlipperAppType.MENUEXTERNAL,
|
|
|
|
]:
|
2023-07-18 09:39:30 +00:00
|
|
|
components.add_app(host_app)
|
2023-04-06 02:44:37 +00:00
|
|
|
else:
|
|
|
|
# host app is a built-in app
|
2023-07-18 09:39:30 +00:00
|
|
|
components.add_app(artifacts_app_to_run)
|
2024-05-20 17:23:47 +00:00
|
|
|
if host_app.name:
|
|
|
|
components.extra_launch_args = f"-a {host_app.name}"
|
2023-04-06 02:44:37 +00:00
|
|
|
else:
|
|
|
|
raise UserError("Host app is unknown")
|
|
|
|
else:
|
|
|
|
_add_host_app_to_targets(artifacts_app_to_run.app)
|
2023-07-18 09:39:30 +00:00
|
|
|
return components
|
2023-04-06 02:44:37 +00:00
|
|
|
|
2023-07-18 09:39:30 +00:00
|
|
|
|
|
|
|
def AddAppLaunchTarget(env, appname, launch_target_name):
|
|
|
|
components = _gather_app_components(env, appname)
|
|
|
|
target = env.PhonyTarget(
|
2023-04-06 02:44:37 +00:00
|
|
|
launch_target_name,
|
2023-11-15 16:27:35 +00:00
|
|
|
[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${APP_RUN_SCRIPT}",
|
|
|
|
"-p",
|
|
|
|
"${FLIP_PORT}",
|
|
|
|
"${EXTRA_ARGS}",
|
|
|
|
"-s",
|
|
|
|
"${SOURCES}",
|
|
|
|
"-t",
|
|
|
|
"${FLIPPER_FILE_TARGETS}",
|
|
|
|
]
|
|
|
|
],
|
2023-07-18 09:39:30 +00:00
|
|
|
source=components.deploy_sources.values(),
|
|
|
|
FLIPPER_FILE_TARGETS=components.deploy_sources.keys(),
|
|
|
|
EXTRA_ARGS=components.extra_launch_args,
|
2023-04-06 02:44:37 +00:00
|
|
|
)
|
2023-07-18 09:39:30 +00:00
|
|
|
env.Alias(launch_target_name, components.validators)
|
|
|
|
return target
|
|
|
|
|
|
|
|
|
|
|
|
def AddAppBuildTarget(env, appname, build_target_name):
|
|
|
|
components = _gather_app_components(env, appname)
|
|
|
|
env.Alias(build_target_name, components.validators)
|
|
|
|
env.Alias(build_target_name, components.deploy_sources.values())
|
2023-04-06 02:44:37 +00:00
|
|
|
|
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
def generate(env, **kw):
|
2022-11-02 15:15:40 +00:00
|
|
|
env.SetDefault(
|
2023-09-21 12:56:00 +00:00
|
|
|
EXT_APPS_WORK_DIR=env.Dir(env["FBT_FAP_DEBUG_ELF_ROOT"]),
|
2022-11-02 15:15:40 +00:00
|
|
|
APP_RUN_SCRIPT="${FBT_SCRIPT_DIR}/runfap.py",
|
|
|
|
)
|
2022-10-25 22:15:02 +00:00
|
|
|
if not env["VERBOSE"]:
|
|
|
|
env.SetDefault(
|
|
|
|
APPMETA_COMSTR="\tAPPMETA\t${TARGET}",
|
2023-03-09 15:01:53 +00:00
|
|
|
APPFILE_COMSTR="\tAPPFILE\t${TARGET}",
|
2022-10-25 22:15:02 +00:00
|
|
|
APPMETAEMBED_COMSTR="\tFAP\t${TARGET}",
|
2023-06-28 08:19:10 +00:00
|
|
|
FASTFAP_COMSTR="\tFASTFAP\t${TARGET}",
|
2022-10-25 22:15:02 +00:00
|
|
|
APPCHECK_COMSTR="\tAPPCHK\t${SOURCE}",
|
|
|
|
)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
env.SetDefault(
|
|
|
|
EXT_APPS={}, # appid -> FlipperExternalAppInfo
|
2023-03-14 14:29:28 +00:00
|
|
|
EXT_LIBS={},
|
|
|
|
_APP_ICONS=[],
|
2023-04-06 02:44:37 +00:00
|
|
|
_FAP_META_SECTION=_FAP_META_SECTION,
|
|
|
|
_FAP_FILEASSETS_SECTION=_FAP_FILEASSETS_SECTION,
|
2022-11-05 11:47:59 +00:00
|
|
|
)
|
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
env.AddMethod(BuildAppElf)
|
2023-03-14 14:29:28 +00:00
|
|
|
env.AddMethod(GetExtAppByIdOrPath)
|
2023-04-06 02:44:37 +00:00
|
|
|
env.AddMethod(AddAppLaunchTarget)
|
2023-07-18 09:39:30 +00:00
|
|
|
env.AddMethod(AddAppBuildTarget)
|
2023-04-06 02:44:37 +00:00
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
|
|
|
"EmbedAppMetadata": Builder(
|
2023-03-09 15:01:53 +00:00
|
|
|
generator=generate_embed_app_metadata_actions,
|
2022-09-14 16:11:38 +00:00
|
|
|
suffix=".fap",
|
|
|
|
src_suffix=".elf",
|
2023-10-30 15:17:30 +00:00
|
|
|
emitter=_embed_app_metadata_emitter,
|
2022-09-14 16:11:38 +00:00
|
|
|
),
|
|
|
|
"ValidateAppImports": Builder(
|
|
|
|
action=[
|
|
|
|
Action(
|
|
|
|
"@${NM} -P -u ${SOURCE} > ${TARGET}",
|
|
|
|
None, # "$APPDUMP_COMSTR",
|
|
|
|
),
|
|
|
|
Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
_validate_app_imports,
|
2022-09-29 11:00:22 +00:00
|
|
|
"$APPCHECK_COMSTR",
|
2022-09-14 16:11:38 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
suffix=".impsyms",
|
|
|
|
src_suffix=".fap",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|