Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning when editing libraries #301

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions libraries_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions phases/libraries_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
41 changes: 21 additions & 20 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down