Skip to content

Add specifier to generated tool property keys #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/arduino.cc/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/arduino.cc/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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"
Expand Down
24 changes: 24 additions & 0 deletions src/arduino.cc/builder/props/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down
4 changes: 4 additions & 0 deletions src/arduino.cc/builder/setup_build_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions src/arduino.cc/builder/tools_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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})
}
}
Expand Down Expand Up @@ -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})
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/arduino.cc/builder/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down