Skip to content

Commit 8ae19e4

Browse files
thinkyheadquiret
andcommitted
🔨 Prevent variant overwrite
Co-Authored-By: Martin Turski <[email protected]>
1 parent aaa5908 commit 8ae19e4

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

buildroot/share/PlatformIO/scripts/generic_create_variant.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# the appropriate framework variants folder, so that its contents
66
# will be picked up by PlatformIO just like any other variant.
77
#
8-
import pioutil
8+
import pioutil, re
9+
marlin_variant_pattern = re.compile("marlin_.*")
910
if pioutil.is_pio_build():
1011
import shutil,marlin
1112
from pathlib import Path
@@ -32,7 +33,7 @@
3233
else:
3334
platform_name = PackageSpec(platform_packages[0]).name
3435

35-
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" ]:
36+
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" ]:
3637
platform_name = "framework-arduinoststm32"
3738

3839
FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
@@ -44,15 +45,20 @@
4445
variant = board.get("build.variant")
4546
#series = mcu_type[:7].upper() + "xx"
4647

47-
# Prepare a new empty folder at the destination
48-
variant_dir = FRAMEWORK_DIR / "variants" / variant
49-
if variant_dir.is_dir():
50-
shutil.rmtree(variant_dir)
51-
if not variant_dir.is_dir():
52-
variant_dir.mkdir()
48+
# Only prepare a new variant if the PlatformIO configuration provides it (board_build.variant).
49+
# This check is important to avoid deleting official board config variants.
50+
if marlin_variant_pattern.match(str(variant).lower()):
51+
# Prepare a new empty folder at the destination
52+
variant_dir = FRAMEWORK_DIR / "variants" / variant
53+
if variant_dir.is_dir():
54+
shutil.rmtree(variant_dir)
55+
if not variant_dir.is_dir():
56+
variant_dir.mkdir()
5357

54-
# Source dir is a local variant sub-folder
55-
source_dir = Path("buildroot/share/PlatformIO/variants", variant)
56-
assert source_dir.is_dir()
58+
# Source dir is a local variant sub-folder
59+
source_dir = Path("buildroot/share/PlatformIO/variants", variant)
60+
assert source_dir.is_dir()
5761

58-
marlin.copytree(source_dir, variant_dir)
62+
print("Copying variant " + str(variant) + " to framework directory...")
63+
64+
marlin.copytree(source_dir, variant_dir)

0 commit comments

Comments
 (0)