func findToolUrl(index map[string]interface{}, tool Tool, host []string) (string, error) {
	if len(tool.OsUrls) > 0 {
		for _, osUrl := range tool.OsUrls {
			if utils.SliceContains(host, osUrl.Os) {
				return osUrl.Url, nil
			}
		}
	} else {
		packages := index["packages"].([]interface{})
		for _, p := range packages {
			pack := p.(map[string]interface{})
			packageTools := pack[constants.PACKAGE_TOOLS].([]interface{})
			for _, pt := range packageTools {
				packageTool := pt.(map[string]interface{})
				name := packageTool[constants.TOOL_NAME].(string)
				version := packageTool[constants.TOOL_VERSION].(string)
				if name == tool.Name && version == tool.Version {
					systems := packageTool["systems"].([]interface{})
					for _, s := range systems {
						system := s.(map[string]interface{})
						if utils.SliceContains(host, system["host"].(string)) {
							return system[constants.TOOL_URL].(string), nil
						}
					}
				}
			}
		}
	}

	return constants.EMPTY_STRING, errors.Errorf("Unable to find tool " + tool.Name + " " + tool.Version)
}
func libraryCompatibleWithPlatform(library *types.Library, platform *types.Platform) bool {
	if len(library.Archs) == 0 {
		return true
	}
	if utils.SliceContains(library.Archs, constants.LIBRARY_ALL_ARCHS) {
		return true
	}
	return utils.SliceContains(library.Archs, platform.PlatformId)
}
Esempio n. 3
0
func (library *Library) SupportsArchitectures(archs []string) bool {
	if utils.SliceContains(archs, constants.LIBRARY_ALL_ARCHS) || utils.SliceContains(library.Archs, constants.LIBRARY_ALL_ARCHS) {
		return true
	}

	for _, libraryArch := range library.Archs {
		if utils.SliceContains(archs, libraryArch) {
			return true
		}
	}

	return false
}
func (s *FilterSketchSource) Run(ctx *types.Context) error {
	fileNames := []string{ctx.Sketch.MainFile.Name}
	for _, file := range ctx.Sketch.OtherSketchFiles {
		fileNames = append(fileNames, file.Name)
	}

	inSketch := false
	filtered := ""

	scanner := bufio.NewScanner(strings.NewReader(*s.Source))
	for scanner.Scan() {
		line := scanner.Text()
		filename := parseLineMarker(line)
		if filename != "" {
			inSketch = utils.SliceContains(fileNames, filename)
		}

		if inSketch {
			filtered += line + "\n"
		}
	}

	*s.Source = filtered
	return nil
}
func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error {
	librariesBuildPath := ctx.LibrariesBuildPath

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

	libraryNames := toLibraryNames(ctx.ImportedLibraries)

	files, err := ioutil.ReadDir(librariesBuildPath)
	if err != nil {
		return i18n.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 i18n.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
}
func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) {
	DownloadCoresAndToolsAndLibraries(t)

	context := make(map[string]interface{})

	buildPath := SetupBuildPath(t, context)
	defer os.RemoveAll(buildPath)

	context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}
	context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"}
	context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
	context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries", "libraries"}
	context[constants.CTX_FQBN] = "arduino:avr:leonardo"
	context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch_with_config", "sketch_with_config.ino")
	context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600"
	context[constants.CTX_VERBOSE] = false

	commands := []types.Command{
		&builder.SetupHumanLoggerIfMissing{},

		&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},

		&builder.ContainerMergeCopySketchFiles{},

		&builder.ContainerFindIncludes{},
	}

	for _, command := range commands {
		err := command.Run(context)
		NoError(t, err)
	}

	require.NotNil(t, context[constants.CTX_INCLUDES])
	includes := context[constants.CTX_INCLUDES].([]string)
	require.True(t, utils.SliceContains(includes, filepath.Join(buildPath, constants.FOLDER_SKETCH, "config.h")))
	require.True(t, utils.SliceContains(includes, filepath.Join(buildPath, constants.FOLDER_SKETCH, "includes")+"/de bug.h"))
	require.True(t, utils.SliceContains(includes, "Bridge.h"))

	importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
	require.Equal(t, 1, len(importedLibraries))
	require.Equal(t, "Bridge", importedLibraries[0].Name)
}
func (s *CollectCTagsFromSketchFiles) Run(context map[string]interface{}) error {
	sketch := context[constants.CTX_SKETCH].(*types.Sketch)
	sketchFileNames := collectSketchFileNamesFrom(sketch)

	allCtags := context[constants.CTX_CTAGS_OF_PREPROC_SOURCE].([]*types.CTag)
	ctagsOfSketch := []*types.CTag{}
	for _, ctag := range allCtags {
		if utils.SliceContains(sketchFileNames, strings.Replace(ctag.Filename, "\\\\", "\\", -1)) {
			ctagsOfSketch = append(ctagsOfSketch, ctag)
		}
	}
func appendPathToLibrariesFolders(librariesFolders []string, newLibrariesFolder string) []string {
	if stat, err := os.Stat(newLibrariesFolder); os.IsNotExist(err) || !stat.IsDir() {
		return librariesFolders
	}

	if utils.SliceContains(librariesFolders, newLibrariesFolder) {
		return librariesFolders
	}

	return append(librariesFolders, newLibrariesFolder)
}
func (s *ComparePrototypesFromSourceAndPreprocSource) Run(context map[string]interface{}) error {
	prototypesOfSource := context[constants.CTX_PROTOTYPES_OF_SOURCE].([]string)
	prototypesOfPreprocSource := context[constants.CTX_PROTOTYPES_OF_PREPROC_SOURCE].([]string)

	var actualPrototypes []string
	for _, prototypeOfSource := range prototypesOfSource {
		if utils.SliceContains(prototypesOfPreprocSource, prototypeOfSource) {
			actualPrototypes = append(actualPrototypes, prototypeOfSource)
		}
	}

	context[constants.CTX_PROTOTYPES] = actualPrototypes

	return nil
}
Esempio n. 11
0
func (s *SketchLoader) Run(ctx *types.Context) error {
	if ctx.SketchLocation == "" {
		return nil
	}

	sketchLocation := ctx.SketchLocation

	sketchLocation, err := filepath.Abs(sketchLocation)
	if err != nil {
		return i18n.WrapError(err)
	}
	mainSketchStat, err := os.Stat(sketchLocation)
	if err != nil {
		return i18n.WrapError(err)
	}
	if mainSketchStat.IsDir() {
		sketchLocation = filepath.Join(sketchLocation, mainSketchStat.Name()+".ino")
	}

	ctx.SketchLocation = sketchLocation

	allSketchFilePaths, err := collectAllSketchFiles(filepath.Dir(sketchLocation))
	if err != nil {
		return i18n.WrapError(err)
	}

	logger := ctx.GetLogger()

	if !utils.SliceContains(allSketchFilePaths, sketchLocation) {
		return i18n.ErrorfWithLogger(logger, constants.MSG_CANT_FIND_SKETCH_IN_PATH, sketchLocation, filepath.Dir(sketchLocation))
	}

	sketch, err := makeSketch(sketchLocation, allSketchFilePaths, logger)
	if err != nil {
		return i18n.WrapError(err)
	}

	ctx.SketchLocation = sketchLocation
	ctx.Sketch = sketch

	return nil
}
Esempio n. 12
0
func (s *SketchLoader) Run(context map[string]interface{}) error {
	if !utils.MapHas(context, constants.CTX_SKETCH_LOCATION) {
		return nil
	}

	sketchLocation := context[constants.CTX_SKETCH_LOCATION].(string)

	sketchLocation, err := filepath.Abs(sketchLocation)
	if err != nil {
		return utils.WrapError(err)
	}
	mainSketchStat, err := os.Stat(sketchLocation)
	if err != nil {
		return utils.WrapError(err)
	}
	if mainSketchStat.IsDir() {
		sketchLocation = filepath.Join(sketchLocation, mainSketchStat.Name()+".ino")
	}
	context[constants.CTX_SKETCH_LOCATION] = sketchLocation

	allSketchFilePaths, err := collectAllSketchFiles(filepath.Dir(sketchLocation))
	if err != nil {
		return utils.WrapError(err)
	}

	if !utils.SliceContains(allSketchFilePaths, sketchLocation) {
		return utils.Errorf(context, constants.MSG_CANT_FIND_SKETCH_IN_PATH, sketchLocation, filepath.Dir(sketchLocation))
	}

	logger := context[constants.CTX_LOGGER].(i18n.Logger)
	sketch, err := makeSketch(sketchLocation, allSketchFilePaths, logger)
	if err != nil {
		return utils.WrapError(err)
	}

	context[constants.CTX_SKETCH_LOCATION] = sketchLocation
	context[constants.CTX_SKETCH] = sketch

	return nil
}
func TestIncludesFinderWithGCCSketchWithConfig(t *testing.T) {
	DownloadCoresAndToolsAndLibraries(t)

	ctx := &types.Context{
		HardwareFolders:         []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"},
		ToolsFolders:            []string{"downloaded_tools"},
		BuiltInLibrariesFolders: []string{"downloaded_libraries"},
		OtherLibrariesFolders:   []string{"dependent_libraries", "libraries"},
		SketchLocation:          filepath.Join("sketch_with_config", "sketch_with_config.ino"),
		FQBN:                    "arduino:avr:leonardo",
		ArduinoAPIVersion:       "10600",
		Verbose:                 true,
	}

	buildPath := SetupBuildPath(t, ctx)
	defer os.RemoveAll(buildPath)

	commands := []types.Command{

		&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},

		&builder.ContainerMergeCopySketchFiles{},

		&builder.ContainerFindIncludes{},
	}

	for _, command := range commands {
		err := command.Run(ctx)
		NoError(t, err)
	}

	includes := ctx.Includes
	require.Equal(t, 1, len(includes))
	require.True(t, utils.SliceContains(includes, "Bridge.h"))

	importedLibraries := ctx.ImportedLibraries
	require.Equal(t, 1, len(importedLibraries))
	require.Equal(t, "Bridge", importedLibraries[0].Name)
}
func libraryCompatibleWithAllPlatforms(library *types.Library) bool {
	if utils.SliceContains(library.Archs, constants.LIBRARY_ALL_ARCHS) {
		return true
	}
	return false
}