environ.scons 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from SCons.Platform import TempFileMunge
  2. from fbt.util import (
  3. tempfile_arg_esc_func,
  4. single_quote,
  5. wrap_tempfile,
  6. extract_abs_dir_path,
  7. )
  8. import os
  9. import multiprocessing
  10. Import("VAR_ENV")
  11. forward_os_env = {
  12. # Import PATH from OS env - scons doesn't do that by default
  13. "PATH": os.environ["PATH"],
  14. }
  15. # Proxying CI environment to child processes & scripts
  16. variables_to_forward = [
  17. # CI/CD variables
  18. "WORKFLOW_BRANCH_OR_TAG",
  19. "DIST_SUFFIX",
  20. # Python & other tools
  21. "HOME",
  22. "APPDATA",
  23. "PYTHONHOME",
  24. "PYTHONNOUSERSITE",
  25. "TMP",
  26. "TEMP",
  27. # Colors for tools
  28. "TERM",
  29. ]
  30. if proxy_env := GetOption("proxy_env"):
  31. variables_to_forward.extend(proxy_env.split(","))
  32. for env_value_name in variables_to_forward:
  33. if environ_value := os.environ.get(env_value_name, None):
  34. forward_os_env[env_value_name] = environ_value
  35. coreenv = VAR_ENV.Clone(
  36. tools=[
  37. "fbt_tweaks",
  38. (
  39. "crosscc",
  40. {
  41. "toolchain_prefix": "arm-none-eabi-",
  42. "versions": VAR_ENV["FBT_TOOLCHAIN_VERSIONS"],
  43. },
  44. ),
  45. "python3",
  46. "sconsmodular",
  47. "sconsrecursiveglob",
  48. "ccache",
  49. ],
  50. TEMPFILE=TempFileMunge,
  51. MAXLINELENGTH=2048,
  52. PROGSUFFIX=".elf",
  53. ENV=forward_os_env,
  54. SINGLEQUOTEFUNC=single_quote,
  55. ABSPATHGETTERFUNC=extract_abs_dir_path,
  56. # Setting up temp file parameters - to overcome command line length limits
  57. TEMPFILEARGESCFUNC=tempfile_arg_esc_func,
  58. ROOT_DIR=Dir("#"),
  59. FBT_SCRIPT_DIR="${ROOT_DIR}/scripts",
  60. )
  61. # If DIST_SUFFIX is set in environment, is has precedence (set by CI)
  62. if os_suffix := os.environ.get("DIST_SUFFIX", None):
  63. coreenv.Replace(
  64. DIST_SUFFIX=os_suffix,
  65. )
  66. # Default value for commandline options
  67. SetOption("num_jobs", multiprocessing.cpu_count())
  68. ## NB - disabled both caches since they seem to do more harm then good in our case
  69. # Avoiding re-scan of all sources on every startup
  70. # SetOption("implicit_cache", True)
  71. # SetOption("implicit_deps_unchanged", True)
  72. # More aggressive caching
  73. SetOption("max_drift", 1)
  74. # Random task queue - to discover isses with build logic faster
  75. # SetOption("random", 1)
  76. wrap_tempfile(coreenv, "LINKCOM")
  77. wrap_tempfile(coreenv, "ARCOM")
  78. Return("coreenv")