generic_create_variant.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #
  2. # generic_create_variant.py
  3. #
  4. # Copy one of the variants from buildroot/platformio/variants into
  5. # the appropriate framework variants folder, so that its contents
  6. # will be picked up by PlatformIO just like any other variant.
  7. #
  8. import pioutil, re
  9. marlin_variant_pattern = re.compile("marlin_.*")
  10. if pioutil.is_pio_build():
  11. import shutil, marlin
  12. from pathlib import Path
  13. #
  14. # Get the platform name from the 'platform_packages' option,
  15. # or look it up by the platform.class.name.
  16. #
  17. env = pioutil.env
  18. platform = env.PioPlatform()
  19. from platformio.package.meta import PackageSpec
  20. platform_packages = env.GetProjectOption('platform_packages')
  21. # Remove all tool items from platform_packages
  22. platform_packages = [x for x in platform_packages if not x.startswith("platformio/tool-")]
  23. if len(platform_packages) == 0:
  24. framewords = {
  25. "Ststm32Platform": "framework-arduinoststm32",
  26. "AtmelavrPlatform": "framework-arduino-avr"
  27. }
  28. platform_name = framewords[platform.__class__.__name__]
  29. else:
  30. spec = PackageSpec(platform_packages[0])
  31. if spec.uri and '@' in spec.uri:
  32. platform_name = re.sub(r'@.+', '', spec.uri)
  33. else:
  34. platform_name = spec.name
  35. FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
  36. assert FRAMEWORK_DIR.is_dir()
  37. #
  38. # Point variants_dir to our variant folder when board_build.variant
  39. # is provided and the variant name begins with "marlin_".
  40. #
  41. board = env.BoardConfig()
  42. variant = board.get("build.variant")
  43. #mcu_type = board.get("build.mcu")[:-2]
  44. #series = mcu_type[:7].upper() + "xx"
  45. # Make sure the local variant sub-folder exists
  46. if marlin_variant_pattern.match(str(variant).lower()):
  47. here = Path.cwd()
  48. variants_dir = here / 'buildroot' / 'share' / 'PlatformIO' / 'variants'
  49. source_dir = variants_dir / variant
  50. assert source_dir.is_dir()
  51. board.update("build.variants_dir", str(variants_dir));