2022-06-26 15:00:03 +03:00
|
|
|
from SCons.Builder import Builder
|
|
|
|
from SCons.Action import Action
|
2022-07-31 02:48:55 +03:00
|
|
|
from SCons.Warnings import warn, WarningOnByDefault
|
2022-06-26 15:00:03 +03:00
|
|
|
import SCons
|
2022-08-02 16:46:43 +03:00
|
|
|
import os.path
|
2022-07-31 02:48:55 +03:00
|
|
|
|
2022-07-14 19:24:26 +03:00
|
|
|
from fbt.appmanifest import (
|
|
|
|
FlipperAppType,
|
|
|
|
AppManager,
|
|
|
|
ApplicationsCGenerator,
|
|
|
|
FlipperManifestException,
|
|
|
|
)
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def LoadApplicationManifests(env):
|
|
|
|
appmgr = env["APPMGR"] = AppManager()
|
2022-09-14 19:11:38 +03:00
|
|
|
for app_dir, _ in env["APPDIRS"]:
|
|
|
|
app_dir_node = env.Dir("#").Dir(app_dir)
|
|
|
|
|
|
|
|
for entry in app_dir_node.glob("*", ondisk=True, source=True):
|
|
|
|
if isinstance(entry, SCons.Node.FS.Dir) and not str(entry).startswith("."):
|
|
|
|
try:
|
|
|
|
app_manifest_file_path = os.path.join(
|
|
|
|
entry.abspath, "application.fam"
|
|
|
|
)
|
|
|
|
appmgr.load_manifest(app_manifest_file_path, entry)
|
|
|
|
env.Append(PY_LINT_SOURCES=[app_manifest_file_path])
|
|
|
|
except FlipperManifestException as e:
|
|
|
|
warn(WarningOnByDefault, str(e))
|
2022-06-26 15:00:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
def PrepareApplicationsBuild(env):
|
2022-09-14 19:11:38 +03:00
|
|
|
appbuild = env["APPBUILD"] = env["APPMGR"].filter_apps(env["APPS"])
|
|
|
|
env.Append(
|
|
|
|
SDK_HEADERS=appbuild.get_sdk_headers(),
|
|
|
|
)
|
2022-06-26 15:00:03 +03:00
|
|
|
env["APPBUILD_DUMP"] = env.Action(
|
|
|
|
DumpApplicationConfig,
|
|
|
|
"\tINFO\t",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def DumpApplicationConfig(target, source, env):
|
|
|
|
print(f"Loaded {len(env['APPMGR'].known_apps)} app definitions.")
|
|
|
|
print("Firmware modules configuration:")
|
|
|
|
for apptype in FlipperAppType:
|
|
|
|
app_sublist = env["APPBUILD"].get_apps_of_type(apptype)
|
|
|
|
if app_sublist:
|
|
|
|
print(
|
|
|
|
f"{apptype.value}:\n\t",
|
|
|
|
", ".join(app.appid for app in app_sublist),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
env.AddMethod(LoadApplicationManifests)
|
|
|
|
env.AddMethod(PrepareApplicationsBuild)
|
|
|
|
|
|
|
|
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
|