Golang arduino-cc-builder-types.Context类(方法)实例源码

下面列出了Golang arduino-cc-builder-types.Context 类(方法)源码代码实例,从而了解它的用法。

作者:facchin    项目:arduino-builde   
func (s *SketchSourceMerger) Run(ctx *types.Context) error {
	sketch := ctx.Sketch

	lineOffset := 0
	includeSection := ""
	if !sketchIncludesArduinoH(&sketch.MainFile) {
		includeSection += "#include <Arduino.h>\n"
		lineOffset++
	}
	includeSection += "#line 1 " + utils.QuoteCppString(sketch.MainFile.Name) + "\n"
	lineOffset++
	ctx.IncludeSection = includeSection

	source := includeSection
	source += addSourceWrappedWithLineDirective(&sketch.MainFile)
	lineOffset += 1
	for _, file := range sketch.OtherSketchFiles {
		source += addSourceWrappedWithLineDirective(&file)
	}

	ctx.LineOffset = lineOffset
	ctx.Source = source

	return nil
}

作者:facchin    项目:arduino-builde   
func (s *PrintUsedAndNotUsedLibraries) Run(ctx *types.Context) error {
	var logLevel string
	// Print this message as warning when the sketch didn't compile,
	// as info when we're verbose and not all otherwise
	if s.SketchError {
		logLevel = constants.LOG_LEVEL_WARN
	} else if ctx.Verbose {
		logLevel = constants.LOG_LEVEL_INFO
	} else {
		return nil
	}

	logger := ctx.GetLogger()
	libraryResolutionResults := ctx.LibrariesResolutionResults

	for header, libResResult := range libraryResolutionResults {
		logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
		logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
		for _, notUsedLibrary := range libResResult.NotUsedLibraries {
			logger.Fprintln(os.Stdout, logLevel, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
		}
	}

	time.Sleep(100 * time.Millisecond)

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *IncludesToIncludeFolders) Run(ctx *types.Context) error {
	includes := ctx.Includes
	headerToLibraries := ctx.HeaderToLibraries

	platform := ctx.TargetPlatform
	actualPlatform := ctx.ActualPlatform
	libraryResolutionResults := ctx.LibrariesResolutionResults
	importedLibraries := ctx.ImportedLibraries

	newlyImportedLibraries, err := resolveLibraries(includes, headerToLibraries, importedLibraries, []*types.Platform{actualPlatform, platform}, libraryResolutionResults)
	if err != nil {
		return i18n.WrapError(err)
	}

	foldersWithSources := ctx.FoldersWithSourceFiles

	for _, newlyImportedLibrary := range newlyImportedLibraries {
		if !sliceContainsLibrary(importedLibraries, newlyImportedLibrary) {
			importedLibraries = append(importedLibraries, newlyImportedLibrary)
			sourceFolders := types.LibraryToSourceFolder(newlyImportedLibrary)
			for _, sourceFolder := range sourceFolders {
				foldersWithSources.Push(sourceFolder)
			}
		}
	}

	ctx.ImportedLibraries = importedLibraries
	ctx.IncludeFolders = resolveIncludeFolders(newlyImportedLibraries, ctx.BuildProperties, ctx.Verbose)

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *FailIfImportedLibraryIsWrong) Run(ctx *types.Context) error {
	if len(ctx.ImportedLibraries) == 0 {
		return nil
	}

	logger := ctx.GetLogger()

	for _, library := range ctx.ImportedLibraries {
		if !library.IsLegacy {
			if stat, err := os.Stat(filepath.Join(library.Folder, constants.LIBRARY_FOLDER_ARCH)); err == nil && stat.IsDir() {
				return i18n.ErrorfWithLogger(logger, constants.MSG_ARCH_FOLDER_NOT_SUPPORTED)
			}
			for _, propName := range LIBRARY_MANDATORY_PROPERTIES {
				if _, ok := library.Properties[propName]; !ok {
					return i18n.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 i18n.ErrorfWithLogger(logger, constants.MSG_LIBRARY_CAN_USE_SRC_AND_UTILITY_FOLDERS, library.Folder)
				}
			}
		}
	}

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *RecipeByPrefixSuffixRunner) Run(ctx *types.Context) error {
	logger := ctx.GetLogger()
	if ctx.DebugLevel >= 10 {
		logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix)
	}

	buildProperties := ctx.BuildProperties.Clone()
	verbose := ctx.Verbose

	recipes := findRecipes(buildProperties, s.Prefix, s.Suffix)

	properties := buildProperties.Clone()
	for _, recipe := range recipes {
		if ctx.DebugLevel >= 10 {
			logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_RECIPE, recipe)
		}
		_, err := builder_utils.ExecRecipe(properties, recipe, false, verbose, verbose, logger)
		if err != nil {
			return i18n.WrapError(err)
		}
	}

	return nil

}

作者:me-no-de    项目:arduino-builde   
func (s *WarnAboutPlatformRewrites) Run(ctx *types.Context) error {
	if ctx.DebugLevel < 0 {
		return nil
	}

	logger := ctx.GetLogger()
	hardwareRewriteResults := ctx.HardwareRewriteResults
	targetPlatform := ctx.TargetPlatform
	actualPlatform := ctx.ActualPlatform

	platforms := []*types.Platform{targetPlatform}
	if actualPlatform != targetPlatform {
		platforms = append(platforms, actualPlatform)
	}

	for _, platform := range platforms {
		if hardwareRewriteResults[platform] != nil {
			for _, rewrite := range hardwareRewriteResults[platform] {
				logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
			}
		}
	}

	return nil
}

作者:facchin    项目:arduino-builde   
func (s *Linker) Run(ctx *types.Context) error {
	objectFilesSketch := ctx.SketchObjectFiles
	objectFilesLibraries := ctx.LibrariesObjectFiles
	objectFilesCore := ctx.CoreObjectsFiles

	var objectFiles []string
	objectFiles = append(objectFiles, objectFilesSketch...)
	objectFiles = append(objectFiles, objectFilesLibraries...)
	objectFiles = append(objectFiles, objectFilesCore...)

	coreArchiveFilePath := ctx.CoreArchiveFilePath
	buildPath := ctx.BuildPath
	coreDotARelPath, err := filepath.Rel(buildPath, coreArchiveFilePath)
	if err != nil {
		return i18n.WrapError(err)
	}

	buildProperties := ctx.BuildProperties
	verbose := ctx.Verbose
	warningsLevel := ctx.WarningsLevel
	logger := ctx.GetLogger()

	err = link(objectFiles, coreDotARelPath, coreArchiveFilePath, buildProperties, verbose, warningsLevel, logger)
	if err != nil {
		return i18n.WrapError(err)
	}

	return nil
}

作者:facchin    项目:arduino-builde   
func (s *SketchBuilder) Run(ctx *types.Context) error {
	sketchBuildPath := ctx.SketchBuildPath
	buildProperties := ctx.BuildProperties
	includes := ctx.IncludeFolders
	includes = utils.Map(includes, utils.WrapWithHyphenI)
	verbose := ctx.Verbose
	warningsLevel := ctx.WarningsLevel
	logger := ctx.GetLogger()

	err := utils.EnsureFolderExists(sketchBuildPath)
	if err != nil {
		return i18n.WrapError(err)
	}

	var objectFiles []string
	objectFiles, err = builder_utils.CompileFiles(objectFiles, sketchBuildPath, false, sketchBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
	if err != nil {
		return i18n.WrapError(err)
	}

	// The "src/" subdirectory of a sketch is compiled recursively
	sketchSrcPath := filepath.Join(sketchBuildPath, constants.SKETCH_FOLDER_SRC)
	if info, err := os.Stat(sketchSrcPath); err == nil && info.IsDir() {
		objectFiles, err = builder_utils.CompileFiles(objectFiles, sketchSrcPath, true, sketchSrcPath, buildProperties, includes, verbose, warningsLevel, logger)
		if err != nil {
			return i18n.WrapError(err)
		}
	}

	ctx.SketchObjectFiles = objectFiles

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *CTagsRunner) Run(ctx *types.Context) error {
	buildProperties := ctx.BuildProperties
	ctagsTargetFilePath := ctx.CTagsTargetFile
	logger := ctx.GetLogger()

	properties := buildProperties.Clone()
	properties.Merge(buildProperties.SubTree(constants.BUILD_PROPERTIES_TOOLS_KEY).SubTree(constants.CTAGS))
	properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = ctagsTargetFilePath

	pattern := properties[constants.BUILD_PROPERTIES_PATTERN]
	if pattern == constants.EMPTY_STRING {
		return i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, constants.CTAGS)
	}

	commandLine := properties.ExpandPropsInString(pattern)
	command, err := utils.PrepareCommand(commandLine, logger)
	if err != nil {
		return i18n.WrapError(err)
	}

	verbose := ctx.Verbose
	if verbose {
		fmt.Println(commandLine)
	}

	sourceBytes, err := command.Output()
	if err != nil {
		return i18n.WrapError(err)
	}

	ctx.CTagsOutput = string(sourceBytes)

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *WarnAboutArchIncompatibleLibraries) Run(ctx *types.Context) error {
	if ctx.DebugLevel < 0 {
		return nil
	}

	targetPlatform := ctx.TargetPlatform
	buildProperties := ctx.BuildProperties
	logger := ctx.GetLogger()

	archs := []string{}
	archs = append(archs, targetPlatform.PlatformId)

	if buildProperties[constants.BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK] != constants.EMPTY_STRING {
		overrides := strings.Split(buildProperties[constants.BUILD_PROPERTIES_ARCH_OVERRIDE_CHECK], ",")
		for _, override := range overrides {
			archs = append(archs, override)
		}
	}

	for _, importedLibrary := range ctx.ImportedLibraries {
		if !importedLibrary.SupportsArchitectures(archs) {
			logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARY_INCOMPATIBLE_ARCH, importedLibrary.Name, importedLibrary.Archs, archs)
		}
	}

	return nil
}

作者:me-no-de    项目:arduino-builde   
func printProgressIfProgressEnabledAndMachineLogger(progressEnabled bool, ctx *types.Context, progress float32) {
	if !progressEnabled {
		return
	}

	log := ctx.GetLogger()
	if log.Name() == "machine" {
		log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32))
	}
}

作者:me-no-de    项目:arduino-builde   
func (s *HardwareLoader) Run(ctx *types.Context) error {
	logger := ctx.GetLogger()

	packages := &types.Packages{}
	packages.Packages = make(map[string]*types.Package)
	packages.Properties = make(map[string]string)

	folders := ctx.HardwareFolders
	folders, err := utils.AbsolutizePaths(folders)
	if err != nil {
		return i18n.WrapError(err)
	}

	for _, folder := range folders {
		stat, err := os.Stat(folder)
		if err != nil {
			return i18n.WrapError(err)
		}
		if !stat.IsDir() {
			return i18n.ErrorfWithLogger(logger, constants.MSG_MUST_BE_A_FOLDER, folder)
		}

		hardwarePlatformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
		if err != nil {
			return i18n.WrapError(err)
		}
		packages.Properties.Merge(hardwarePlatformTxt)

		subfolders, err := utils.ReadDirFiltered(folder, utils.FilterDirs)
		if err != nil {
			return i18n.WrapError(err)
		}
		subfolders = utils.FilterOutFoldersByNames(subfolders, constants.FOLDER_TOOLS)

		for _, subfolder := range subfolders {
			subfolderPath := filepath.Join(folder, subfolder.Name())
			packageId := subfolder.Name()

			if _, err := os.Stat(filepath.Join(subfolderPath, constants.FOLDER_HARDWARE)); err == nil {
				subfolderPath = filepath.Join(subfolderPath, constants.FOLDER_HARDWARE)
			}

			targetPackage := getOrCreatePackage(packages, packageId)
			err = loadPackage(targetPackage, subfolderPath, logger)
			if err != nil {
				return i18n.WrapError(err)
			}
			packages.Packages[packageId] = targetPackage
		}
	}

	ctx.Hardware = packages

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *CreateBuildOptionsMap) Run(ctx *types.Context) error {
	buildOptions := ctx.ExtractBuildOptions()
	bytes, err := json.MarshalIndent(buildOptions, "", "  ")
	if err != nil {
		return i18n.WrapError(err)
	}

	ctx.BuildOptionsJson = string(bytes)

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *CTagsToPrototypes) Run(ctx *types.Context) error {
	tags := ctx.CTagsCollected

	lineWhereToInsertPrototypes := findLineWhereToInsertPrototypes(tags)
	if lineWhereToInsertPrototypes != -1 {
		ctx.PrototypesLineWhereToInsert = lineWhereToInsertPrototypes
	}

	ctx.Prototypes = toPrototypes(tags)
	return nil
}

作者:me-no-de    项目:arduino-builde   
func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, ctx *types.Context) {
	for _, tag := range tags {
		if !tag.SkipMe {
			skip := skipFunc(tag)
			if skip && ctx.DebugLevel >= 10 {
				ctx.GetLogger().Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_WITH_REASON, tag.FunctionName, runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name())
			}
			tag.SkipMe = skip
		}
	}
}

作者:facchin    项目:arduino-builde   
func (s *IncludesFinderWithRegExp) Run(ctx *types.Context) error {
	source := *s.Source

	match := INCLUDE_REGEXP.FindStringSubmatch(source)
	if match != nil {
		ctx.IncludeJustFound = strings.TrimSpace(match[1])
	} else {
		ctx.IncludeJustFound = findIncludeForOldCompilers(source)
	}

	return nil
}

作者:me-no-de    项目:arduino-builde   
func (s *SetCustomBuildProperties) Run(ctx *types.Context) error {
	logger := ctx.GetLogger()
	buildProperties := ctx.BuildProperties
	customBuildProperties, err := props.LoadFromSlice(ctx.CustomBuildProperties, logger)
	if err != nil {
		return i18n.WrapError(err)
	}

	for key, value := range customBuildProperties {
		buildProperties[key] = value
	}

	return nil
}

作者:me-no-de    项目:arduino-builde   
func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error {
	targetFilePath := utils.NULLFile()
	importedLibraries := ctx.ImportedLibraries
	done := false
	for !done {
		commands := []types.Command{
			&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath},
			&IncludesFinderWithRegExp{Source: &ctx.SourceGccMinusE},
			&IncludesToIncludeFolders{},
		}
		for _, command := range commands {
			err := runCommand(ctx, command)
			if err != nil {
				return i18n.WrapError(err)
			}
		}
		if len(ctx.IncludesJustFound) == 0 {
			done = true
		} else if len(ctx.ImportedLibraries) == len(importedLibraries) {
			err := runCommand(ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
			return i18n.WrapError(err)
		}
		importedLibraries = ctx.ImportedLibraries
		ctx.IncludesJustFound = []string{}
	}
	return nil
}

作者:me-no-de    项目:arduino-builde   
func tryPreprocessWithContext(t *testing.T, ctx *types.Context, sketchPath ...string) {
	sketchLocation := filepath.Join(sketchPath...)
	ctx.SketchLocation = sketchLocation

	err := builder.RunPreprocess(ctx)
	NoError(t, err, "Build error for "+sketchLocation)
}

作者:me-no-de    项目:arduino-builde   
func (s *ToolsLoader) Run(ctx *types.Context) error {
	folders := ctx.ToolsFolders

	tools := []*types.Tool{}

	for _, folder := range folders {
		builtinToolsVersionsFile, err := findBuiltinToolsVersionsFile(folder)
		if err != nil {
			return i18n.WrapError(err)
		}
		if builtinToolsVersionsFile != constants.EMPTY_STRING {
			err = loadToolsFrom(&tools, builtinToolsVersionsFile)
			if err != nil {
				return i18n.WrapError(err)
			}
		} else {
			subfolders, err := collectAllToolsFolders(folder)
			if err != nil {
				return i18n.WrapError(err)
			}

			for _, subfolder := range subfolders {
				err = loadToolsFromFolderStructure(&tools, subfolder)
				if err != nil {
					return i18n.WrapError(err)
				}
			}
		}
	}

	ctx.Tools = tools

	return nil
}


问题


面经


文章

微信
公众号

扫码关注公众号