My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preprocessor.py 2.7KB

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