My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

common-dependencies.py 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #
  2. # common-dependencies.py
  3. # Convenience script to check dependencies and add libs and sources for Marlin Enabled Features
  4. #
  5. import pioutil
  6. if pioutil.is_pio_build():
  7. import subprocess,os,re
  8. Import("env")
  9. from platformio.package.meta import PackageSpec
  10. from platformio.project.config import ProjectConfig
  11. verbose = 0
  12. FEATURE_CONFIG = {}
  13. def validate_pio():
  14. PIO_VERSION_MIN = (6, 0, 1)
  15. try:
  16. from platformio import VERSION as PIO_VERSION
  17. weights = (1000, 100, 1)
  18. version_min = sum([x[0] * float(re.sub(r'[^0-9]', '.', str(x[1]))) for x in zip(weights, PIO_VERSION_MIN)])
  19. version_cur = sum([x[0] * float(re.sub(r'[^0-9]', '.', str(x[1]))) for x in zip(weights, PIO_VERSION)])
  20. if version_cur < version_min:
  21. print()
  22. print("**************************************************")
  23. print("****** An update to PlatformIO is ******")
  24. print("****** required to build Marlin Firmware. ******")
  25. print("****** ******")
  26. print("****** Minimum version: ", PIO_VERSION_MIN, " ******")
  27. print("****** Current Version: ", PIO_VERSION, " ******")
  28. print("****** ******")
  29. print("****** Update PlatformIO and try again. ******")
  30. print("**************************************************")
  31. print()
  32. exit(1)
  33. except SystemExit:
  34. exit(1)
  35. except:
  36. print("Can't detect PlatformIO Version")
  37. def blab(str,level=1):
  38. if verbose >= level:
  39. print("[deps] %s" % str)
  40. def add_to_feat_cnf(feature, flines):
  41. try:
  42. feat = FEATURE_CONFIG[feature]
  43. except:
  44. FEATURE_CONFIG[feature] = {}
  45. # Get a reference to the FEATURE_CONFIG under construction
  46. feat = FEATURE_CONFIG[feature]
  47. # Split up passed lines on commas or newlines and iterate
  48. # Add common options to the features config under construction
  49. # For lib_deps replace a previous instance of the same library
  50. atoms = re.sub(r',\s*', '\n', flines).strip().split('\n')
  51. for line in atoms:
  52. parts = line.split('=')
  53. name = parts.pop(0)
  54. if name in ['build_flags', 'extra_scripts', 'src_filter', 'lib_ignore']:
  55. feat[name] = '='.join(parts)
  56. blab("[%s] %s=%s" % (feature, name, feat[name]), 3)
  57. else:
  58. for dep in re.split(r',\s*', line):
  59. lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0)
  60. lib_re = re.compile('(?!^' + lib_name + '\\b)')
  61. feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]
  62. blab("[%s] lib_deps = %s" % (feature, dep), 3)
  63. def load_features():
  64. blab("========== Gather [features] entries...")
  65. for key in ProjectConfig().items('features'):
  66. feature = key[0].upper()
  67. if not feature in FEATURE_CONFIG:
  68. FEATURE_CONFIG[feature] = { 'lib_deps': [] }
  69. add_to_feat_cnf(feature, key[1])
  70. # Add options matching custom_marlin.MY_OPTION to the pile
  71. blab("========== Gather custom_marlin entries...")
  72. for n in env.GetProjectOptions():
  73. key = n[0]
  74. mat = re.match(r'custom_marlin\.(.+)', key)
  75. if mat:
  76. try:
  77. val = env.GetProjectOption(key)
  78. except:
  79. val = None
  80. if val:
  81. opt = mat[1].upper()
  82. blab("%s.custom_marlin.%s = '%s'" % ( env['PIOENV'], opt, val ))
  83. add_to_feat_cnf(opt, val)
  84. def get_all_known_libs():
  85. known_libs = []
  86. for feature in FEATURE_CONFIG:
  87. feat = FEATURE_CONFIG[feature]
  88. if not 'lib_deps' in feat:
  89. continue
  90. for dep in feat['lib_deps']:
  91. known_libs.append(PackageSpec(dep).name)
  92. return known_libs
  93. def get_all_env_libs():
  94. env_libs = []
  95. lib_deps = env.GetProjectOption('lib_deps')
  96. for dep in lib_deps:
  97. env_libs.append(PackageSpec(dep).name)
  98. return env_libs
  99. def set_env_field(field, value):
  100. proj = env.GetProjectConfig()
  101. proj.set("env:" + env['PIOENV'], field, value)
  102. # All unused libs should be ignored so that if a library
  103. # exists in .pio/lib_deps it will not break compilation.
  104. def force_ignore_unused_libs():
  105. env_libs = get_all_env_libs()
  106. known_libs = get_all_known_libs()
  107. diff = (list(set(known_libs) - set(env_libs)))
  108. lib_ignore = env.GetProjectOption('lib_ignore') + diff
  109. blab("Ignore libraries: %s" % lib_ignore)
  110. set_env_field('lib_ignore', lib_ignore)
  111. def apply_features_config():
  112. load_features()
  113. blab("========== Apply enabled features...")
  114. for feature in FEATURE_CONFIG:
  115. if not env.MarlinHas(feature):
  116. continue
  117. feat = FEATURE_CONFIG[feature]
  118. if 'lib_deps' in feat and len(feat['lib_deps']):
  119. blab("========== Adding lib_deps for %s... " % feature, 2)
  120. # feat to add
  121. deps_to_add = {}
  122. for dep in feat['lib_deps']:
  123. deps_to_add[PackageSpec(dep).name] = dep
  124. blab("==================== %s... " % dep, 2)
  125. # Does the env already have the dependency?
  126. deps = env.GetProjectOption('lib_deps')
  127. for dep in deps:
  128. name = PackageSpec(dep).name
  129. if name in deps_to_add:
  130. del deps_to_add[name]
  131. # Are there any libraries that should be ignored?
  132. lib_ignore = env.GetProjectOption('lib_ignore')
  133. for dep in deps:
  134. name = PackageSpec(dep).name
  135. if name in deps_to_add:
  136. del deps_to_add[name]
  137. # Is there anything left?
  138. if len(deps_to_add) > 0:
  139. # Only add the missing dependencies
  140. set_env_field('lib_deps', deps + list(deps_to_add.values()))
  141. if 'build_flags' in feat:
  142. f = feat['build_flags']
  143. blab("========== Adding build_flags for %s: %s" % (feature, f), 2)
  144. new_flags = env.GetProjectOption('build_flags') + [ f ]
  145. env.Replace(BUILD_FLAGS=new_flags)
  146. if 'extra_scripts' in feat:
  147. blab("Running extra_scripts for %s... " % feature, 2)
  148. env.SConscript(feat['extra_scripts'], exports="env")
  149. if 'src_filter' in feat:
  150. blab("========== Adding build_src_filter for %s... " % feature, 2)
  151. src_filter = ' '.join(env.GetProjectOption('src_filter'))
  152. # first we need to remove the references to the same folder
  153. my_srcs = re.findall(r'[+-](<.*?>)', feat['src_filter'])
  154. cur_srcs = re.findall(r'[+-](<.*?>)', src_filter)
  155. for d in my_srcs:
  156. if d in cur_srcs:
  157. src_filter = re.sub(r'[+-]' + d, '', src_filter)
  158. src_filter = feat['src_filter'] + ' ' + src_filter
  159. set_env_field('build_src_filter', [src_filter])
  160. env.Replace(SRC_FILTER=src_filter)
  161. if 'lib_ignore' in feat:
  162. blab("========== Adding lib_ignore for %s... " % feature, 2)
  163. lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']]
  164. set_env_field('lib_ignore', lib_ignore)
  165. #
  166. # Use the compiler to get a list of all enabled features
  167. #
  168. def load_marlin_features():
  169. if 'MARLIN_FEATURES' in env:
  170. return
  171. # Process defines
  172. from preprocessor import run_preprocessor
  173. define_list = run_preprocessor(env)
  174. marlin_features = {}
  175. for define in define_list:
  176. feature = define[8:].strip().decode().split(' ')
  177. feature, definition = feature[0], ' '.join(feature[1:])
  178. marlin_features[feature] = definition
  179. env['MARLIN_FEATURES'] = marlin_features
  180. #
  181. # Return True if a matching feature is enabled
  182. #
  183. def MarlinHas(env, feature):
  184. load_marlin_features()
  185. r = re.compile('^' + feature + '$')
  186. found = list(filter(r.match, env['MARLIN_FEATURES']))
  187. # Defines could still be 'false' or '0', so check
  188. some_on = False
  189. if len(found):
  190. for f in found:
  191. val = env['MARLIN_FEATURES'][f]
  192. if val in [ '', '1', 'true' ]:
  193. some_on = True
  194. elif val in env['MARLIN_FEATURES']:
  195. some_on = env.MarlinHas(val)
  196. return some_on
  197. validate_pio()
  198. try:
  199. verbose = int(env.GetProjectOption('custom_verbose'))
  200. except:
  201. pass
  202. #
  203. # Add a method for other PIO scripts to query enabled features
  204. #
  205. env.AddMethod(MarlinHas)
  206. #
  207. # Add dependencies for enabled Marlin features
  208. #
  209. apply_features_config()
  210. force_ignore_unused_libs()
  211. #print(env.Dump())
  212. from signature import compute_build_signature
  213. compute_build_signature(env)