fbt_apps.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from SCons.Builder import Builder
  2. from SCons.Action import Action
  3. from SCons.Warnings import warn, WarningOnByDefault
  4. import SCons
  5. from ansi.color import fg
  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 LoadAppManifest(env, entry):
  16. try:
  17. APP_MANIFEST_NAME = "application.fam"
  18. manifest_glob = entry.glob(APP_MANIFEST_NAME)
  19. if len(manifest_glob) == 0:
  20. raise FlipperManifestException(
  21. f"Folder {entry}: manifest {APP_MANIFEST_NAME} is missing"
  22. )
  23. app_manifest_file_path = manifest_glob[0].rfile().abspath
  24. env["APPMGR"].load_manifest(app_manifest_file_path, entry)
  25. env.Append(PY_LINT_SOURCES=[app_manifest_file_path])
  26. except FlipperManifestException as e:
  27. warn(WarningOnByDefault, str(e))
  28. def PrepareApplicationsBuild(env):
  29. appbuild = env["APPBUILD"] = env["APPMGR"].filter_apps(env["APPS"])
  30. env.Append(
  31. SDK_HEADERS=appbuild.get_sdk_headers(),
  32. )
  33. env["APPBUILD_DUMP"] = env.Action(
  34. DumpApplicationConfig,
  35. "\tINFO\t",
  36. )
  37. def DumpApplicationConfig(target, source, env):
  38. print(f"Loaded {len(env['APPMGR'].known_apps)} app definitions.")
  39. print(fg.boldgreen("Firmware modules configuration:"))
  40. for apptype in FlipperAppType:
  41. app_sublist = env["APPBUILD"].get_apps_of_type(apptype)
  42. if app_sublist:
  43. print(
  44. fg.green(f"{apptype.value}:\n\t"),
  45. ", ".join(app.appid for app in app_sublist),
  46. )
  47. def build_apps_c(target, source, env):
  48. target_file_name = target[0].path
  49. gen = ApplicationsCGenerator(env["APPBUILD"], env.subst("$LOADER_AUTOSTART"))
  50. with open(target_file_name, "w") as file:
  51. file.write(gen.generate())
  52. def generate(env):
  53. env.AddMethod(LoadAppManifest)
  54. env.AddMethod(PrepareApplicationsBuild)
  55. env.SetDefault(
  56. APPMGR=AppManager(),
  57. )
  58. env.Append(
  59. BUILDERS={
  60. "ApplicationsC": Builder(
  61. action=Action(
  62. build_apps_c,
  63. "${APPSCOMSTR}",
  64. ),
  65. suffix=".c",
  66. ),
  67. }
  68. )
  69. def exists(env):
  70. return True