SConstruct 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #
  2. # Main Fipper Build System entry point
  3. #
  4. # This file is evaluated by scons (the build system) every time fbt is invoked.
  5. # Scons constructs all referenced environments & their targets' dependency
  6. # trees on startup. So, to keep startup time as low as possible, we're hiding
  7. # construction of certain targets behind command-line options.
  8. import os
  9. DefaultEnvironment(tools=[])
  10. # Progress(["OwO\r", "owo\r", "uwu\r", "owo\r"], interval=15)
  11. # This environment is created only for loading options & validating file/dir existance
  12. fbt_variables = SConscript("site_scons/commandline.scons")
  13. cmd_environment = Environment(tools=[], variables=fbt_variables)
  14. Help(fbt_variables.GenerateHelpText(cmd_environment))
  15. # Building basic environment - tools, utility methods, cross-compilation
  16. # settings, gcc flags for Cortex-M4, basic builders and more
  17. coreenv = SConscript(
  18. "site_scons/environ.scons",
  19. exports={"VAR_ENV": cmd_environment},
  20. )
  21. SConscript("site_scons/cc.scons", exports={"ENV": coreenv})
  22. # Store root dir in environment for certain tools
  23. coreenv["ROOT_DIR"] = Dir(".")
  24. # Create a separate "dist" environment and add construction envs to it
  25. distenv = coreenv.Clone(
  26. tools=["fbt_dist", "openocd"],
  27. GDBOPTS="-ex 'target extended-remote | ${OPENOCD} -c \"gdb_port pipe\" ${OPENOCD_OPTS}' "
  28. '-ex "set confirm off" ',
  29. ENV=os.environ,
  30. )
  31. firmware_out = distenv.AddFwProject(
  32. base_env=coreenv,
  33. fw_type="firmware",
  34. fw_env_key="FW_ENV",
  35. )
  36. # If enabled, initialize updater-related targets
  37. if GetOption("fullenv"):
  38. updater_out = distenv.AddFwProject(
  39. base_env=coreenv,
  40. fw_type="updater",
  41. fw_env_key="UPD_ENV",
  42. )
  43. # Target for self-update package
  44. dist_arguments = [
  45. "-r",
  46. '"${ROOT_DIR.abspath}/assets/resources"',
  47. "--bundlever",
  48. '"${UPDATE_VERSION_STRING}"',
  49. "--radio",
  50. '"${ROOT_DIR.abspath}/${COPRO_STACK_BIN_DIR}/${COPRO_STACK_BIN}"',
  51. "--radiotype",
  52. "${COPRO_STACK_TYPE}",
  53. "${COPRO_DISCLAIMER}",
  54. "--obdata",
  55. '"${ROOT_DIR.abspath}/${COPRO_OB_DATA}"',
  56. ]
  57. if distenv["UPDATE_SPLASH"]:
  58. dist_arguments += [
  59. "--splash",
  60. distenv.subst("assets/slideshow/$UPDATE_SPLASH"),
  61. ]
  62. selfupdate_dist = distenv.DistBuilder(
  63. "selfupdate.pseudo",
  64. (distenv["DIST_DEPENDS"], firmware_out["FW_RESOURCES"]),
  65. DIST_EXTRA=dist_arguments,
  66. )
  67. distenv.Pseudo("selfupdate.pseudo")
  68. AlwaysBuild(selfupdate_dist)
  69. Alias("updater_package", selfupdate_dist)
  70. # Updater debug
  71. debug_updater_elf = distenv.AddDebugTarget(updater_out, False)
  72. Alias("updater_debug", debug_updater_elf)
  73. # Target for copying & renaming binaries to dist folder
  74. basic_dist = distenv.DistBuilder("dist.pseudo", distenv["DIST_DEPENDS"])
  75. distenv.Pseudo("dist.pseudo")
  76. AlwaysBuild(basic_dist)
  77. Alias("fw_dist", basic_dist)
  78. Default(basic_dist)
  79. # Target for bundling core2 package for qFlipper
  80. copro_dist = distenv.CoproBuilder(
  81. Dir("assets/core2_firmware"),
  82. [],
  83. )
  84. AlwaysBuild(copro_dist)
  85. Alias("copro_dist", copro_dist)
  86. # Debugging firmware
  87. debug_fw_elf = distenv.AddDebugTarget(firmware_out)
  88. Alias("debug", debug_fw_elf)
  89. # Debug alien elf
  90. debug_other = distenv.GDBPy(
  91. "debugother.pseudo",
  92. None,
  93. GDBPYOPTS=
  94. # '-ex "source ${ROOT_DIR.abspath}/debug/FreeRTOS/FreeRTOS.py" '
  95. '-ex "source debug/PyCortexMDebug/PyCortexMDebug.py" '
  96. )
  97. distenv.Pseudo("debugother.pseudo")
  98. AlwaysBuild(debug_other)
  99. Alias("debug_other", debug_other)
  100. # Just start OpenOCD
  101. openocd = distenv.OOCDCommand("openocd.pseudo", [])
  102. distenv.Pseudo("openocd.pseudo")
  103. AlwaysBuild(openocd)
  104. Alias("openocd", openocd)
  105. # Linter
  106. lint_check = distenv.Command(
  107. "lint.check.pseudo",
  108. [],
  109. "${PYTHON3} scripts/lint.py check $LINT_SOURCES",
  110. LINT_SOURCES=firmware_out["LINT_SOURCES"],
  111. )
  112. distenv.Pseudo("lint.check.pseudo")
  113. AlwaysBuild(lint_check)
  114. Alias("lint", lint_check)
  115. lint_format = distenv.Command(
  116. "lint.format.pseudo",
  117. [],
  118. "${PYTHON3} scripts/lint.py format $LINT_SOURCES",
  119. LINT_SOURCES=firmware_out["LINT_SOURCES"],
  120. )
  121. distenv.Pseudo("lint.format.pseudo")
  122. AlwaysBuild(lint_format)
  123. Alias("format", lint_format)