Skip to content

legacy: Builder refactorization (part 5...) #2312

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

Merged
merged 34 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1709a8f
move customBuildProperties to arduino/builder
alessio-perugini Sep 12, 2023
c19a712
remove BuildProperties from context
alessio-perugini Sep 12, 2023
c22f1c7
remove BuildPath from context
alessio-perugini Sep 12, 2023
2c22616
remove sketch,libraries,core build path from Context
alessio-perugini Sep 12, 2023
0afe884
remove buildPath parameter to PrepareSketchBuildPath func
alessio-perugini Sep 12, 2023
7ff4427
Make CoreBuilder a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
2297f2b
Add BuilderLogger in arduino/builder
alessio-perugini Sep 12, 2023
d704e4c
Remove BuilderLogger from CoreBuild parameter
alessio-perugini Sep 12, 2023
f8cbfe5
Make getCachedCoreArchiveDirName unexported
alessio-perugini Sep 12, 2023
5916daa
heavily refactored the ContainerBuildOptions
alessio-perugini Sep 12, 2023
895c593
remove fqbn from Context
alessio-perugini Sep 12, 2023
b4891ea
remove clean from Context
alessio-perugini Sep 12, 2023
870f624
remove unsued properties in Context
alessio-perugini Sep 12, 2023
a6e1ef2
remove sourceOverrides from Context
alessio-perugini Sep 12, 2023
776ed23
make SketchBuilder a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
93a9cfa
make BuildLibraries a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
e965599
make RunRecipe a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
f1fdf17
make RemoveUnusedCompiledLibraries a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
41b47b7
make MergeSketchWithBootloader a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
4f99d33
make WarnAboutArchIncompatibleLibraries a method recevier of arduino/…
alessio-perugini Sep 12, 2023
16f7fe0
make PrintUsedLibraries a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
97a15a4
make ExportCmake and PreprocessorSketch a method recevier of arduino/…
alessio-perugini Sep 12, 2023
f4f7298
remove legacy/constans pkg
alessio-perugini Sep 12, 2023
5e9f9ca
make Linker a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
290e8b1
make Size a method recevier of arduino/builder
alessio-perugini Sep 12, 2023
2279e9b
remove onlyUpdateCompilationDatabase from Context
alessio-perugini Sep 12, 2023
a0f8e30
remove Progress from Context
alessio-perugini Sep 12, 2023
aa904b6
remove ExecutableSectionSize from Context
alessio-perugini Sep 12, 2023
34e6204
remove CompilationDatabase from Context
alessio-perugini Sep 12, 2023
d5c040f
remove LineOffset from Context
alessio-perugini Sep 12, 2023
8995aff
introduce BuilderArtifacts to better isolate write operations
alessio-perugini Sep 12, 2023
e005586
remove ActualPlatform and TargetPlatform from Context
alessio-perugini Sep 13, 2023
a7963f4
directly pass the remaining properties of Context in the builder cons…
alessio-perugini Sep 13, 2023
6004057
polish legacy test
alessio-perugini Sep 13, 2023
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
Prev Previous commit
Next Next commit
introduce BuilderArtifacts to better isolate write operations
  • Loading branch information
alessio-perugini committed Sep 15, 2023
commit 8995aff4cf134c9d1a99e7e07857beeed2e03040
17 changes: 17 additions & 0 deletions arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,24 @@ type Builder struct {
// C++ Parsing
lineOffset int

buildArtifacts *BuildArtifacts

*BuildOptionsManager
}

// BuildArtifacts contains the result of various build
type BuildArtifacts struct {
// populated by BuildCore
coreArchiveFilePath *paths.Path
coreObjectsFiles paths.PathList

// populated by BuildLibraries
librariesObjectFiles paths.PathList

// populated by BuildSketch
sketchObjectFiles paths.PathList
}

// NewBuilder creates a sketch Builder.
func NewBuilder(
sk *sketch.Sketch,
Expand Down Expand Up @@ -160,6 +175,8 @@ func NewBuilder(
onlyUpdateCompilationDatabase: onlyUpdateCompilationDatabase,
compilationDatabase: compilation.NewDatabase(buildPath.Join("compile_commands.json")),
Progress: progressStats,
executableSectionsSize: []ExecutableSectionSize{},
buildArtifacts: &BuildArtifacts{},
BuildOptionsManager: NewBuildOptionsManager(
hardwareDirs, builtInToolsDirs, otherLibrariesDirs,
builtInLibrariesDirs, buildPath,
Expand Down
13 changes: 7 additions & 6 deletions arduino/builder/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
)

// BuildCore fixdoc
func (b *Builder) BuildCore(actualPlatform *cores.PlatformRelease) (paths.PathList, *paths.Path, error) {
func (b *Builder) BuildCore(actualPlatform *cores.PlatformRelease) error {
if err := b.coreBuildPath.MkdirAll(); err != nil {
return nil, nil, errors.WithStack(err)
return errors.WithStack(err)
}

if b.coreBuildCachePath != nil {
Expand All @@ -45,16 +45,17 @@ func (b *Builder) BuildCore(actualPlatform *cores.PlatformRelease) (paths.PathLi
// compileCore function).
b.coreBuildCachePath = nil
} else if err := b.coreBuildCachePath.MkdirAll(); err != nil {
return nil, nil, errors.WithStack(err)
return errors.WithStack(err)
}
}

archiveFile, objectFiles, err := b.compileCore(actualPlatform)
if err != nil {
return nil, nil, errors.WithStack(err)
return errors.WithStack(err)
}

return objectFiles, archiveFile, nil
b.buildArtifacts.coreObjectsFiles = objectFiles
b.buildArtifacts.coreArchiveFilePath = archiveFile
return nil
}

func (b *Builder) compileCore(actualPlatform *cores.PlatformRelease) (*paths.Path, paths.PathList, error) {
Expand Down
10 changes: 5 additions & 5 deletions arduino/builder/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ var (
)

// BuildLibraries fixdoc
func (b *Builder) BuildLibraries(includesFolders paths.PathList, importedLibraries libraries.List) (paths.PathList, error) {
func (b *Builder) BuildLibraries(includesFolders paths.PathList, importedLibraries libraries.List) error {
includes := f.Map(includesFolders.AsStrings(), cpp.WrapWithHyphenI)
libs := importedLibraries

if err := b.librariesBuildPath.MkdirAll(); err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}

librariesObjectFiles, err := b.compileLibraries(libs, includes)
if err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}

return librariesObjectFiles, nil
b.buildArtifacts.librariesObjectFiles = librariesObjectFiles
return nil
}

func directoryContainsFile(folder *paths.Path) bool {
Expand Down
12 changes: 6 additions & 6 deletions arduino/builder/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// Link fixdoc
func (b *Builder) Link(sketchObjectFiles, librariesObjectFiles, coreObjectsFiles paths.PathList, coreArchiveFilePath *paths.Path) error {
func (b *Builder) Link() error {
if b.onlyUpdateCompilationDatabase {
if b.logger.Verbose() {
b.logger.Info(tr("Skip linking of final executable."))
Expand All @@ -34,21 +34,21 @@ func (b *Builder) Link(sketchObjectFiles, librariesObjectFiles, coreObjectsFiles
}

// TODO can we remove this multiple assignations?
objectFilesSketch := sketchObjectFiles
objectFilesLibraries := librariesObjectFiles
objectFilesCore := coreObjectsFiles
objectFilesSketch := b.buildArtifacts.sketchObjectFiles
objectFilesLibraries := b.buildArtifacts.librariesObjectFiles
objectFilesCore := b.buildArtifacts.coreObjectsFiles

objectFiles := paths.NewPathList()
objectFiles.AddAll(objectFilesSketch)
objectFiles.AddAll(objectFilesLibraries)
objectFiles.AddAll(objectFilesCore)

coreDotARelPath, err := b.buildPath.RelTo(coreArchiveFilePath)
coreDotARelPath, err := b.buildPath.RelTo(b.buildArtifacts.coreArchiveFilePath)
if err != nil {
return errors.WithStack(err)
}

if err := b.link(objectFiles, coreDotARelPath, coreArchiveFilePath); err != nil {
if err := b.link(objectFiles, coreDotARelPath, b.buildArtifacts.coreArchiveFilePath); err != nil {
return errors.WithStack(err)
}

Expand Down
11 changes: 6 additions & 5 deletions arduino/builder/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ func writeIfDifferent(source []byte, destPath *paths.Path) error {
}

// BuildSketch fixdoc
func (b *Builder) BuildSketch(includesFolders paths.PathList) (paths.PathList, error) {
func (b *Builder) BuildSketch(includesFolders paths.PathList) error {
includes := f.Map(includesFolders.AsStrings(), cpp.WrapWithHyphenI)

if err := b.sketchBuildPath.MkdirAll(); err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}

sketchObjectFiles, err := utils.CompileFiles(
Expand All @@ -197,7 +197,7 @@ func (b *Builder) BuildSketch(includesFolders paths.PathList) (paths.PathList, e
b.Progress,
)
if err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}

// The "src/" subdirectory of a sketch is compiled recursively
Expand All @@ -212,12 +212,13 @@ func (b *Builder) BuildSketch(includesFolders paths.PathList) (paths.PathList, e
b.Progress,
)
if err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}
sketchObjectFiles.AddAll(srcObjectFiles)
}

return sketchObjectFiles, nil
b.buildArtifacts.sketchObjectFiles = sketchObjectFiles
return nil
}

// MergeSketchWithBootloader fixdoc
Expand Down
32 changes: 4 additions & 28 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ func (s *Builder) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
sketchObjectFiles, err := ctx.Builder.BuildSketch(ctx.SketchLibrariesDetector.IncludeFolders())
if err != nil {
return err
}
ctx.SketchObjectFiles = sketchObjectFiles
return nil
return ctx.Builder.BuildSketch(ctx.SketchLibrariesDetector.IncludeFolders())
}),

types.BareCommand(func(ctx *types.Context) error {
Expand All @@ -87,16 +82,7 @@ func (s *Builder) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
librariesObjectFiles, err := ctx.Builder.BuildLibraries(
ctx.SketchLibrariesDetector.IncludeFolders(),
ctx.SketchLibrariesDetector.ImportedLibraries(),
)
if err != nil {
return err
}
ctx.LibrariesObjectFiles = librariesObjectFiles

return nil
return ctx.Builder.BuildLibraries(ctx.SketchLibrariesDetector.IncludeFolders(), ctx.SketchLibrariesDetector.ImportedLibraries())
}),
types.BareCommand(func(ctx *types.Context) error {
return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.libraries.postbuild", ".pattern", true)
Expand All @@ -108,12 +94,7 @@ func (s *Builder) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
objectFiles, archiveFile, err := ctx.Builder.BuildCore(ctx.ActualPlatform)

ctx.CoreObjectsFiles = objectFiles
ctx.CoreArchiveFilePath = archiveFile

return err
return ctx.Builder.BuildCore(ctx.ActualPlatform)
}),

types.BareCommand(func(ctx *types.Context) error {
Expand All @@ -126,12 +107,7 @@ func (s *Builder) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
return ctx.Builder.Link(
ctx.SketchObjectFiles,
ctx.LibrariesObjectFiles,
ctx.CoreObjectsFiles,
ctx.CoreArchiveFilePath,
)
return ctx.Builder.Link()
}),

types.BareCommand(func(ctx *types.Context) error {
Expand Down
5 changes: 0 additions & 5 deletions legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ type Context struct {
PackageManager *packagemanager.Explorer
TargetPlatform *cores.PlatformRelease
ActualPlatform *cores.PlatformRelease

CoreArchiveFilePath *paths.Path
CoreObjectsFiles paths.PathList
LibrariesObjectFiles paths.PathList
SketchObjectFiles paths.PathList
}