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
}
func downloadAndUnpackLibrary(library Library, url string, targetPath string) error {
	if libraryAlreadyDownloadedAndUnpacked(targetPath, library) {
		return nil
	}

	targetPath, err := filepath.Abs(targetPath)
	if err != nil {
		return utils.WrapError(err)
	}

	unpackFolder, files, err := downloadAndUnpack(url)
	if err != nil {
		return utils.WrapError(err)
	}
	defer os.RemoveAll(unpackFolder)

	_, err = os.Stat(filepath.Join(targetPath, strings.Replace(library.Name, " ", "_", -1)))
	if err == nil {
		err = os.RemoveAll(filepath.Join(targetPath, strings.Replace(library.Name, " ", "_", -1)))
		if err != nil {
			return utils.WrapError(err)
		}
	}

	err = copyRecursive(filepath.Join(unpackFolder, files[0].Name()), filepath.Join(targetPath, strings.Replace(library.Name, " ", "_", -1)))
	if err != nil {
		return utils.WrapError(err)
	}

	return nil
}
func compileCore(buildPath string, buildProperties map[string]string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
	coreFolder := buildProperties[constants.BUILD_PROPERTIES_BUILD_CORE_PATH]
	variantFolder := buildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH]

	var includes []string
	includes = append(includes, coreFolder)
	if variantFolder != constants.EMPTY_STRING {
		includes = append(includes, variantFolder)
	}
	includes = utils.Map(includes, utils.WrapWithHyphenI)

	var err error

	var variantObjectFiles []string
	if variantFolder != constants.EMPTY_STRING {
		variantObjectFiles, err = builder_utils.CompileFiles(variantObjectFiles, variantFolder, true, buildPath, buildProperties, includes, verbose, warningsLevel, logger)
		if err != nil {
			return "", utils.WrapError(err)
		}
	}

	coreObjectFiles, err := builder_utils.CompileFiles([]string{}, coreFolder, true, buildPath, buildProperties, includes, verbose, warningsLevel, logger)
	if err != nil {
		return "", utils.WrapError(err)
	}

	objectFiles := append(coreObjectFiles, variantObjectFiles...)

	archiveFile, err := builder_utils.ArchiveCompiledFiles(buildPath, "core.a", objectFiles, buildProperties, verbose, logger)
	if err != nil {
		return "", utils.WrapError(err)
	}

	return archiveFile, nil
}
Example #4
0
func (s *ToolsLoader) Run(context map[string]interface{}) error {
	folders := context[constants.CTX_TOOLS_FOLDERS].([]string)

	tools := []*types.Tool{}

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

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

	context[constants.CTX_TOOLS] = tools

	return nil
}
Example #5
0
func collectAllToolsFolders(from string) ([]string, error) {
	folders := []string{}
	walkFunc := func(currentPath string, info os.FileInfo, err error) error {
		if err != nil {
			return nil
		}

		if !info.IsDir() {
			return nil
		}

		rel, err := filepath.Rel(from, currentPath)
		if err != nil {
			return utils.WrapError(err)
		}
		depth := len(strings.Split(rel, string(os.PathSeparator)))

		if info.Name() == constants.FOLDER_TOOLS && depth == 2 {
			folders = append(folders, currentPath)
		} else if depth > 2 {
			return filepath.SkipDir
		}

		return nil
	}
	err := gohasissues.Walk(from, walkFunc)

	if len(folders) == 0 {
		folders = append(folders, from)
	}

	return folders, utils.WrapError(err)
}
Example #6
0
func loadToolsFrom(tools *[]*types.Tool, builtinToolsVersionsFilePath string) error {
	rows, err := utils.ReadFileToRows(builtinToolsVersionsFilePath)
	if err != nil {
		return utils.WrapError(err)
	}

	folder, err := filepath.Abs(filepath.Dir(builtinToolsVersionsFilePath))
	if err != nil {
		return utils.WrapError(err)
	}

	for _, row := range rows {
		row = strings.TrimSpace(row)
		if row != constants.EMPTY_STRING {
			rowParts := strings.Split(row, "=")
			toolName := strings.Split(rowParts[0], ".")[1]
			toolVersion := rowParts[1]
			if !toolsSliceContains(tools, toolName, toolVersion) {
				*tools = append(*tools, &types.Tool{Name: toolName, Version: toolVersion, Folder: folder})
			}
		}
	}

	return nil
}
func downloadToolsMultipleVersions(tools []Tool, index map[string]interface{}) error {
	host := translateGOOSGOARCHToPackageIndexValue()

	for _, tool := range tools {
		if !toolAlreadyDownloadedAndUnpacked(TOOLS_FOLDER, tool) {
			_, err := os.Stat(filepath.Join(TOOLS_FOLDER, tool.Name))
			if err == nil {
				err = os.RemoveAll(filepath.Join(TOOLS_FOLDER, tool.Name))
				if err != nil {
					return utils.WrapError(err)
				}
			}
		}
	}

	for _, tool := range tools {
		url, err := findToolUrl(index, tool, host)
		if err != nil {
			return utils.WrapError(err)
		}
		err = downloadAndUnpackTool(tool, url, TOOLS_FOLDER, false)
		if err != nil {
			return utils.WrapError(err)
		}
	}

	return nil
}
func (s *UnusedCompiledLibrariesRemover) Run(context map[string]interface{}) error {
	librariesBuildPath := context[constants.CTX_LIBRARIES_BUILD_PATH].(string)
	libraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)

	_, err := os.Stat(librariesBuildPath)
	if err != nil && os.IsNotExist(err) {
		return nil
	}

	libraryNames := toLibraryNames(libraries)

	files, err := ioutil.ReadDir(librariesBuildPath)
	if err != nil {
		return utils.WrapError(err)
	}
	for _, file := range files {
		if file.IsDir() {
			if !utils.SliceContains(libraryNames, file.Name()) {
				err := os.RemoveAll(filepath.Join(librariesBuildPath, file.Name()))
				if err != nil {
					return utils.WrapError(err)
				}
			}
		}
	}

	return nil
}
Example #9
0
func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties map[string]string, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
	properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
	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 "", utils.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 "", utils.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 "", utils.WrapError(err)
	}

	if !objIsUpToDate {
		_, err = ExecRecipe(properties, recipe, false, verbose, verbose, logger)
		if err != nil {
			return "", utils.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
}
Example #10
0
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 loadBoards(boards map[string]*types.Board, packageId string, platformId string, folder string, logger i18n.Logger) error {
	properties, err := props.Load(filepath.Join(folder, constants.FILE_BOARDS_TXT), logger)
	if err != nil {
		return utils.WrapError(err)
	}

	localProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_BOARDS_LOCAL_TXT), logger)
	if err != nil {
		return utils.WrapError(err)
	}

	properties = utils.MergeMapsOfStrings(properties, localProperties)

	propertiesByBoardId := props.FirstLevelOf(properties)
	delete(propertiesByBoardId, constants.BOARD_PROPERTIES_MENU)

	for boardId, properties := range propertiesByBoardId {
		properties[constants.ID] = boardId
		board := getOrCreateBoard(boards, boardId)
		board.Properties = utils.MergeMapsOfStrings(board.Properties, properties)
		boards[boardId] = board
	}

	return nil
}
Example #12
0
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 findIncludesUntilDone(context map[string]interface{}, sourceFilePath string) error {
	targetFilePath := utils.NULLFile()
	importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
	done := false
	for !done {
		commands := []types.Command{
			&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath},
			&IncludesFinderWithRegExp{ContextField: constants.CTX_GCC_MINUS_E_SOURCE},
			&IncludesToIncludeFolders{},
		}
		for _, command := range commands {
			err := runCommand(context, command)
			if err != nil {
				return utils.WrapError(err)
			}
		}
		if len(context[constants.CTX_INCLUDES_JUST_FOUND].([]string)) == 0 {
			done = true
		} else if len(context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)) == len(importedLibraries) {
			err := runCommand(context, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
			return utils.WrapError(err)
		}
		importedLibraries = context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
		context[constants.CTX_INCLUDES_JUST_FOUND] = []string{}
	}
	return nil
}
func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}) error {
	sketch := context[constants.CTX_SKETCH].(*types.Sketch)
	sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)

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

	sketchBasePath := filepath.Dir(sketch.MainFile.Name)

	for _, file := range sketch.AdditionalFiles {
		relativePath, err := filepath.Rel(sketchBasePath, file.Name)
		if err != nil {
			return utils.WrapError(err)
		}

		targetFilePath := filepath.Join(sketchBuildPath, relativePath)
		err = utils.EnsureFolderExists(filepath.Dir(targetFilePath))
		if err != nil {
			return utils.WrapError(err)
		}

		bytes, err := ioutil.ReadFile(file.Name)
		if err != nil {
			return utils.WrapError(err)
		}

		utils.WriteFileBytes(targetFilePath, bytes)
	}

	return nil
}
Example #15
0
func (s *Linker) Run(context map[string]interface{}) error {
	objectFilesSketch := context[constants.CTX_OBJECT_FILES_SKETCH].([]string)
	objectFilesLibraries := context[constants.CTX_OBJECT_FILES_LIBRARIES].([]string)
	objectFilesCore := context[constants.CTX_OBJECT_FILES_CORE].([]string)

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

	coreArchiveFilePath := context[constants.CTX_ARCHIVE_FILE_PATH_CORE].(string)
	buildPath := context[constants.CTX_BUILD_PATH].(string)
	coreDotARelPath, err := filepath.Rel(buildPath, coreArchiveFilePath)
	if err != nil {
		return utils.WrapError(err)
	}

	buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)
	verbose := context[constants.CTX_VERBOSE].(bool)
	warningsLevel := context[constants.CTX_WARNINGS_LEVEL].(string)
	logger := context[constants.CTX_LOGGER].(i18n.Logger)

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

	return nil
}
Example #16
0
func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]string, error) {
	files, err := utils.ReadDirFiltered(sourcePath, utils.FilterFilesWithExtension(extension))
	if err != nil {
		return nil, utils.WrapError(err)
	}
	var sources []string
	for _, file := range files {
		sources = append(sources, filepath.Join(sourcePath, file.Name()))
	}

	if recurse {
		folders, err := utils.ReadDirFiltered(sourcePath, utils.FilterDirs)
		if err != nil {
			return nil, utils.WrapError(err)
		}

		for _, folder := range folders {
			otherSources, err := findFilesInFolder(filepath.Join(sourcePath, folder.Name()), extension, recurse)
			if err != nil {
				return nil, utils.WrapError(err)
			}
			sources = append(sources, otherSources...)
		}
	}

	return sources, nil
}
func (s *AdditionalSketchFilesCopier) Run(context map[string]interface{}) error {
	sketch := context[constants.CTX_SKETCH].(*types.Sketch)
	sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)

	err := os.MkdirAll(sketchBuildPath, os.FileMode(0755))
	if err != nil {
		return utils.WrapError(err)
	}

	sketchBasePath := filepath.Dir(sketch.MainFile.Name)

	for _, file := range sketch.AdditionalFiles {
		relativePath, err := filepath.Rel(sketchBasePath, file.Name)
		if err != nil {
			return utils.WrapError(err)
		}

		targetFilePath := filepath.Join(sketchBuildPath, relativePath)
		os.MkdirAll(filepath.Dir(targetFilePath), os.FileMode(0755))

		bytes, err := ioutil.ReadFile(file.Name)
		if err != nil {
			return utils.WrapError(err)
		}

		ioutil.WriteFile(targetFilePath, bytes, os.FileMode(0644))
	}

	return nil
}
func compileLibrary(objectFiles []string, library *types.Library, buildPath string, buildProperties map[string]string, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
	libraryBuildPath := filepath.Join(buildPath, library.Name)

	err := os.MkdirAll(libraryBuildPath, os.FileMode(0755))
	if err != nil {
		return nil, utils.WrapError(err)
	}

	if library.Layout == types.LIBRARY_RECURSIVE {
		objectFiles, err = builder_utils.CompileFilesRecursive(objectFiles, library.SrcFolder, libraryBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
		if err != nil {
			return nil, utils.WrapError(err)
		}
	} else {
		utilitySourcePath := filepath.Join(library.SrcFolder, constants.LIBRARY_FOLDER_UTILITY)
		_, utilitySourcePathErr := os.Stat(utilitySourcePath)
		if utilitySourcePathErr == nil {
			includes = append(includes, utils.WrapWithHyphenI(utilitySourcePath))
		}
		objectFiles, err = builder_utils.CompileFiles(objectFiles, library.SrcFolder, false, libraryBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
		if err != nil {
			return nil, utils.WrapError(err)
		}

		if utilitySourcePathErr == nil {
			utilityBuildPath := filepath.Join(libraryBuildPath, constants.LIBRARY_FOLDER_UTILITY)
			objectFiles, err = builder_utils.CompileFiles(objectFiles, utilitySourcePath, false, utilityBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
			if err != nil {
				return nil, utils.WrapError(err)
			}
		}
	}

	return objectFiles, nil
}
func (s *HardwareLoader) Run(context map[string]interface{}) error {
	logger := context[constants.CTX_LOGGER].(i18n.Logger)

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

	folders := context[constants.CTX_HARDWARE_FOLDERS].([]string)
	folders, err := utils.AbsolutizePaths(folders)
	if err != nil {
		return utils.WrapError(err)
	}

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

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

		subfolders, err := utils.ReadDirFiltered(folder, utils.FilterDirs)
		if err != nil {
			return utils.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 utils.WrapError(err)
			}
			packages.Packages[packageId] = targetPackage
		}
	}

	context[constants.CTX_HARDWARE] = packages

	return nil
}
func (s *GCCPreprocSourceSaver) Run(context map[string]interface{}) error {
	preprocPath := context[constants.CTX_PREPROC_PATH].(string)
	err := utils.EnsureFolderExists(preprocPath)
	if err != nil {
		return utils.WrapError(err)
	}

	source := context[constants.CTX_SOURCE].(string)

	err = utils.WriteFile(filepath.Join(preprocPath, constants.FILE_GCC_PREPROC_TARGET), source)
	return utils.WrapError(err)
}
Example #21
0
func (s *SketchSaver) Run(context map[string]interface{}) error {
	sketch := context[constants.CTX_SKETCH].(*types.Sketch)
	sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)
	source := context[constants.CTX_SOURCE].(string)

	err := os.MkdirAll(sketchBuildPath, os.FileMode(0755))
	if err != nil {
		return utils.WrapError(err)
	}

	err = ioutil.WriteFile(filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), []byte(source), os.FileMode(0644))
	return utils.WrapError(err)
}
Example #22
0
func (s *SketchSaver) Run(context map[string]interface{}) error {
	sketch := context[constants.CTX_SKETCH].(*types.Sketch)
	sketchBuildPath := context[constants.CTX_SKETCH_BUILD_PATH].(string)
	source := context[constants.CTX_SOURCE].(string)

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

	err = utils.WriteFile(filepath.Join(sketchBuildPath, filepath.Base(sketch.MainFile.Name)+".cpp"), source)
	return utils.WrapError(err)
}
func downloadBoardManagerCores(cores []Core, index map[string]interface{}) error {
	for _, core := range cores {
		url, err := findCoreUrl(index, core)
		if err != nil {
			return utils.WrapError(err)
		}
		err = downloadAndUnpackBoardManagerCore(core, url, BOARD_MANAGER_FOLDER)
		if err != nil {
			return utils.WrapError(err)
		}
	}
	return nil
}
func downloadCores(cores []Core, index map[string]interface{}) error {
	for _, core := range cores {
		url, err := findCoreUrl(index, core)
		if err != nil {
			return utils.WrapError(err)
		}
		err = downloadAndUnpackCore(core, url, HARDWARE_FOLDER)
		if err != nil {
			return utils.WrapError(err)
		}
	}
	return nil
}
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
}
func downloadLibraries(libraries []Library, index map[string]interface{}) error {
	for _, library := range libraries {
		url, err := findLibraryUrl(index, library)
		if err != nil {
			return utils.WrapError(err)
		}
		err = downloadAndUnpackLibrary(library, url, LIBRARIES_FOLDER)
		if err != nil {
			return utils.WrapError(err)
		}
	}

	return nil
}
func copyRecursive(from, to string) error {
	copyFunc := func(currentPath string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		rel, err := filepath.Rel(from, currentPath)
		if err != nil {
			return utils.WrapError(err)
		}
		targetPath := filepath.Join(to, rel)
		if info.IsDir() {
			err := os.MkdirAll(targetPath, info.Mode())
			if err != nil {
				return utils.WrapError(err)
			}
		} else if info.Mode().IsRegular() {
			fromFile, err := os.Open(currentPath)
			if err != nil {
				return utils.WrapError(err)
			}
			defer fromFile.Close()
			targetFile, err := os.Create(targetPath)
			if err != nil {
				return utils.WrapError(err)
			}
			defer targetFile.Close()
			_, err = io.Copy(targetFile, fromFile)
			if err != nil {
				return utils.WrapError(err)
			}
			err = os.Chmod(targetPath, info.Mode())
			if err != nil {
				return utils.WrapError(err)
			}
		} else if info.Mode()&os.ModeSymlink == os.ModeSymlink {
			linkedFile, err := os.Readlink(currentPath)
			if err != nil {
				return utils.WrapError(err)
			}
			fromFile := filepath.Join(filepath.Dir(targetPath), linkedFile)
			err = os.Symlink(fromFile, targetPath)
			if err != nil {
				return utils.WrapError(err)
			}
		} else {
			return errors.Errorf("unable to copy file " + currentPath)
		}

		return nil
	}
	err := gohasissues.Walk(from, copyFunc)
	return utils.WrapError(err)
}
Example #28
0
func CompileFiles(objectFiles []string, sourcePath string, recurse bool, buildPath string, buildProperties map[string]string, includes []string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
	objectFiles, err := compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".S", constants.RECIPE_S_PATTERN, verbose, warningsLevel, logger)
	if err != nil {
		return nil, utils.WrapError(err)
	}
	objectFiles, err = compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".c", constants.RECIPE_C_PATTERN, verbose, warningsLevel, logger)
	if err != nil {
		return nil, utils.WrapError(err)
	}
	objectFiles, err = compileFilesWithExtensionWithRecipe(objectFiles, sourcePath, recurse, buildPath, buildProperties, includes, ".cpp", constants.RECIPE_CPP_PATTERN, verbose, warningsLevel, logger)
	if err != nil {
		return nil, utils.WrapError(err)
	}
	return objectFiles, nil
}
Example #29
0
func compileCore(buildPath string, buildProperties map[string]string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
	var objectFiles []string
	coreFolder := buildProperties[constants.BUILD_PROPERTIES_BUILD_CORE_PATH]
	variantFolder := buildProperties[constants.BUILD_PROPERTIES_BUILD_VARIANT_PATH]

	var includes []string
	includes = append(includes, coreFolder)
	if variantFolder != constants.EMPTY_STRING {
		includes = append(includes, variantFolder)
	}
	includes = utils.Map(includes, utils.WrapWithHyphenI)

	var err error

	if variantFolder != constants.EMPTY_STRING {
		objectFiles, err = builder_utils.CompileFiles(objectFiles, variantFolder, true, buildPath, buildProperties, includes, verbose, warningsLevel, logger)
		if err != nil {
			return nil, utils.WrapError(err)
		}
	}

	coreObjectFiles, err := builder_utils.CompileFiles([]string{}, coreFolder, true, buildPath, buildProperties, includes, verbose, warningsLevel, logger)
	if err != nil {
		return nil, utils.WrapError(err)
	}

	coreArchiveFilePath := filepath.Join(buildPath, "core.a")
	if _, err := os.Stat(coreArchiveFilePath); err == nil {
		err = os.Remove(coreArchiveFilePath)
		if err != nil {
			return nil, utils.WrapError(err)
		}
	}

	for _, coreObjectFile := range coreObjectFiles {
		properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
		properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
		properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = filepath.Base(coreArchiveFilePath)
		properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = coreObjectFile

		_, err := builder_utils.ExecRecipe(properties, "recipe.ar.pattern", false, verbose, verbose, logger)
		if err != nil {
			return nil, utils.WrapError(err)
		}
	}

	return objectFiles, nil
}
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
}