Skip to content

Commit afdee0d

Browse files
author
Federico Fissore
committed
compileWithRecipe -> compileFilesWithRecipe + compileFileWithRecipe
Signed-off-by: Federico Fissore <[email protected]>
1 parent b817f6f commit afdee0d

File tree

1 file changed

+39
-30
lines changed
  • src/arduino.cc/builder/builder_utils

1 file changed

+39
-30
lines changed

src/arduino.cc/builder/builder_utils/utils.go

+39-30
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func compileFilesWithExtensionWithRecipe(objectFiles []string, sourcePath string
8282
if err != nil {
8383
return nil, utils.WrapError(err)
8484
}
85-
return compileWithRecipe(objectFiles, sourcePath, sources, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger)
85+
return compileFilesWithRecipe(objectFiles, sourcePath, sources, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger)
8686
}
8787

8888
func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]string, error) {
@@ -113,45 +113,54 @@ func findFilesInFolder(sourcePath string, extension string, recurse bool) ([]str
113113
return sources, nil
114114
}
115115

116-
func compileWithRecipe(objectFiles []string, sourcePath string, sources []string, buildPath string, buildProperties map[string]string, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
116+
func compileFilesWithRecipe(objectFiles []string, sourcePath string, sources []string, buildPath string, buildProperties map[string]string, includes []string, recipe string, verbose bool, warningsLevel string, logger i18n.Logger) ([]string, error) {
117117
for _, source := range sources {
118-
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
119-
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
120-
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
121-
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source
122-
relativeSource, err := filepath.Rel(sourcePath, source)
118+
objectFile, err := compileFileWithRecipe(sourcePath, source, buildPath, buildProperties, includes, recipe, verbose, warningsLevel, logger)
123119
if err != nil {
124120
return nil, utils.WrapError(err)
125121
}
126-
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = filepath.Join(buildPath, relativeSource+".o")
127122

128-
err = os.MkdirAll(filepath.Dir(properties[constants.BUILD_PROPERTIES_OBJECT_FILE]), os.FileMode(0755))
129-
if err != nil {
130-
return nil, utils.WrapError(err)
131-
}
123+
objectFiles = append(objectFiles, objectFile)
124+
}
125+
return objectFiles, nil
126+
}
132127

133-
sourceFileStat, err := os.Stat(properties[constants.BUILD_PROPERTIES_SOURCE_FILE])
134-
if err != nil {
135-
return nil, utils.WrapError(err)
136-
}
128+
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) {
129+
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
130+
properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS] = properties[constants.BUILD_PROPERTIES_COMPILER_WARNING_FLAGS+"."+warningsLevel]
131+
properties[constants.BUILD_PROPERTIES_INCLUDES] = strings.Join(includes, constants.SPACE)
132+
properties[constants.BUILD_PROPERTIES_SOURCE_FILE] = source
133+
relativeSource, err := filepath.Rel(sourcePath, source)
134+
if err != nil {
135+
return "", utils.WrapError(err)
136+
}
137+
properties[constants.BUILD_PROPERTIES_OBJECT_FILE] = filepath.Join(buildPath, relativeSource+".o")
137138

138-
objectFileStat, err := os.Stat(properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
139-
if err != nil && !os.IsNotExist(err) {
140-
return nil, utils.WrapError(err)
141-
}
139+
err = os.MkdirAll(filepath.Dir(properties[constants.BUILD_PROPERTIES_OBJECT_FILE]), os.FileMode(0755))
140+
if err != nil {
141+
return "", utils.WrapError(err)
142+
}
142143

143-
if !objFileIsUpToDateWithSourceFile(sourceFileStat, objectFileStat) {
144-
_, err = ExecRecipe(properties, recipe, false, verbose, verbose, logger)
145-
if err != nil {
146-
return nil, utils.WrapError(err)
147-
}
148-
} else if verbose {
149-
logger.Println(constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
150-
}
144+
sourceFileStat, err := os.Stat(properties[constants.BUILD_PROPERTIES_SOURCE_FILE])
145+
if err != nil {
146+
return "", utils.WrapError(err)
147+
}
151148

152-
objectFiles = append(objectFiles, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
149+
objectFileStat, err := os.Stat(properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
150+
if err != nil && !os.IsNotExist(err) {
151+
return "", utils.WrapError(err)
153152
}
154-
return objectFiles, nil
153+
154+
if !objFileIsUpToDateWithSourceFile(sourceFileStat, objectFileStat) {
155+
_, err = ExecRecipe(properties, recipe, false, verbose, verbose, logger)
156+
if err != nil {
157+
return "", utils.WrapError(err)
158+
}
159+
} else if verbose {
160+
logger.Println(constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
161+
}
162+
163+
return properties[constants.BUILD_PROPERTIES_OBJECT_FILE], nil
155164
}
156165

157166
func objFileIsUpToDateWithSourceFile(sourceFileStat, objectFileStat os.FileInfo) bool {

0 commit comments

Comments
 (0)