diff --git a/arduino/builder/core.go b/arduino/builder/core.go index 9bec697cb96..5f43ef4a2ca 100644 --- a/arduino/builder/core.go +++ b/arduino/builder/core.go @@ -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" ) @@ -42,37 +41,31 @@ func (b *Builder) CoreBuildCachePath() *paths.Path { } // CoreBuilder fixdoc -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, ) @@ -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() { @@ -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, ) @@ -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)) } @@ -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, ) @@ -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() { diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index fb09a742088..1faad1e67c5 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -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, )