2021-02-14 03:51:26 +00:00
|
|
|
#
|
2021-04-27 09:49:21 +00:00
|
|
|
# generic_create_variant.py
|
2021-02-14 03:51:26 +00:00
|
|
|
#
|
2021-04-27 09:49:21 +00:00
|
|
|
# Copy one of the variants from buildroot/platformio/variants into
|
|
|
|
# the appropriate framework variants folder, so that its contents
|
|
|
|
# will be picked up by PlatformIO just like any other variant.
|
|
|
|
#
|
2021-11-04 10:28:42 +00:00
|
|
|
import pioutil
|
|
|
|
if pioutil.is_pio_build():
|
2022-08-01 06:14:58 +00:00
|
|
|
import shutil,marlin
|
|
|
|
from pathlib import Path
|
2021-11-04 10:28:42 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Get the platform name from the 'platform_packages' option,
|
|
|
|
# or look it up by the platform.class.name.
|
|
|
|
#
|
2022-08-01 06:14:58 +00:00
|
|
|
env = marlin.env
|
2021-11-04 10:28:42 +00:00
|
|
|
platform = env.PioPlatform()
|
|
|
|
|
|
|
|
from platformio.package.meta import PackageSpec
|
|
|
|
platform_packages = env.GetProjectOption('platform_packages')
|
2022-06-30 01:16:16 +00:00
|
|
|
|
|
|
|
# Remove all tool items from platform_packages
|
|
|
|
platform_packages = [x for x in platform_packages if not x.startswith("platformio/tool-")]
|
|
|
|
|
2021-11-04 10:28:42 +00:00
|
|
|
if len(platform_packages) == 0:
|
|
|
|
framewords = {
|
|
|
|
"Ststm32Platform": "framework-arduinoststm32",
|
|
|
|
"AtmelavrPlatform": "framework-arduino-avr"
|
|
|
|
}
|
|
|
|
platform_name = framewords[platform.__class__.__name__]
|
|
|
|
else:
|
|
|
|
platform_name = PackageSpec(platform_packages[0]).name
|
|
|
|
|
2021-12-10 19:38:03 +00:00
|
|
|
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" ]:
|
2021-11-04 10:28:42 +00:00
|
|
|
platform_name = "framework-arduinoststm32"
|
|
|
|
|
2022-08-01 06:14:58 +00:00
|
|
|
FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
|
|
|
|
assert FRAMEWORK_DIR.is_dir()
|
2021-11-04 10:28:42 +00:00
|
|
|
|
|
|
|
board = env.BoardConfig()
|
|
|
|
|
|
|
|
#mcu_type = board.get("build.mcu")[:-2]
|
|
|
|
variant = board.get("build.variant")
|
|
|
|
#series = mcu_type[:7].upper() + "xx"
|
|
|
|
|
|
|
|
# Prepare a new empty folder at the destination
|
2022-08-01 06:14:58 +00:00
|
|
|
variant_dir = FRAMEWORK_DIR / "variants" / variant
|
|
|
|
if variant_dir.is_dir():
|
2021-11-04 10:28:42 +00:00
|
|
|
shutil.rmtree(variant_dir)
|
2022-08-01 06:14:58 +00:00
|
|
|
if not variant_dir.is_dir():
|
|
|
|
variant_dir.mkdir()
|
2021-11-04 10:28:42 +00:00
|
|
|
|
|
|
|
# Source dir is a local variant sub-folder
|
2022-08-01 06:14:58 +00:00
|
|
|
source_dir = Path("buildroot/share/PlatformIO/variants", variant)
|
|
|
|
assert source_dir.is_dir()
|
2021-11-04 10:28:42 +00:00
|
|
|
|
|
|
|
marlin.copytree(source_dir, variant_dir)
|