diff --git a/src/arduino.cc/builder/builder_utils/utils.go b/src/arduino.cc/builder/builder_utils/utils.go index 17c04fca..e5938761 100644 --- a/src/arduino.cc/builder/builder_utils/utils.go +++ b/src/arduino.cc/builder/builder_utils/utils.go @@ -309,7 +309,10 @@ func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, remo } var err error - commandLine := properties.ExpandPropsInString(pattern) + // 1st pass with platform specifiers + commandLine := properties.ExpandPropsInStringWithSpecifier(pattern, properties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE]) + // 2nd pass, raw + commandLine = properties.ExpandPropsInString(commandLine) if removeUnsetProperties { commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine) if err != nil { diff --git a/src/arduino.cc/builder/constants/constants.go b/src/arduino.cc/builder/constants/constants.go index bf5cfc35..bda30d4c 100644 --- a/src/arduino.cc/builder/constants/constants.go +++ b/src/arduino.cc/builder/constants/constants.go @@ -62,6 +62,7 @@ const BUILD_PROPERTIES_PATTERN = "pattern" const BUILD_PROPERTIES_PID = "pid" const BUILD_PROPERTIES_PREPROCESSED_FILE_PATH = "preprocessed_file_path" const BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH = "runtime.hardware.path" +const BUILD_PROPERTIES_RUNTIME_HARDWARE = "runtime.hardware" const BUILD_PROPERTIES_RUNTIME_OS = "runtime.os" const BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH = "runtime.platform.path" const BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX = "runtime.tools." @@ -74,6 +75,7 @@ const BUILD_PROPERTIES_TOOLS_KEY = "tools" const BUILD_PROPERTIES_VID = "vid" const CTAGS = "ctags" const EMPTY_STRING = "" +const ARDUINO_STRING = "arduino" const FILE_BOARDS_LOCAL_TXT = "boards.local.txt" const FILE_BOARDS_TXT = "boards.txt" const FILE_BUILTIN_TOOLS_VERSIONS_TXT = "builtin_tools_versions.txt" diff --git a/src/arduino.cc/builder/props/properties.go b/src/arduino.cc/builder/props/properties.go index c75d747a..75e98c98 100644 --- a/src/arduino.cc/builder/props/properties.go +++ b/src/arduino.cc/builder/props/properties.go @@ -143,6 +143,30 @@ func (aMap PropertiesMap) SubTree(key string) PropertiesMap { return aMap.FirstLevelOf()[key] } +func (aMap PropertiesMap) ExpandPropsInStringWithSpecifier(str string, _package string) string { + replaced := true + for i := 0; i < 10 && replaced; i++ { + replaced = false + for key, _ := range aMap { + // runtime path keys MAY be expressed as subkey.vendor.arch.path + // try this before the standard substitution + if strings.Contains(key, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX) && + strings.Contains(key, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX) { + + specifiedKey := strings.Replace(key, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX, "", -1) + specifiedKey = strings.Replace(specifiedKey, constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX, "", -1) + specifiedKey = constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX + + specifiedKey + "." + _package + constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX + + newStr := strings.Replace(str, "{"+key+"}", aMap[specifiedKey], -1) + replaced = replaced || str != newStr + str = newStr + } + } + } + return str +} + func (aMap PropertiesMap) ExpandPropsInString(str string) string { replaced := true for i := 0; i < 10 && replaced; i++ { diff --git a/src/arduino.cc/builder/setup_build_properties.go b/src/arduino.cc/builder/setup_build_properties.go index 9523a09d..19bf8e19 100644 --- a/src/arduino.cc/builder/setup_build_properties.go +++ b/src/arduino.cc/builder/setup_build_properties.go @@ -47,6 +47,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { targetPlatform := ctx.TargetPlatform actualPlatform := ctx.ActualPlatform + targetPackage := ctx.TargetPackage targetBoard := ctx.TargetBoard buildProperties := make(props.PropertiesMap) @@ -67,6 +68,7 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { buildProperties[constants.BUILD_PROPERTIES_BUILD_SYSTEM_PATH] = filepath.Join(actualPlatform.Folder, constants.FOLDER_SYSTEM) buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH] = targetPlatform.Folder buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH] = filepath.Join(targetPlatform.Folder, "..") + buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE] = targetPackage.PackageId buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = ctx.ArduinoAPIVersion buildProperties[constants.IDE_VERSION] = ctx.ArduinoAPIVersion buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS] = utils.PrettyOSName() @@ -90,6 +92,8 @@ func (s *SetupBuildProperties) Run(ctx *types.Context) error { for _, tool := range tools { buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+"-"+tool.Version+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder + buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+"."+tool.PlatformId+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder + buildProperties[constants.BUILD_PROPERTIES_RUNTIME_TOOLS_PREFIX+tool.Name+"-"+tool.Version+"."+tool.PlatformId+constants.BUILD_PROPERTIES_RUNTIME_TOOLS_SUFFIX] = tool.Folder } if !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_SOFTWARE) { diff --git a/src/arduino.cc/builder/tools_loader.go b/src/arduino.cc/builder/tools_loader.go index 621a5391..a5d5a9cd 100644 --- a/src/arduino.cc/builder/tools_loader.go +++ b/src/arduino.cc/builder/tools_loader.go @@ -111,9 +111,9 @@ func collectAllToolsFolders(from string) ([]string, error) { return folders, i18n.WrapError(err) } -func toolsSliceContains(tools *[]*types.Tool, name, version string) bool { +func toolsSliceContains(tools *[]*types.Tool, name, version string, platform string) bool { for _, tool := range *tools { - if name == tool.Name && version == tool.Version { + if name == tool.Name && version == tool.Version && platform == tool.PlatformId { return true } } @@ -137,7 +137,7 @@ func loadToolsFrom(tools *[]*types.Tool, builtinToolsVersionsFilePath string) er rowParts := strings.Split(row, "=") toolName := strings.Split(rowParts[0], ".")[1] toolVersion := rowParts[1] - if !toolsSliceContains(tools, toolName, toolVersion) { + if !toolsSliceContains(tools, toolName, toolVersion, constants.ARDUINO_STRING) { *tools = append(*tools, &types.Tool{Name: toolName, Version: toolVersion, Folder: folder}) } } @@ -175,13 +175,14 @@ func loadToolsFromFolderStructure(tools *[]*types.Tool, folder string) error { if err != nil { return i18n.WrapError(err) } + _, toolPlatform := filepath.Split(filepath.Join(folder, "..")) for _, toolVersion := range toolVersions { toolFolder, err := filepath.Abs(filepath.Join(folder, toolName.Name(), toolVersion.Name())) if err != nil { return i18n.WrapError(err) } - if !toolsSliceContains(tools, toolName.Name(), toolVersion.Name()) { - *tools = append(*tools, &types.Tool{Name: toolName.Name(), Version: toolVersion.Name(), Folder: toolFolder}) + if !toolsSliceContains(tools, toolName.Name(), toolVersion.Name(), toolPlatform) { + *tools = append(*tools, &types.Tool{Name: toolName.Name(), Version: toolVersion.Name(), Folder: toolFolder, PlatformId: toolPlatform}) } } } diff --git a/src/arduino.cc/builder/types/types.go b/src/arduino.cc/builder/types/types.go index e45bee91..9d85766a 100644 --- a/src/arduino.cc/builder/types/types.go +++ b/src/arduino.cc/builder/types/types.go @@ -88,9 +88,10 @@ type Board struct { } type Tool struct { - Name string - Version string - Folder string + Name string + Version string + Folder string + PlatformId string } type LibraryLayout uint16