From 96f366de36090aab20b2690f291af383137d8905 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 9 Oct 2018 16:51:50 +0200 Subject: [PATCH 1/2] Add a method to discover if a library is being modified To be in isBeingModified state, a library must: - have one of its file modified in the last 24 hours - have a time difference between oldest and newest file bigger than 5 minutes (aka, the lib has not just been extracted from a zip) --- libraries_loader.go | 27 +++++++++++++++++++++++++++ types/types.go | 41 +++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/libraries_loader.go b/libraries_loader.go index 1730bf44..088ef8ed 100644 --- a/libraries_loader.go +++ b/libraries_loader.go @@ -30,9 +30,12 @@ package builder import ( + "math" "os" "path/filepath" + "strconv" "strings" + "time" "github.com/arduino/arduino-builder/constants" "github.com/arduino/arduino-builder/i18n" @@ -153,6 +156,11 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (* return nil, i18n.WrapError(err) } + timeDiff, newestFile := newestAndOldestFileDifferBy(libraryFolder) + if timeDiff > (5*time.Minute) && time.Since(newestFile) < 24*time.Hour { + library.IsBeingModified = true + } + if debugLevel >= 0 { for _, subFolder := range subFolders { if utils.IsSCCSOrHiddenFile(subFolder) { @@ -220,3 +228,22 @@ func appendPathToLibrariesFolders(librariesFolders []string, newLibrariesFolder return utils.AppendIfNotPresent(librariesFolders, newLibrariesFolder) } + +func newestAndOldestFileDifferBy(path string) (time.Duration, time.Time) { + var newestTime int64 = 0 + var oldestTime int64 = math.MaxInt64 + + filepath.Walk(path, + func(path string, info os.FileInfo, err error) error { + currTime := info.ModTime().Unix() + if currTime > newestTime { + newestTime = currTime + } + if currTime < oldestTime { + oldestTime = currTime + } + return nil + }) + duration, _ := time.ParseDuration(strconv.FormatInt(newestTime-oldestTime, 10) + "s") + return duration, time.Unix(newestTime, 0) +} diff --git a/types/types.go b/types/types.go index d535386d..4d2f6e80 100644 --- a/types/types.go +++ b/types/types.go @@ -162,26 +162,27 @@ const ( ) type Library struct { - Folder string - SrcFolder string - UtilityFolder string - Layout LibraryLayout - Name string - RealName string - Archs []string - DotALinkage bool - Precompiled bool - LDflags string - IsLegacy bool - Version string - Author string - Maintainer string - Sentence string - Paragraph string - URL string - Category string - License string - Properties map[string]string + Folder string + SrcFolder string + UtilityFolder string + Layout LibraryLayout + Name string + RealName string + Archs []string + DotALinkage bool + Precompiled bool + LDflags string + IsLegacy bool + Version string + Author string + Maintainer string + Sentence string + Paragraph string + URL string + Category string + License string + Properties map[string]string + IsBeingModified bool } func (library *Library) String() string { From 2fd815bf31e6a7b0a19b252232b731345697d8a8 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 9 Oct 2018 16:54:49 +0200 Subject: [PATCH 2/2] Force warning level to all if a library is being modified --- phases/libraries_builder.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phases/libraries_builder.go b/phases/libraries_builder.go index dc0fdf12..ed0285bc 100644 --- a/phases/libraries_builder.go +++ b/phases/libraries_builder.go @@ -98,8 +98,16 @@ func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libraries []*types.Lib func compileLibraries(ctx *types.Context, libraries []*types.Library, buildPath string, buildProperties properties.Map, includes []string) ([]string, error) { objectFiles := []string{} + warningLevelToBeRestored := ctx.WarningsLevel + for _, library := range libraries { + if library.IsBeingModified { + ctx.WarningsLevel = "all" + } libraryObjectFiles, err := compileLibrary(ctx, library, buildPath, buildProperties, includes) + if library.IsBeingModified { + ctx.WarningsLevel = warningLevelToBeRestored + } if err != nil { return nil, i18n.WrapError(err) }