From bb1039d4c91b7bfd282cd5b2b86e1466db80ba28 Mon Sep 17 00:00:00 2001 From: ellensp Date: Fri, 26 Feb 2021 03:15:55 +1300 Subject: [PATCH] Preflight checks for PlatformIO builds (#21068) Co-authored-by: Alexander D. Kanevskiy --- Marlin/src/pins/pins.h | 6 +- Marlin/src/pins/ramps/pins_ZRIB_V52.h | 1 + .../PlatformIO/scripts/common-dependencies.py | 11 ---- .../PlatformIO/scripts/preflight-checks.py | 62 +++++++++++++++++++ buildroot/tests/mega1280-tests | 4 +- platformio.ini | 1 + 6 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 buildroot/share/PlatformIO/scripts/preflight-checks.py diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h index f5b80fd4d..8f0215d4c 100644 --- a/Marlin/src/pins/pins.h +++ b/Marlin/src/pins/pins.h @@ -481,9 +481,9 @@ #elif MB(MKS_ROBIN_MINI) #include "stm32f1/pins_MKS_ROBIN_MINI.h" // STM32F1 env:mks_robin_mini #elif MB(MKS_ROBIN_NANO) - #include "stm32f1/pins_MKS_ROBIN_NANO.h" // STM32F1 env:mks_robin_nano35 + #include "stm32f1/pins_MKS_ROBIN_NANO.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_stm32 #elif MB(MKS_ROBIN_NANO_V2) - #include "stm32f1/pins_MKS_ROBIN_NANO_V2.h" // STM32F1 env:mks_robin_nano35 + #include "stm32f1/pins_MKS_ROBIN_NANO_V2.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_stm32 #elif MB(MKS_ROBIN_LITE) #include "stm32f1/pins_MKS_ROBIN_LITE.h" // STM32F1 env:mks_robin_lite #elif MB(MKS_ROBIN_LITE3) @@ -513,7 +513,7 @@ #elif MB(BTT_SKR_E3_DIP) #include "stm32f1/pins_BTT_SKR_E3_DIP.h" // STM32F1 env:STM32F103RE_btt env:STM32F103RE_btt_USB env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB #elif MB(BTT_SKR_CR6) - #include "stm32f1/pins_BTT_SKR_CR6.h" // STM32F1 env:STM32F103RC_btt_512K_USB + #include "stm32f1/pins_BTT_SKR_CR6.h" // STM32F1 env:STM32F103RE_btt env:STM32F103RE_btt_USB #elif MB(JGAURORA_A5S_A1) #include "stm32f1/pins_JGAURORA_A5S_A1.h" // STM32F1 env:jgaurora_a5s_a1 #elif MB(FYSETC_AIO_II) diff --git a/Marlin/src/pins/ramps/pins_ZRIB_V52.h b/Marlin/src/pins/ramps/pins_ZRIB_V52.h index 983c840bb..f4db07ef8 100644 --- a/Marlin/src/pins/ramps/pins_ZRIB_V52.h +++ b/Marlin/src/pins/ramps/pins_ZRIB_V52.h @@ -46,6 +46,7 @@ #define E2_STEP_PIN 4 #define E2_DIR_PIN 5 #define E2_ENABLE_PIN 22 +#define HEATER_1_PIN 7 #include "pins_MKS_BASE_common.h" diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index 4500f529a..30e168d83 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -312,16 +312,6 @@ def MarlinFeatureIsEnabled(env, feature): return some_on -# -# Check for Configfiles in two common incorrect places -# -def check_configfile_locations(): - for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]: - for f in [ "Configuration.h", "Configuration_adv.h" ]: - if os.path.isfile(os.path.join(p, f)): - err = 'ERROR: Config files found in directory ' + str(p) + '. Please move them into the Marlin subdirectory.' - raise SystemExit(err) - # # Add a method for other PIO scripts to query enabled features # @@ -330,6 +320,5 @@ env.AddMethod(MarlinFeatureIsEnabled) # # Add dependencies for enabled Marlin features # -check_configfile_locations() apply_features_config() force_ignore_unused_libs() diff --git a/buildroot/share/PlatformIO/scripts/preflight-checks.py b/buildroot/share/PlatformIO/scripts/preflight-checks.py new file mode 100644 index 000000000..14807d954 --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/preflight-checks.py @@ -0,0 +1,62 @@ +# +# preflight-checks.py +# Script to check for common issues prior to compiling +# +import os +import re +Import("env") + +def get_envs_for_board(board): + if board.startswith("BOARD_"): + board = board[6:] + with open(os.path.join("Marlin", "src", "pins", "pins.h"),"r") as f: + board_found = "" + r=re.compile(r"if\s+MB\((.+)\)") + for line in f.readlines(): + mbs = r.findall(line) + if mbs: + board_found = board if board in re.split(r",\s*", mbs[0]) else "" + if board_found and "#include " in line and "env:" in line: + return re.findall(r"env:\w+", line) + return [] + +def check_envs(build_env, base_envs, config): + if build_env in base_envs: + return True + ext = config.get(build_env, 'extends', default=None) + if ext: + for ext_env in ext: + if check_envs(ext_env, base_envs, config): + return True + return False + +# Sanity checks: +if 'PIOENV' not in env: + raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO") + +if 'MARLIN_FEATURES' not in env: + raise SystemExit("Error: this script should be used after common Marlin scripts") + +if 'MOTHERBOARD' not in env['MARLIN_FEATURES']: + raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h") + +build_env = env['PIOENV'] +motherboard = env['MARLIN_FEATURES']['MOTHERBOARD'] +base_envs = get_envs_for_board(motherboard) +config = env.GetProjectConfig() +result = check_envs("env:"+build_env, base_envs, config) + +if not result: + err = "Error: your selected build environment '%s' is not compatible with MOTHERBOARD=%s in Configuration.h. " \ + "Please use one of compatible build environments for this board: %s" % \ + (build_env, motherboard, ",".join([e[4:] for e in base_envs if e.startswith("env:")])) + raise SystemExit(err) + +# +# Check for Config files in two common incorrect places +# +for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]: + for f in [ "Configuration.h", "Configuration_adv.h" ]: + if os.path.isfile(os.path.join(p, f)): + err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p + raise SystemExit(err) diff --git a/buildroot/tests/mega1280-tests b/buildroot/tests/mega1280-tests index ac1b5f692..9110e9feb 100755 --- a/buildroot/tests/mega1280-tests +++ b/buildroot/tests/mega1280-tests @@ -33,13 +33,13 @@ exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD # Test DUAL_X_CARRIAGE # restore_configs -opt_set MOTHERBOARD BOARD_TT_OSCAR +opt_set MOTHERBOARD BOARD_ZRIB_V52 opt_set LCD_LANGUAGE pt opt_set EXTRUDERS 2 opt_set TEMP_SENSOR_1 1 opt_enable USE_XMAX_PLUG DUAL_X_CARRIAGE REPRAPWORLD_KEYPAD opt_set REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 -exec_test $1 $2 "TT Oscar | DUAL_X_CARRIAGE" "$3" +exec_test $1 $2 "ZRIB_V52 | DUAL_X_CARRIAGE" "$3" # # Delta Config (generic) + Probeless diff --git a/platformio.ini b/platformio.ini index fab20018d..c03b22453 100644 --- a/platformio.ini +++ b/platformio.ini @@ -212,6 +212,7 @@ default_src_filter = + - - + extra_scripts = pre:buildroot/share/PlatformIO/scripts/common-dependencies.py pre:buildroot/share/PlatformIO/scripts/common-cxxflags.py + pre:buildroot/share/PlatformIO/scripts/preflight-checks.py post:buildroot/share/PlatformIO/scripts/common-dependencies-post.py build_flags = -fmax-errors=5 -g3 -D__MARLIN_FIRMWARE__ -fmerge-constants lib_deps =