My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

preprocessor.py 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #
  2. # preprocessor.py
  3. #
  4. import subprocess,os,re
  5. verbose = 0
  6. def blab(str):
  7. if verbose:
  8. print(str)
  9. ################################################################################
  10. #
  11. # Invoke GCC to run the preprocessor and extract enabled features
  12. #
  13. preprocessor_cache = {}
  14. def run_preprocessor(env, fn=None):
  15. filename = fn or 'buildroot/share/PlatformIO/scripts/common-dependencies.h'
  16. if filename in preprocessor_cache:
  17. return preprocessor_cache[filename]
  18. # Process defines
  19. build_flags = env.get('BUILD_FLAGS')
  20. build_flags = env.ParseFlagsExtended(build_flags)
  21. cxx = search_compiler(env)
  22. cmd = ['"' + cxx + '"']
  23. # Build flags from board.json
  24. #if 'BOARD' in env:
  25. # cmd += [env.BoardConfig().get("build.extra_flags")]
  26. for s in build_flags['CPPDEFINES']:
  27. if isinstance(s, tuple):
  28. cmd += ['-D' + s[0] + '=' + str(s[1])]
  29. else:
  30. cmd += ['-D' + s]
  31. cmd += ['-D__MARLIN_DEPS__ -w -dM -E -x c++']
  32. depcmd = cmd + [ filename ]
  33. cmd = ' '.join(depcmd)
  34. blab(cmd)
  35. define_list = subprocess.check_output(cmd, shell=True).splitlines()
  36. preprocessor_cache[filename] = define_list
  37. return define_list
  38. ################################################################################
  39. #
  40. # Find a compiler, considering the OS
  41. #
  42. def search_compiler(env):
  43. ENV_BUILD_PATH = os.path.join(env.Dictionary('PROJECT_BUILD_DIR'), env['PIOENV'])
  44. GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path")
  45. try:
  46. filepath = env.GetProjectOption('custom_gcc')
  47. blab("Getting compiler from env")
  48. return filepath
  49. except:
  50. pass
  51. if os.path.exists(GCC_PATH_CACHE):
  52. blab("Getting g++ path from cache")
  53. with open(GCC_PATH_CACHE, 'r') as f:
  54. return f.read()
  55. # Find the current platform compiler by searching the $PATH
  56. # which will be in a platformio toolchain bin folder
  57. path_regex = re.escape(env['PROJECT_PACKAGES_DIR'])
  58. gcc = "g++"
  59. if env['PLATFORM'] == 'win32':
  60. path_separator = ';'
  61. path_regex += r'.*\\bin'
  62. gcc += ".exe"
  63. else:
  64. path_separator = ':'
  65. path_regex += r'/.+/bin'
  66. # Search for the compiler
  67. for pathdir in env['ENV']['PATH'].split(path_separator):
  68. if not re.search(path_regex, pathdir, re.IGNORECASE):
  69. continue
  70. for filepath in os.listdir(pathdir):
  71. if not filepath.endswith(gcc):
  72. continue
  73. # Use entire path to not rely on env PATH
  74. filepath = os.path.sep.join([pathdir, filepath])
  75. # Cache the g++ path to no search always
  76. if os.path.exists(ENV_BUILD_PATH):
  77. blab("Caching g++ for current env")
  78. with open(GCC_PATH_CACHE, 'w+') as f:
  79. f.write(filepath)
  80. return filepath
  81. filepath = env.get('CXX')
  82. blab("Couldn't find a compiler! Fallback to %s" % filepath)
  83. return filepath