fbt_apps.py 2.0 KB

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