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].(map[string]string)
	VIDPIDIndex, err := findVIDPIDIndex(buildProperties, vid, pid)
	if err != nil {
		return utils.WrapError(err)
	}
	if VIDPIDIndex < 0 {
		return nil
	}

	vidPidSpecificProperties := props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_VID), strconv.Itoa(VIDPIDIndex))
	utils.MergeMapsOfStrings(buildProperties, vidPidSpecificProperties)

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

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

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

	context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600"
	context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"}
	context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "./tools_builtin"}
	context[constants.CTX_FQBN] = "my_avr_platform:avr:custom_yun"
	context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino")

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

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

	buildProperties := context[constants.CTX_BUILD_PROPERTIES].(map[string]string)

	require.Equal(t, "ARDUINO", buildProperties[constants.BUILD_PROPERTIES_SOFTWARE])

	require.Equal(t, "custom_yun", buildProperties[constants.ID])
	require.Equal(t, "Arduino Yún", buildProperties["name"])
	require.Equal(t, "0x2341", buildProperties["vid.0"])
	require.Equal(t, "\"{compiler.path}{compiler.c.cmd}\" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} \"{source_file}\" -o \"{object_file}\"", buildProperties["recipe.c.o.pattern"])
	require.Equal(t, "{path}/etc/avrdude.conf", buildProperties["tools.avrdude.config.path"])

	coanProps := props.SubTree(props.SubTree(buildProperties, constants.BUILD_PROPERTIES_TOOLS_KEY), constants.COAN)
	require.Equal(t, "{path}/coan", coanProps["cmd.path"])
	require.Equal(t, "\"{cmd.path}\" source -m -E -P -kb {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} \"{source_file}\"", coanProps[constants.BUILD_PROPERTIES_PATTERN])

	require.Equal(t, Abs(t, "user_hardware/my_avr_platform/avr"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH])
	require.Equal(t, Abs(t, "user_hardware/my_avr_platform"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH])
	require.Equal(t, "10600", buildProperties[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION])
	require.NotEmpty(t, buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS])

	require.Equal(t, Abs(t, "./downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1"), buildProperties["runtime.tools.arm-none-eabi-gcc.path"])
	require.Equal(t, Abs(t, "./downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1"), buildProperties["runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path"])
	require.Equal(t, Abs(t, "./downloaded_tools/bossac/1.6.1-arduino"), buildProperties["runtime.tools.bossac-1.6.1-arduino.path"])
	require.Equal(t, Abs(t, "./downloaded_tools/bossac/1.5-arduino"), buildProperties["runtime.tools.bossac-1.5-arduino.path"])
	require.True(t, buildProperties["runtime.tools.bossac.path"] == Abs(t, "./downloaded_tools/bossac/1.6.1-arduino") || buildProperties["runtime.tools.bossac.path"] == Abs(t, "./downloaded_tools/bossac/1.5-arduino"))
	require.Equal(t, Abs(t, "./downloaded_tools/avrdude/6.0.1-arduino5"), buildProperties["runtime.tools.avrdude.path"])
	require.Equal(t, Abs(t, "./downloaded_tools/avrdude/6.0.1-arduino5"), buildProperties["runtime.tools.avrdude-6.0.1-arduino5.path"])
	require.Equal(t, Abs(t, "./downloaded_tools/avr-gcc/4.8.1-arduino5"), buildProperties["runtime.tools.avr-gcc.path"])
	require.Equal(t, Abs(t, "./downloaded_tools/avr-gcc/4.8.1-arduino5"), buildProperties["runtime.tools.avr-gcc-4.8.1-arduino5.path"])

	require.Equal(t, Abs(t, "sketch1"), buildProperties[constants.BUILD_PROPERTIES_SOURCE_PATH])

	require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_UTC))
	require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_LOCAL))
	require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_ZONE))
	require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_DST))
}
Exemplo n.º 3
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 findVIDPIDIndex(buildProperties map[string]string, vid, pid string) (int, error) {
	for key, value := range props.SubTree(buildProperties, constants.BUILD_PROPERTIES_VID) {
		if !strings.Contains(key, ".") {
			if vid == strings.ToLower(value) && pid == strings.ToLower(buildProperties[constants.BUILD_PROPERTIES_PID+"."+key]) {
				return strconv.Atoi(key)
			}
		}
	}

	return -1, nil
}
Exemplo n.º 5
0
func TestPropertiesBoardsTxt(t *testing.T) {
	properties, err := props.Load(filepath.Join("props", "boards.txt"))

	NoError(t, err)

	require.Equal(t, "Processor", properties["menu.cpu"])
	require.Equal(t, "32256", properties["ethernet.upload.maximum_size"])
	require.Equal(t, "{build.usb_flags}", properties["robotMotor.build.extra_flags"])

	ethernet := props.SubTree(properties, "ethernet")
	require.Equal(t, "Arduino Ethernet", ethernet[constants.LIBRARY_NAME])
}
Exemplo n.º 6
0
func TestPropertiesRedBeearLabBoardsTxt(t *testing.T) {
	properties, err := props.Load(filepath.Join("props", "redbearlab_boards.txt"))

	NoError(t, err)

	require.Equal(t, 83, len(properties))
	require.Equal(t, "Blend", properties["blend.name"])
	require.Equal(t, "arduino:arduino", properties["blend.build.core"])
	require.Equal(t, "0x2404", properties["blendmicro16.pid.0"])

	ethernet := props.SubTree(properties, "blend")
	require.Equal(t, "arduino:arduino", ethernet[constants.BUILD_PROPERTIES_BUILD_CORE])
}
func addAdditionalPropertiesToTargetBoard(board *types.Board, options string) {
	optionsParts := strings.Split(options, ",")
	optionsParts = utils.Map(optionsParts, utils.TrimSpace)

	for _, optionPart := range optionsParts {
		parts := strings.Split(optionPart, "=")
		parts = utils.Map(parts, utils.TrimSpace)

		key := parts[0]
		value := parts[1]
		if key != constants.EMPTY_STRING && value != constants.EMPTY_STRING {
			menu := props.SubTree(board.Properties, constants.BOARD_PROPERTIES_MENU)
			if len(menu) == 0 {
				return
			}
			propertiesOfKey := props.SubTree(menu, key)
			if len(propertiesOfKey) == 0 {
				return
			}
			propertiesOfKeyValue := props.SubTree(propertiesOfKey, value)
			utils.MergeMapsOfStrings(board.Properties, propertiesOfKeyValue)
		}
	}
}
Exemplo n.º 8
0
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
}
Exemplo n.º 9
0
func (platform *Platform) GetTool(toolName string) map[string]string {
	return props.SubTree(platform.Properties, toolName)
}