buildroot fix

This commit is contained in:
Sergey
2020-09-06 14:07:05 +03:00
parent f5cd440cbf
commit 89e1ee15a4
23 changed files with 521 additions and 361 deletions

View File

@@ -65,3 +65,94 @@
#ifdef HAL_PATH
#include HAL_PATH(../../../../Marlin/src/HAL, inc/Conditionals_post.h)
#endif
//
// Conditionals only used for [features]
//
#if ENABLED(SR_LCD_3W_NL)
// Feature checks for SR_LCD_3W_NL
#elif EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008)
#define USES_LIQUIDTWI2
#elif ANY(HAS_CHARACTER_LCD, LCD_I2C_TYPE_PCF8575, LCD_I2C_TYPE_PCA8574, SR_LCD_2W_NL, LCM1602)
#define USES_LIQUIDCRYSTAL
#endif
#if BOTH(ANYCUBIC_LCD_I3MEGA, EXTENSIBLE_UI)
#define HAS_ANYCUBIC_TFT_EXTUI
#endif
#if SAVED_POSITIONS
#define HAS_SAVED_POSITIONS
#endif
#if ENABLED(HOST_PROMPT_SUPPORT) && DISABLED(EMERGENCY_PARSER)
#define HAS_GCODE_M876
#endif
#if PREHEAT_COUNT
#define HAS_PREHEAT_COUNT
#endif
#if EXTRUDERS
#define HAS_EXTRUDERS
#if EXTRUDERS > 1
#define HAS_MULTI_EXTRUDER
#endif
#endif
#if HAS_LCD_MENU
#if ENABLED(BACKLASH_GCODE)
#define HAS_MENU_BACKLASH
#endif
#if ENABLED(LEVEL_BED_CORNERS)
#define HAS_MENU_BED_CORNERS
#endif
#if ENABLED(CANCEL_OBJECTS)
#define HAS_MENU_CANCELOBJECT
#endif
#if ENABLED(CUSTOM_USER_MENUS)
#define HAS_MENU_CUSTOM
#endif
#if EITHER(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION)
#define HAS_MENU_DELTA_CALIBRATE
#endif
#if EITHER(LED_CONTROL_MENU, CASE_LIGHT_MENU)
#define HAS_MENU_LED
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
#define HAS_MENU_FILAMENT
#endif
#if ENABLED(SDSUPPORT)
#define HAS_MENU_MEDIA
#endif
#if ENABLED(MIXING_EXTRUDER)
#define HAS_MENU_MIXER
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
#define HAS_MENU_JOB_RECOVERY
#endif
#if HAS_POWER_MONITOR
#define HAS_MENU_POWER_MONITOR
#endif
#if HAS_CUTTER
#define HAS_MENU_CUTTER
#endif
#if HAS_TEMPERATURE
#define HAS_MENU_TEMPERATURE
#endif
#if ENABLED(MMU2_MENUS)
#define HAS_MENU_MMU2
#endif
#if ENABLED(PASSWORD_FEATURE)
#define HAS_MENU_PASSWORD
#endif
#if HAS_TRINAMIC_CONFIG
#define HAS_MENU_TMC
#endif
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#define HAS_MENU_TOUCH_SCREEN
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
#define HAS_MENU_UBL
#endif
#endif

View File

@@ -6,42 +6,80 @@ import subprocess
import os
import re
try:
import configparser
import configparser
except ImportError:
import ConfigParser as configparser
from platformio.managers.package import PackageManager
import ConfigParser as configparser
try:
# PIO < 4.4
from platformio.managers.package import PackageManager
except ImportError:
# PIO >= 4.4
from platformio.package.meta import PackageSpec as PackageManager
Import("env")
FEATURE_DEPENDENCIES = {}
#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):
if PackageManager.__name__ == 'PackageSpec':
return PackageManager(spec).name
else:
name, _, _ = PackageManager.parse_pkg_uri(spec)
return name
FEATURE_CONFIG = {}
def add_to_feat_cnf(feature, flines):
feat = FEATURE_CONFIG[feature]
atoms = re.sub(',\\s*', '\n', flines).strip().split('\n')
for dep in atoms:
parts = dep.split('=')
name = parts.pop(0)
rest = '='.join(parts)
if name in ['extra_scripts', 'src_filter', 'lib_ignore']:
feat[name] = rest
else:
feat['lib_deps'] += [dep]
def load_config():
config = configparser.ConfigParser()
config.read("platformio.ini")
items = config.items('features')
for key in items:
ukey = key[0].upper()
if not ukey in FEATURE_DEPENDENCIES:
FEATURE_DEPENDENCIES[ukey] = {
'lib_deps': []
}
deps = re.sub(',\\s*', '\n', key[1]).strip().split('\n')
for dep in deps:
parts = dep.split('=')
name = parts.pop(0)
rest = '='.join(parts)
if name in ['extra_scripts', 'src_filter', 'lib_ignore']:
FEATURE_DEPENDENCIES[ukey][name] = rest
else:
FEATURE_DEPENDENCIES[ukey]['lib_deps'] += [dep]
feature = key[0].upper()
if not feature in FEATURE_CONFIG:
FEATURE_CONFIG[feature] = { 'lib_deps': [] }
add_to_feat_cnf(feature, key[1])
# Add options matching custom_marlin.MY_OPTION to the pile
all_opts = env.GetProjectOptions()
for n in all_opts:
mat = re.match(r'custom_marlin\.(.+)', n[0])
if mat:
try:
val = env.GetProjectOption(n[0])
except:
val = None
if val:
add_to_feat_cnf(mat.group(1).upper(), val)
def get_all_known_libs():
known_libs = []
for feature in FEATURE_DEPENDENCIES:
if not 'lib_deps' in FEATURE_DEPENDENCIES[feature]:
for feature in FEATURE_CONFIG:
feat = FEATURE_CONFIG[feature]
if not 'lib_deps' in feat:
continue
for dep in FEATURE_DEPENDENCIES[feature]['lib_deps']:
name, _, _ = PackageManager.parse_pkg_uri(dep)
for dep in feat['lib_deps']:
name = parse_pkg_uri(dep)
known_libs.append(name)
return known_libs
@@ -49,7 +87,7 @@ def get_all_env_libs():
env_libs = []
lib_deps = env.GetProjectOption('lib_deps')
for dep in lib_deps:
name, _, _ = PackageManager.parse_pkg_uri(dep)
name = parse_pkg_uri(dep)
env_libs.append(name)
return env_libs
@@ -64,35 +102,38 @@ def force_ignore_unused_libs():
known_libs = get_all_known_libs()
diff = (list(set(known_libs) - set(env_libs)))
lib_ignore = env.GetProjectOption('lib_ignore') + diff
print("Ignoring libs:", lib_ignore)
if verbose:
print("Ignore libraries:", lib_ignore)
set_env_field('lib_ignore', lib_ignore)
def install_features_dependencies():
def apply_features_config():
load_config()
for feature in FEATURE_DEPENDENCIES:
for feature in FEATURE_CONFIG:
if not env.MarlinFeatureIsEnabled(feature):
continue
if 'lib_deps' in FEATURE_DEPENDENCIES[feature]:
print("Adding lib_deps for %s... " % feature)
feat = FEATURE_CONFIG[feature]
# deps to add
if 'lib_deps' in feat and len(feat['lib_deps']):
blab("Adding lib_deps for %s... " % feature)
# feat to add
deps_to_add = {}
for dep in FEATURE_DEPENDENCIES[feature]['lib_deps']:
name, _, _ = PackageManager.parse_pkg_uri(dep)
for dep in feat['lib_deps']:
name = parse_pkg_uri(dep)
deps_to_add[name] = dep
# Does the env already have the dependency?
deps = env.GetProjectOption('lib_deps')
for dep in deps:
name, _, _ = PackageManager.parse_pkg_uri(dep)
name = parse_pkg_uri(dep)
if name in deps_to_add:
del deps_to_add[name]
# Are there any libraries that should be ignored?
lib_ignore = env.GetProjectOption('lib_ignore')
for dep in deps:
name, _, _ = PackageManager.parse_pkg_uri(dep)
name = parse_pkg_uri(dep)
if name in deps_to_add:
del deps_to_add[name]
@@ -101,27 +142,27 @@ def install_features_dependencies():
# Only add the missing dependencies
set_env_field('lib_deps', deps + list(deps_to_add.values()))
if 'extra_scripts' in FEATURE_DEPENDENCIES[feature]:
print("Executing extra_scripts for %s... " % feature)
env.SConscript(FEATURE_DEPENDENCIES[feature]['extra_scripts'], exports="env")
if 'extra_scripts' in feat:
blab("Running extra_scripts for %s... " % feature)
env.SConscript(feat['extra_scripts'], exports="env")
if 'src_filter' in FEATURE_DEPENDENCIES[feature]:
print("Adding src_filter for %s... " % feature)
if 'src_filter' in feat:
blab("Adding src_filter for %s... " % feature)
src_filter = ' '.join(env.GetProjectOption('src_filter'))
# first we need to remove the references to the same folder
my_srcs = re.findall( r'[+-](<.*?>)', FEATURE_DEPENDENCIES[feature]['src_filter'])
my_srcs = re.findall( r'[+-](<.*?>)', feat['src_filter'])
cur_srcs = re.findall( r'[+-](<.*?>)', src_filter)
for d in my_srcs:
if d in cur_srcs:
src_filter = re.sub(r'[+-]' + d, '', src_filter)
src_filter = FEATURE_DEPENDENCIES[feature]['src_filter'] + ' ' + src_filter
src_filter = feat['src_filter'] + ' ' + src_filter
set_env_field('src_filter', [src_filter])
env.Replace(SRC_FILTER=src_filter)
if 'lib_ignore' in FEATURE_DEPENDENCIES[feature]:
print("Ignoring libs for %s... " % feature)
lib_ignore = env.GetProjectOption('lib_ignore') + [FEATURE_DEPENDENCIES[feature]['lib_ignore']]
if 'lib_ignore' in feat:
blab("Adding lib_ignore for %s... " % feature)
lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']]
set_env_field('lib_ignore', lib_ignore)
#
@@ -130,51 +171,58 @@ def install_features_dependencies():
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():
try:
filepath = env.GetProjectOption('custom_gcc')
blab('Getting compiler from env')
return filepath
except:
pass
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:
return f.read()
# PlatformIO inserts the toolchain bin folder on the front of 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':
path_separator = ';'
path_regex = r'platformio\\packages.*\\bin'
gcc = "g++.exe"
path_regex += r'.*\\bin'
gcc += ".exe"
else:
path_separator = ':'
path_regex = r'platformio/packages.*/bin'
gcc = "g++"
path_regex += r'/.+/bin'
# Search for the compiler
for path in env['ENV']['PATH'].split(path_separator):
if not re.search(path_regex, path):
for pathdir in env['ENV']['PATH'].split(path_separator):
if not re.search(path_regex, pathdir, re.IGNORECASE):
continue
for file in os.listdir(path):
if not file.endswith(gcc):
for filepath in os.listdir(pathdir):
if not filepath.endswith(gcc):
continue
# Cache the g++ path to no search always
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:
f.write(file)
f.write(filepath)
return file
return filepath
file = env.get('CXX')
print("Couldn't find a compiler! Fallback to", file)
return file
filepath = env.get('CXX')
blab("Couldn't find a compiler! Fallback to %s" % filepath)
return filepath
#
# Use the compiler to get a list of all enabled features
#
def load_marlin_features():
if "MARLIN_FEATURES" in env:
if 'MARLIN_FEATURES' in env:
return
# Process defines
#print(env.Dump())
build_flags = env.get('BUILD_FLAGS')
build_flags = env.ParseFlagsExtended(build_flags)
@@ -192,23 +240,34 @@ def load_marlin_features():
cmd += ['-w -dM -E -x c++ buildroot/share/PlatformIO/scripts/common-dependencies.h']
cmd = ' '.join(cmd)
print(cmd)
blab(cmd)
define_list = subprocess.check_output(cmd, shell=True).splitlines()
marlin_features = {}
for define in define_list:
feature = define[8:].strip().decode().split(' ')
feature, definition = feature[0], ' '.join(feature[1:])
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):
load_marlin_features()
r = re.compile(feature)
matches = list(filter(r.match, env["MARLIN_FEATURES"]))
return len(matches) > 0
r = re.compile('^' + feature + '$')
found = list(filter(r.match, env['MARLIN_FEATURES']))
# Defines could still be 'false' or '0', so check
some_on = False
if len(found):
for f in found:
val = env['MARLIN_FEATURES'][f]
if val in [ '', '1', 'true' ]:
some_on = True
elif val in env['MARLIN_FEATURES']:
some_on = env.MarlinFeatureIsEnabled(val)
return some_on
#
# Add a method for other PIO scripts to query enabled features
@@ -218,5 +277,5 @@ env.AddMethod(MarlinFeatureIsEnabled)
#
# Add dependencies for enabled Marlin features
#
install_features_dependencies()
apply_features_config()
force_ignore_unused_libs()

View File

@@ -1,6 +1,19 @@
import os,shutil
from SCons.Script import DefaultEnvironment
from platformio import util
try:
# PIO < 4.4
from platformio.managers.package import PackageManager
except ImportError:
# PIO >= 4.4
from platformio.package.meta import PackageSpec as PackageManager
def parse_pkg_uri(spec):
if PackageManager.__name__ == 'PackageSpec':
return PackageManager(spec).name
else:
name, _, _ = PackageManager.parse_pkg_uri(spec)
return name
def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src):
@@ -16,7 +29,18 @@ platform = env.PioPlatform()
board = env.BoardConfig()
variant = board.get("build.variant")
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoststm32")
platform_packages = env.GetProjectOption('platform_packages')
# if there's no framework defined, take it from the class name of platform
framewords = {
"Ststm32Platform": "framework-arduinoststm32",
"AtmelavrPlatform": "framework-arduino-avr"
}
if len(platform_packages) == 0:
platform_name = framewords[platform.__class__.__name__]
else:
platform_name = parse_pkg_uri(platform_packages[0])
FRAMEWORK_DIR = platform.get_package_dir(platform_name)
assert os.path.isdir(FRAMEWORK_DIR)
assert os.path.isdir("buildroot/share/PlatformIO/variants")