Browse Source

Fix search for best compiler (#18779)

vanilla_fb_2.0.x
Victor Oliveira 4 years ago
committed by GitHub
parent
commit
89722d2196
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      buildroot/share/PlatformIO/scripts/common-features-dependencies.h
  2. 93
      buildroot/share/PlatformIO/scripts/common-features-dependencies.py

31
buildroot/share/PlatformIO/scripts/common-features-dependencies.h

@ -27,15 +27,11 @@
* Used by common-features-dependencies.py * Used by common-features-dependencies.py
*/ */
#ifndef __MARLIN_FIRMWARE__
#define __MARLIN_FIRMWARE__
#endif
//
// Prefix header to acquire configurations
//
#include <stdint.h> #include <stdint.h>
// Include platform headers
//#include "../../../../Marlin/src/HAL/platforms.h"
#include "../../../../Marlin/src/core/boards.h" #include "../../../../Marlin/src/core/boards.h"
#include "../../../../Marlin/src/core/macros.h" #include "../../../../Marlin/src/core/macros.h"
#include "../../../../Marlin/Configuration.h" #include "../../../../Marlin/Configuration.h"
@ -44,7 +40,28 @@
#include "../../../../Marlin/src/inc/Conditionals_LCD.h" #include "../../../../Marlin/src/inc/Conditionals_LCD.h"
#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_LCD.h)
#endif
#include "../../../../Marlin/src/core/drivers.h" #include "../../../../Marlin/src/core/drivers.h"
#include "../../../../Marlin/Configuration_adv.h" #include "../../../../Marlin/Configuration_adv.h"
#include "../../../../Marlin/src/inc/Conditionals_adv.h" #include "../../../../Marlin/src/inc/Conditionals_adv.h"
#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_adv.h)
#endif
//#include "../../../../Marlin/src/pins/pins.h"
#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, timers.h)
#include HAL_PATH(../../../../Marlin/src/HAL, spi_pins.h)
#endif
#include "../../../../Marlin/src/inc/Conditionals_post.h"
#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_post.h)
#endif

93
buildroot/share/PlatformIO/scripts/common-features-dependencies.py

@ -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,15 +53,14 @@ 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()
diff = (list(set(known_libs) - set(env_libs))) diff = (list(set(known_libs) - set(env_libs)))
lib_ignore = env.GetProjectOption("lib_ignore") + diff lib_ignore = env.GetProjectOption("lib_ignore") + diff
print("Ignoring libs: ", lib_ignore) print("Ignoring libs:", lib_ignore)
proj = env.GetProjectConfig() proj = env.GetProjectConfig()
proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore) proj.set("env:" + env["PIOENV"], "lib_ignore", lib_ignore)
@ -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,45 +124,72 @@ 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)
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']:
if isinstance(s, tuple): if isinstance(s, tuple):
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()

Loading…
Cancel
Save