作者:facchin
项目:arduino-builde
func PrepareCommandForRecipe(buildProperties properties.Map, recipe string, removeUnsetProperties bool, echoCommandLine bool, echoOutput bool, logger i18n.Logger) (*exec.Cmd, error) {
pattern := buildProperties[recipe]
if pattern == constants.EMPTY_STRING {
return nil, i18n.ErrorfWithLogger(logger, constants.MSG_PATTERN_MISSING, recipe)
}
var err error
commandLine := buildProperties.ExpandPropsInString(pattern)
if removeUnsetProperties {
commandLine, err = properties.DeleteUnexpandedPropsFromString(commandLine)
if err != nil {
return nil, i18n.WrapError(err)
}
}
command, err := utils.PrepareCommand(commandLine, logger)
if err != nil {
return nil, i18n.WrapError(err)
}
if echoCommandLine {
fmt.Println(commandLine)
}
return command, nil
}
作者:facchin
项目:arduino-builde
func compileFileWithRecipe(sourcePath string, source string, buildPath string, buildProperties properties.Map, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) (string, error) {
properties := buildProperties.Clone()
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 "", i18n.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 "", i18n.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 "", i18n.WrapError(err)
}
if !objIsUpToDate {
_, err = ExecRecipe(properties, recipe, false, verbose, verbose, logger)
if err != nil {
return "", i18n.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
}
作者:facchin
项目:arduino-builde
func findVIDPIDIndex(buildProperties properties.Map, vid, pid string) (int, error) {
for key, value := range buildProperties.SubTree(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
}
作者:facchin
项目:arduino-builde
func link(objectFiles []string, coreDotARelPath string, coreArchiveFilePath string, buildProperties properties.Map, verbose bool, warningsLevel string, logger i18n.Logger) error {
optRelax := addRelaxTrickIfATMEGA2560(buildProperties)
objectFiles = utils.Map(objectFiles, wrapWithDoubleQuotes)
objectFileList := strings.Join(objectFiles, constants.SPACE)
properties := buildProperties.Clone()
properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_C_ELF_FLAGS] + optRelax
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = coreDotARelPath
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = coreArchiveFilePath
properties[constants.BUILD_PROPERTIES_OBJECT_FILES] = objectFileList
_, err := builder_utils.ExecRecipe(properties, constants.RECIPE_C_COMBINE_PATTERN, false, verbose, verbose, logger)
return err
}
作者:facchin
项目:arduino-builde
func ArchiveCompiledFiles(buildPath string, archiveFile string, objectFiles []string, buildProperties properties.Map, verbose bool, logger i18n.Logger) (string, error) {
archiveFilePath := filepath.Join(buildPath, archiveFile)
if _, err := os.Stat(archiveFilePath); err == nil {
err = os.Remove(archiveFilePath)
if err != nil {
return "", i18n.WrapError(err)
}
}
for _, objectFile := range objectFiles {
properties := buildProperties.Clone()
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE] = filepath.Base(archiveFilePath)
properties[constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH] = archiveFilePath
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = objectFile
_, err := ExecRecipe(properties, constants.RECIPE_AR_PATTERN, false, verbose, verbose, logger)
if err != nil {
return "", i18n.WrapError(err)
}
}
return archiveFilePath, nil
}
作者:facchin
项目:arduino-builde
func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
if ctx.BuildOptionsJsonPrevious == "" {
return nil
}
buildOptionsJson := ctx.BuildOptionsJson
previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious
logger := ctx.GetLogger()
var opts properties.Map
var prevOpts properties.Map
json.Unmarshal([]byte(buildOptionsJson), &opts)
json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts)
// If SketchLocation path is different but filename is the same, consider it equal
if filepath.Base(opts["sketchLocation"]) == filepath.Base(prevOpts["sketchLocation"]) {
delete(opts, "sketchLocation")
delete(prevOpts, "sketchLocation")
}
if opts.Equals(prevOpts) {
return nil
}
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)
buildPath := ctx.BuildPath
files, err := gohasissues.ReadDir(buildPath)
if err != nil {
return i18n.WrapError(err)
}
for _, file := range files {
os.RemoveAll(filepath.Join(buildPath, file.Name()))
}
return nil
}
作者:facchin
项目:arduino-builde
func checkSize(buildProperties properties.Map, verbose bool, warningsLevel string, logger i18n.Logger) error {
properties := buildProperties.Clone()
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
maxTextSizeString := properties[constants.PROPERTY_UPLOAD_MAX_SIZE]
maxDataSizeString := properties[constants.PROPERTY_UPLOAD_MAX_DATA_SIZE]
if maxTextSizeString == "" {
return nil
}
maxTextSize, err := strconv.Atoi(maxTextSizeString)
if err != nil {
return err
}
maxDataSize := -1
if maxDataSizeString != "" {
maxDataSize, err = strconv.Atoi(maxDataSizeString)
if err != nil {
return err
}
}
textSize, dataSize, _, err := execSizeReceipe(properties, logger)
if err != nil {
logger.Println(constants.LOG_LEVEL_WARN, constants.MSG_SIZER_ERROR_NO_RULE)
return nil
}
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_SIZER_TEXT_FULL, strconv.Itoa(textSize), strconv.Itoa(maxTextSize), strconv.Itoa(textSize*100/maxTextSize))
if dataSize >= 0 {
if maxDataSize > 0 {
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_SIZER_DATA_FULL, strconv.Itoa(dataSize), strconv.Itoa(maxDataSize), strconv.Itoa(dataSize*100/maxDataSize), strconv.Itoa(maxDataSize-dataSize))
} else {
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_SIZER_DATA, strconv.Itoa(dataSize))
}
}
if textSize > maxTextSize {
logger.Println(constants.LOG_LEVEL_ERROR, constants.MSG_SIZER_TEXT_TOO_BIG)
return errors.New("")
}
if maxDataSize > 0 && dataSize > maxDataSize {
logger.Println(constants.LOG_LEVEL_ERROR, constants.MSG_SIZER_DATA_TOO_BIG)
return errors.New("")
}
if properties[constants.PROPERTY_WARN_DATA_PERCENT] != "" {
warnDataPercentage, err := strconv.Atoi(properties[constants.PROPERTY_WARN_DATA_PERCENT])
if err != nil {
return err
}
if maxDataSize > 0 && dataSize > maxDataSize*warnDataPercentage/100 {
logger.Println(constants.LOG_LEVEL_WARN, constants.MSG_SIZER_LOW_MEMORY)
}
}
return nil
}