fbt_apps.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from SCons.Builder import Builder
  2. from SCons.Action import Action
  3. from SCons.Warnings import warn, WarningOnByDefault
  4. import SCons
  5. import os.path
  6. from fbt.appmanifest import (
  7. FlipperAppType,
  8. AppManager,
  9. ApplicationsCGenerator,
  10. FlipperManifestException,
  11. )
  12. # Adding objects for application management to env
  13. # AppManager env["APPMGR"] - loads all manifests; manages list of known apps
  14. # AppBuildset env["APPBUILD"] - contains subset of apps, filtered for current config
  15. def LoadApplicationManifests(env):
  16. appmgr = env["APPMGR"] = AppManager()
  17. for entry in env.Glob("#/applications/*", ondisk=True, source=True):
  18. if isinstance(entry, SCons.Node.FS.Dir) and not str(entry).startswith("."):
  19. try:
  20. app_manifest_file_path = os.path.join(entry.abspath, "application.fam")
  21. appmgr.load_manifest(app_manifest_file_path, entry.name)
  22. env.Append(PY_LINT_SOURCES=[app_manifest_file_path])
  23. except FlipperManifestException as e:
  24. warn(WarningOnByDefault, str(e))
  25. def PrepareApplicationsBuild(env):
  26. env["APPBUILD"] = env["APPMGR"].filter_apps(env["APPS"])
  27. env["APPBUILD_DUMP"] = env.Action(
  28. DumpApplicationConfig,
  29. "\tINFO\t",
  30. )
  31. def DumpApplicationConfig(target, source, env):
  32. print(f"Loaded {len(env['APPMGR'].known_apps)} app definitions.")
  33. print("Firmware modules configuration:")
  34. for apptype in FlipperAppType:
  35. app_sublist = env["APPBUILD"].get_apps_of_type(apptype)
  36. if app_sublist:
  37. print(
  38. f"{apptype.value}:\n\t",
  39. ", ".join(app.appid for app in app_sublist),
  40. )
  41. def build_apps_c(target, source, env):
  42. target_file_name = target[0].path
  43. gen = ApplicationsCGenerator(env["APPBUILD"], env.subst("$LOADER_AUTOSTART"))
  44. with open(target_file_name, "w") as file:
  45. file.write(gen.generate())
  46. def generate(env):
  47. env.AddMethod(LoadApplicationManifests)
  48. env.AddMethod(PrepareApplicationsBuild)
  49. env.Append(
  50. BUILDERS={
  51. "ApplicationsC": Builder(
  52. action=Action(
  53. build_apps_c,
  54. "${APPSCOMSTR}",
  55. ),
  56. suffix=".c",
  57. ),
  58. }
  59. )
  60. def exists(env):
  61. return True