2022-11-02 15:15:40 +00:00
|
|
|
from ansi.color import fg
|
2022-07-14 16:24:26 +00:00
|
|
|
from fbt.appmanifest import (
|
2023-05-03 05:48:49 +00:00
|
|
|
AppManager,
|
2023-11-15 16:27:35 +00:00
|
|
|
AppBuildset,
|
|
|
|
FlipperApplication,
|
2023-05-03 05:48:49 +00:00
|
|
|
FlipperAppType,
|
2022-07-14 16:24:26 +00:00
|
|
|
FlipperManifestException,
|
|
|
|
)
|
2023-05-03 05:48:49 +00:00
|
|
|
from SCons.Action import Action
|
|
|
|
from SCons.Builder import Builder
|
|
|
|
from SCons.Errors import StopError
|
2023-05-08 11:01:52 +00:00
|
|
|
from SCons.Script import GetOption
|
2023-11-15 16:27:35 +00:00
|
|
|
from SCons.Warnings import WarningOnByDefault, warn
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
# Adding objects for application management to env
|
|
|
|
# AppManager env["APPMGR"] - loads all manifests; manages list of known apps
|
|
|
|
# AppBuildset env["APPBUILD"] - contains subset of apps, filtered for current config
|
|
|
|
|
|
|
|
|
2023-11-15 16:27:35 +00:00
|
|
|
class ApplicationsCGenerator:
|
|
|
|
APP_TYPE_MAP = {
|
|
|
|
FlipperAppType.SERVICE: ("FlipperInternalApplication", "FLIPPER_SERVICES"),
|
|
|
|
FlipperAppType.SYSTEM: ("FlipperInternalApplication", "FLIPPER_SYSTEM_APPS"),
|
|
|
|
FlipperAppType.APP: ("FlipperInternalApplication", "FLIPPER_APPS"),
|
|
|
|
FlipperAppType.DEBUG: ("FlipperInternalApplication", "FLIPPER_DEBUG_APPS"),
|
|
|
|
FlipperAppType.SETTINGS: (
|
|
|
|
"FlipperInternalApplication",
|
|
|
|
"FLIPPER_SETTINGS_APPS",
|
|
|
|
),
|
|
|
|
FlipperAppType.STARTUP: (
|
|
|
|
"FlipperInternalOnStartHook",
|
|
|
|
"FLIPPER_ON_SYSTEM_START",
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
APP_EXTERNAL_TYPE = (
|
|
|
|
"FlipperExternalApplication",
|
|
|
|
"FLIPPER_EXTERNAL_APPS",
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, buildset: AppBuildset, autorun_app: str = ""):
|
|
|
|
self.buildset = buildset
|
|
|
|
self.autorun = autorun_app
|
|
|
|
|
|
|
|
def get_app_ep_forward(self, app: FlipperApplication):
|
|
|
|
if app.apptype == FlipperAppType.STARTUP:
|
2024-04-01 17:02:45 +00:00
|
|
|
return f"extern void {app.entry_point}(void);"
|
2023-11-15 16:27:35 +00:00
|
|
|
return f"extern int32_t {app.entry_point}(void* p);"
|
|
|
|
|
|
|
|
def get_app_descr(self, app: FlipperApplication):
|
|
|
|
if app.apptype == FlipperAppType.STARTUP:
|
|
|
|
return app.entry_point
|
|
|
|
return f"""
|
|
|
|
{{.app = {app.entry_point},
|
|
|
|
.name = "{app.name}",
|
|
|
|
.appid = "{app.appid}",
|
|
|
|
.stack_size = {app.stack_size},
|
|
|
|
.icon = {f"&{app.icon}" if app.icon else "NULL"},
|
|
|
|
.flags = {'|'.join(f"FlipperInternalApplicationFlag{flag}" for flag in app.flags)} }}"""
|
|
|
|
|
|
|
|
def get_external_app_descr(self, app: FlipperApplication):
|
|
|
|
app_path = "/ext/apps"
|
|
|
|
if app.fap_category:
|
|
|
|
app_path += f"/{app.fap_category}"
|
|
|
|
app_path += f"/{app.appid}.fap"
|
|
|
|
return f"""
|
|
|
|
{{
|
|
|
|
.name = "{app.name}",
|
|
|
|
.icon = {f"&{app.icon}" if app.icon else "NULL"},
|
|
|
|
.path = "{app_path}" }}"""
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
contents = [
|
|
|
|
'#include "applications.h"',
|
|
|
|
"#include <assets_icons.h>",
|
|
|
|
f'const char* FLIPPER_AUTORUN_APP_NAME = "{self.autorun}";',
|
|
|
|
]
|
|
|
|
for apptype in self.APP_TYPE_MAP:
|
|
|
|
contents.extend(
|
|
|
|
map(self.get_app_ep_forward, self.buildset.get_apps_of_type(apptype))
|
|
|
|
)
|
|
|
|
entry_type, entry_block = self.APP_TYPE_MAP[apptype]
|
|
|
|
contents.append(f"const {entry_type} {entry_block}[] = {{")
|
|
|
|
contents.append(
|
|
|
|
",\n".join(
|
|
|
|
map(self.get_app_descr, self.buildset.get_apps_of_type(apptype))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
contents.append("};")
|
|
|
|
contents.append(
|
|
|
|
f"const size_t {entry_block}_COUNT = COUNT_OF({entry_block});"
|
|
|
|
)
|
|
|
|
|
|
|
|
archive_app = self.buildset.get_apps_of_type(FlipperAppType.ARCHIVE)
|
|
|
|
if archive_app:
|
|
|
|
contents.extend(
|
|
|
|
[
|
|
|
|
self.get_app_ep_forward(archive_app[0]),
|
|
|
|
f"const FlipperInternalApplication FLIPPER_ARCHIVE = {self.get_app_descr(archive_app[0])};",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
entry_type, entry_block = self.APP_EXTERNAL_TYPE
|
|
|
|
external_apps = self.buildset.get_apps_of_type(FlipperAppType.MENUEXTERNAL)
|
|
|
|
contents.append(f"const {entry_type} {entry_block}[] = {{")
|
|
|
|
contents.append(",\n".join(map(self.get_external_app_descr, external_apps)))
|
|
|
|
contents.append("};")
|
|
|
|
contents.append(f"const size_t {entry_block}_COUNT = COUNT_OF({entry_block});")
|
|
|
|
|
|
|
|
return "\n".join(contents)
|
|
|
|
|
|
|
|
|
2022-11-02 15:15:40 +00:00
|
|
|
def LoadAppManifest(env, entry):
|
|
|
|
try:
|
2023-11-15 16:27:35 +00:00
|
|
|
manifest_glob = entry.glob(FlipperApplication.APP_MANIFEST_DEFAULT_NAME)
|
2022-11-02 15:15:40 +00:00
|
|
|
if len(manifest_glob) == 0:
|
2023-11-02 13:28:39 +00:00
|
|
|
try:
|
|
|
|
disk_node = next(filter(lambda d: d.exists(), entry.get_all_rdirs()))
|
|
|
|
except Exception:
|
|
|
|
disk_node = entry
|
|
|
|
|
2022-11-02 15:15:40 +00:00
|
|
|
raise FlipperManifestException(
|
2023-11-15 16:27:35 +00:00
|
|
|
f"App folder '{disk_node.abspath}': missing manifest ({FlipperApplication.APP_MANIFEST_DEFAULT_NAME})"
|
2022-11-02 15:15:40 +00:00
|
|
|
)
|
2022-09-14 16:11:38 +00:00
|
|
|
|
2022-11-02 15:15:40 +00:00
|
|
|
app_manifest_file_path = manifest_glob[0].rfile().abspath
|
|
|
|
env["APPMGR"].load_manifest(app_manifest_file_path, entry)
|
|
|
|
except FlipperManifestException as e:
|
2023-05-08 11:01:52 +00:00
|
|
|
if not GetOption("silent"):
|
|
|
|
warn(WarningOnByDefault, str(e))
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def PrepareApplicationsBuild(env):
|
2023-02-07 16:33:05 +00:00
|
|
|
try:
|
|
|
|
appbuild = env["APPBUILD"] = env["APPMGR"].filter_apps(
|
2023-09-05 11:49:39 +00:00
|
|
|
applist=env["APPS"],
|
|
|
|
ext_applist=env["EXTRA_EXT_APPS"],
|
|
|
|
hw_target=env.subst("f${TARGET_HW}"),
|
2023-02-07 16:33:05 +00:00
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
raise StopError(e)
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
env.Append(
|
|
|
|
SDK_HEADERS=appbuild.get_sdk_headers(),
|
|
|
|
)
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def DumpApplicationConfig(target, source, env):
|
|
|
|
print(f"Loaded {len(env['APPMGR'].known_apps)} app definitions.")
|
2022-11-02 15:15:40 +00:00
|
|
|
print(fg.boldgreen("Firmware modules configuration:"))
|
2022-06-26 12:00:03 +00:00
|
|
|
for apptype in FlipperAppType:
|
|
|
|
app_sublist = env["APPBUILD"].get_apps_of_type(apptype)
|
|
|
|
if app_sublist:
|
|
|
|
print(
|
2022-11-02 15:15:40 +00:00
|
|
|
fg.green(f"{apptype.value}:\n\t"),
|
2022-06-26 12:00:03 +00:00
|
|
|
", ".join(app.appid for app in app_sublist),
|
|
|
|
)
|
2023-09-05 11:49:39 +00:00
|
|
|
if incompatible_ext_apps := env["APPBUILD"].get_incompatible_ext_apps():
|
|
|
|
print(
|
|
|
|
fg.blue("Incompatible apps (skipped):\n\t"),
|
|
|
|
", ".join(app.appid for app in incompatible_ext_apps),
|
|
|
|
)
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def build_apps_c(target, source, env):
|
|
|
|
target_file_name = target[0].path
|
|
|
|
|
2022-08-12 22:17:11 +00:00
|
|
|
gen = ApplicationsCGenerator(env["APPBUILD"], env.subst("$LOADER_AUTOSTART"))
|
2022-06-26 12:00:03 +00:00
|
|
|
with open(target_file_name, "w") as file:
|
|
|
|
file.write(gen.generate())
|
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
2022-11-02 15:15:40 +00:00
|
|
|
env.AddMethod(LoadAppManifest)
|
2022-06-26 12:00:03 +00:00
|
|
|
env.AddMethod(PrepareApplicationsBuild)
|
2022-11-02 15:15:40 +00:00
|
|
|
env.SetDefault(
|
|
|
|
APPMGR=AppManager(),
|
2022-11-10 11:55:11 +00:00
|
|
|
APPBUILD_DUMP=env.Action(
|
|
|
|
DumpApplicationConfig,
|
|
|
|
"\tINFO\t",
|
|
|
|
),
|
2022-11-02 15:15:40 +00:00
|
|
|
)
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
|
|
|
"ApplicationsC": Builder(
|
2022-06-30 16:06:12 +00:00
|
|
|
action=Action(
|
|
|
|
build_apps_c,
|
|
|
|
"${APPSCOMSTR}",
|
|
|
|
),
|
2022-08-02 14:05:31 +00:00
|
|
|
suffix=".c",
|
2022-06-26 12:00:03 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|