|
@ -30,12 +30,8 @@ def load_config(): |
|
|
parts = dep.split('=') |
|
|
parts = dep.split('=') |
|
|
name = parts.pop(0) |
|
|
name = parts.pop(0) |
|
|
rest = '='.join(parts) |
|
|
rest = '='.join(parts) |
|
|
if name == 'extra_scripts': |
|
|
if name in ['extra_scripts', 'src_filter', 'lib_ignore']: |
|
|
FEATURE_DEPENDENCIES[ukey]['extra_scripts'] = rest |
|
|
FEATURE_DEPENDENCIES[ukey][name] = rest |
|
|
elif name == 'src_filter': |
|
|
|
|
|
FEATURE_DEPENDENCIES[ukey]['src_filter'] = rest |
|
|
|
|
|
elif name == 'lib_ignore': |
|
|
|
|
|
FEATURE_DEPENDENCIES[ukey]['lib_ignore'] = rest |
|
|
|
|
|
else: |
|
|
else: |
|
|
FEATURE_DEPENDENCIES[ukey]['lib_deps'] += [dep] |
|
|
FEATURE_DEPENDENCIES[ukey]['lib_deps'] += [dep] |
|
|
|
|
|
|
|
@ -57,9 +53,8 @@ def get_all_env_libs(): |
|
|
env_libs.append(name) |
|
|
env_libs.append(name) |
|
|
return env_libs |
|
|
return env_libs |
|
|
|
|
|
|
|
|
# We need to ignore all non-used libs, |
|
|
# All unused libs should be ignored so that if a library |
|
|
# so if a lib folder lay forgotten in .pio/lib_deps, it |
|
|
# exists in .pio/lib_deps it will not break compilation. |
|
|
# will not break compiling |
|
|
|
|
|
def force_ignore_unused_libs(): |
|
|
def force_ignore_unused_libs(): |
|
|
env_libs = get_all_env_libs() |
|
|
env_libs = get_all_env_libs() |
|
|
known_libs = get_all_known_libs() |
|
|
known_libs = get_all_known_libs() |
|
@ -84,23 +79,23 @@ def install_features_dependencies(): |
|
|
name, _, _ = PackageManager.parse_pkg_uri(dep) |
|
|
name, _, _ = PackageManager.parse_pkg_uri(dep) |
|
|
deps_to_add[name] = dep |
|
|
deps_to_add[name] = dep |
|
|
|
|
|
|
|
|
# first check if the env already have the dep |
|
|
# Does the env already have the dependency? |
|
|
deps = env.GetProjectOption("lib_deps") |
|
|
deps = env.GetProjectOption("lib_deps") |
|
|
for dep in deps: |
|
|
for dep in deps: |
|
|
name, _, _ = PackageManager.parse_pkg_uri(dep) |
|
|
name, _, _ = PackageManager.parse_pkg_uri(dep) |
|
|
if name in deps_to_add: |
|
|
if name in deps_to_add: |
|
|
del deps_to_add[name] |
|
|
del deps_to_add[name] |
|
|
|
|
|
|
|
|
# check if we need ignore any lib |
|
|
# Are there any libraries that should be ignored? |
|
|
lib_ignore = env.GetProjectOption("lib_ignore") |
|
|
lib_ignore = env.GetProjectOption("lib_ignore") |
|
|
for dep in deps: |
|
|
for dep in deps: |
|
|
name, _, _ = PackageManager.parse_pkg_uri(dep) |
|
|
name, _, _ = PackageManager.parse_pkg_uri(dep) |
|
|
if name in deps_to_add: |
|
|
if name in deps_to_add: |
|
|
del deps_to_add[name] |
|
|
del deps_to_add[name] |
|
|
|
|
|
|
|
|
# any left? |
|
|
# Is there anything left? |
|
|
if len(deps_to_add) > 0: |
|
|
if len(deps_to_add) > 0: |
|
|
# add only the missing deps |
|
|
# Only add the missing dependencies |
|
|
proj = env.GetProjectConfig() |
|
|
proj = env.GetProjectConfig() |
|
|
proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values())) |
|
|
proj.set("env:" + env["PIOENV"], "lib_deps", deps + list(deps_to_add.values())) |
|
|
|
|
|
|
|
@ -129,29 +124,56 @@ def install_features_dependencies(): |
|
|
proj = env.GetProjectConfig() |
|
|
proj = env.GetProjectConfig() |
|
|
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore) |
|
|
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore) |
|
|
|
|
|
|
|
|
# search the current compiler, considering the OS |
|
|
# |
|
|
|
|
|
# Find a compiler, considering the OS |
|
|
|
|
|
# |
|
|
|
|
|
ENV_BUILD_PATH = os.path.join(env.Dictionary("PROJECT_BUILD_DIR"), env["PIOENV"]) |
|
|
|
|
|
GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path") |
|
|
def search_compiler(): |
|
|
def search_compiler(): |
|
|
|
|
|
if os.path.exists(GCC_PATH_CACHE): |
|
|
|
|
|
print('Getting g++ path from cache') |
|
|
|
|
|
with open(GCC_PATH_CACHE, 'r') as f: |
|
|
|
|
|
return f.read() |
|
|
|
|
|
|
|
|
|
|
|
# PlatformIO inserts the toolchain bin folder on the front of the $PATH |
|
|
|
|
|
# Find the current platform compiler by searching the $PATH |
|
|
if env['PLATFORM'] == 'win32': |
|
|
if env['PLATFORM'] == 'win32': |
|
|
# the first path have the compiler |
|
|
path_separator = ';' |
|
|
for path in env['ENV']['PATH'].split(';'): |
|
|
path_regex = r'platformio\\packages.*\\bin' |
|
|
if not re.search(r'platformio\\packages.*\\bin', path): |
|
|
gcc = "g++.exe" |
|
|
|
|
|
else: |
|
|
|
|
|
path_separator = ':' |
|
|
|
|
|
path_regex = r'platformio/packages.*/bin' |
|
|
|
|
|
gcc = "g++" |
|
|
|
|
|
|
|
|
|
|
|
# Search for the compiler |
|
|
|
|
|
for path in env['ENV']['PATH'].split(path_separator): |
|
|
|
|
|
if not re.search(path_regex, path): |
|
|
continue |
|
|
continue |
|
|
#print(path) |
|
|
|
|
|
for file in os.listdir(path): |
|
|
for file in os.listdir(path): |
|
|
if file.endswith("g++.exe"): |
|
|
if not file.endswith(gcc): |
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
# Cache the g++ path to no search always |
|
|
|
|
|
if os.path.exists(ENV_BUILD_PATH): |
|
|
|
|
|
print('Caching g++ for current env') |
|
|
|
|
|
with open(GCC_PATH_CACHE, 'w+') as f: |
|
|
|
|
|
f.write(file) |
|
|
|
|
|
|
|
|
return file |
|
|
return file |
|
|
print("Could not find the g++") |
|
|
|
|
|
return None |
|
|
|
|
|
else: |
|
|
|
|
|
return env.get('CXX') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file = env.get('CXX') |
|
|
|
|
|
print("Couldn't find a compiler! Fallback to", file) |
|
|
|
|
|
return file |
|
|
|
|
|
|
|
|
# load marlin features |
|
|
# |
|
|
|
|
|
# Use the compiler to get a list of all enabled features |
|
|
|
|
|
# |
|
|
def load_marlin_features(): |
|
|
def load_marlin_features(): |
|
|
if "MARLIN_FEATURES" in env: |
|
|
if "MARLIN_FEATURES" in env: |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
# procces defines |
|
|
# Process defines |
|
|
#print(env.Dump()) |
|
|
#print(env.Dump()) |
|
|
build_flags = env.get('BUILD_FLAGS') |
|
|
build_flags = env.get('BUILD_FLAGS') |
|
|
build_flags = env.ParseFlagsExtended(build_flags) |
|
|
build_flags = env.ParseFlagsExtended(build_flags) |
|
@ -159,7 +181,7 @@ def load_marlin_features(): |
|
|
cxx = search_compiler() |
|
|
cxx = search_compiler() |
|
|
cmd = [cxx] |
|
|
cmd = [cxx] |
|
|
|
|
|
|
|
|
# build flags from board.json |
|
|
# Build flags from board.json |
|
|
#if 'BOARD' in env: |
|
|
#if 'BOARD' in env: |
|
|
# cmd += [env.BoardConfig().get("build.extra_flags")] |
|
|
# cmd += [env.BoardConfig().get("build.extra_flags")] |
|
|
for s in build_flags['CPPDEFINES']: |
|
|
for s in build_flags['CPPDEFINES']: |
|
@ -167,7 +189,7 @@ def load_marlin_features(): |
|
|
cmd += ['-D' + s[0] + '=' + str(s[1])] |
|
|
cmd += ['-D' + s[0] + '=' + str(s[1])] |
|
|
else: |
|
|
else: |
|
|
cmd += ['-D' + s] |
|
|
cmd += ['-D' + s] |
|
|
# cmd += ['-w -dM -E -x c++ Marlin/src/inc/MarlinConfigPre.h'] |
|
|
|
|
|
cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-features-dependencies.h'] |
|
|
cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-features-dependencies.h'] |
|
|
cmd = ' '.join(cmd) |
|
|
cmd = ' '.join(cmd) |
|
|
print(cmd) |
|
|
print(cmd) |
|
@ -179,15 +201,22 @@ def load_marlin_features(): |
|
|
marlin_features[feature] = definition |
|
|
marlin_features[feature] = definition |
|
|
env["MARLIN_FEATURES"] = marlin_features |
|
|
env["MARLIN_FEATURES"] = marlin_features |
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
|
# Return True if a matching feature is enabled |
|
|
|
|
|
# |
|
|
def MarlinFeatureIsEnabled(env, feature): |
|
|
def MarlinFeatureIsEnabled(env, feature): |
|
|
load_marlin_features() |
|
|
load_marlin_features() |
|
|
r = re.compile(feature) |
|
|
r = re.compile(feature) |
|
|
matches = list(filter(r.match, env["MARLIN_FEATURES"])) |
|
|
matches = list(filter(r.match, env["MARLIN_FEATURES"])) |
|
|
return len(matches) > 0 |
|
|
return len(matches) > 0 |
|
|
|
|
|
|
|
|
# add a method for others scripts to check if a feature is enabled |
|
|
# |
|
|
|
|
|
# Add a method for other PIO scripts to query enabled features |
|
|
|
|
|
# |
|
|
env.AddMethod(MarlinFeatureIsEnabled) |
|
|
env.AddMethod(MarlinFeatureIsEnabled) |
|
|
|
|
|
|
|
|
# install all dependencies for features enabled in Configuration.h |
|
|
# |
|
|
|
|
|
# Add dependencies for enabled Marlin features |
|
|
|
|
|
# |
|
|
install_features_dependencies() |
|
|
install_features_dependencies() |
|
|
force_ignore_unused_libs() |
|
|
force_ignore_unused_libs() |
|
|