Skip to content

Commit 4652f98

Browse files
committed
Add specifier to generated tool property keys
port of arduino/Arduino#4795 to golang should solve arduino/Arduino#5042
1 parent 0b55777 commit 4652f98

File tree

6 files changed

+43
-9
lines changed

6 files changed

+43
-9
lines changed

Diff for: src/arduino.cc/builder/builder_utils/utils.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, remo
309309
}
310310

311311
var err error
312-
commandLine := properties.ExpandPropsInString(pattern)
312+
// 1st pass with platform specifiers
313+
commandLine := properties.ExpandPropsInStringWithSpecifier(pattern, properties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE])
314+
// 2nd pass, raw
315+
commandLine = properties.ExpandPropsInString(commandLine)
313316
if removeUnsetProperties {
314317
commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine)
315318
if err != nil {

Diff for: src/arduino.cc/builder/constants/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const BUILD_PROPERTIES_PATTERN = "pattern"
6262
const BUILD_PROPERTIES_PID = "pid"
6363
const BUILD_PROPERTIES_PREPROCESSED_FILE_PATH = "preprocessed_file_path"
6464
const BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH = "runtime.hardware.path"
65+
const BUILD_PROPERTIES_RUNTIME_HARDWARE = "runtime.hardware"
6566
const BUILD_PROPERTIES_RUNTIME_OS = "runtime.os"
6667
const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path"
6768
const BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX = "runtime.tools."

Diff for: src/arduino.cc/builder/props/properties.go

+24
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@ func (aMap PropertiesMap) SubTree(key string) PropertiesMap {
143143
return aMap.FirstLevelOf()[key]
144144
}
145145

146+
func (aMap PropertiesMap) ExpandPropsInStringWithSpecifier(str string, _package string) string {
147+
replaced := true
148+
for i := 0; i < 10 && replaced; i++ {
149+
replaced = false
150+
for key, _ := range aMap {
151+
// runtime path keys MAY be expressed as subkey.vendor.arch.path
152+
// try this before the standard substitution
153+
if strings.Contains(key, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX) &&
154+
strings.Contains(key, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX) {
155+
156+
specifiedKey := strings.Replace(key, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX, "", -1)
157+
specifiedKey = strings.Replace(specifiedKey, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX, "", -1)
158+
specifiedKey = constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX +
159+
specifiedKey + "." + _package + constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX
160+
161+
newStr := strings.Replace(str, "{"+key+"}", aMap[specifiedKey], -1)
162+
replaced = replaced || str != newStr
163+
str = newStr
164+
}
165+
}
166+
}
167+
return str
168+
}
169+
146170
func (aMap PropertiesMap) ExpandPropsInString(str string) string {
147171
replaced := true
148172
for i := 0; i < 10 && replaced; i++ {

Diff for: src/arduino.cc/builder/setup_build_properties.go

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
4747

4848
targetPlatform := ctx.TargetPlatform
4949
actualPlatform := ctx.ActualPlatform
50+
targetPackage := ctx.TargetPackage
5051
targetBoard := ctx.TargetBoard
5152

5253
buildProperties := make(props.PropertiesMap)
@@ -67,6 +68,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
6768
buildProperties[constants.BUILD_PROPERTIES_BUILD_SYSTEM_PATH] = filepath.Join(actualPlatform.Folder, constants.FOLDER_SYSTEM)
6869
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH] = targetPlatform.Folder
6970
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH] = filepath.Join(targetPlatform.Folder, "..")
71+
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE] = targetPackage.PackageId
7072
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = ctx.ArduinoAPIVersion
7173
buildProperties[constants.IDE_VERSION] = ctx.ArduinoAPIVersion
7274
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS] = utils.PrettyOSName()
@@ -90,6 +92,8 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error {
9092
for _, tool := range tools {
9193
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder
9294
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+"-"+tool.Version+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder
95+
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+"."+tool.PlatformId+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder
96+
buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+"-"+tool.Version+"."+tool.PlatformId+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder
9397
}
9498

9599
if !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_SOFTWARE) {

Diff for: src/arduino.cc/builder/tools_loader.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ func collectAllToolsFolders(from string) ([]string, error) {
111111
return folders, i18n.WrapError(err)
112112
}
113113

114-
func toolsSliceContains(tools *[]*types.Tool, name, version string) bool {
114+
func toolsSliceContains(tools *[]*types.Tool, name, version string, platform string) bool {
115115
for _, tool := range *tools {
116-
if name == tool.Name && version == tool.Version {
116+
if name == tool.Name && version == tool.Version && platform == tool.PlatformId {
117117
return true
118118
}
119119
}
@@ -137,7 +137,7 @@ func loadToolsFrom(tools *[]*types.Tool, builtinToolsVersionsFilePath string) er
137137
rowParts := strings.Split(row, "=")
138138
toolName := strings.Split(rowParts[0], ".")[1]
139139
toolVersion := rowParts[1]
140-
if !toolsSliceContains(tools, toolName, toolVersion) {
140+
if !toolsSliceContains(tools, toolName, toolVersion, constants.EMPTY_STRING) {
141141
*tools = append(*tools, &types.Tool{Name: toolName, Version: toolVersion, Folder: folder})
142142
}
143143
}
@@ -175,13 +175,14 @@ func loadToolsFromFolderStructure(tools *[]*types.Tool, folder string) error {
175175
if err != nil {
176176
return i18n.WrapError(err)
177177
}
178+
_, toolPlatform := filepath.Split(filepath.Join(folder, ".."))
178179
for _, toolVersion := range toolVersions {
179180
toolFolder, err := filepath.Abs(filepath.Join(folder, toolName.Name(), toolVersion.Name()))
180181
if err != nil {
181182
return i18n.WrapError(err)
182183
}
183-
if !toolsSliceContains(tools, toolName.Name(), toolVersion.Name()) {
184-
*tools = append(*tools, &types.Tool{Name: toolName.Name(), Version: toolVersion.Name(), Folder: toolFolder})
184+
if !toolsSliceContains(tools, toolName.Name(), toolVersion.Name(), toolPlatform) {
185+
*tools = append(*tools, &types.Tool{Name: toolName.Name(), Version: toolVersion.Name(), Folder: toolFolder, PlatformId: toolPlatform})
185186
}
186187
}
187188
}

Diff for: src/arduino.cc/builder/types/types.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ type Board struct {
8888
}
8989

9090
type Tool struct {
91-
Name string
92-
Version string
93-
Folder string
91+
Name string
92+
Version string
93+
Folder string
94+
PlatformId string
9495
}
9596

9697
type LibraryLayout uint16

0 commit comments

Comments
 (0)