Skip to content

Commit afbcc4d

Browse files
committed
Introduce OutputCache file
This file should cache warnings and other compiler output between compilations. Directly maps to ctx.OutputCache map
1 parent e0819ed commit afbcc4d

6 files changed

+50
-4
lines changed

Diff for: builder.go

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ func (s *Builder) Run(ctx *types.Context) error {
129129

130130
&PrintUsedLibrariesIfVerbose{},
131131

132+
&StoreOutputCacheMap{},
133+
132134
&ExportProjectCMake{SketchError: mainErr != nil},
133135

134136
&phases.Sizer{SketchError: mainErr != nil},

Diff for: constants/constants.go

+1
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_OUTPUT_CACHE = "output.cache"
9394
const FOLDER_BOOTLOADERS = "bootloaders"
9495
const FOLDER_CORE = "core"
9596
const FOLDER_CORES = "cores"

Diff for: container_build_options.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (s *ContainerBuildOptions) Run(ctx *types.Context) error {
4141
&CreateBuildOptionsMap{},
4242
&LoadPreviousBuildOptionsMap{},
4343
&WipeoutBuildPathIfBuildOptionsChanged{},
44+
&LoadPreviousOutputCacheMap{},
4445
&StoreBuildOptionsMap{},
4546
}
4647

Diff for: load_previous_build_options.go

+29-3
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 LoadPreviousOutputCacheMap struct{}
67+
68+
func (s *LoadPreviousOutputCacheMap) Run(ctx *types.Context) error {
69+
cachedWarningsFile := filepath.Join(ctx.BuildPath, constants.FILE_OUTPUT_CACHE)
70+
ctx.OutputCache = make(map[string]types.Streams)
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.OutputCache)
86+
87+
return nil
88+
}

Diff for: store_build_options_map.go

+11-1
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 StoreOutputCacheMap struct{}
49+
50+
func (s *StoreOutputCacheMap) Run(ctx *types.Context) error {
51+
data, _ := json.Marshal(ctx.OutputCache)
52+
utils.WriteFile(filepath.Join(ctx.BuildPath, constants.FILE_OUTPUT_CACHE), string(data))
53+
return nil
54+
}

Diff for: types/context.go

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ type ProgressStruct struct {
1414
Progress float64
1515
}
1616

17+
type Streams struct {
18+
Stdout []byte
19+
Stderr []byte
20+
}
21+
1722
// Context structure
1823
type Context struct {
1924
// Build options
@@ -65,6 +70,7 @@ type Context struct {
6570
CodeCompletions string
6671

6772
WarningsLevel string
73+
OutputCache map[string]Streams
6874

6975
// Libraries handling
7076
Libraries []*Library

0 commit comments

Comments
 (0)