func PrepareCommandForRecipe(properties map[string]string, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) { pattern := properties[recipe] if pattern == constants.EMPTY_STRING { return nil, utils.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe) } var err error commandLine := props.ExpandPropsInString(properties, pattern) if removeUnsetProperties { commandLine, err = props.DeleteUnexpandedPropsFromString(commandLine) if err != nil { return nil, utils.WrapError(err) } } command, err := utils.PrepareCommand(commandLine, logger) if err != nil { return nil, utils.WrapError(err) } if echoCommandLine { fmt.Println(commandLine) } return command, nil }
func (s *CTagsRunner) Run(context map[string]interface{}) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string) ctagsTargetFileName := context[constants.CTX_CTAGS_TEMP_FILE_NAME].(string) logger := context[constants.CTX_LOGGER].(i18n.Logger) properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties, props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_TOOLS_KEY), constants.CTAGS)) properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = ctagsTargetFileName pattern := properties[constants.BUILD_PROPERTIES_PATTERN] if pattern == constants.EMPTY_STRING { return utils.Errorf(context, constants.MSG_PATTERN_MISSING, constants.CTAGS) } commandLine := props.ExpandPropsInString(properties, pattern) command, err := utils.PrepareCommand(commandLine, logger) if err != nil { return utils.WrapError(err) } verbose := context[constants.CTX_VERBOSE].(bool) if verbose { fmt.Println(commandLine) } sourceBytes, err := command.Output() if err != nil { return utils.WrapError(err) } context[constants.CTX_CTAGS_OUTPUT] = string(sourceBytes) return nil }
func TestExpandPropsInString2(t *testing.T) { aMap := make(map[string]string) aMap["key2"] = "{key2}" aMap["key1"] = "42" str := "{key1} == {key2} == true" str = props.ExpandPropsInString(aMap, str) require.Equal(t, "42 == {key2} == true", str) }
func TestDeleteUnexpandedPropsFromString2(t *testing.T) { aMap := make(map[string]string) aMap["key2"] = "42" str := "{key1} == {key2} == {key3} == true" str = props.ExpandPropsInString(aMap, str) str, err := props.DeleteUnexpandedPropsFromString(str) NoError(t, err) require.Equal(t, " == 42 == == true", str) }
func (s *MergeSketchWithBootloader) Run(context map[string]interface{}) error { buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string) if !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) && !utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_FILE) { return nil } buildPath := context[constants.CTX_BUILD_PATH].(string) sketch := context[constants.CTX_SKETCH].(*types.Sketch) sketchFileName := filepath.Base(sketch.MainFile.Name) logger := context[constants.CTX_LOGGER].(i18n.Logger) sketchInBuildPath := filepath.Join(buildPath, sketchFileName+".hex") sketchInSubfolder := filepath.Join(buildPath, constants.FOLDER_SKETCH, sketchFileName+".hex") builtSketchPath := constants.EMPTY_STRING if _, err := os.Stat(sketchInBuildPath); err == nil { builtSketchPath = sketchInBuildPath } else if _, err := os.Stat(sketchInSubfolder); err == nil { builtSketchPath = sketchInSubfolder } else { return nil } bootloader := constants.EMPTY_STRING if utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK) { bootloader = buildProperties[constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK] } else { bootloader = buildProperties[constants.BUILD_PROPERTIES_BOOTLOADER_FILE] } bootloader = props.ExpandPropsInString(buildProperties, bootloader) bootloaderPath := filepath.Join(buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH], constants.FOLDER_BOOTLOADERS, bootloader) if _, err := os.Stat(bootloaderPath); err != nil { logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_BOOTLOADER_FILE_MISSING, bootloaderPath) return nil } mergedSketchPath := filepath.Join(filepath.Dir(builtSketchPath), sketchFileName+".with_bootloader.hex") err := merge(builtSketchPath, bootloaderPath, mergedSketchPath) return err }
func (s *CoanRunner) Run(context map[string]interface{}) error { source := context[constants.CTX_SOURCE].(string) source += "\n" verbose := context[constants.CTX_VERBOSE].(bool) preprocPath := context[constants.CTX_PREPROC_PATH].(string) err := utils.EnsureFolderExists(preprocPath) if err != nil { return utils.WrapError(err) } coanTargetFileName := filepath.Join(preprocPath, constants.FILE_COAN_TARGET) err = utils.WriteFile(coanTargetFileName, source) if err != nil { return utils.WrapError(err) } buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string) properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties, props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_TOOLS_KEY), constants.COAN)) properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = coanTargetFileName pattern := properties[constants.BUILD_PROPERTIES_PATTERN] if pattern == constants.EMPTY_STRING { return utils.Errorf(context, constants.MSG_PATTERN_MISSING, constants.COAN) } logger := context[constants.CTX_LOGGER].(i18n.Logger) commandLine := props.ExpandPropsInString(properties, pattern) command, err := utils.PrepareCommandFilteredArgs(commandLine, filterAllowedArg, logger) if verbose { fmt.Println(commandLine) } sourceBytes, _ := command.Output() context[constants.CTX_SOURCE] = string(sourceBytes) return nil }