|
@@ -30,12 +30,8 @@ def load_config():
|
30
|
30
|
parts = dep.split('=')
|
31
|
31
|
name = parts.pop(0)
|
32
|
32
|
rest = '='.join(parts)
|
33
|
|
- if name == 'extra_scripts':
|
34
|
|
- FEATURE_DEPENDENCIES[ukey]['extra_scripts'] = rest
|
35
|
|
- elif name == 'src_filter':
|
36
|
|
- FEATURE_DEPENDENCIES[ukey]['src_filter'] = rest
|
37
|
|
- elif name == 'lib_ignore':
|
38
|
|
- FEATURE_DEPENDENCIES[ukey]['lib_ignore'] = rest
|
|
33
|
+ if name in ['extra_scripts', 'src_filter', 'lib_ignore']:
|
|
34
|
+ FEATURE_DEPENDENCIES[ukey][name] = rest
|
39
|
35
|
else:
|
40
|
36
|
FEATURE_DEPENDENCIES[ukey]['lib_deps'] += [dep]
|
41
|
37
|
|
|
@@ -57,15 +53,14 @@ def get_all_env_libs():
|
57
|
53
|
env_libs.append(name)
|
58
|
54
|
return env_libs
|
59
|
55
|
|
60
|
|
-# We need to ignore all non-used libs,
|
61
|
|
-# so if a lib folder lay forgotten in .pio/lib_deps, it
|
62
|
|
-# will not break compiling
|
|
56
|
+# All unused libs should be ignored so that if a library
|
|
57
|
+# exists in .pio/lib_deps it will not break compilation.
|
63
|
58
|
def force_ignore_unused_libs():
|
64
|
59
|
env_libs = get_all_env_libs()
|
65
|
60
|
known_libs = get_all_known_libs()
|
66
|
61
|
diff = (list(set(known_libs) - set(env_libs)))
|
67
|
62
|
lib_ignore = env.GetProjectOption("lib_ignore") + diff
|
68
|
|
- print("Ignoring libs: ", lib_ignore)
|
|
63
|
+ print("Ignoring libs:", lib_ignore)
|
69
|
64
|
proj = env.GetProjectConfig()
|
70
|
65
|
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
|
71
|
66
|
|
|
@@ -84,23 +79,23 @@ def install_features_dependencies():
|
84
|
79
|
name, _, _ = PackageManager.parse_pkg_uri(dep)
|
85
|
80
|
deps_to_add[name] = dep
|
86
|
81
|
|
87
|
|
- # first check if the env already have the dep
|
|
82
|
+ # Does the env already have the dependency?
|
88
|
83
|
deps = env.GetProjectOption("lib_deps")
|
89
|
84
|
for dep in deps:
|
90
|
85
|
name, _, _ = PackageManager.parse_pkg_uri(dep)
|
91
|
86
|
if name in deps_to_add:
|
92
|
87
|
del deps_to_add[name]
|
93
|
88
|
|
94
|
|
- # check if we need ignore any lib
|
|
89
|
+ # Are there any libraries that should be ignored?
|
95
|
90
|
lib_ignore = env.GetProjectOption("lib_ignore")
|
96
|
91
|
for dep in deps:
|
97
|
92
|
name, _, _ = PackageManager.parse_pkg_uri(dep)
|
98
|
93
|
if name in deps_to_add:
|
99
|
94
|
del deps_to_add[name]
|
100
|
95
|
|
101
|
|
- # any left?
|
|
96
|
+ # Is there anything left?
|
102
|
97
|
if len(deps_to_add) > 0:
|
103
|
|
- # add only the missing deps
|
|
98
|
+ # Only add the missing dependencies
|
104
|
99
|
proj = env.GetProjectConfig()
|
105
|
100
|
proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values()))
|
106
|
101
|
|
|
@@ -129,45 +124,72 @@ def install_features_dependencies():
|
129
|
124
|
proj = env.GetProjectConfig()
|
130
|
125
|
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
|
131
|
126
|
|
132
|
|
-# search the current compiler, considering the OS
|
|
127
|
+#
|
|
128
|
+# Find a compiler, considering the OS
|
|
129
|
+#
|
|
130
|
+ENV_BUILD_PATH = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env["PIOENV"])
|
|
131
|
+GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path")
|
133
|
132
|
def search_compiler():
|
|
133
|
+ if os.path.exists(GCC_PATH_CACHE):
|
|
134
|
+ print('Getting g++ path from cache')
|
|
135
|
+ with open(GCC_PATH_CACHE, 'r') as f:
|
|
136
|
+ return f.read()
|
|
137
|
+
|
|
138
|
+ # PlatformIO inserts the toolchain bin folder on the front of the $PATH
|
|
139
|
+ # Find the current platform compiler by searching the $PATH
|
134
|
140
|
if env['PLATFORM'] == 'win32':
|
135
|
|
- # the first path have the compiler
|
136
|
|
- for path in env['ENV']['PATH'].split(';'):
|
137
|
|
- if not re.search(r'platformio\\packages.*\\bin', path):
|
138
|
|
- continue
|
139
|
|
- #print(path)
|
140
|
|
- for file in os.listdir(path):
|
141
|
|
- if file.endswith("g++.exe"):
|
142
|
|
- return file
|
143
|
|
- print("Could not find the g++")
|
144
|
|
- return None
|
|
141
|
+ path_separator = ';'
|
|
142
|
+ path_regex = r'platformio\\packages.*\\bin'
|
|
143
|
+ gcc = "g++.exe"
|
145
|
144
|
else:
|
146
|
|
- return env.get('CXX')
|
|
145
|
+ path_separator = ':'
|
|
146
|
+ path_regex = r'platformio/packages.*/bin'
|
|
147
|
+ gcc = "g++"
|
|
148
|
+
|
|
149
|
+ # Search for the compiler
|
|
150
|
+ for path in env['ENV']['PATH'].split(path_separator):
|
|
151
|
+ if not re.search(path_regex, path):
|
|
152
|
+ continue
|
|
153
|
+ for file in os.listdir(path):
|
|
154
|
+ if not file.endswith(gcc):
|
|
155
|
+ continue
|
|
156
|
+
|
|
157
|
+ # Cache the g++ path to no search always
|
|
158
|
+ if os.path.exists(ENV_BUILD_PATH):
|
|
159
|
+ print('Caching g++ for current env')
|
|
160
|
+ with open(GCC_PATH_CACHE, 'w+') as f:
|
|
161
|
+ f.write(file)
|
|
162
|
+
|
|
163
|
+ return file
|
147
|
164
|
|
|
165
|
+ file = env.get('CXX')
|
|
166
|
+ print("Couldn't find a compiler! Fallback to", file)
|
|
167
|
+ return file
|
148
|
168
|
|
149
|
|
-# load marlin features
|
|
169
|
+#
|
|
170
|
+# Use the compiler to get a list of all enabled features
|
|
171
|
+#
|
150
|
172
|
def load_marlin_features():
|
151
|
173
|
if "MARLIN_FEATURES" in env:
|
152
|
174
|
return
|
153
|
175
|
|
154
|
|
- # procces defines
|
155
|
|
- # print(env.Dump())
|
|
176
|
+ # Process defines
|
|
177
|
+ #print(env.Dump())
|
156
|
178
|
build_flags = env.get('BUILD_FLAGS')
|
157
|
179
|
build_flags = env.ParseFlagsExtended(build_flags)
|
158
|
180
|
|
159
|
181
|
cxx = search_compiler()
|
160
|
182
|
cmd = [cxx]
|
161
|
183
|
|
162
|
|
- # build flags from board.json
|
163
|
|
- # if 'BOARD' in env:
|
164
|
|
- # cmd += [env.BoardConfig().get("build.extra_flags")]
|
|
184
|
+ # Build flags from board.json
|
|
185
|
+ #if 'BOARD' in env:
|
|
186
|
+ # cmd += [env.BoardConfig().get("build.extra_flags")]
|
165
|
187
|
for s in build_flags['CPPDEFINES']:
|
166
|
188
|
if isinstance(s, tuple):
|
167
|
189
|
cmd += ['-D' + s[0] + '=' + str(s[1])]
|
168
|
190
|
else:
|
169
|
191
|
cmd += ['-D' + s]
|
170
|
|
- # cmd += ['-w -dM -E -x c++ Marlin/src/inc/MarlinConfigPre.h']
|
|
192
|
+
|
171
|
193
|
cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-features-dependencies.h']
|
172
|
194
|
cmd = ' '.join(cmd)
|
173
|
195
|
print(cmd)
|
|
@@ -179,15 +201,22 @@ def load_marlin_features():
|
179
|
201
|
marlin_features[feature] = definition
|
180
|
202
|
env["MARLIN_FEATURES"] = marlin_features
|
181
|
203
|
|
|
204
|
+#
|
|
205
|
+# Return True if a matching feature is enabled
|
|
206
|
+#
|
182
|
207
|
def MarlinFeatureIsEnabled(env, feature):
|
183
|
208
|
load_marlin_features()
|
184
|
209
|
r = re.compile(feature)
|
185
|
210
|
matches = list(filter(r.match, env["MARLIN_FEATURES"]))
|
186
|
211
|
return len(matches) > 0
|
187
|
212
|
|
188
|
|
-# add a method for others scripts to check if a feature is enabled
|
|
213
|
+#
|
|
214
|
+# Add a method for other PIO scripts to query enabled features
|
|
215
|
+#
|
189
|
216
|
env.AddMethod(MarlinFeatureIsEnabled)
|
190
|
217
|
|
191
|
|
-# install all dependencies for features enabled in Configuration.h
|
|
218
|
+#
|
|
219
|
+# Add dependencies for enabled Marlin features
|
|
220
|
+#
|
192
|
221
|
install_features_dependencies()
|
193
|
222
|
force_ignore_unused_libs()
|