Skip to content

Commit d3d4ed6

Browse files
remove onlyUpdateCompilationDatabase from Context
1 parent 4c85a16 commit d3d4ed6

15 files changed

+55
-83
lines changed

arduino/builder/builder.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type Builder struct {
5656
// The keys of the map are paths relative to sketch folder.
5757
sourceOverrides map[string]string
5858

59+
// Set to true to skip build and produce only Compilation Database
60+
onlyUpdateCompilationDatabase bool
61+
5962
*BuildOptionsManager
6063
}
6164

@@ -73,6 +76,7 @@ func NewBuilder(
7376
fqbn *cores.FQBN,
7477
clean bool,
7578
sourceOverrides map[string]string,
79+
onlyUpdateCompilationDatabase bool,
7680
logger *logger.BuilderLogger,
7781
) (*Builder, error) {
7882
buildProperties := properties.NewMap()
@@ -123,18 +127,19 @@ func NewBuilder(
123127
}
124128

125129
return &Builder{
126-
sketch: sk,
127-
buildProperties: buildProperties,
128-
buildPath: buildPath,
129-
sketchBuildPath: sketchBuildPath,
130-
coreBuildPath: coreBuildPath,
131-
librariesBuildPath: librariesBuildPath,
132-
jobs: jobs,
133-
customBuildProperties: customBuildPropertiesArgs,
134-
coreBuildCachePath: coreBuildCachePath,
135-
logger: logger,
136-
clean: clean,
137-
sourceOverrides: sourceOverrides,
130+
sketch: sk,
131+
buildProperties: buildProperties,
132+
buildPath: buildPath,
133+
sketchBuildPath: sketchBuildPath,
134+
coreBuildPath: coreBuildPath,
135+
librariesBuildPath: librariesBuildPath,
136+
jobs: jobs,
137+
customBuildProperties: customBuildPropertiesArgs,
138+
coreBuildCachePath: coreBuildCachePath,
139+
logger: logger,
140+
clean: clean,
141+
sourceOverrides: sourceOverrides,
142+
onlyUpdateCompilationDatabase: onlyUpdateCompilationDatabase,
138143
BuildOptionsManager: NewBuildOptionsManager(
139144
hardwareDirs, builtInToolsDirs, otherLibrariesDirs,
140145
builtInLibrariesDirs, buildPath,

arduino/builder/core.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
// BuildCore fixdoc
3838
func (b *Builder) BuildCore(
3939
actualPlatform *cores.PlatformRelease,
40-
onlyUpdateCompilationDatabase bool,
4140
compilationDatabase *compilation.Database,
4241
progress *progress.Struct, progressCB rpc.TaskProgressCB,
4342
) (paths.PathList, *paths.Path, error) {
@@ -58,7 +57,6 @@ func (b *Builder) BuildCore(
5857
}
5958

6059
archiveFile, objectFiles, err := b.compileCore(
61-
onlyUpdateCompilationDatabase,
6260
actualPlatform,
6361
compilationDatabase,
6462
progress, progressCB,
@@ -71,7 +69,6 @@ func (b *Builder) BuildCore(
7169
}
7270

7371
func (b *Builder) compileCore(
74-
onlyUpdateCompilationDatabase bool,
7572
actualPlatform *cores.PlatformRelease,
7673
compilationDatabase *compilation.Database,
7774
progress *progress.Struct, progressCB rpc.TaskProgressCB,
@@ -91,7 +88,7 @@ func (b *Builder) compileCore(
9188
if variantFolder != nil && variantFolder.IsDir() {
9289
variantObjectFiles, err = utils.CompileFilesRecursive(
9390
variantFolder, b.coreBuildPath, b.buildProperties, includes,
94-
onlyUpdateCompilationDatabase,
91+
b.onlyUpdateCompilationDatabase,
9592
compilationDatabase,
9693
b.jobs,
9794
b.logger,
@@ -117,7 +114,7 @@ func (b *Builder) compileCore(
117114
}
118115

119116
var canUseArchivedCore bool
120-
if onlyUpdateCompilationDatabase || b.clean {
117+
if b.onlyUpdateCompilationDatabase || b.clean {
121118
canUseArchivedCore = false
122119
} else if isOlder, err := utils.DirContentIsOlderThan(realCoreFolder, targetArchivedCore); err != nil || !isOlder {
123120
// Recreate the archive if ANY of the core files (including platform.txt) has changed
@@ -142,7 +139,7 @@ func (b *Builder) compileCore(
142139

143140
coreObjectFiles, err := utils.CompileFilesRecursive(
144141
coreFolder, b.coreBuildPath, b.buildProperties, includes,
145-
onlyUpdateCompilationDatabase,
142+
b.onlyUpdateCompilationDatabase,
146143
compilationDatabase,
147144
b.jobs,
148145
b.logger,
@@ -154,7 +151,7 @@ func (b *Builder) compileCore(
154151

155152
archiveFile, verboseInfo, err := utils.ArchiveCompiledFiles(
156153
b.coreBuildPath, paths.New("core.a"), coreObjectFiles, b.buildProperties,
157-
onlyUpdateCompilationDatabase, b.logger.Verbose(), b.logger.Stdout(), b.logger.Stderr(),
154+
b.onlyUpdateCompilationDatabase, b.logger.Verbose(), b.logger.Stdout(), b.logger.Stderr(),
158155
)
159156
if b.logger.Verbose() {
160157
b.logger.Info(string(verboseInfo))
@@ -164,7 +161,7 @@ func (b *Builder) compileCore(
164161
}
165162

166163
// archive core.a
167-
if targetArchivedCore != nil && !onlyUpdateCompilationDatabase {
164+
if targetArchivedCore != nil && !b.onlyUpdateCompilationDatabase {
168165
err := archiveFile.CopyTo(targetArchivedCore)
169166
if b.logger.Verbose() {
170167
if err == nil {

arduino/builder/export_cmake.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (b *Builder) ExportProjectCMake(
4040
importedLibraries libraries.List,
4141
includeFolders paths.PathList,
4242
lineOffset int,
43-
onlyUpdateCompilationDatabase bool,
4443
) error {
4544
// copies the contents of the file named src to the file named
4645
// by dst. The file will be created if it does not already exist. If the
@@ -243,7 +242,7 @@ func (b *Builder) ExportProjectCMake(
243242
fmt.Println(err)
244243
}
245244

246-
if err := b.PreprocessSketch(includeFolders, lineOffset, onlyUpdateCompilationDatabase); err != nil {
245+
if err := b.PreprocessSketch(includeFolders, lineOffset); err != nil {
247246
return err
248247
}
249248

arduino/builder/libraries.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var (
4343
func (b *Builder) BuildLibraries(
4444
includesFolders paths.PathList,
4545
importedLibraries libraries.List,
46-
onlyUpdateCompilationDatabase bool,
4746
compilationDatabase *compilation.Database,
4847
progress *progress.Struct, progressCB rpc.TaskProgressCB,
4948
) (paths.PathList, error) {
@@ -56,7 +55,6 @@ func (b *Builder) BuildLibraries(
5655

5756
librariesObjectFiles, err := b.compileLibraries(
5857
libs, includes,
59-
onlyUpdateCompilationDatabase,
6058
compilationDatabase,
6159
progress, progressCB,
6260
)
@@ -128,7 +126,6 @@ func (b *Builder) findExpectedPrecompiledLibFolder(
128126

129127
func (b *Builder) compileLibraries(
130128
libraries libraries.List, includes []string,
131-
onlyUpdateCompilationDatabase bool,
132129
compilationDatabase *compilation.Database,
133130
progress *progress.Struct, progressCB rpc.TaskProgressCB,
134131
) (paths.PathList, error) {
@@ -139,7 +136,6 @@ func (b *Builder) compileLibraries(
139136
for _, library := range libraries {
140137
libraryObjectFiles, err := b.compileLibrary(
141138
library, includes,
142-
onlyUpdateCompilationDatabase,
143139
compilationDatabase,
144140
progress, progressCB,
145141
)
@@ -163,7 +159,6 @@ func (b *Builder) compileLibraries(
163159

164160
func (b *Builder) compileLibrary(
165161
library *libraries.Library, includes []string,
166-
onlyUpdateCompilationDatabase bool,
167162
compilationDatabase *compilation.Database,
168163
progress *progress.Struct, progressCB rpc.TaskProgressCB,
169164
) (paths.PathList, error) {
@@ -228,7 +223,7 @@ func (b *Builder) compileLibrary(
228223
if library.Layout == libraries.RecursiveLayout {
229224
libObjectFiles, err := utils.CompileFilesRecursive(
230225
library.SourceDir, libraryBuildPath, b.buildProperties, includes,
231-
onlyUpdateCompilationDatabase,
226+
b.onlyUpdateCompilationDatabase,
232227
compilationDatabase,
233228
b.jobs,
234229
b.logger,
@@ -240,7 +235,7 @@ func (b *Builder) compileLibrary(
240235
if library.DotALinkage {
241236
archiveFile, verboseInfo, err := utils.ArchiveCompiledFiles(
242237
libraryBuildPath, paths.New(library.DirName+".a"), libObjectFiles, b.buildProperties,
243-
onlyUpdateCompilationDatabase, b.logger.Verbose(),
238+
b.onlyUpdateCompilationDatabase, b.logger.Verbose(),
244239
b.logger.Stdout(), b.logger.Stderr(),
245240
)
246241
if b.logger.Verbose() {
@@ -259,7 +254,7 @@ func (b *Builder) compileLibrary(
259254
}
260255
libObjectFiles, err := utils.CompileFiles(
261256
library.SourceDir, libraryBuildPath, b.buildProperties, includes,
262-
onlyUpdateCompilationDatabase,
257+
b.onlyUpdateCompilationDatabase,
263258
compilationDatabase,
264259
b.jobs,
265260
b.logger,
@@ -274,7 +269,7 @@ func (b *Builder) compileLibrary(
274269
utilityBuildPath := libraryBuildPath.Join("utility")
275270
utilityObjectFiles, err := utils.CompileFiles(
276271
library.UtilityDir, utilityBuildPath, b.buildProperties, includes,
277-
onlyUpdateCompilationDatabase,
272+
b.onlyUpdateCompilationDatabase,
278273
compilationDatabase,
279274
b.jobs,
280275
b.logger,

arduino/builder/linker.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ import (
2525
)
2626

2727
// Link fixdoc
28-
func (b *Builder) Link(
29-
onlyUpdateCompilationDatabase bool,
30-
sketchObjectFiles, librariesObjectFiles, coreObjectsFiles paths.PathList,
31-
coreArchiveFilePath *paths.Path,
32-
) error {
33-
if onlyUpdateCompilationDatabase {
28+
func (b *Builder) Link(sketchObjectFiles, librariesObjectFiles, coreObjectsFiles paths.PathList, coreArchiveFilePath *paths.Path) error {
29+
if b.onlyUpdateCompilationDatabase {
3430
if b.logger.Verbose() {
3531
b.logger.Info(tr("Skip linking of final executable."))
3632
}

arduino/builder/preprocess_sketch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
)
2222

2323
// PreprocessSketch fixdoc
24-
func (b *Builder) PreprocessSketch(includes paths.PathList, lineOffset int, onlyUpdateCompilationDatabase bool) error {
24+
func (b *Builder) PreprocessSketch(includes paths.PathList, lineOffset int) error {
2525
// In the future we might change the preprocessor
2626
normalOutput, verboseOutput, err := preprocessor.PreprocessSketchWithCtags(
2727
b.sketch, b.buildPath, includes, lineOffset,
28-
b.buildProperties, onlyUpdateCompilationDatabase,
28+
b.buildProperties, b.onlyUpdateCompilationDatabase,
2929
)
3030
if b.logger.Verbose() {
3131
b.logger.WriteStdout(verboseOutput)

arduino/builder/recipe.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// RunRecipe fixdoc
3030
func (b *Builder) RunRecipe(
3131
prefix, suffix string,
32-
skipIfOnlyUpdatingCompilationDatabase, onlyUpdateCompilationDatabase bool,
32+
skipIfOnlyUpdatingCompilationDatabase bool,
3333
) error {
3434
logrus.Debugf(fmt.Sprintf("Looking for recipes like %s", prefix+"*"+suffix))
3535

@@ -47,7 +47,7 @@ func (b *Builder) RunRecipe(
4747
return errors.WithStack(err)
4848
}
4949

50-
if onlyUpdateCompilationDatabase && skipIfOnlyUpdatingCompilationDatabase {
50+
if b.onlyUpdateCompilationDatabase && skipIfOnlyUpdatingCompilationDatabase {
5151
if b.logger.Verbose() {
5252
b.logger.Info(tr("Skipping: %[1]s", strings.Join(command.GetArgs(), " ")))
5353
}

arduino/builder/sizer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.Execut
5151
}
5252

5353
// Size fixdoc
54-
func (b *Builder) Size(onlyUpdateCompilationDatabase, sketchError bool) (ExecutablesFileSections, error) {
55-
if onlyUpdateCompilationDatabase || sketchError {
54+
func (b *Builder) Size(sketchError bool) (ExecutablesFileSections, error) {
55+
if b.onlyUpdateCompilationDatabase || sketchError {
5656
return nil, nil
5757
}
5858

arduino/builder/sketch.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error {
184184
// BuildSketch fixdoc
185185
func (b *Builder) BuildSketch(
186186
includesFolders paths.PathList,
187-
onlyUpdateCompilationDatabase bool,
188187
compilationDatabase *compilation.Database,
189188
progress *progress.Struct, progressCB rpc.TaskProgressCB,
190189
) (paths.PathList, error) {
@@ -196,7 +195,7 @@ func (b *Builder) BuildSketch(
196195

197196
sketchObjectFiles, err := utils.CompileFiles(
198197
b.sketchBuildPath, b.sketchBuildPath, b.buildProperties, includes,
199-
onlyUpdateCompilationDatabase,
198+
b.onlyUpdateCompilationDatabase,
200199
compilationDatabase,
201200
b.jobs,
202201
b.builderLogger,
@@ -211,7 +210,7 @@ func (b *Builder) BuildSketch(
211210
if sketchSrcPath.IsDir() {
212211
srcObjectFiles, err := utils.CompileFilesRecursive(
213212
sketchSrcPath, sketchSrcPath, b.buildProperties, includes,
214-
onlyUpdateCompilationDatabase,
213+
b.onlyUpdateCompilationDatabase,
215214
compilationDatabase,
216215
b.jobs,
217216
b.builderLogger,
@@ -227,8 +226,8 @@ func (b *Builder) BuildSketch(
227226
}
228227

229228
// MergeSketchWithBootloader fixdoc
230-
func (b *Builder) MergeSketchWithBootloader(onlyUpdateCompilationDatabase bool) error {
231-
if onlyUpdateCompilationDatabase {
229+
func (b *Builder) MergeSketchWithBootloader() error {
230+
if b.onlyUpdateCompilationDatabase {
232231
return nil
233232
}
234233

arduino/builder/sketch_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestMergeSketchSources(t *testing.T) {
5454

5555
b, err := NewBuilder(
5656
sk, nil, paths.New("testdata"), false, nil, 0, nil,
57-
nil, nil, nil, nil, fqbn, false, nil, nil)
57+
nil, nil, nil, nil, fqbn, false, nil, false, nil)
5858
require.NoError(t, err)
5959

6060
offset, source, err := b.sketchMergeSources(nil)
@@ -73,7 +73,7 @@ func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
7373

7474
// ensure not to include Arduino.h when it's already there
7575
b, err := NewBuilder(sk, nil, paths.New("testdata"), false, nil, 0, nil,
76-
nil, nil, nil, nil, fqbn, false, nil, nil)
76+
nil, nil, nil, nil, fqbn, false, nil, false, nil)
7777
require.NoError(t, err)
7878

7979
_, source, err := b.sketchMergeSources(nil)
@@ -95,7 +95,7 @@ func TestCopyAdditionalFiles(t *testing.T) {
9595
require.NoError(t, err)
9696

9797
b1, err := NewBuilder(sk1, nil, paths.New("testdata"), false, nil, 0, nil,
98-
nil, nil, nil, nil, fqbn, false, nil, nil)
98+
nil, nil, nil, nil, fqbn, false, nil, false, nil)
9999
require.NoError(t, err)
100100

101101
// copy the sketch over, create a fake main file we don't care about it

commands/compile/compile.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
188188

189189
builderCtx.BuiltInLibrariesDirs = configuration.IDEBuiltinLibrariesDir(configuration.Settings)
190190

191-
builderCtx.OnlyUpdateCompilationDatabase = req.GetCreateCompilationDatabaseOnly()
192-
193191
builderLogger := logger.New(outStream, errStream, req.GetVerbose(), req.GetWarnings())
194192
builderCtx.BuilderLogger = builderLogger
195193

@@ -208,6 +206,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
208206
fqbn,
209207
req.GetClean(),
210208
req.GetSourceOverride(),
209+
req.GetCreateCompilationDatabaseOnly(),
211210
builderLogger,
212211
)
213212
if err != nil {
@@ -339,10 +338,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
339338
exportBinaries = false
340339
}
341340
if exportBinaries {
342-
err := sketchBuilder.RunRecipe(
343-
"recipe.hooks.savehex.presavehex", ".pattern", false,
344-
builderCtx.OnlyUpdateCompilationDatabase,
345-
)
341+
err := sketchBuilder.RunRecipe("recipe.hooks.savehex.presavehex", ".pattern", false)
346342
if err != nil {
347343
return r, err
348344
}
@@ -381,10 +377,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
381377
}
382378
}
383379

384-
err = sketchBuilder.RunRecipe(
385-
"recipe.hooks.savehex.postsavehex", ".pattern", false,
386-
builderCtx.OnlyUpdateCompilationDatabase,
387-
)
380+
err = sketchBuilder.RunRecipe("recipe.hooks.savehex.postsavehex", ".pattern", false)
388381
if err != nil {
389382
return r, err
390383
}

0 commit comments

Comments
 (0)