mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-13 13:29:50 +04:00
fbt: improvements (#3217)
* fbt: changed cdefines & lib handling for external apps; added extra checks for app manifest fields; moved around AppsC generator * fbt: commandline fixes for spaces in paths * fbt: fixed stringification for FAP_VERSION * fbt: Removed excessive quoting for gdb * docs: update for cdefines; fbt: typo fix * fbt: enforcing at least 2 components in app version= Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,25 +1,118 @@
|
||||
from ansi.color import fg
|
||||
from fbt.appmanifest import (
|
||||
ApplicationsCGenerator,
|
||||
AppManager,
|
||||
AppBuildset,
|
||||
FlipperApplication,
|
||||
FlipperAppType,
|
||||
FlipperManifestException,
|
||||
)
|
||||
from SCons.Action import Action
|
||||
from SCons.Builder import Builder
|
||||
from SCons.Errors import StopError
|
||||
from SCons.Warnings import WarningOnByDefault, warn
|
||||
from SCons.Script import GetOption
|
||||
from SCons.Warnings import WarningOnByDefault, warn
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def LoadAppManifest(env, entry):
|
||||
try:
|
||||
APP_MANIFEST_NAME = "application.fam"
|
||||
manifest_glob = entry.glob(APP_MANIFEST_NAME)
|
||||
manifest_glob = entry.glob(FlipperApplication.APP_MANIFEST_DEFAULT_NAME)
|
||||
if len(manifest_glob) == 0:
|
||||
try:
|
||||
disk_node = next(filter(lambda d: d.exists(), entry.get_all_rdirs()))
|
||||
@@ -27,7 +120,7 @@ def LoadAppManifest(env, entry):
|
||||
disk_node = entry
|
||||
|
||||
raise FlipperManifestException(
|
||||
f"App folder '{disk_node.abspath}': missing manifest ({APP_MANIFEST_NAME})"
|
||||
f"App folder '{disk_node.abspath}': missing manifest ({FlipperApplication.APP_MANIFEST_DEFAULT_NAME})"
|
||||
)
|
||||
|
||||
app_manifest_file_path = manifest_glob[0].rfile().abspath
|
||||
|
||||
Reference in New Issue
Block a user