2022-11-05 14:47:59 +03:00
|
|
|
from dataclasses import dataclass, field
|
2023-03-14 17:29:28 +03:00
|
|
|
|
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
|
|
|
|
2023-04-06 05:44:37 +03:00
|
|
|
|
2022-09-14 19:11:38 +03:00
|
|
|
if appsrc := appenv.subst("$APPSRC"):
|
2023-04-06 05:44:37 +03:00
|
|
|
appenv.AddAppLaunchTarget(appsrc, "launch_app")
|
|
|
|
|
2022-09-14 19:11:38 +03:00
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
# SDK management
|
|
|
|
|
2023-04-06 05:44:37 +03:00
|
|
|
amalgamated_api = "${BUILD_DIR}/sdk_origin"
|
|
|
|
sdk_source = appenv.ApiAmalgamator(
|
|
|
|
amalgamated_api,
|
2022-11-02 18:15:40 +03:00
|
|
|
# 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
|
2023-04-06 05:44:37 +03:00
|
|
|
Depends(sdk_source, appenv.ProcessSdkDepends(f"{amalgamated_api}.d"))
|
2022-11-02 18:15:40 +03:00
|
|
|
|
2023-04-06 05:44:37 +03:00
|
|
|
appenv["SDK_DIR"] = appenv.Dir("${BUILD_DIR}/sdk_headers")
|
|
|
|
sdk_header_tree = appenv.SDKHeaderTreeExtractor(appenv["SDK_DIR"], amalgamated_api)
|
2023-04-10 17:46:22 +03:00
|
|
|
Depends(sdk_header_tree, appenv["SDK_DEFINITION"])
|
2022-11-02 18:15:40 +03:00
|
|
|
# AlwaysBuild(sdk_tree)
|
2023-04-06 05:44:37 +03:00
|
|
|
Alias("sdk_tree", sdk_header_tree)
|
|
|
|
extapps.sdk_tree = sdk_header_tree
|
2022-11-02 18:15:40 +03:00
|
|
|
|
2023-04-06 05:44:37 +03:00
|
|
|
api_check = appenv.ApiTableValidator(appenv["SDK_DEFINITION"], amalgamated_api)
|
|
|
|
Precious(api_check)
|
|
|
|
NoClean(api_check)
|
|
|
|
AlwaysBuild(api_check)
|
|
|
|
Alias("api_check", api_check)
|
2022-11-02 18:15:40 +03:00
|
|
|
|
2023-04-06 05:44:37 +03:00
|
|
|
firmware_apitable = appenv.ApiSymbolTable(
|
|
|
|
"${BUILD_DIR}/assets/compiled/firmware_api_table.h", appenv["SDK_DEFINITION"]
|
2022-11-02 18:15:40 +03:00
|
|
|
)
|
2023-04-06 05:44:37 +03:00
|
|
|
Alias("api_table", firmware_apitable)
|
2023-01-17 15:55:49 +03:00
|
|
|
ENV.Replace(
|
2023-04-06 05:44:37 +03:00
|
|
|
FW_API_TABLE=firmware_apitable,
|
2023-01-17 15:55:49 +03:00
|
|
|
_APP_ICONS=appenv["_APP_ICONS"],
|
|
|
|
)
|
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
|
|
|
|
if appenv["FORCE"]:
|
2023-04-06 05:44:37 +03:00
|
|
|
appenv.AlwaysBuild(sdk_source, sdk_header_tree, api_check, firmware_apitable)
|
2022-11-02 18:15:40 +03:00
|
|
|
|
|
|
|
|
2022-09-14 19:11:38 +03:00
|
|
|
Return("extapps")
|