func PrepareCommandForRecipe(properties props.PropertiesMap, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) { pattern := properties[recipe] if pattern == constants.EMPTY_STRING { return nil, i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe) } var err error commandLine := properties.ExpandPropsInString(pattern) if removeUnsetProperties { commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine) if err != nil { return nil, i18n.WrapError(err) } } command, err := utils.PrepareCommand(commandLine, logger) if err != nil { return nil, i18n.WrapError(err) } if echoCommandLine { fmt.Println(commandLine) } return command, nil }
func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties props.PropertiesMap, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) { properties := buildProperties.Clone() properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel] properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE) properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source relativeSource, err := filepath.Rel(sourcePath, source) if err != nil { return "", i18n.WrapError(err) } properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = filepath.Join(buildPath, relativeSource+".o") err = utils.EnsureFolderExists(filepath.Dir(properties[constants.BUILD_PROPERTIES_OBJECT_FILE])) if err != nil { return "", i18n.WrapError(err) } objIsUpToDate, err := ObjFileIsUpToDate(properties[constants.BUILD_PROPERTIES_SOURCE_FILE], properties[constants.BUILD_PROPERTIES_OBJECT_FILE], filepath.Join(buildPath, relativeSource+".d")) if err != nil { return "", i18n.WrapError(err) } if !objIsUpToDate { _, err = ExecRecipe(properties, recipe, false, verbose, verbose, logger) if err != nil { return "", i18n.WrapError(err) } } else if verbose { logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE]) } return properties[constants.BUILD_PROPERTIES_OBJECT_FILE], nil }
func findVIDPIDIndex(buildProperties props.PropertiesMap, vid, pid string) (int, error) { for key, value := range buildProperties.SubTree(constants.BUILD_PROPERTIES_VID) { if !strings.Contains(key, ".") { if vid == strings.ToLower(value) && pid == strings.ToLower(buildProperties[constants.BUILD_PROPERTIES_PID+"."+key]) { return strconv.Atoi(key) } } } return -1, nil }
func link(objectFiles []string, coreDotARelPath string, coreArchiveFilePath string, buildProperties props.PropertiesMap, verbose bool, warningsLevel string, logger i18n.Logger) error { optRelax := addRelaxTrickIfATMEGA2560(buildProperties) objectFiles = utils.Map(objectFiles, wrapWithDoubleQuotes) objectFileList := strings.Join(objectFiles, constants.SPACE) properties := buildProperties.Clone() properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] + optRelax properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel] properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = coreDotARelPath properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = coreArchiveFilePath properties[constants.BUILD_PROPERTIES_OBJECT_FILES] = objectFileList _, err := builder_utils.ExecRecipe(properties, constants.RECIPE_C_COMBINE_PATTERN, false, verbose, verbose, logger) return err }
func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties props.PropertiesMap, verbose bool, logger i18n.Logger) (string, error) { archiveFilePath := filepath.Join(buildPath, archiveFile) if _, err := os.Stat(archiveFilePath); err == nil { err = os.Remove(archiveFilePath) if err != nil { return "", i18n.WrapError(err) } } for _, objectFile := range objectFiles { properties := buildProperties.Clone() properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = filepath.Base(archiveFilePath) properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = archiveFilePath properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = objectFile _, err := ExecRecipe(properties, constants.RECIPE_AR_PATTERN, false, verbose, verbose, logger) if err != nil { return "", i18n.WrapError(err) } } return archiveFilePath, nil }
func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { if ctx.BuildOptionsJsonPrevious == "" { return nil } buildOptionsJson := ctx.BuildOptionsJson previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious logger := ctx.GetLogger() var opts props.PropertiesMap var prevOpts props.PropertiesMap json.Unmarshal([]byte(buildOptionsJson), &opts) json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts) // If SketchLocation path is different but filename is the same, consider it equal if filepath.Base(opts["sketchLocation"]) == filepath.Base(prevOpts["sketchLocation"]) { delete(opts, "sketchLocation") delete(prevOpts, "sketchLocation") } if opts.Equals(prevOpts) { return nil } logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED) buildPath := ctx.BuildPath files, err := gohasissues.ReadDir(buildPath) if err != nil { return i18n.WrapError(err) } for _, file := range files { os.RemoveAll(filepath.Join(buildPath, file.Name())) } return nil }