Skip to content

Commit

Permalink
Generalize ObjFileIsUpToDate to BuildResultIsUpToDate
Browse files Browse the repository at this point in the history
This renames this function and adds a resultFile parameter. This
resultFile is used for all timestamp checks against other files (source
file, dep file, header files from the dep file), while the objectFile
passed is now only used to check against the contents of the dep file.

Both calls to this function still pass the same filename as objectFile
and resultFile, so this commit should not change any behavior.

Signed-off-by: Matthijs Kooijman <[email protected]>
  • Loading branch information
matthijskooijman committed Mar 2, 2017
1 parent 21c5c9e commit 4e6ceff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/arduino.cc/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func compileFileWithRecipe(sourcePath string, source string, buildPath string, b
return "", i18n.WrapError(err)
}

objIsUpToDate, err := ObjFileIsUpToDate(properties[constants.BUILD_PROPERTIES_SOURCE_FILE], properties[constants.BUILD_PROPERTIES_OBJECT_FILE], filepath.Join(buildPath, relativeSource+".d"), debugLevel, logger)
objIsUpToDate, err := BuildResultIsUpToDate(properties[constants.BUILD_PROPERTIES_SOURCE_FILE], properties[constants.BUILD_PROPERTIES_OBJECT_FILE], properties[constants.BUILD_PROPERTIES_OBJECT_FILE], filepath.Join(buildPath, relativeSource+".d"), debugLevel, logger)
if err != nil {
return "", i18n.WrapError(err)
}
Expand All @@ -161,25 +161,26 @@ func compileFileWithRecipe(sourcePath string, source string, buildPath string, b
return properties[constants.BUILD_PROPERTIES_OBJECT_FILE], nil
}

func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string, debugLevel int, logger i18n.Logger) (bool, error) {
func BuildResultIsUpToDate(sourceFile, resultFile, objectFile, dependencyFile string, debugLevel int, logger i18n.Logger) (bool, error) {
sourceFile = filepath.Clean(sourceFile)
resultFile = filepath.Clean(resultFile)
objectFile = filepath.Clean(objectFile)
dependencyFile = filepath.Clean(dependencyFile)

if debugLevel >= 20 {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Checking previous results for {0} (result = {1}, dep = {2})", sourceFile, objectFile, dependencyFile);
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Checking build results for {0} (result = {1}, dep = {2})", sourceFile, objectFile, dependencyFile);
}

sourceFileStat, err := os.Stat(sourceFile)
if err != nil {
return false, i18n.WrapError(err)
}

objectFileStat, err := os.Stat(objectFile)
resultFileStat, err := os.Stat(resultFile)
if err != nil {
if os.IsNotExist(err) {
if debugLevel >= 20 {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", objectFile);
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "Not found: {0}", resultFile);
}
return false, nil
} else {
Expand All @@ -199,9 +200,9 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string, debugLevel
}
}

if sourceFileStat.ModTime().After(objectFileStat.ModTime()) {
if sourceFileStat.ModTime().After(resultFileStat.ModTime()) {
if debugLevel >= 20 {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", sourceFile, objectFile);
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", sourceFile, resultFile);
}
return false, nil
}
Expand Down Expand Up @@ -259,9 +260,9 @@ func ObjFileIsUpToDate(sourceFile, objectFile, dependencyFile string, debugLevel
}
return false, nil
}
if depStat.ModTime().After(objectFileStat.ModTime()) {
if depStat.ModTime().After(resultFileStat.ModTime()) {
if debugLevel >= 20 {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", row, objectFile);
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, "{0} newer than {1}", row, resultFile);
}
return false, nil
}
Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t
// TODO: This reads the dependency file, but the actual building
// does it again. Should the result be somehow cached? Perhaps
// remove the object file if it is found to be stale?
unchanged, err := builder_utils.ObjFileIsUpToDate(sourcePath, objPath, depPath, ctx.DebugLevel, ctx.GetLogger())
unchanged, err := builder_utils.BuildResultIsUpToDate(sourcePath, objPath, objPath, depPath, ctx.DebugLevel, ctx.GetLogger())
if err != nil {
return i18n.WrapError(err)
}
Expand Down

0 comments on commit 4e6ceff

Please sign in to comment.