2022-11-02 18:15:40 +03:00
|
|
|
from ansi.color import fg
|
2022-07-14 19:24:26 +03:00
|
|
|
from fbt.appmanifest import (
|
2023-05-03 08:48:49 +03:00
|
|
|
AppManager,
|
2023-11-15 19:27:35 +03:00
|
|
|
AppBuildset,
|
|
|
|
FlipperApplication,
|
2023-05-03 08:48:49 +03:00
|
|
|
FlipperAppType,
|
2022-07-14 19:24:26 +03:00
|
|
|
FlipperManifestException,
|
|
|
|
)
|
2023-05-03 08:48:49 +03:00
|
|
|
from SCons.Action import Action
|
|
|
|
from SCons.Builder import Builder
|
|
|
|
from SCons.Errors import StopError
|
2023-05-08 14:01:52 +03:00
|
|
|
from SCons.Script import GetOption
|
2023-11-15 19:27:35 +03:00
|
|
|
from SCons.Warnings import WarningOnByDefault, warn
|
2022-06-26 15:00:03 +03: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 19:27:35 +03: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:
|
|
|
|
return f"extern void {app.entry_point}();"
|
|
|
|
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 18:15:40 +03:00
|
|
|
def LoadAppManifest(env, entry):
|
|
|
|
try:
|
2023-11-15 19:27:35 +03:00
|
|
|
manifest_glob = entry.glob(FlipperApplication.APP_MANIFEST_DEFAULT_NAME)
|
2022-11-02 18:15:40 +03:00
|
|
|
if len(manifest_glob) == 0:
|
2023-11-02 16:28:39 +03:00
|
|
|
try:
|
|
|
|
disk_node = next(filter(lambda d: d.exists(), entry.get_all_rdirs()))
|
|
|
|
except Exception:
|
|
|
|
disk_node = entry
|
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
raise FlipperManifestException(
|
2023-11-15 19:27:35 +03:00
|
|
|
f"App folder '{disk_node.abspath}': missing manifest ({FlipperApplication.APP_MANIFEST_DEFAULT_NAME})"
|
2022-11-02 18:15:40 +03:00
|
|
|
)
|
2022-09-14 19:11:38 +03:00
|
|
|
|
2022-11-02 18:15:40 +03:00
|
|
|
app_manifest_file_path = manifest_glob[0].rfile().abspath
|
|
|
|
env["APPMGR"].load_manifest(app_manifest_file_path, entry)
|
|
|
|
env.Append(PY_LINT_SOURCES=[app_manifest_file_path])
|
|
|
|
except FlipperManifestException as e:
|
2023-05-08 14:01:52 +03:00
|
|
|
if not GetOption("silent"):
|
|
|
|
warn(WarningOnByDefault, str(e))
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
def PrepareApplicationsBuild(env):
|
2023-02-07 19:33:05 +03:00
|
|
|
try:
|
|
|
|
appbuild = env["APPBUILD"] = env["APPMGR"].filter_apps(
|
2023-09-05 14:49:39 +03:00
|
|
|
applist=env["APPS"],
|
|
|
|
ext_applist=env["EXTRA_EXT_APPS"],
|
|
|
|
hw_target=env.subst("f${TARGET_HW}"),
|
2023-02-07 19:33:05 +03:00
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
raise StopError(e)
|
|
|
|
|
2022-09-14 19:11:38 +03:00
|
|
|
env.Append(
|
|
|
|
SDK_HEADERS=appbuild.get_sdk_headers(),
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
def DumpApplicationConfig(target, source, env):
|
|
|
|
print(f"Loaded {len(env['APPMGR'].known_apps)} app definitions.")
|
2022-11-02 18:15:40 +03:00
|
|
|
print(fg.boldgreen("Firmware modules configuration:"))
|
2022-06-26 15:00:03 +03:00
|
|
|
for apptype in FlipperAppType:
|
|
|
|
app_sublist = env["APPBUILD"].get_apps_of_type(apptype)
|
|
|
|
if app_sublist:
|
|
|
|
print(
|
2022-11-02 18:15:40 +03:00
|
|
|
fg.green(f"{apptype.value}:\n\t"),
|
2022-06-26 15:00:03 +03:00
|
|
|
", ".join(app.appid for app in app_sublist),
|
|
|
|
)
|
2023-09-05 14:49:39 +03: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 15:00:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
def build_apps_c(target, source, env):
|
|
|
|
target_file_name = target[0].path
|
|
|
|
|
2022-08-13 01:17:11 +03:00
|
|
|
gen = ApplicationsCGenerator(env["APPBUILD"], env.subst("$LOADER_AUTOSTART"))
|
2022-06-26 15:00:03 +03:00
|
|
|
with open(target_file_name, "w") as file:
|
|
|
|
file.write(gen.generate())
|
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
2022-11-02 18:15:40 +03:00
|
|
|
env.AddMethod(LoadAppManifest)
|
2022-06-26 15:00:03 +03:00
|
|
|
env.AddMethod(PrepareApplicationsBuild)
|
2022-11-02 18:15:40 +03:00
|
|
|
env.SetDefault(
|
|
|
|
APPMGR=AppManager(),
|
2022-11-10 14:55:11 +03:00
|
|
|
APPBUILD_DUMP=env.Action(
|
|
|
|
DumpApplicationConfig,
|
|
|
|
"\tINFO\t",
|
|
|
|
),
|
2022-11-02 18:15:40 +03:00
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
|
|
|
"ApplicationsC": Builder(
|
2022-06-30 19:06:12 +03:00
|
|
|
action=Action(
|
|
|
|
build_apps_c,
|
|
|
|
"${APPSCOMSTR}",
|
|
|
|
),
|
2022-08-02 17:05:31 +03:00
|
|
|
suffix=".c",
|
2022-06-26 15:00:03 +03:00
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|