作者:ricklo
项目:arduino-builde
func (s *IncludesToIncludeFolders) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_LIBRARIES) {
return nil
}
includes := context[constants.CTX_INCLUDES].([]string)
headerToLibraries := context[constants.CTX_HEADER_TO_LIBRARIES].(map[string][]*types.Library)
debugLevel := utils.DebugLevel(context)
logger := context[constants.CTX_LOGGER].(i18n.Logger)
platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform)
actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform)
var previousImportedLibraries []*types.Library
if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
previousImportedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
}
importedLibraries, err := resolveLibraries(includes, headerToLibraries, previousImportedLibraries, []*types.Platform{actualPlatform, platform}, debugLevel, logger)
if err != nil {
return utils.WrapError(err)
}
context[constants.CTX_IMPORTED_LIBRARIES] = importedLibraries
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
verbose := context[constants.CTX_VERBOSE].(bool)
includeFolders := resolveIncludeFolders(importedLibraries, buildProperties, verbose)
context[constants.CTX_INCLUDE_FOLDERS] = includeFolders
return nil
}
作者:stevemarpl
项目:arduino-builde
func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}) error {
if utils.MapHas(context, constants.CTX_BUILD_PATH) {
buildPath := context[constants.CTX_BUILD_PATH].(string)
preprocPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_PREPROC))
if err != nil {
return utils.WrapError(err)
}
sketchBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_SKETCH))
if err != nil {
return utils.WrapError(err)
}
librariesBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_LIBRARIES))
if err != nil {
return utils.WrapError(err)
}
coreBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_CORE))
if err != nil {
return utils.WrapError(err)
}
context[constants.CTX_PREPROC_PATH] = preprocPath
context[constants.CTX_SKETCH_BUILD_PATH] = sketchBuildPath
context[constants.CTX_LIBRARIES_BUILD_PATH] = librariesBuildPath
context[constants.CTX_CORE_BUILD_PATH] = coreBuildPath
}
if !utils.MapHas(context, constants.CTX_WARNINGS_LEVEL) {
context[constants.CTX_WARNINGS_LEVEL] = DEFAULT_WARNINGS_LEVEL
}
if !utils.MapHas(context, constants.CTX_VERBOSE) {
context[constants.CTX_VERBOSE] = false
}
if !utils.MapHas(context, constants.CTX_DEBUG_LEVEL) {
context[constants.CTX_DEBUG_LEVEL] = DEFAULT_DEBUG_LEVEL
}
if !utils.MapHas(context, constants.CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH) {
context[constants.CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH] = DEFAULT_LIBRARY_DISCOVERY_RECURSION_DEPTH
}
sourceFiles := &types.UniqueStringQueue{}
context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE] = sourceFiles
foldersWithSources := &types.UniqueSourceFolderQueue{}
context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE] = foldersWithSources
context[constants.CTX_LIBRARY_RESOLUTION_RESULTS] = make(map[string]types.LibraryResolutionResult)
return nil
}
作者:stevemarpl
项目:arduino-builde
func (s *ContainerFindIncludes) Run(context map[string]interface{}) error {
err := runCommand(context, &IncludesToIncludeFolders{})
if err != nil {
return utils.WrapError(err)
}
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)
wheelSpins := context[constants.CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH].(int)
for i := 0; i < wheelSpins; i++ {
commands := []types.Command{
&IncludesFinderWithGCC{SourceFile: filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")},
&GCCMinusMOutputParser{},
&IncludesToIncludeFolders{},
}
for _, command := range commands {
err := runCommand(context, command)
if err != nil {
return utils.WrapError(err)
}
}
}
foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue)
foldersWithSources.Push(types.SourceFolder{Folder: context[constants.CTX_SKETCH_BUILD_PATH].(string), Recurse: true})
if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
for _, library := range context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library) {
sourceFolders := utils.LibraryToSourceFolder(library)
for _, sourceFolder := range sourceFolders {
foldersWithSources.Push(sourceFolder)
}
}
}
err = runCommand(context, &CollectAllSourceFilesFromFoldersWithSources{})
if err != nil {
return utils.WrapError(err)
}
sourceFiles := context[constants.CTX_COLLECTED_SOURCE_FILES_QUEUE].(*types.UniqueStringQueue)
for !sourceFiles.Empty() {
commands := []types.Command{
&IncludesFinderWithGCC{SourceFile: sourceFiles.Pop().(string)},
&GCCMinusMOutputParser{},
&IncludesToIncludeFolders{},
&CollectAllSourceFilesFromFoldersWithSources{},
}
for _, command := range commands {
err := runCommand(context, command)
if err != nil {
return utils.WrapError(err)
}
}
}
return nil
}
作者:ricklo
项目:arduino-builde
func (s *PrototypesAdder) Run(context map[string]interface{}) error {
source := context[constants.CTX_SOURCE].(string)
sourceRows := strings.Split(source, "\n")
if !utils.MapHas(context, constants.CTX_FIRST_FUNCTION_AT_LINE) {
return nil
}
firstFunctionLine := context[constants.CTX_FIRST_FUNCTION_AT_LINE].(int)
if firstFunctionOutsideOfSource(firstFunctionLine, sourceRows) {
return nil
}
firstFunctionChar := len(strings.Join(sourceRows[:firstFunctionLine-1], "\n")) + 1
if firstFunctionLine > 1 {
firstFunctionLine -= context[constants.CTX_LINE_OFFSET].(int)
}
prototypeSection := composePrototypeSection(firstFunctionLine, context[constants.CTX_PROTOTYPES].([]string))
context[constants.CTX_PROTOTYPE_SECTION] = prototypeSection
source = source[:firstFunctionChar] + prototypeSection + source[firstFunctionChar:]
includeSection := composeIncludeArduinoSection()
context[constants.CTX_INCLUDE_SECTION] = includeSection
source = includeSection + source
context[constants.CTX_SOURCE] = source
return nil
}
作者:andy52
项目:arduino-builde
func (s *SetupHumanLoggerIfMissing) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_LOGGER) {
context[constants.CTX_LOGGER] = i18n.HumanLogger{}
}
return nil
}
作者:andy52
项目:arduino-builde
func (s *RewriteHardwareKeys) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_PLATFORM_KEYS_REWRITE) {
return nil
}
packages := context[constants.CTX_HARDWARE].(*types.Packages)
platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite)
hardwareRewriteResults := context[constants.CTX_HARDWARE_REWRITE_RESULTS].(map[*types.Platform][]types.PlatforKeyRewrite)
for _, aPackage := range packages.Packages {
for _, platform := range aPackage.Platforms {
if platform.Properties[constants.REWRITING] != constants.REWRITING_DISABLED {
for _, rewrite := range platformKeysRewrite.Rewrites {
if platform.Properties[rewrite.Key] != constants.EMPTY_STRING && platform.Properties[rewrite.Key] == rewrite.OldValue {
platform.Properties[rewrite.Key] = rewrite.NewValue
appliedRewrites := rewritesAppliedToPlatform(platform, hardwareRewriteResults)
appliedRewrites = append(appliedRewrites, rewrite)
hardwareRewriteResults[platform] = appliedRewrites
}
}
}
}
}
return nil
}
作者:andy52
项目:arduino-builde
func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}) error {
verbose := context[constants.CTX_VERBOSE].(bool)
logger := context[constants.CTX_LOGGER].(i18n.Logger)
if !verbose || !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
return nil
}
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
for _, library := range importedLibraries {
legacy := constants.EMPTY_STRING
if library.IsLegacy {
legacy = constants.MSG_LIB_LEGACY
}
if library.Version == constants.EMPTY_STRING {
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_LIBRARY, library.Name, library.Folder, legacy)
} else {
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_LIBRARY_AT_VERSION, library.Name, library.Version, library.Folder, legacy)
}
}
time.Sleep(100 * time.Millisecond)
return nil
}
作者:andy52
项目:arduino-builde
func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON) {
return nil
}
buildOptionsJson := context[constants.CTX_BUILD_OPTIONS_JSON].(string)
previousBuildOptionsJson := context[constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON].(string)
logger := context[constants.CTX_LOGGER].(i18n.Logger)
if buildOptionsJson == previousBuildOptionsJson {
return nil
}
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)
buildPath := context[constants.CTX_BUILD_PATH].(string)
files, err := gohasissues.ReadDir(buildPath)
if err != nil {
return utils.WrapError(err)
}
for _, file := range files {
os.RemoveAll(filepath.Join(buildPath, file.Name()))
}
return nil
}
作者:andy52
项目:arduino-builde
func (s *IncludesFinderWithRegExp) Run(context map[string]interface{}) error {
source := context[s.ContextField].(string)
matches := INCLUDE_REGEXP.FindAllStringSubmatch(source, -1)
includes := []string{}
for _, match := range matches {
includes = append(includes, strings.TrimSpace(match[1]))
}
if len(includes) == 0 {
include := findIncludesForOldCompilers(source)
if include != "" {
includes = append(includes, include)
}
}
context[constants.CTX_INCLUDES_JUST_FOUND] = includes
if !utils.MapHas(context, constants.CTX_INCLUDES) {
context[constants.CTX_INCLUDES] = includes
return nil
}
context[constants.CTX_INCLUDES] = utils.AddStringsToStringsSet(context[constants.CTX_INCLUDES].([]string), includes)
return nil
}
作者:ricklo
项目:arduino-builde
func (s *RewriteHardwareKeys) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_PLATFORM_KEYS_REWRITE) {
return nil
}
hardware := context[constants.CTX_HARDWARE].(map[string]*types.Package)
platformKeysRewrite := context[constants.CTX_PLATFORM_KEYS_REWRITE].(types.PlatforKeysRewrite)
logger := context[constants.CTX_LOGGER].(i18n.Logger)
warn := utils.DebugLevel(context) > 0
for _, aPackage := range hardware {
for _, platform := range aPackage.Platforms {
if platform.Properties[constants.REWRITING] != constants.REWRITING_DISABLED {
for _, rewrite := range platformKeysRewrite.Rewrites {
if platform.Properties[rewrite.Key] != constants.EMPTY_STRING && platform.Properties[rewrite.Key] == rewrite.OldValue {
platform.Properties[rewrite.Key] = rewrite.NewValue
if warn {
logger.Fprintln(os.Stderr, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
}
}
}
}
}
}
return nil
}
作者:spiderkey
项目:arduino-builde
func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error {
buildProperties := make(props.PropertiesMap)
if p, ok := context[constants.CTX_BUILD_PROPERTIES]; ok {
buildProperties = p.(props.PropertiesMap).Clone()
}
verbose := context[constants.CTX_VERBOSE].(bool)
logger := context[constants.CTX_LOGGER].(i18n.Logger)
includesParams := constants.EMPTY_STRING
if utils.MapHas(context, constants.CTX_INCLUDE_FOLDERS) {
includes := context[constants.CTX_INCLUDE_FOLDERS].([]string)
includes = utils.Map(includes, utils.WrapWithHyphenI)
includesParams = strings.Join(includes, " ")
}
properties := buildProperties.Clone()
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = s.SourceFile
properties[constants.BUILD_PROPERTIES_INCLUDES] = includesParams
builder_utils.RemoveHyphenMDDFlagFromGCCCommandLine(properties)
output, err := builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_INCLUDES, true, verbose, false, logger)
if err != nil {
return utils.WrapError(err)
}
context[constants.CTX_GCC_MINUS_M_OUTPUT] = string(output)
return nil
}
作者:ricklo
项目:arduino-builde
func (s *GCCMinusMOutputParser) Run(context map[string]interface{}) error {
output := context[constants.CTX_GCC_MINUS_M_OUTPUT].(string)
rows := strings.Split(output, "\n")
includes := make([]string, 0)
if len(rows) > 2 {
for _, row := range rows[2:] {
if !strings.HasPrefix(row, constants.SPACE) {
row = strings.TrimSpace(row)
if row != constants.EMPTY_STRING {
row = strings.TrimSuffix(row, ":")
row = strings.Replace(row, "\\ ", " ", -1)
includes = append(includes, row)
}
}
}
}
if !utils.MapHas(context, constants.CTX_INCLUDES) {
context[constants.CTX_INCLUDES] = includes
return nil
}
previousIncludes := utils.SliceToMapStringBool(context[constants.CTX_INCLUDES].([]string), true)
currentIncludes := utils.SliceToMapStringBool(includes, true)
mergedIncludes := utils.MergeMapsOfStringBool(previousIncludes, currentIncludes)
context[constants.CTX_INCLUDES] = utils.KeysOfMapOfStringBool(mergedIncludes)
return nil
}
作者:andy52
项目:arduino-builde
func (s *FailIfImportedLibraryIsWrong) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
return nil
}
logger := context[constants.CTX_LOGGER].(i18n.Logger)
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
for _, library := range importedLibraries {
if !library.IsLegacy {
if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_ARCH)); err == nil && stat.IsDir() {
return utils.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED)
}
for _, propName := range LIBRARY_MANDATORY_PROPERTIES {
if _, ok := library.Properties[propName]; !ok {
return utils.ErrorfWithLogger(logger, constants.MSG_PROP_IN_LIBRARY, propName, library.Folder)
}
}
if library.Layout == types.LIBRARY_RECURSIVE {
if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_UTILITY)); err == nil && stat.IsDir() {
return utils.ErrorfWithLogger(logger, constants.MSG_LIBRARY_CAN_USE_SRC_AND_UTILITY_FOLDERS, library.Folder)
}
}
}
}
return nil
}
作者:andy52
项目:arduino-builde
func (s *GCCMinusMOutputParser) Run(context map[string]interface{}) error {
output := context[constants.CTX_GCC_MINUS_M_OUTPUT].(string)
rows := strings.Split(output, "\n")
includes := make([]string, 0)
if len(rows) > 2 {
for _, row := range rows[2:] {
if !strings.HasPrefix(row, constants.SPACE) {
row = strings.TrimSpace(row)
if row != constants.EMPTY_STRING {
row = strings.TrimSuffix(row, ":")
row = strings.Replace(row, "\\ ", " ", -1)
includes = append(includes, row)
}
}
}
}
if !utils.MapHas(context, constants.CTX_INCLUDES) {
context[constants.CTX_INCLUDES] = includes
return nil
}
context[constants.CTX_INCLUDES] = utils.AddStringsToStringsSet(context[constants.CTX_INCLUDES].([]string), includes)
return nil
}
作者:spiderkey
项目:arduino-builde
func (s *LoadVIDPIDSpecificProperties) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_VIDPID) {
return nil
}
vidPid := context[constants.CTX_VIDPID].(string)
vidPid = strings.ToLower(vidPid)
vidPidParts := strings.Split(vidPid, "_")
vid := vidPidParts[0]
pid := vidPidParts[1]
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
VIDPIDIndex, err := findVIDPIDIndex(buildProperties, vid, pid)
if err != nil {
return utils.WrapError(err)
}
if VIDPIDIndex < 0 {
return nil
}
vidPidSpecificProperties := buildProperties.SubTree(constants.BUILD_PROPERTIES_VID).SubTree(strconv.Itoa(VIDPIDIndex))
buildProperties.Merge(vidPidSpecificProperties)
return nil
}
作者:ricklo
项目:arduino-builde
func (s *IncludesFinderWithGCC) Run(context map[string]interface{}) error {
buildProperties := utils.GetMapStringStringOrDefault(context, constants.CTX_BUILD_PROPERTIES)
sketch := context[constants.CTX_SKETCH].(*types.Sketch)
sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)
verbose := context[constants.CTX_VERBOSE].(bool)
logger := context[constants.CTX_LOGGER].(i18n.Logger)
includesParams := ""
if utils.MapHas(context, constants.CTX_INCLUDE_FOLDERS) {
includes := context[constants.CTX_INCLUDE_FOLDERS].([]string)
includes = utils.Map(includes, utils.WrapWithHyphenI)
includesParams = strings.Join(includes, " ")
}
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp")
properties[constants.BUILD_PROPERTIES_INCLUDES] = includesParams
builder_utils.RemoveHyphenMDDFlagFromGCCCommandLine(properties)
output, err := builder_utils.ExecRecipe(properties, constants.RECIPE_PREPROC_INCLUDES, true, verbose, false, logger)
if err != nil {
return utils.WrapError(err)
}
context[constants.CTX_GCC_MINUS_M_OUTPUT] = string(output)
return nil
}
作者:ricklo
项目:arduino-builde
func (s *AddAdditionalEntriesToContext) Run(context map[string]interface{}) error {
if utils.MapHas(context, constants.CTX_BUILD_PATH) {
buildPath := context[constants.CTX_BUILD_PATH].(string)
preprocPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_PREPROC))
if err != nil {
return utils.WrapError(err)
}
sketchBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_SKETCH))
if err != nil {
return utils.WrapError(err)
}
librariesBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_LIBRARIES))
if err != nil {
return utils.WrapError(err)
}
coreBuildPath, err := filepath.Abs(filepath.Join(buildPath, constants.FOLDER_CORE))
if err != nil {
return utils.WrapError(err)
}
context[constants.CTX_PREPROC_PATH] = preprocPath
context[constants.CTX_SKETCH_BUILD_PATH] = sketchBuildPath
context[constants.CTX_LIBRARIES_BUILD_PATH] = librariesBuildPath
context[constants.CTX_CORE_BUILD_PATH] = coreBuildPath
}
if !utils.MapHas(context, constants.CTX_WARNINGS_LEVEL) {
context[constants.CTX_WARNINGS_LEVEL] = DEFAULT_WARNINGS_LEVEL
}
if !utils.MapHas(context, constants.CTX_VERBOSE) {
context[constants.CTX_VERBOSE] = false
}
if !utils.MapHas(context, constants.CTX_DEBUG_LEVEL) {
context[constants.CTX_DEBUG_LEVEL] = DEFAULT_DEBUG_LEVEL
}
if !utils.MapHas(context, constants.CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH) {
context[constants.CTX_LIBRARY_DISCOVERY_RECURSION_DEPTH] = DEFAULT_LIBRARY_DISCOVERY_RECURSION_DEPTH
}
return nil
}
作者:spiderkey
项目:arduino-builde
func (s *IncludesToIncludeFolders) Run(context map[string]interface{}) error {
includes := []string{}
if utils.MapHas(context, constants.CTX_INCLUDES) {
includes = context[constants.CTX_INCLUDES].([]string)
}
headerToLibraries := make(map[string][]*types.Library)
if utils.MapHas(context, constants.CTX_HEADER_TO_LIBRARIES) {
headerToLibraries = context[constants.CTX_HEADER_TO_LIBRARIES].(map[string][]*types.Library)
}
platform := context[constants.CTX_TARGET_PLATFORM].(*types.Platform)
actualPlatform := context[constants.CTX_ACTUAL_PLATFORM].(*types.Platform)
libraryResolutionResults := context[constants.CTX_LIBRARY_RESOLUTION_RESULTS].(map[string]types.LibraryResolutionResult)
importedLibraries := []*types.Library{}
if utils.MapHas(context, constants.CTX_IMPORTED_LIBRARIES) {
importedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
}
newlyImportedLibraries, err := resolveLibraries(includes, headerToLibraries, importedLibraries, []*types.Platform{actualPlatform, platform}, libraryResolutionResults)
if err != nil {
return utils.WrapError(err)
}
foldersWithSources := context[constants.CTX_FOLDERS_WITH_SOURCES_QUEUE].(*types.UniqueSourceFolderQueue)
for _, newlyImportedLibrary := range newlyImportedLibraries {
if !sliceContainsLibrary(importedLibraries, newlyImportedLibrary) {
importedLibraries = append(importedLibraries, newlyImportedLibrary)
sourceFolders := types.LibraryToSourceFolder(newlyImportedLibrary)
for _, sourceFolder := range sourceFolders {
foldersWithSources.Push(sourceFolder)
}
}
}
context[constants.CTX_IMPORTED_LIBRARIES] = importedLibraries
buildProperties := context[constants.CTX_BUILD_PROPERTIES].(props.PropertiesMap)
verbose := context[constants.CTX_VERBOSE].(bool)
includeFolders := resolveIncludeFolders(newlyImportedLibraries, buildProperties, verbose)
context[constants.CTX_INCLUDE_FOLDERS] = includeFolders
return nil
}
作者:andy52
项目:arduino-builde
func TestLoadPreviousBuildOptionsMapMissingFile(t *testing.T) {
context := make(map[string]interface{})
buildPath := SetupBuildPath(t, context)
defer os.RemoveAll(buildPath)
command := builder.LoadPreviousBuildOptionsMap{}
err := command.Run(context)
NoError(t, err)
require.False(t, utils.MapHas(context, constants.CTX_BUILD_OPTIONS_PREVIOUS_JSON))
}
作者:andy52
项目:arduino-builde
func (s *FailIfBuildPathEqualsSketchPath) Run(context map[string]interface{}) error {
if !utils.MapHas(context, constants.CTX_BUILD_PATH) || !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) {
return nil
}
buildPath, err := filepath.Abs(context[constants.CTX_BUILD_PATH].(string))
if err != nil {
return utils.WrapError(err)
}
sketchPath, err := filepath.Abs(context[constants.CTX_SKETCH_LOCATION].(string))
if err != nil {
return utils.WrapError(err)
}
sketchPath = filepath.Dir(sketchPath)
if buildPath == sketchPath {
return utils.Errorf(context, constants.MSG_SKETCH_CANT_BE_IN_BUILDPATH)
}
return nil
}