2022-11-05 14:47:59 +03:00
|
|
|
from dataclasses import dataclass, field
|
2023-03-14 17:29:28 +03:00
|
|
|
from os.path import dirname
|
|
|
|
|
2022-11-05 14:47:59 +03:00
|
|
|
from SCons.Node import NodeList
|
2022-11-10 14:55:11 +03:00
|
|
|
from SCons.Warnings import warn, WarningOnByDefault
|
2023-03-14 17:29:28 +03:00
|
|
|
from SCons.Errors import UserError
|
2022-10-06 16:55:57 +03:00
|
|
|
|
2022-09-14 19:11:38 +03:00
|
|
|
Import("ENV")
|
|
|
|
|
|
|
|
from fbt.appmanifest import FlipperAppType
|
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
appenv = ENV["APPENV"] = ENV.Clone(
|
2022-10-06 16:55:57 +03:00
|
|
|
tools=[
|
2022-11-05 14:47:59 +03:00
|
|
|
"fbt_extapps",
|
2022-10-06 16:55:57 +03:00
|
|
|
"fbt_assets",
|
2022-11-02 18:15:40 +03:00
|
|
|
"fbt_sdk",
|
2023-03-14 17:29:28 +03:00
|
|
|
],
|
|
|
|
RESOURCES_ROOT=ENV.Dir("#/assets/resources"),
|
2022-09-14 19:11:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
appenv.Replace(
|
2023-02-07 19:33:05 +03:00
|
|
|
LINKER_SCRIPT_PATH=appenv["APP_LINKER_SCRIPT_PATH"],
|
2022-09-14 19:11:38 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
appenv.AppendUnique(
|
|
|
|
CCFLAGS=[
|
|
|
|
"-ggdb3",
|
|
|
|
"-mword-relocations",
|
|
|
|
"-mlong-calls",
|
|
|
|
"-fno-common",
|
|
|
|
"-nostdlib",
|
|
|
|
"-fvisibility=hidden",
|
|
|
|
],
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-Ur",
|
|
|
|
"-Wl,-Ur",
|
|
|
|
# "-Wl,--orphan-handling=error",
|
|
|
|
"-Bsymbolic",
|
|
|
|
"-nostartfiles",
|
|
|
|
"-mlong-calls",
|
|
|
|
"-fno-common",
|
|
|
|
"-nostdlib",
|
|
|
|
"-Wl,--gc-sections",
|
|
|
|
"-Wl,--no-export-dynamic",
|
|
|
|
"-fvisibility=hidden",
|
|
|
|
"-Wl,-e${APP_ENTRY}",
|
|
|
|
"-Xlinker",
|
|
|
|
"-Map=${TARGET}.map",
|
|
|
|
"-specs=nano.specs",
|
|
|
|
"-specs=nosys.specs",
|
|
|
|
],
|
|
|
|
LIBS=[
|
|
|
|
"m",
|
|
|
|
"gcc",
|
|
|
|
"stdc++",
|
|
|
|
"supc++",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-05 14:47:59 +03:00
|
|
|
@dataclass
|
|
|
|
class FlipperExtAppBuildArtifacts:
|
2023-03-14 17:29:28 +03:00
|
|
|
application_map: dict = field(default_factory=dict)
|
2022-11-05 14:47:59 +03:00
|
|
|
resources_dist: NodeList = field(default_factory=NodeList)
|
|
|
|
sdk_tree: NodeList = field(default_factory=NodeList)
|
2022-09-14 19:11:38 +03:00
|
|
|
|
|
|
|
|
2022-09-19 15:39:00 +03:00
|
|
|
apps_to_build_as_faps = [
|
|
|
|
FlipperAppType.PLUGIN,
|
|
|
|
FlipperAppType.EXTERNAL,
|
2023-01-17 18:07:47 +03:00
|
|
|
FlipperAppType.DEBUG,
|
2022-09-19 15:39:00 +03:00
|
|
|
]
|
2022-09-14 19:11:38 +03:00
|
|
|
|
2022-11-05 14:47:59 +03:00
|
|
|
known_extapps = [
|
|
|
|
app
|
|
|
|
for apptype in apps_to_build_as_faps
|
|
|
|
for app in appenv["APPBUILD"].get_apps_of_type(apptype, True)
|
|
|
|
]
|
2022-09-14 19:11:38 +03:00
|
|
|
|
|
|
|
# Ugly access to global option
|
|
|
|
if extra_app_list := GetOption("extra_ext_apps"):
|
2022-11-05 14:47:59 +03:00
|
|
|
known_extapps.extend(map(appenv["APPMGR"].get, extra_app_list.split(",")))
|
2022-10-06 16:55:57 +03:00
|
|
|
|
2023-02-07 19:33:05 +03:00
|
|
|
incompatible_apps = []
|
2022-11-05 14:47:59 +03:00
|
|
|
for app in known_extapps:
|
2023-02-07 19:33:05 +03:00
|
|
|
if not app.supports_hardware_target(appenv.subst("f${TARGET_HW}")):
|
|
|
|
incompatible_apps.append(app)
|
2022-11-10 14:55:11 +03:00
|
|
|
continue
|
|
|
|
|
2022-11-05 14:47:59 +03:00
|
|
|
appenv.BuildAppElf(app)
|
2022-10-06 16:55:57 +03:00
|
|
|
|
2023-03-14 17:29:28 +03:00
|
|
|
extapps = FlipperExtAppBuildArtifacts()
|
|
|
|
extapps.application_map = appenv["EXT_APPS"]
|
|
|
|
|
2023-02-07 19:33:05 +03:00
|
|
|
if incompatible_apps:
|
|
|
|
warn(
|
|
|
|
WarningOnByDefault,
|
|
|
|
f"Skipping build of {len(incompatible_apps)} incompatible app(s): "
|
|
|
|
+ ", ".join(f"'{app.name}' (id '{app.appid}')" for app in incompatible_apps),
|
|
|
|
)
|
2022-10-06 16:55:57 +03:00
|
|
|
|
2022-11-05 14:47:59 +03:00
|
|
|
if appenv["FORCE"]:
|
|
|
|
appenv.AlwaysBuild(
|
2023-03-14 17:29:28 +03:00
|
|
|
list(app_artifact.compact for app_artifact in extapps.application_map.values())
|
2022-11-05 14:47:59 +03:00
|
|
|
)
|
2022-10-06 16:55:57 +03:00
|
|
|
|
|
|
|
|
2022-11-05 14:47:59 +03:00
|
|
|
Alias(
|
2023-03-14 17:29:28 +03:00
|
|
|
"faps",
|
|
|
|
list(app_artifact.validator for app_artifact in extapps.application_map.values()),
|
2022-11-05 14:47:59 +03:00
|
|
|
)
|
2022-09-14 19:11:38 +03:00
|
|
|
|
2023-03-14 17:29:28 +03:00
|
|
|
extapps.resources_dist = appenv.FapDist(appenv["RESOURCES_ROOT"], [])
|
2022-10-26 01:15:02 +03:00
|
|
|
|
2022-09-14 19:11:38 +03:00
|
|
|
if appsrc := appenv.subst("$APPSRC"):
|
2023-03-14 17:29:28 +03:00
|
|
|
deploy_sources, flipp_dist_paths, validators = [], [], []
|
|
|
|
run_script_extra_ars = ""
|
|
|
|
|
|
|
|
def _add_dist_targets(app_artifacts):
|
|
|
|
validators.append(app_artifacts.validator)
|
|
|
|
for _, ext_path in app_artifacts.dist_entries:
|
|
|
|
deploy_sources.append(app_artifacts.compact)
|
|
|
|
flipp_dist_paths.append(f"/ext/{ext_path}")
|
|
|
|
return app_artifacts
|
|
|
|
|
|
|
|
def _add_host_app_to_targets(host_app):
|
|
|
|
artifacts_app_to_run = appenv["EXT_APPS"].get(host_app.appid, None)
|
|
|
|
_add_dist_targets(artifacts_app_to_run)
|
|
|
|
for plugin in host_app._plugins:
|
|
|
|
_add_dist_targets(appenv["EXT_APPS"].get(plugin.appid, None))
|
|
|
|
|
|
|
|
artifacts_app_to_run = appenv.GetExtAppByIdOrPath(appsrc)
|
|
|
|
if artifacts_app_to_run.app.apptype == FlipperAppType.PLUGIN:
|
|
|
|
# We deploy host app instead
|
|
|
|
host_app = appenv["APPMGR"].get(artifacts_app_to_run.app.requires[0])
|
|
|
|
|
|
|
|
if host_app:
|
|
|
|
if host_app.apptype == FlipperAppType.EXTERNAL:
|
|
|
|
_add_host_app_to_targets(host_app)
|
|
|
|
else:
|
|
|
|
# host app is a built-in app
|
|
|
|
run_script_extra_ars = f"-a {host_app.name}"
|
|
|
|
_add_dist_targets(artifacts_app_to_run)
|
|
|
|
else:
|
|
|
|
raise UserError("Host app is unknown")
|
|
|
|
else:
|
|
|
|
_add_host_app_to_targets(artifacts_app_to_run.app)
|
|
|
|
|
|
|
|
# print(deploy_sources, flipp_dist_paths)
|
2022-09-14 19:11:38 +03:00
|
|
|
appenv.PhonyTarget(
|
|
|
|
"launch_app",
|
2023-03-14 17:29:28 +03:00
|
|
|
'${PYTHON3} "${APP_RUN_SCRIPT}" ${EXTRA_ARGS} -s ${SOURCES} -t ${FLIPPER_FILE_TARGETS}',
|
|
|
|
source=deploy_sources,
|
|
|
|
FLIPPER_FILE_TARGETS=flipp_dist_paths,
|
|
|
|
EXTRA_ARGS=run_script_extra_ars,
|
2022-09-14 19:11:38 +03:00
|
|
|
)
|
2023-03-14 17:29:28 +03:00
|
|
|
appenv.Alias("launch_app", validators)
|
2022-09-14 19:11:38 +03:00
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
# SDK management
|
|
|
|
|
|
|
|
sdk_origin_path = "${BUILD_DIR}/sdk_origin"
|
|
|
|
sdk_source = appenv.SDKPrebuilder(
|
|
|
|
sdk_origin_path,
|
|
|
|
# Deps on root SDK headers and generated files
|
|
|
|
(appenv["SDK_HEADERS"], appenv["FW_ASSETS_HEADERS"]),
|
|
|
|
)
|
|
|
|
# Extra deps on headers included in deeper levels
|
2022-11-05 14:47:59 +03:00
|
|
|
# Available on second and subsequent builds
|
2022-11-02 18:15:40 +03:00
|
|
|
Depends(sdk_source, appenv.ProcessSdkDepends(f"{sdk_origin_path}.d"))
|
|
|
|
|
|
|
|
appenv["SDK_DIR"] = appenv.Dir("${BUILD_DIR}/sdk")
|
2022-11-05 14:47:59 +03:00
|
|
|
sdk_tree = appenv.SDKTree(appenv["SDK_DIR"], sdk_origin_path)
|
2022-11-02 18:15:40 +03:00
|
|
|
# AlwaysBuild(sdk_tree)
|
|
|
|
Alias("sdk_tree", sdk_tree)
|
2022-11-05 14:47:59 +03:00
|
|
|
extapps.sdk_tree = sdk_tree
|
2022-11-02 18:15:40 +03:00
|
|
|
|
|
|
|
sdk_apicheck = appenv.SDKSymUpdater(appenv["SDK_DEFINITION"], sdk_origin_path)
|
|
|
|
Precious(sdk_apicheck)
|
|
|
|
NoClean(sdk_apicheck)
|
|
|
|
AlwaysBuild(sdk_apicheck)
|
|
|
|
Alias("sdk_check", sdk_apicheck)
|
|
|
|
|
|
|
|
sdk_apisyms = appenv.SDKSymGenerator(
|
|
|
|
"${BUILD_DIR}/assets/compiled/symbols.h", appenv["SDK_DEFINITION"]
|
|
|
|
)
|
|
|
|
Alias("api_syms", sdk_apisyms)
|
2023-01-17 15:55:49 +03:00
|
|
|
ENV.Replace(
|
|
|
|
SDK_APISYMS=sdk_apisyms,
|
|
|
|
_APP_ICONS=appenv["_APP_ICONS"],
|
|
|
|
)
|
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
|
|
|
|
if appenv["FORCE"]:
|
|
|
|
appenv.AlwaysBuild(sdk_source, sdk_tree, sdk_apicheck, sdk_apisyms)
|
|
|
|
|
|
|
|
|
2022-09-14 19:11:38 +03:00
|
|
|
Return("extapps")
|