Skip to content

Commit e876260

Browse files
Add support for custom boards variants directory (#238)
1 parent 42773a2 commit e876260

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

builder/frameworks/arduino/arduino-sam.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import os
2626

27+
from arduino_common import get_variants_dir
28+
2729
from SCons.Script import DefaultEnvironment
2830

2931
env = DefaultEnvironment()
@@ -40,7 +42,7 @@
4042
assert os.path.isdir(SYSTEM_DIR)
4143
assert os.path.isdir(FRAMEWORK_DIR)
4244

43-
env.SConscript("arduino-common.py")
45+
env.SConscript("arduino_common.py")
4446

4547
env.Append(
4648
CPPDEFINES=[
@@ -71,9 +73,7 @@
7173
libs = []
7274

7375
if "build.variant" in board:
74-
variants_dir = os.path.join(
75-
"$PROJECT_DIR", board.get("build.variants_dir")) if board.get(
76-
"build.variants_dir", "") else os.path.join(FRAMEWORK_DIR, "variants")
76+
variants_dir = get_variants_dir()
7777
env.Append(
7878
CPPPATH=[
7979
os.path.join(variants_dir, board.get("build.variant"))

builder/frameworks/arduino/arduino-samd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import os
2626

27+
from arduino_common import get_variants_dir
28+
2729
from SCons.Script import DefaultEnvironment
2830

2931
env = DefaultEnvironment()
@@ -41,7 +43,7 @@
4143

4244
assert all(os.path.isdir(d) for d in (FRAMEWORK_DIR, CMSIS_DIR, CMSIS_ATMEL_DIR))
4345

44-
env.SConscript("arduino-common.py")
46+
env.SConscript("arduino_common.py")
4547

4648
BUILD_CORE = "arduino"
4749
if VENDOR_CORE == "sparkfun" and board.get("build.mcu", "").startswith("samd51"):
@@ -178,9 +180,7 @@
178180
libs = []
179181

180182
if "build.variant" in board:
181-
variants_dir = os.path.join(
182-
"$PROJECT_DIR", board.get("build.variants_dir")) if board.get(
183-
"build.variants_dir", "") else os.path.join(FRAMEWORK_DIR, "variants")
183+
variants_dir = get_variants_dir()
184184

185185
env.Append(
186186
CPPPATH=[os.path.join(variants_dir, board.get("build.variant"))]

builder/frameworks/arduino/arduino-common.py renamed to builder/frameworks/arduino/arduino_common.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@
4242

4343
assert os.path.isdir(FRAMEWORK_DIR)
4444

45+
46+
def get_variants_dir():
47+
if "build.variants_dir" not in board:
48+
return os.path.join(FRAMEWORK_DIR, "variants")
49+
50+
if os.path.isabs(env.subst(board.get("build.variants_dir"))):
51+
return board.get("build.variants_dir", "")
52+
53+
return os.path.join("$PROJECT_DIR", board.get("build.variants_dir"))
54+
55+
4556
machine_flags = [
4657
"-mcpu=%s" % board.get("build.cpu"),
4758
"-mthumb",
@@ -95,19 +106,18 @@
95106
LIBS=["m"]
96107
)
97108

98-
variants_dir = os.path.join(
99-
"$PROJECT_DIR", board.get("build.variants_dir")) if board.get(
100-
"build.variants_dir", "") else os.path.join(FRAMEWORK_DIR, "variants")
101-
102109
if not board.get("build.ldscript", ""):
103110
env.Append(
104111
LIBPATH=[
105-
os.path.join(variants_dir, board.get("build.variant"), "linker_scripts", "gcc")
112+
os.path.join(
113+
get_variants_dir(),
114+
board.get("build.variant"),
115+
"linker_scripts",
116+
"gcc",
117+
)
106118
]
107119
)
108-
env.Replace(
109-
LDSCRIPT_PATH=board.get("build.arduino.ldscript", "")
110-
)
120+
env.Replace(LDSCRIPT_PATH=board.get("build.arduino.ldscript", ""))
111121

112122
if "build.usb_product" in board:
113123
env.Append(

0 commit comments

Comments
 (0)