Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4c0d72e

Browse files
authoredSep 15, 2023
[skip-changelog] bye bye legacy (#2317)
* Move Preprocess and Build in arduino/builder * Move the detector inside arduino/builder * remove legacy targets from TaskFile * inline some variable declaration * remove no longer used builder getters * make only necessary function public in the new builder * fix CR: avoid mutating internal state * fix CR: only print normaloutput when is not verbose
1 parent 6d57ce6 commit 4c0d72e

File tree

18 files changed

+312
-586
lines changed

18 files changed

+312
-586
lines changed
 

‎.github/workflows/test-go-task.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ jobs:
154154
- name: Run tests
155155
run: task go:test
156156

157-
- name: Run unit tests on the legacy package
158-
# Run legacy tests on one platform only
159-
if: runner.os == 'Linux'
160-
run: task test-legacy
161-
162157
- name: Upload coverage data to workflow artifact
163158
if: runner.os == 'Linux'
164159
uses: actions/upload-artifact@v3
@@ -167,7 +162,6 @@ jobs:
167162
name: ${{ env.COVERAGE_ARTIFACT }}
168163
path: |
169164
./coverage_unit.txt
170-
./coverage_legacy.txt
171165
172166
coverage-upload:
173167
runs-on: ubuntu-latest

‎Taskfile.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -284,21 +284,11 @@ tasks:
284284
- task: go:build
285285

286286
test:
287-
desc: Run the full testsuite, `legacy` will be skipped
287+
desc: Run the full testsuite
288288
cmds:
289289
- task: go:test
290290
- task: go:integration-test
291291

292-
test-legacy:
293-
desc: Run tests for the `legacy` package
294-
cmds:
295-
- |
296-
go test \
297-
{{ default "-v -failfast" .GOFLAGS }} \
298-
-coverprofile=coverage_legacy.txt \
299-
./legacy/... \
300-
{{.TEST_LDFLAGS}}
301-
302292
test-unit-race:
303293
desc: Run unit tests only with race condition detection
304294
cmds:
@@ -311,18 +301,12 @@ tasks:
311301
{{.TEST_LDFLAGS}}
312302
313303
check:
314-
desc: Check fmt and lint, `legacy` will be skipped
304+
desc: Check fmt and lint
315305
cmds:
316306
- task: go:vet
317307
- task: go:lint
318308
- task: protoc:check
319309

320-
check-legacy:
321-
desc: Check fmt and lint for the `legacy` package
322-
cmds:
323-
- test -z $(go fmt ./legacy/...)
324-
- go vet ./legacy/...
325-
326310
rpc-client:
327311
desc: Run the rpc client test routine (server must be already started)
328312
cmds:
@@ -376,10 +360,10 @@ tasks:
376360
vars:
377361
PROJECT_NAME: "arduino-cli"
378362
DIST_DIR: "dist"
379-
# all modules of this project except for "legacy/..." module and integration test
363+
# all modules of this project except for integration test
380364
DEFAULT_GO_PACKAGES:
381365
sh: |
382-
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | grep -v internal/integrationtest | grep -v legacy | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
366+
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | grep -v internal/integrationtest | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
383367
DEFAULT_INTEGRATIONTEST_GO_PACKAGES:
384368
sh: |
385369
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | grep internal/integrationtest | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')

‎arduino/builder/build_options_manager.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,16 @@ func (m *BuildOptionsManager) wipeBuildPath() error {
154154
return wipe()
155155
}
156156

157+
// Since we might apply a side effect we clone it
158+
currentOptions := m.currentOptions.Clone()
157159
// If SketchLocation path is different but filename is the same, consider it equal
158-
if filepath.Base(m.currentOptions.Get("sketchLocation")) == filepath.Base(prevOpts.Get("sketchLocation")) {
159-
m.currentOptions.Remove("sketchLocation")
160+
if filepath.Base(currentOptions.Get("sketchLocation")) == filepath.Base(prevOpts.Get("sketchLocation")) {
161+
currentOptions.Remove("sketchLocation")
160162
prevOpts.Remove("sketchLocation")
161163
}
162164

163165
// If options are not changed check if core has
164-
if m.currentOptions.Equals(prevOpts) {
166+
if currentOptions.Equals(prevOpts) {
165167
// check if any of the files contained in the core folders has changed
166168
// since the json was generated - like platform.txt or similar
167169
// if so, trigger a "safety" wipe

‎arduino/builder/builder.go

Lines changed: 254 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020
"fmt"
2121

2222
"github.com/arduino/arduino-cli/arduino/builder/compilation"
23+
"github.com/arduino/arduino-cli/arduino/builder/detector"
2324
"github.com/arduino/arduino-cli/arduino/builder/logger"
2425
"github.com/arduino/arduino-cli/arduino/builder/progress"
2526
"github.com/arduino/arduino-cli/arduino/cores"
27+
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2628
"github.com/arduino/arduino-cli/arduino/sketch"
2729
"github.com/arduino/go-paths-helper"
2830
"github.com/arduino/go-properties-orderedmap"
@@ -77,6 +79,7 @@ type Builder struct {
7779

7880
buildArtifacts *BuildArtifacts
7981

82+
*detector.SketchLibrariesDetector
8083
*BuildOptionsManager
8184
}
8285

@@ -109,6 +112,9 @@ func NewBuilder(
109112
sourceOverrides map[string]string,
110113
onlyUpdateCompilationDatabase bool,
111114
targetPlatform, actualPlatform *cores.PlatformRelease,
115+
useCachedLibrariesResolution bool,
116+
librariesManager *librariesmanager.LibrariesManager,
117+
libraryDirs paths.PathList,
112118
logger *logger.BuilderLogger,
113119
progressStats *progress.Struct,
114120
) (*Builder, error) {
@@ -163,6 +169,18 @@ func NewBuilder(
163169
progressStats = progress.New(nil)
164170
}
165171

172+
libsManager, libsResolver, verboseOut, err := detector.LibrariesLoader(
173+
useCachedLibrariesResolution, librariesManager,
174+
builtInLibrariesDirs, libraryDirs, otherLibrariesDirs,
175+
actualPlatform, targetPlatform,
176+
)
177+
if err != nil {
178+
return nil, err
179+
}
180+
if logger.Verbose() {
181+
logger.Warn(string(verboseOut))
182+
}
183+
166184
return &Builder{
167185
sketch: sk,
168186
buildProperties: buildProperties,
@@ -183,6 +201,12 @@ func NewBuilder(
183201
buildArtifacts: &BuildArtifacts{},
184202
targetPlatform: targetPlatform,
185203
actualPlatform: actualPlatform,
204+
SketchLibrariesDetector: detector.NewSketchLibrariesDetector(
205+
libsManager, libsResolver,
206+
useCachedLibrariesResolution,
207+
onlyUpdateCompilationDatabase,
208+
logger,
209+
),
186210
BuildOptionsManager: NewBuildOptionsManager(
187211
hardwareDirs, builtInToolsDirs, otherLibrariesDirs,
188212
builtInLibrariesDirs, buildPath,
@@ -208,29 +232,243 @@ func (b *Builder) GetBuildPath() *paths.Path {
208232
return b.buildPath
209233
}
210234

211-
// GetSketchBuildPath returns the sketch build path
212-
func (b *Builder) GetSketchBuildPath() *paths.Path {
213-
return b.sketchBuildPath
235+
// ExecutableSectionsSize fixdoc
236+
func (b *Builder) ExecutableSectionsSize() ExecutablesFileSections {
237+
return b.executableSectionsSize
214238
}
215239

216-
// GetLibrariesBuildPath returns the libraries build path
217-
func (b *Builder) GetLibrariesBuildPath() *paths.Path {
218-
return b.librariesBuildPath
240+
// Preprocess fixdoc
241+
func (b *Builder) Preprocess() error {
242+
b.Progress.AddSubSteps(6)
243+
defer b.Progress.RemoveSubSteps()
244+
return b.preprocess()
219245
}
220246

221-
// ExecutableSectionsSize fixdoc
222-
func (b *Builder) ExecutableSectionsSize() ExecutablesFileSections {
223-
return b.executableSectionsSize
247+
func (b *Builder) preprocess() error {
248+
if err := b.buildPath.MkdirAll(); err != nil {
249+
return err
250+
}
251+
252+
if err := b.BuildOptionsManager.WipeBuildPath(); err != nil {
253+
return err
254+
}
255+
b.Progress.CompleteStep()
256+
b.Progress.PushProgress()
257+
258+
if err := b.RunRecipe("recipe.hooks.prebuild", ".pattern", false); err != nil {
259+
return err
260+
}
261+
b.Progress.CompleteStep()
262+
b.Progress.PushProgress()
263+
264+
if err := b.prepareSketchBuildPath(); err != nil {
265+
return err
266+
}
267+
b.Progress.CompleteStep()
268+
b.Progress.PushProgress()
269+
270+
b.logIfVerbose(false, tr("Detecting libraries used..."))
271+
err := b.SketchLibrariesDetector.FindIncludes(
272+
b.buildPath,
273+
b.buildProperties.GetPath("build.core.path"),
274+
b.buildProperties.GetPath("build.variant.path"),
275+
b.sketchBuildPath,
276+
b.sketch,
277+
b.librariesBuildPath,
278+
b.buildProperties,
279+
b.targetPlatform.Platform.Architecture,
280+
)
281+
if err != nil {
282+
return err
283+
}
284+
b.Progress.CompleteStep()
285+
b.Progress.PushProgress()
286+
287+
b.warnAboutArchIncompatibleLibraries(b.SketchLibrariesDetector.ImportedLibraries())
288+
b.Progress.CompleteStep()
289+
b.Progress.PushProgress()
290+
291+
b.logIfVerbose(false, tr("Generating function prototypes..."))
292+
if err := b.preprocessSketch(b.SketchLibrariesDetector.IncludeFolders()); err != nil {
293+
return err
294+
}
295+
b.Progress.CompleteStep()
296+
b.Progress.PushProgress()
297+
298+
// Output arduino-preprocessed source
299+
preprocessedSketch, err := b.sketchBuildPath.Join(b.sketch.MainFile.Base() + ".cpp").ReadFile()
300+
if err != nil {
301+
return err
302+
}
303+
b.logger.WriteStdout(preprocessedSketch)
304+
305+
return nil
224306
}
225307

226-
// SaveCompilationDatabase fixdoc
227-
func (b *Builder) SaveCompilationDatabase() {
228-
if b.compilationDatabase != nil {
229-
b.compilationDatabase.SaveToFile()
308+
func (b *Builder) logIfVerbose(warn bool, msg string) {
309+
if !b.logger.Verbose() {
310+
return
311+
}
312+
if warn {
313+
b.logger.Warn(msg)
314+
return
315+
}
316+
b.logger.Info(msg)
317+
}
318+
319+
// Build fixdoc
320+
func (b *Builder) Build() error {
321+
b.Progress.AddSubSteps(6 /** preprocess **/ + 21 /** build **/)
322+
defer b.Progress.RemoveSubSteps()
323+
324+
if err := b.preprocess(); err != nil {
325+
return err
326+
}
327+
328+
buildErr := b.build()
329+
330+
b.SketchLibrariesDetector.PrintUsedAndNotUsedLibraries(buildErr != nil)
331+
b.Progress.CompleteStep()
332+
b.Progress.PushProgress()
333+
334+
b.printUsedLibraries(b.SketchLibrariesDetector.ImportedLibraries())
335+
b.Progress.CompleteStep()
336+
b.Progress.PushProgress()
337+
338+
if buildErr != nil {
339+
return buildErr
340+
}
341+
if err := b.exportProjectCMake(b.SketchLibrariesDetector.ImportedLibraries(), b.SketchLibrariesDetector.IncludeFolders()); err != nil {
342+
return err
230343
}
344+
b.Progress.CompleteStep()
345+
b.Progress.PushProgress()
346+
347+
if err := b.size(); err != nil {
348+
return err
349+
}
350+
b.Progress.CompleteStep()
351+
b.Progress.PushProgress()
352+
353+
return nil
231354
}
232355

233-
// TargetPlatform fixdoc
234-
func (b *Builder) TargetPlatform() *cores.PlatformRelease {
235-
return b.targetPlatform
356+
// Build fixdoc
357+
func (b *Builder) build() error {
358+
b.logIfVerbose(false, tr("Compiling sketch..."))
359+
if err := b.RunRecipe("recipe.hooks.sketch.prebuild", ".pattern", false); err != nil {
360+
return err
361+
}
362+
b.Progress.CompleteStep()
363+
b.Progress.PushProgress()
364+
365+
if err := b.BuildSketch(b.SketchLibrariesDetector.IncludeFolders()); err != nil {
366+
return err
367+
}
368+
b.Progress.CompleteStep()
369+
b.Progress.PushProgress()
370+
371+
if err := b.RunRecipe("recipe.hooks.sketch.postbuild", ".pattern", true); err != nil {
372+
return err
373+
}
374+
b.Progress.CompleteStep()
375+
b.Progress.PushProgress()
376+
377+
b.logIfVerbose(false, tr("Compiling libraries..."))
378+
if err := b.RunRecipe("recipe.hooks.libraries.prebuild", ".pattern", false); err != nil {
379+
return err
380+
}
381+
b.Progress.CompleteStep()
382+
b.Progress.PushProgress()
383+
384+
if err := b.removeUnusedCompiledLibraries(b.SketchLibrariesDetector.ImportedLibraries()); err != nil {
385+
return err
386+
}
387+
b.Progress.CompleteStep()
388+
b.Progress.PushProgress()
389+
390+
if err := b.buildLibraries(b.SketchLibrariesDetector.IncludeFolders(), b.SketchLibrariesDetector.ImportedLibraries()); err != nil {
391+
return err
392+
}
393+
b.Progress.CompleteStep()
394+
b.Progress.PushProgress()
395+
396+
if err := b.RunRecipe("recipe.hooks.libraries.postbuild", ".pattern", true); err != nil {
397+
return err
398+
}
399+
b.Progress.CompleteStep()
400+
b.Progress.PushProgress()
401+
402+
b.logIfVerbose(false, tr("Compiling core..."))
403+
if err := b.RunRecipe("recipe.hooks.core.prebuild", ".pattern", false); err != nil {
404+
return err
405+
}
406+
b.Progress.CompleteStep()
407+
b.Progress.PushProgress()
408+
409+
if err := b.buildCore(); err != nil {
410+
return err
411+
}
412+
b.Progress.CompleteStep()
413+
b.Progress.PushProgress()
414+
415+
if err := b.RunRecipe("recipe.hooks.core.postbuild", ".pattern", true); err != nil {
416+
return err
417+
}
418+
b.Progress.CompleteStep()
419+
b.Progress.PushProgress()
420+
421+
b.logIfVerbose(false, tr("Linking everything together..."))
422+
if err := b.RunRecipe("recipe.hooks.linking.prelink", ".pattern", false); err != nil {
423+
return err
424+
}
425+
b.Progress.CompleteStep()
426+
b.Progress.PushProgress()
427+
428+
if err := b.link(); err != nil {
429+
return err
430+
}
431+
b.Progress.CompleteStep()
432+
b.Progress.PushProgress()
433+
434+
if err := b.RunRecipe("recipe.hooks.linking.postlink", ".pattern", true); err != nil {
435+
return err
436+
}
437+
b.Progress.CompleteStep()
438+
b.Progress.PushProgress()
439+
440+
if err := b.RunRecipe("recipe.hooks.objcopy.preobjcopy", ".pattern", false); err != nil {
441+
return err
442+
}
443+
b.Progress.CompleteStep()
444+
b.Progress.PushProgress()
445+
446+
if err := b.RunRecipe("recipe.objcopy.", ".pattern", true); err != nil {
447+
return err
448+
}
449+
b.Progress.CompleteStep()
450+
b.Progress.PushProgress()
451+
452+
if err := b.RunRecipe("recipe.hooks.objcopy.postobjcopy", ".pattern", true); err != nil {
453+
return err
454+
}
455+
b.Progress.CompleteStep()
456+
b.Progress.PushProgress()
457+
458+
if err := b.MergeSketchWithBootloader(); err != nil {
459+
return err
460+
}
461+
b.Progress.CompleteStep()
462+
b.Progress.PushProgress()
463+
464+
if err := b.RunRecipe("recipe.hooks.postbuild", ".pattern", true); err != nil {
465+
return err
466+
}
467+
b.Progress.CompleteStep()
468+
b.Progress.PushProgress()
469+
470+
if b.compilationDatabase != nil {
471+
b.compilationDatabase.SaveToFile()
472+
}
473+
return nil
236474
}

‎arduino/builder/core.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
"github.com/pkg/errors"
3131
)
3232

33-
// BuildCore fixdoc
34-
func (b *Builder) BuildCore() error {
33+
// buildCore fixdoc
34+
func (b *Builder) buildCore() error {
3535
if err := b.coreBuildPath.MkdirAll(); err != nil {
3636
return errors.WithStack(err)
3737
}

‎arduino/builder/export_cmake.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ import (
3434

3535
var lineMatcher = regexp.MustCompile(`^#line\s\d+\s"`)
3636

37-
// ExportProjectCMake fixdoc
38-
func (b *Builder) ExportProjectCMake(
39-
sketchError bool, // Was there an error while compiling the sketch?
40-
importedLibraries libraries.List,
41-
includeFolders paths.PathList,
42-
) error {
37+
// exportProjectCMake fixdoc
38+
func (b *Builder) exportProjectCMake(importedLibraries libraries.List, includeFolders paths.PathList) error {
4339
// copies the contents of the file named src to the file named
4440
// by dst. The file will be created if it does not already exist. If the
4541
// destination file exists, all it's contents will be replaced by the contents
@@ -175,8 +171,8 @@ func (b *Builder) ExportProjectCMake(
175171
}
176172
var validStaticLibExtensions = []string{".a"}
177173

178-
// If sketch error or cannot export Cmake project
179-
if sketchError || b.buildProperties.Get("compiler.export_cmake") == "" {
174+
// If cannot export Cmake project
175+
if b.buildProperties.Get("compiler.export_cmake") == "" {
180176
return nil
181177
}
182178

@@ -241,7 +237,7 @@ func (b *Builder) ExportProjectCMake(
241237
fmt.Println(err)
242238
}
243239

244-
if err := b.PreprocessSketch(includeFolders); err != nil {
240+
if err := b.preprocessSketch(includeFolders); err != nil {
245241
return err
246242
}
247243

‎arduino/builder/libraries.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var (
3535
FpuCflag = "fpu"
3636
)
3737

38-
// BuildLibraries fixdoc
39-
func (b *Builder) BuildLibraries(includesFolders paths.PathList, importedLibraries libraries.List) error {
38+
// buildLibraries fixdoc
39+
func (b *Builder) buildLibraries(includesFolders paths.PathList, importedLibraries libraries.List) error {
4040
includes := f.Map(includesFolders.AsStrings(), cpp.WrapWithHyphenI)
4141
libs := importedLibraries
4242

@@ -254,8 +254,8 @@ func (b *Builder) compileLibrary(library *libraries.Library, includes []string)
254254
return objectFiles, nil
255255
}
256256

257-
// RemoveUnusedCompiledLibraries fixdoc
258-
func (b *Builder) RemoveUnusedCompiledLibraries(importedLibraries libraries.List) error {
257+
// removeUnusedCompiledLibraries fixdoc
258+
func (b *Builder) removeUnusedCompiledLibraries(importedLibraries libraries.List) error {
259259
if b.librariesBuildPath.NotExist() {
260260
return nil
261261
}
@@ -287,8 +287,8 @@ func (b *Builder) RemoveUnusedCompiledLibraries(importedLibraries libraries.List
287287
return nil
288288
}
289289

290-
// WarnAboutArchIncompatibleLibraries fixdoc
291-
func (b *Builder) WarnAboutArchIncompatibleLibraries(importedLibraries libraries.List) {
290+
// warnAboutArchIncompatibleLibraries fixdoc
291+
func (b *Builder) warnAboutArchIncompatibleLibraries(importedLibraries libraries.List) {
292292
archs := []string{b.targetPlatform.Platform.Architecture}
293293
overrides, _ := b.buildProperties.GetOk("architecture.override_check")
294294
if overrides != "" {
@@ -306,10 +306,10 @@ func (b *Builder) WarnAboutArchIncompatibleLibraries(importedLibraries libraries
306306
}
307307
}
308308

309-
// PrintUsedLibraries fixdoc
309+
// printUsedLibraries fixdoc
310310
// TODO here we can completly remove this part as it's duplicated in what we can
311311
// read in the gRPC response
312-
func (b *Builder) PrintUsedLibraries(importedLibraries libraries.List) {
312+
func (b *Builder) printUsedLibraries(importedLibraries libraries.List) {
313313
if !b.logger.Verbose() || len(importedLibraries) == 0 {
314314
return
315315
}

‎arduino/builder/linker.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/pkg/errors"
2525
)
2626

27-
// Link fixdoc
28-
func (b *Builder) Link() error {
27+
// link fixdoc
28+
func (b *Builder) link() error {
2929
if b.onlyUpdateCompilationDatabase {
3030
if b.logger.Verbose() {
3131
b.logger.Info(tr("Skip linking of final executable."))
@@ -43,14 +43,6 @@ func (b *Builder) Link() error {
4343
return errors.WithStack(err)
4444
}
4545

46-
if err := b.link(objectFiles, coreDotARelPath, b.buildArtifacts.coreArchiveFilePath); err != nil {
47-
return errors.WithStack(err)
48-
}
49-
50-
return nil
51-
}
52-
53-
func (b *Builder) link(objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path) error {
5446
wrapWithDoubleQuotes := func(value string) string { return "\"" + value + "\"" }
5547
objectFileList := strings.Join(f.Map(objectFiles.AsStrings(), wrapWithDoubleQuotes), " ")
5648

@@ -101,7 +93,7 @@ func (b *Builder) link(objectFiles paths.PathList, coreDotARelPath *paths.Path,
10193
properties.Set("compiler.c.elf.flags", properties.Get("compiler.c.elf.flags"))
10294
properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+b.logger.WarningsLevel()))
10395
properties.Set("archive_file", coreDotARelPath.String())
104-
properties.Set("archive_file_path", coreArchiveFilePath.String())
96+
properties.Set("archive_file_path", b.buildArtifacts.coreArchiveFilePath.String())
10597
properties.Set("object_files", objectFileList)
10698

10799
command, err := utils.PrepareCommandForRecipe(properties, "recipe.c.combine.pattern", false)
@@ -113,5 +105,8 @@ func (b *Builder) link(objectFiles paths.PathList, coreDotARelPath *paths.Path,
113105
if b.logger.Verbose() {
114106
b.logger.Info(string(verboseInfo))
115107
}
116-
return err
108+
if err != nil {
109+
return err
110+
}
111+
return nil
117112
}

‎arduino/builder/preprocess_sketch.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ import (
2020
"github.com/arduino/go-paths-helper"
2121
)
2222

23-
// PreprocessSketch fixdoc
24-
func (b *Builder) PreprocessSketch(includes paths.PathList) error {
23+
// preprocessSketch fixdoc
24+
func (b *Builder) preprocessSketch(includes paths.PathList) error {
2525
// In the future we might change the preprocessor
2626
normalOutput, verboseOutput, err := preprocessor.PreprocessSketchWithCtags(
2727
b.sketch, b.buildPath, includes, b.lineOffset,
2828
b.buildProperties, b.onlyUpdateCompilationDatabase,
2929
)
3030
if b.logger.Verbose() {
3131
b.logger.WriteStdout(verboseOutput)
32+
} else {
33+
b.logger.WriteStdout(normalOutput)
3234
}
33-
b.logger.WriteStdout(normalOutput)
3435

3536
return err
3637
}

‎arduino/builder/recipe.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ import (
2727
)
2828

2929
// RunRecipe fixdoc
30-
func (b *Builder) RunRecipe(
31-
prefix, suffix string,
32-
skipIfOnlyUpdatingCompilationDatabase bool,
33-
) error {
30+
func (b *Builder) RunRecipe(prefix, suffix string, skipIfOnlyUpdatingCompilationDatabase bool) error {
3431
logrus.Debugf(fmt.Sprintf("Looking for recipes like %s", prefix+"*"+suffix))
3532

3633
// TODO is it necessary to use Clone?

‎arduino/builder/sizer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.Execut
5050
return res
5151
}
5252

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

‎arduino/builder/sketch.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/arduino/arduino-cli/arduino/builder/cpp"
2727
"github.com/arduino/arduino-cli/arduino/builder/utils"
28-
"github.com/arduino/arduino-cli/arduino/sketch"
2928
"github.com/arduino/arduino-cli/i18n"
3029
f "github.com/arduino/arduino-cli/internal/algorithms"
3130
"github.com/arduino/go-paths-helper"
@@ -39,15 +38,10 @@ var (
3938
tr = i18n.Tr
4039
)
4140

42-
// Sketch fixdoc
43-
func (b *Builder) Sketch() *sketch.Sketch {
44-
return b.sketch
45-
}
46-
47-
// PrepareSketchBuildPath copies the sketch source files in the build path.
41+
// prepareSketchBuildPath copies the sketch source files in the build path.
4842
// The .ino files are merged together to create a .cpp file (by the way, the
4943
// .cpp file still needs to be Arduino-preprocessed to compile).
50-
func (b *Builder) PrepareSketchBuildPath() error {
44+
func (b *Builder) prepareSketchBuildPath() error {
5145
if err := b.sketchBuildPath.MkdirAll(); err != nil {
5246
return errors.Wrap(err, tr("unable to create a folder to save the sketch"))
5347
}

‎commands/compile/compile.go

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import (
2424
"strings"
2525

2626
"github.com/arduino/arduino-cli/arduino"
27-
bldr "github.com/arduino/arduino-cli/arduino/builder"
28-
"github.com/arduino/arduino-cli/arduino/builder/detector"
27+
"github.com/arduino/arduino-cli/arduino/builder"
2928
"github.com/arduino/arduino-cli/arduino/builder/logger"
3029
"github.com/arduino/arduino-cli/arduino/builder/progress"
3130
"github.com/arduino/arduino-cli/arduino/cores"
@@ -37,8 +36,6 @@ import (
3736
"github.com/arduino/arduino-cli/configuration"
3837
"github.com/arduino/arduino-cli/i18n"
3938
"github.com/arduino/arduino-cli/internal/inventory"
40-
"github.com/arduino/arduino-cli/legacy/builder"
41-
"github.com/arduino/arduino-cli/legacy/builder/types"
4239
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
4340
paths "github.com/arduino/go-paths-helper"
4441
"github.com/sirupsen/logrus"
@@ -174,16 +171,15 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
174171
return nil, err
175172
}
176173

177-
builderCtx := &types.Context{}
178174
actualPlatform := buildPlatform
179-
builtinLibrariesDir := configuration.IDEBuiltinLibrariesDir(configuration.Settings)
180175
otherLibrariesDirs := paths.NewPathList(req.GetLibraries()...)
181176
otherLibrariesDirs.Add(configuration.LibrariesDir(configuration.Settings))
182177

183-
builderLogger := logger.New(outStream, errStream, req.GetVerbose(), req.GetWarnings())
184-
builderCtx.BuilderLogger = builderLogger
185-
186-
sketchBuilder, err := bldr.NewBuilder(
178+
var libsManager *librariesmanager.LibrariesManager
179+
if pme.GetProfile() != nil {
180+
libsManager = lm
181+
}
182+
sketchBuilder, err := builder.NewBuilder(
187183
sk,
188184
boardBuildProperties,
189185
buildPath,
@@ -194,53 +190,29 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
194190
configuration.HardwareDirectories(configuration.Settings),
195191
configuration.BuiltinToolsDirectories(configuration.Settings),
196192
otherLibrariesDirs,
197-
builtinLibrariesDir,
193+
configuration.IDEBuiltinLibrariesDir(configuration.Settings),
198194
fqbn,
199195
req.GetClean(),
200196
req.GetSourceOverride(),
201197
req.GetCreateCompilationDatabaseOnly(),
202-
actualPlatform, targetPlatform,
203-
builderLogger,
198+
targetPlatform, actualPlatform,
199+
req.GetSkipLibrariesDiscovery(),
200+
libsManager,
201+
paths.NewPathList(req.Library...),
202+
logger.New(outStream, errStream, req.GetVerbose(), req.GetWarnings()),
204203
progress.New(progressCB),
205204
)
206205
if err != nil {
207206
if strings.Contains(err.Error(), "invalid build properties") {
208207
return nil, &arduino.InvalidArgumentError{Message: tr("Invalid build properties"), Cause: err}
209208
}
210-
if errors.Is(err, bldr.ErrSketchCannotBeLocatedInBuildPath) {
209+
if errors.Is(err, builder.ErrSketchCannotBeLocatedInBuildPath) {
211210
return r, &arduino.CompileFailedError{
212211
Message: tr("Sketch cannot be located in build path. Please specify a different build path"),
213212
}
214213
}
215214
return r, &arduino.CompileFailedError{Message: err.Error()}
216215
}
217-
builderCtx.Builder = sketchBuilder
218-
219-
var libsManager *librariesmanager.LibrariesManager
220-
if pme.GetProfile() != nil {
221-
libsManager = lm
222-
}
223-
useCachedLibrariesResolution := req.GetSkipLibrariesDiscovery()
224-
libraryDir := paths.NewPathList(req.Library...)
225-
libsManager, libsResolver, verboseOut, err := detector.LibrariesLoader(
226-
useCachedLibrariesResolution, libsManager,
227-
builtinLibrariesDir, libraryDir, otherLibrariesDirs,
228-
actualPlatform, targetPlatform,
229-
)
230-
if err != nil {
231-
return r, &arduino.CompileFailedError{Message: err.Error()}
232-
}
233-
234-
if builderLogger.Verbose() {
235-
builderLogger.Warn(string(verboseOut))
236-
}
237-
238-
builderCtx.SketchLibrariesDetector = detector.NewSketchLibrariesDetector(
239-
libsManager, libsResolver,
240-
useCachedLibrariesResolution,
241-
req.GetCreateCompilationDatabaseOnly(),
242-
builderLogger,
243-
)
244216

245217
defer func() {
246218
if p := sketchBuilder.GetBuildPath(); p != nil {
@@ -270,7 +242,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
270242

271243
if req.GetPreprocess() {
272244
// Just output preprocessed source code and exit
273-
compileErr := builder.RunPreprocess(builderCtx)
245+
compileErr := sketchBuilder.Preprocess()
274246
if compileErr != nil {
275247
compileErr = &arduino.CompileFailedError{Message: compileErr.Error()}
276248
}
@@ -279,7 +251,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
279251

280252
defer func() {
281253
importedLibs := []*rpc.Library{}
282-
for _, lib := range builderCtx.SketchLibrariesDetector.ImportedLibraries() {
254+
for _, lib := range sketchBuilder.SketchLibrariesDetector.ImportedLibraries() {
283255
rpcLib, err := lib.ToRPCLibrary()
284256
if err != nil {
285257
msg := tr("Error getting information for library %s", lib.Name) + ": " + err.Error() + "\n"
@@ -315,7 +287,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
315287
targetBoard.String(), "'build.board'", sketchBuilder.GetBuildProperties().Get("build.board")) + "\n"))
316288
}
317289

318-
if err := builder.RunBuilder(builderCtx); err != nil {
290+
if err := sketchBuilder.Build(); err != nil {
319291
return r, &arduino.CompileFailedError{Message: err.Error()}
320292
}
321293

‎internal/integrationtest/daemon/daemon_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestDaemonCompileOptions(t *testing.T) {
187187
// https://github.com/arduino/arduino-cli/issues/2016
188188
// assert that the task progress is increasing and doesn't contain multiple 100% values
189189
results := analyzer.Results[""]
190-
require.True(t, results[len(results)-1].Completed)
190+
require.True(t, results[len(results)-1].Completed, fmt.Sprintf("latest percent value: %v", results[len(results)-1].Percent))
191191
require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent))
192192
}
193193

‎legacy/builder/.gitignore

Lines changed: 0 additions & 81 deletions
This file was deleted.

‎legacy/builder/builder.go

Lines changed: 0 additions & 311 deletions
This file was deleted.

‎legacy/builder/types/context.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎legacy/builder/types/types.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.