2022-11-05 11:47:59 +00:00
|
|
|
from dataclasses import dataclass, field
|
2022-10-06 13:55:57 +00:00
|
|
|
from SCons.Errors import UserError
|
2022-11-05 11:47:59 +00:00
|
|
|
from SCons.Node import NodeList
|
2022-10-06 13:55:57 +00:00
|
|
|
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
Import("ENV")
|
|
|
|
|
|
|
|
from fbt.appmanifest import FlipperAppType
|
|
|
|
|
2022-11-02 15:15:40 +00:00
|
|
|
appenv = ENV["APPENV"] = ENV.Clone(
|
2022-10-06 13:55:57 +00:00
|
|
|
tools=[
|
2022-11-05 11:47:59 +00:00
|
|
|
"fbt_extapps",
|
2022-10-06 13:55:57 +00:00
|
|
|
"fbt_assets",
|
2022-11-02 15:15:40 +00:00
|
|
|
"fbt_sdk",
|
2022-10-06 13:55:57 +00:00
|
|
|
]
|
2022-09-14 16:11:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
appenv.Replace(
|
2022-10-28 15:32:06 +00:00
|
|
|
LINKER_SCRIPT=appenv.subst("$APP_LINKER_SCRIPT"),
|
2022-09-14 16:11:38 +00: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 11:47:59 +00:00
|
|
|
@dataclass
|
|
|
|
class FlipperExtAppBuildArtifacts:
|
|
|
|
applications: dict = field(default_factory=dict)
|
|
|
|
resources_dist: NodeList = field(default_factory=NodeList)
|
|
|
|
sdk_tree: NodeList = field(default_factory=NodeList)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
|
|
|
|
2022-09-19 12:39:00 +00:00
|
|
|
apps_to_build_as_faps = [
|
|
|
|
FlipperAppType.PLUGIN,
|
|
|
|
FlipperAppType.EXTERNAL,
|
|
|
|
]
|
2022-09-14 16:11:38 +00:00
|
|
|
if appenv["DEBUG_TOOLS"]:
|
|
|
|
apps_to_build_as_faps.append(FlipperAppType.DEBUG)
|
|
|
|
|
2022-11-05 11:47:59 +00: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 16:11:38 +00:00
|
|
|
|
|
|
|
# Ugly access to global option
|
|
|
|
if extra_app_list := GetOption("extra_ext_apps"):
|
2022-11-05 11:47:59 +00:00
|
|
|
known_extapps.extend(map(appenv["APPMGR"].get, extra_app_list.split(",")))
|
2022-10-06 13:55:57 +00:00
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
for app in known_extapps:
|
|
|
|
appenv.BuildAppElf(app)
|
2022-10-06 13:55:57 +00:00
|
|
|
|
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
if appenv["FORCE"]:
|
|
|
|
appenv.AlwaysBuild(
|
|
|
|
list(app_artifact.compact for app_artifact in appenv["EXT_APPS"].values())
|
|
|
|
)
|
2022-10-06 13:55:57 +00:00
|
|
|
|
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
Alias(
|
|
|
|
"faps", list(app_artifact.validator for app_artifact in appenv["EXT_APPS"].values())
|
|
|
|
)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2022-11-05 11:47:59 +00:00
|
|
|
extapps = FlipperExtAppBuildArtifacts()
|
|
|
|
extapps.applications = appenv["EXT_APPS"]
|
|
|
|
extapps.resources_dist = appenv.FapDist(appenv.Dir("#/assets/resources/apps"), [])
|
2022-10-25 22:15:02 +00:00
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
if appsrc := appenv.subst("$APPSRC"):
|
2022-09-29 11:00:22 +00:00
|
|
|
app_manifest, fap_file, app_validator = appenv.GetExtAppFromPath(appsrc)
|
2022-09-14 16:11:38 +00:00
|
|
|
appenv.PhonyTarget(
|
|
|
|
"launch_app",
|
2022-11-05 11:47:59 +00:00
|
|
|
'${PYTHON3} "${APP_RUN_SCRIPT}" "${SOURCE}" --fap_dst_dir "/ext/apps/${FAP_CATEGORY}"',
|
2022-09-14 16:11:38 +00:00
|
|
|
source=fap_file,
|
|
|
|
FAP_CATEGORY=app_manifest.fap_category,
|
|
|
|
)
|
2022-09-29 11:00:22 +00:00
|
|
|
appenv.Alias("launch_app", app_validator)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2022-11-02 15:15:40 +00: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 11:47:59 +00:00
|
|
|
# Available on second and subsequent builds
|
2022-11-02 15:15:40 +00:00
|
|
|
Depends(sdk_source, appenv.ProcessSdkDepends(f"{sdk_origin_path}.d"))
|
|
|
|
|
|
|
|
appenv["SDK_DIR"] = appenv.Dir("${BUILD_DIR}/sdk")
|
2022-11-05 11:47:59 +00:00
|
|
|
sdk_tree = appenv.SDKTree(appenv["SDK_DIR"], sdk_origin_path)
|
2022-11-02 15:15:40 +00:00
|
|
|
# AlwaysBuild(sdk_tree)
|
|
|
|
Alias("sdk_tree", sdk_tree)
|
2022-11-05 11:47:59 +00:00
|
|
|
extapps.sdk_tree = sdk_tree
|
2022-11-02 15:15:40 +00: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)
|
|
|
|
|
|
|
|
if appenv["FORCE"]:
|
|
|
|
appenv.AlwaysBuild(sdk_source, sdk_tree, sdk_apicheck, sdk_apisyms)
|
|
|
|
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
Return("extapps")
|