Add custom_verbose, custom_gcc deps flags

This commit is contained in:
Scott Lahteine 2020-08-20 02:47:16 -05:00
parent 16e1dbbb21
commit 28a0650cf3
1 changed files with 43 additions and 24 deletions

View File

@ -18,7 +18,16 @@ except ImportError:
Import("env") Import("env")
FEATURE_CONFIG = {} #print(env.Dump())
try:
verbose = int(env.GetProjectOption('custom_verbose'))
except:
verbose = 0
def blab(str):
if verbose:
print(str)
def parse_pkg_uri(spec): def parse_pkg_uri(spec):
if PackageManager.__name__ == 'PackageSpec': if PackageManager.__name__ == 'PackageSpec':
@ -27,6 +36,8 @@ def parse_pkg_uri(spec):
name, _, _ = PackageManager.parse_pkg_uri(spec) name, _, _ = PackageManager.parse_pkg_uri(spec)
return name return name
FEATURE_CONFIG = {}
def add_to_feat_cnf(feature, flines): def add_to_feat_cnf(feature, flines):
feat = FEATURE_CONFIG[feature] feat = FEATURE_CONFIG[feature]
atoms = re.sub(',\\s*', '\n', flines).strip().split('\n') atoms = re.sub(',\\s*', '\n', flines).strip().split('\n')
@ -91,7 +102,8 @@ def force_ignore_unused_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("Ignore libraries:", lib_ignore) if verbose:
print("Ignore libraries:", lib_ignore)
set_env_field('lib_ignore', lib_ignore) set_env_field('lib_ignore', lib_ignore)
def apply_features_config(): def apply_features_config():
@ -103,7 +115,7 @@ def apply_features_config():
feat = FEATURE_CONFIG[feature] feat = FEATURE_CONFIG[feature]
if 'lib_deps' in feat and len(feat['lib_deps']): if 'lib_deps' in feat and len(feat['lib_deps']):
print("Adding lib_deps for %s... " % feature) blab("Adding lib_deps for %s... " % feature)
# feat to add # feat to add
deps_to_add = {} deps_to_add = {}
@ -131,11 +143,11 @@ def apply_features_config():
set_env_field('lib_deps', deps + list(deps_to_add.values())) set_env_field('lib_deps', deps + list(deps_to_add.values()))
if 'extra_scripts' in feat: if 'extra_scripts' in feat:
print("Running extra_scripts for %s... " % feature) blab("Running extra_scripts for %s... " % feature)
env.SConscript(feat['extra_scripts'], exports="env") env.SConscript(feat['extra_scripts'], exports="env")
if 'src_filter' in feat: if 'src_filter' in feat:
print("Adding src_filter for %s... " % feature) blab("Adding src_filter for %s... " % feature)
src_filter = ' '.join(env.GetProjectOption('src_filter')) src_filter = ' '.join(env.GetProjectOption('src_filter'))
# first we need to remove the references to the same folder # first we need to remove the references to the same folder
my_srcs = re.findall( r'[+-](<.*?>)', feat['src_filter']) my_srcs = re.findall( r'[+-](<.*?>)', feat['src_filter'])
@ -149,7 +161,7 @@ def apply_features_config():
env.Replace(SRC_FILTER=src_filter) env.Replace(SRC_FILTER=src_filter)
if 'lib_ignore' in feat: if 'lib_ignore' in feat:
print("Adding lib_ignore for %s... " % feature) blab("Adding lib_ignore for %s... " % feature)
lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']] lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']]
set_env_field('lib_ignore', lib_ignore) set_env_field('lib_ignore', lib_ignore)
@ -159,41 +171,49 @@ def apply_features_config():
ENV_BUILD_PATH = os.path.join(env.Dictionary('PROJECT_BUILD_DIR'), env['PIOENV']) ENV_BUILD_PATH = os.path.join(env.Dictionary('PROJECT_BUILD_DIR'), env['PIOENV'])
GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path") GCC_PATH_CACHE = os.path.join(ENV_BUILD_PATH, ".gcc_path")
def search_compiler(): def search_compiler():
try:
filepath = env.GetProjectOption('custom_gcc')
blab('Getting compiler from env')
return filepath
except:
pass
if os.path.exists(GCC_PATH_CACHE): if os.path.exists(GCC_PATH_CACHE):
print('Getting g++ path from cache') blab('Getting g++ path from cache')
with open(GCC_PATH_CACHE, 'r') as f: with open(GCC_PATH_CACHE, 'r') as f:
return f.read() return f.read()
# PlatformIO inserts the toolchain bin folder on the front of the $PATH
# Find the current platform compiler by searching the $PATH # Find the current platform compiler by searching the $PATH
# which will be in a platformio toolchain bin folder
path_regex = re.escape(env['PROJECT_PACKAGES_DIR'])
gcc = "g++"
if env['PLATFORM'] == 'win32': if env['PLATFORM'] == 'win32':
path_separator = ';' path_separator = ';'
path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*\\bin' path_regex += r'.*\\bin'
gcc = "g++.exe" gcc += ".exe"
else: else:
path_separator = ':' path_separator = ':'
path_regex = re.escape(env['PROJECT_PACKAGES_DIR']) + r'.*/bin' path_regex += r'/.+/bin'
gcc = "g++"
# Search for the compiler # Search for the compiler
for path in env['ENV']['PATH'].split(path_separator): for pathdir in env['ENV']['PATH'].split(path_separator):
if not re.search(path_regex, path, re.IGNORECASE): if not re.search(path_regex, pathdir, re.IGNORECASE):
continue continue
for file in os.listdir(path): for filepath in os.listdir(pathdir):
if not file.endswith(gcc): if not filepath.endswith(gcc):
continue continue
# Cache the g++ path to no search always # Cache the g++ path to no search always
if os.path.exists(ENV_BUILD_PATH): if os.path.exists(ENV_BUILD_PATH):
print('Caching g++ for current env') blab('Caching g++ for current env')
with open(GCC_PATH_CACHE, 'w+') as f: with open(GCC_PATH_CACHE, 'w+') as f:
f.write(file) f.write(filepath)
return file return filepath
file = env.get('CXX') filepath = env.get('CXX')
print("Couldn't find a compiler! Fallback to", file) blab("Couldn't find a compiler! Fallback to %s" % filepath)
return file return filepath
# #
# Use the compiler to get a list of all enabled features # Use the compiler to get a list of all enabled features
@ -203,7 +223,6 @@ def load_marlin_features():
return return
# Process defines # Process defines
#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)
@ -221,7 +240,7 @@ def load_marlin_features():
cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-dependencies.h'] cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-dependencies.h']
cmd = ' '.join(cmd) cmd = ' '.join(cmd)
print(cmd) blab(cmd)
define_list = subprocess.check_output(cmd, shell=True).splitlines() define_list = subprocess.check_output(cmd, shell=True).splitlines()
marlin_features = {} marlin_features = {}
for define in define_list: for define in define_list: