Skip to content

Commit

Permalink
Make CoreBuilder a method recevier of arduino/builder
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 12, 2023
1 parent 1ebabcd commit 8e1ab03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
52 changes: 21 additions & 31 deletions arduino/builder/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
f "github.com/arduino/arduino-cli/internal/algorithms"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
"github.com/pkg/errors"
)

Expand All @@ -42,37 +41,31 @@ func (b *Builder) CoreBuildCachePath() *paths.Path {
}

// CoreBuilder fixdoc

Check failure on line 43 in arduino/builder/core.go

View workflow job for this annotation

GitHub Actions / check-style (./)

comment on exported method Builder.BuildCore should be of the form "BuildCore ..."
func CoreBuilder(
buildPath, coreBuildPath, coreBuildCachePath *paths.Path,
buildProperties *properties.Map,
func (b *Builder) BuildCore(
actualPlatform *cores.PlatformRelease,
onlyUpdateCompilationDatabase, clean bool,
compilationDatabase *compilation.Database,
jobs int,
builderLogger *logger.BuilderLogger,
progress *progress.Struct, progressCB rpc.TaskProgressCB,
) (paths.PathList, *paths.Path, error) {
if err := coreBuildPath.MkdirAll(); err != nil {
if err := b.coreBuildPath.MkdirAll(); err != nil {
return nil, nil, errors.WithStack(err)
}

if coreBuildCachePath != nil {
if _, err := coreBuildCachePath.RelTo(buildPath); err != nil {
if b.coreBuildCachePath != nil {
if _, err := b.coreBuildCachePath.RelTo(b.buildPath); err != nil {
builderLogger.Info(tr("Couldn't deeply cache core build: %[1]s", err))
builderLogger.Info(tr("Running normal build of the core..."))
coreBuildCachePath = nil
} else if err := coreBuildCachePath.MkdirAll(); err != nil {
b.coreBuildCachePath = nil
} else if err := b.coreBuildCachePath.MkdirAll(); err != nil {
return nil, nil, errors.WithStack(err)
}
}

archiveFile, objectFiles, err := compileCore(
archiveFile, objectFiles, err := b.compileCore(
onlyUpdateCompilationDatabase, clean,
actualPlatform,
coreBuildPath, coreBuildCachePath,
buildProperties,
compilationDatabase,
jobs,
builderLogger,
progress, progressCB,
)
Expand All @@ -83,19 +76,16 @@ func CoreBuilder(
return objectFiles, archiveFile, nil
}

func compileCore(
func (b *Builder) compileCore(
onlyUpdateCompilationDatabase, clean bool,
actualPlatform *cores.PlatformRelease,
buildPath, buildCachePath *paths.Path,
buildProperties *properties.Map,
compilationDatabase *compilation.Database,
jobs int,
builderLogger *logger.BuilderLogger,
progress *progress.Struct, progressCB rpc.TaskProgressCB,
) (*paths.Path, paths.PathList, error) {
coreFolder := buildProperties.GetPath("build.core.path")
variantFolder := buildProperties.GetPath("build.variant.path")
targetCoreFolder := buildProperties.GetPath("runtime.platform.path")
coreFolder := b.buildProperties.GetPath("build.core.path")
variantFolder := b.buildProperties.GetPath("build.variant.path")
targetCoreFolder := b.buildProperties.GetPath("runtime.platform.path")

includes := []string{coreFolder.String()}
if variantFolder != nil && variantFolder.IsDir() {
Expand All @@ -107,10 +97,10 @@ func compileCore(
variantObjectFiles := paths.NewPathList()
if variantFolder != nil && variantFolder.IsDir() {
variantObjectFiles, err = utils.CompileFilesRecursive(
variantFolder, buildPath, buildProperties, includes,
variantFolder, b.coreBuildPath, b.buildProperties, includes,
onlyUpdateCompilationDatabase,
compilationDatabase,
jobs,
b.jobs,
builderLogger,
progress, progressCB,
)
Expand All @@ -120,16 +110,16 @@ func compileCore(
}

var targetArchivedCore *paths.Path
if buildCachePath != nil {
if b.coreBuildCachePath != nil {
realCoreFolder := coreFolder.Parent().Parent()
archivedCoreName := GetCachedCoreArchiveDirName(
buildProperties.Get("build.fqbn"),
buildProperties.Get("compiler.optimization_flags"),
b.buildProperties.Get("build.fqbn"),
b.buildProperties.Get("compiler.optimization_flags"),
realCoreFolder,
)
targetArchivedCore = buildCachePath.Join(archivedCoreName, "core.a")
targetArchivedCore = b.coreBuildCachePath.Join(archivedCoreName, "core.a")

if _, err := buildcache.New(buildCachePath).GetOrCreate(archivedCoreName); errors.Is(err, buildcache.CreateDirErr) {
if _, err := buildcache.New(b.coreBuildCachePath).GetOrCreate(archivedCoreName); errors.Is(err, buildcache.CreateDirErr) {
return nil, nil, fmt.Errorf(tr("creating core cache folder: %s", err))
}

Expand Down Expand Up @@ -158,10 +148,10 @@ func compileCore(
}

coreObjectFiles, err := utils.CompileFilesRecursive(
coreFolder, buildPath, buildProperties, includes,
coreFolder, b.coreBuildPath, b.buildProperties, includes,
onlyUpdateCompilationDatabase,
compilationDatabase,
jobs,
b.jobs,
builderLogger,
progress, progressCB,
)
Expand All @@ -170,7 +160,7 @@ func compileCore(
}

archiveFile, verboseInfo, err := utils.ArchiveCompiledFiles(
buildPath, paths.New("core.a"), coreObjectFiles, buildProperties,
b.coreBuildPath, paths.New("core.a"), coreObjectFiles, b.buildProperties,
onlyUpdateCompilationDatabase, builderLogger.Verbose(), builderLogger.Stdout(), builderLogger.Stderr(),
)
if builderLogger.Verbose() {
Expand Down
5 changes: 1 addition & 4 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,10 @@ func (s *Builder) Run(ctx *types.Context) error {
}),

types.BareCommand(func(ctx *types.Context) error {
objectFiles, archiveFile, err := builder.CoreBuilder(
ctx.Builder.GetBuildPath(), ctx.Builder.GetCoreBuildPath(), ctx.Builder.CoreBuildCachePath(),
ctx.Builder.GetBuildProperties(),
objectFiles, archiveFile, err := ctx.Builder.BuildCore(
ctx.ActualPlatform,
ctx.OnlyUpdateCompilationDatabase, ctx.Clean,
ctx.CompilationDatabase,
ctx.Builder.Jobs(),
ctx.BuilderLogger,
&ctx.Progress, ctx.ProgressCB,
)
Expand Down

0 comments on commit 8e1ab03

Please sign in to comment.