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.
|
|
|
|
#
|
2023-08-03 06:28:06 +00:00
|
|
|
import pioutil, re
|
2024-11-25 03:12:24 +00:00
|
|
|
|
2023-08-03 06:28:06 +00:00
|
|
|
marlin_variant_pattern = re.compile("marlin_.*")
|
2021-11-04 10:28:42 +00:00
|
|
|
if pioutil.is_pio_build():
|
2024-06-14 21:01:34 +00:00
|
|
|
import shutil, marlin
|
2022-08-19 16:00:52 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
#
|
|
|
|
# Get the platform name from the 'platform_packages' option,
|
|
|
|
# or look it up by the platform.class.name.
|
|
|
|
#
|
2024-06-14 21:01:34 +00:00
|
|
|
env = pioutil.env
|
2022-08-19 16:00:52 +00:00
|
|
|
platform = env.PioPlatform()
|
|
|
|
|
|
|
|
from platformio.package.meta import PackageSpec
|
|
|
|
platform_packages = env.GetProjectOption('platform_packages')
|
|
|
|
|
|
|
|
# Remove all tool items from platform_packages
|
|
|
|
platform_packages = [x for x in platform_packages if not x.startswith("platformio/tool-")]
|
|
|
|
|
|
|
|
if len(platform_packages) == 0:
|
|
|
|
framewords = {
|
|
|
|
"Ststm32Platform": "framework-arduinoststm32",
|
|
|
|
"AtmelavrPlatform": "framework-arduino-avr"
|
|
|
|
}
|
|
|
|
platform_name = framewords[platform.__class__.__name__]
|
|
|
|
else:
|
2023-11-14 07:52:22 +00:00
|
|
|
spec = PackageSpec(platform_packages[0])
|
|
|
|
if spec.uri and '@' in spec.uri:
|
|
|
|
platform_name = re.sub(r'@.+', '', spec.uri)
|
2023-11-12 02:13:23 +00:00
|
|
|
else:
|
2023-11-14 07:52:22 +00:00
|
|
|
platform_name = spec.name
|
2022-08-19 16:00:52 +00:00
|
|
|
|
|
|
|
FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
|
|
|
|
assert FRAMEWORK_DIR.is_dir()
|
|
|
|
|
2024-11-02 23:42:20 +00:00
|
|
|
#
|
|
|
|
# Point variants_dir to our variant folder when board_build.variant
|
|
|
|
# is provided and the variant name begins with "marlin_".
|
|
|
|
#
|
2022-08-19 16:00:52 +00:00
|
|
|
board = env.BoardConfig()
|
|
|
|
variant = board.get("build.variant")
|
2024-11-02 23:42:20 +00:00
|
|
|
#mcu_type = board.get("build.mcu")[:-2]
|
2022-08-19 16:00:52 +00:00
|
|
|
#series = mcu_type[:7].upper() + "xx"
|
|
|
|
|
2024-11-02 23:42:20 +00:00
|
|
|
# Make sure the local variant sub-folder exists
|
2023-08-03 06:28:06 +00:00
|
|
|
if marlin_variant_pattern.match(str(variant).lower()):
|
2024-11-12 23:44:34 +00:00
|
|
|
here = Path.cwd()
|
|
|
|
variants_dir = here / 'buildroot' / 'share' / 'PlatformIO' / 'variants'
|
|
|
|
source_dir = variants_dir / variant
|
2023-08-03 06:28:06 +00:00
|
|
|
assert source_dir.is_dir()
|
2024-11-25 03:12:24 +00:00
|
|
|
board.update("build.variants_dir", str(variants_dir))
|