🔨 Prevent variant overwrite
Co-Authored-By: Martin Turski <turningtides@outlook.de>
This commit is contained in:
parent
aaa590855a
commit
8ae19e45d6
|
@ -5,7 +5,8 @@
|
||||||
# the appropriate framework variants folder, so that its contents
|
# the appropriate framework variants folder, so that its contents
|
||||||
# will be picked up by PlatformIO just like any other variant.
|
# will be picked up by PlatformIO just like any other variant.
|
||||||
#
|
#
|
||||||
import pioutil
|
import pioutil, re
|
||||||
|
marlin_variant_pattern = re.compile("marlin_.*")
|
||||||
if pioutil.is_pio_build():
|
if pioutil.is_pio_build():
|
||||||
import shutil,marlin
|
import shutil,marlin
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -32,7 +33,7 @@ if pioutil.is_pio_build():
|
||||||
else:
|
else:
|
||||||
platform_name = PackageSpec(platform_packages[0]).name
|
platform_name = PackageSpec(platform_packages[0]).name
|
||||||
|
|
||||||
if platform_name in [ "usb-host-msc", "usb-host-msc-cdc-msc", "usb-host-msc-cdc-msc-2", "usb-host-msc-cdc-msc-3", "tool-stm32duino", "biqu-bx-workaround", "main" ]:
|
if platform_name in [ "Arduino_Core_STM32", "usb-host-msc", "usb-host-msc-cdc-msc", "usb-host-msc-cdc-msc-2", "usb-host-msc-cdc-msc-3", "tool-stm32duino", "biqu-bx-workaround", "main" ]:
|
||||||
platform_name = "framework-arduinoststm32"
|
platform_name = "framework-arduinoststm32"
|
||||||
|
|
||||||
FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
|
FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
|
||||||
|
@ -44,15 +45,20 @@ if pioutil.is_pio_build():
|
||||||
variant = board.get("build.variant")
|
variant = board.get("build.variant")
|
||||||
#series = mcu_type[:7].upper() + "xx"
|
#series = mcu_type[:7].upper() + "xx"
|
||||||
|
|
||||||
# Prepare a new empty folder at the destination
|
# Only prepare a new variant if the PlatformIO configuration provides it (board_build.variant).
|
||||||
variant_dir = FRAMEWORK_DIR / "variants" / variant
|
# This check is important to avoid deleting official board config variants.
|
||||||
if variant_dir.is_dir():
|
if marlin_variant_pattern.match(str(variant).lower()):
|
||||||
shutil.rmtree(variant_dir)
|
# Prepare a new empty folder at the destination
|
||||||
if not variant_dir.is_dir():
|
variant_dir = FRAMEWORK_DIR / "variants" / variant
|
||||||
variant_dir.mkdir()
|
if variant_dir.is_dir():
|
||||||
|
shutil.rmtree(variant_dir)
|
||||||
|
if not variant_dir.is_dir():
|
||||||
|
variant_dir.mkdir()
|
||||||
|
|
||||||
# Source dir is a local variant sub-folder
|
# Source dir is a local variant sub-folder
|
||||||
source_dir = Path("buildroot/share/PlatformIO/variants", variant)
|
source_dir = Path("buildroot/share/PlatformIO/variants", variant)
|
||||||
assert source_dir.is_dir()
|
assert source_dir.is_dir()
|
||||||
|
|
||||||
marlin.copytree(source_dir, variant_dir)
|
print("Copying variant " + str(variant) + " to framework directory...")
|
||||||
|
|
||||||
|
marlin.copytree(source_dir, variant_dir)
|
||||||
|
|
Loading…
Reference in a new issue