Skip to content

Commit 89e7213

Browse files
committed
Introduce warnings.cache file
It shares the file with build options cache at the moment, since they match almost perfectly
1 parent f9d69df commit 89e7213

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
lines changed

builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (s *Builder) Run(ctx *types.Context) error {
120120
&MergeSketchWithBootloader{},
121121

122122
&RecipeByPrefixSuffixRunner{Prefix: constants.HOOKS_POSTBUILD, Suffix: constants.HOOKS_PATTERN_SUFFIX},
123+
&StoreWarningsMap{},
123124
}
124125

125126
mainErr := runCommands(ctx, commands, true)

constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const FILE_PLATFORM_LOCAL_TXT = "platform.local.txt"
9090
const FILE_PLATFORM_TXT = "platform.txt"
9191
const FILE_PROGRAMMERS_TXT = "programmers.txt"
9292
const FILE_INCLUDES_CACHE = "includes.cache"
93+
const FILE_WARNINGS_CACHE = "warnings.cache"
9394
const FOLDER_BOOTLOADERS = "bootloaders"
9495
const FOLDER_CORE = "core"
9596
const FOLDER_CORES = "cores"

container_build_options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (s *ContainerBuildOptions) Run(ctx *types.Context) error {
4040
commands := []types.Command{
4141
&CreateBuildOptionsMap{},
4242
&LoadPreviousBuildOptionsMap{},
43+
&LoadPreviousWarningsMap{},
4344
&WipeoutBuildPathIfBuildOptionsChanged{},
4445
&StoreBuildOptionsMap{},
4546
}

load_previous_build_options.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
package builder
3131

3232
import (
33-
"github.com/arduino/arduino-builder/constants"
34-
"github.com/arduino/arduino-builder/i18n"
35-
"github.com/arduino/arduino-builder/types"
33+
"encoding/json"
3634
"io/ioutil"
3735
"os"
3836
"path/filepath"
37+
38+
"github.com/arduino/arduino-builder/constants"
39+
"github.com/arduino/arduino-builder/i18n"
40+
"github.com/arduino/arduino-builder/types"
3941
)
4042

4143
type LoadPreviousBuildOptionsMap struct{}
@@ -60,3 +62,27 @@ func (s *LoadPreviousBuildOptionsMap) Run(ctx *types.Context) error {
6062

6163
return nil
6264
}
65+
66+
type LoadPreviousWarningsMap struct{}
67+
68+
func (s *LoadPreviousWarningsMap) Run(ctx *types.Context) error {
69+
cachedWarningsFile := filepath.Join(ctx.BuildPath, constants.FILE_WARNINGS_CACHE)
70+
ctx.WarningsCache = make(map[string]string)
71+
72+
_, err := os.Stat(cachedWarningsFile)
73+
if err != nil {
74+
if os.IsNotExist(err) {
75+
return nil
76+
}
77+
return i18n.WrapError(err)
78+
}
79+
80+
bytes, err := ioutil.ReadFile(cachedWarningsFile)
81+
if err != nil {
82+
return i18n.WrapError(err)
83+
}
84+
85+
json.Unmarshal(bytes, &ctx.WarningsCache)
86+
87+
return nil
88+
}

store_build_options_map.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
package builder
3131

3232
import (
33+
"encoding/json"
34+
"path/filepath"
35+
3336
"github.com/arduino/arduino-builder/constants"
3437
"github.com/arduino/arduino-builder/types"
3538
"github.com/arduino/arduino-builder/utils"
36-
"path/filepath"
3739
)
3840

3941
type StoreBuildOptionsMap struct{}
@@ -42,3 +44,11 @@ func (s *StoreBuildOptionsMap) Run(ctx *types.Context) error {
4244
utils.WriteFile(filepath.Join(ctx.BuildPath, constants.BUILD_OPTIONS_FILE), ctx.BuildOptionsJson)
4345
return nil
4446
}
47+
48+
type StoreWarningsMap struct{}
49+
50+
func (s *StoreWarningsMap) Run(ctx *types.Context) error {
51+
data, _ := json.Marshal(ctx.WarningsCache)
52+
utils.WriteFile(filepath.Join(ctx.BuildPath, constants.FILE_WARNINGS_CACHE), string(data))
53+
return nil
54+
}

types/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type Context struct {
6565
CodeCompletions string
6666

6767
WarningsLevel string
68+
WarningsCache map[string]string
6869

6970
// Libraries handling
7071
Libraries []*Library

0 commit comments

Comments
 (0)