diff --git a/arduino/builder/builder.go b/arduino/builder/builder.go index a856106d574..af1ead37ec1 100644 --- a/arduino/builder/builder.go +++ b/arduino/builder/builder.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/arduino/arduino-cli/arduino/builder/compilation" + "github.com/arduino/arduino-cli/arduino/builder/detector" "github.com/arduino/arduino-cli/arduino/builder/logger" "github.com/arduino/arduino-cli/arduino/builder/progress" "github.com/arduino/arduino-cli/arduino/cores" @@ -223,14 +224,243 @@ func (b *Builder) ExecutableSectionsSize() ExecutablesFileSections { return b.executableSectionsSize } -// SaveCompilationDatabase fixdoc -func (b *Builder) SaveCompilationDatabase() { - if b.compilationDatabase != nil { - b.compilationDatabase.SaveToFile() - } -} - // TargetPlatform fixdoc func (b *Builder) TargetPlatform() *cores.PlatformRelease { return b.targetPlatform } + +// Preprocess fixdoc +func (b *Builder) Preprocess(detector *detector.SketchLibrariesDetector) error { + b.Progress.AddSubSteps(6) + defer b.Progress.RemoveSubSteps() + return b.preprocess(detector) +} + +func (b *Builder) preprocess(detector *detector.SketchLibrariesDetector) error { + if err := b.buildPath.MkdirAll(); err != nil { + return err + } + + if err := b.BuildOptionsManager.WipeBuildPath(); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.prebuild", ".pattern", false); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.PrepareSketchBuildPath(); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + b.logIfVerbose(false, tr("Detecting libraries used...")) + err := detector.FindIncludes( + b.GetBuildPath(), + b.GetBuildProperties().GetPath("build.core.path"), + b.GetBuildProperties().GetPath("build.variant.path"), + b.GetSketchBuildPath(), + b.Sketch(), + b.GetLibrariesBuildPath(), + b.GetBuildProperties(), + b.TargetPlatform().Platform.Architecture, + ) + if err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + b.WarnAboutArchIncompatibleLibraries(detector.ImportedLibraries()) + b.Progress.CompleteStep() + b.Progress.PushProgress() + + b.logIfVerbose(false, tr("Generating function prototypes...")) + if err := b.PreprocessSketch(detector.IncludeFolders()); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + // Output arduino-preprocessed source + preprocessedSketch, err := b.sketchBuildPath.Join(b.sketch.MainFile.Base() + ".cpp").ReadFile() + if err != nil { + return err + } + b.logger.WriteStdout(preprocessedSketch) + + return nil +} + +func (b *Builder) logIfVerbose(warn bool, msg string) { + if !b.logger.Verbose() { + return + } + if warn { + b.logger.Warn(msg) + return + } + b.logger.Info(msg) +} + +// Build fixdoc +func (b *Builder) Build(detector *detector.SketchLibrariesDetector) error { + b.Progress.AddSubSteps(6 /** preprocess **/ + 21 /** build **/) + defer b.Progress.RemoveSubSteps() + + if err := b.preprocess(detector); err != nil { + return err + } + + buildErr := b.build(detector) + + detector.PrintUsedAndNotUsedLibraries(buildErr != nil) + b.Progress.CompleteStep() + b.Progress.PushProgress() + + b.PrintUsedLibraries(detector.ImportedLibraries()) + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if buildErr != nil { + return buildErr + } + if err := b.ExportProjectCMake(detector.ImportedLibraries(), detector.IncludeFolders()); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.Size(); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + return nil +} + +// Build fixdoc +func (b *Builder) build(detector *detector.SketchLibrariesDetector) error { + b.logIfVerbose(false, tr("Compiling sketch...")) + if err := b.RunRecipe("recipe.hooks.sketch.prebuild", ".pattern", false); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.BuildSketch(detector.IncludeFolders()); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.sketch.postbuild", ".pattern", true); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + b.logIfVerbose(false, tr("Compiling libraries...")) + if err := b.RunRecipe("recipe.hooks.libraries.prebuild", ".pattern", false); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RemoveUnusedCompiledLibraries(detector.ImportedLibraries()); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.BuildLibraries(detector.IncludeFolders(), detector.ImportedLibraries()); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.libraries.postbuild", ".pattern", true); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + b.logIfVerbose(false, tr("Compiling core...")) + if err := b.RunRecipe("recipe.hooks.core.prebuild", ".pattern", false); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.BuildCore(); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.core.postbuild", ".pattern", true); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + b.logIfVerbose(false, tr("Linking everything together...")) + if err := b.RunRecipe("recipe.hooks.linking.prelink", ".pattern", false); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.Link(); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.linking.postlink", ".pattern", true); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.objcopy.preobjcopy", ".pattern", false); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.objcopy.", ".pattern", true); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.objcopy.postobjcopy", ".pattern", true); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.MergeSketchWithBootloader(); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if err := b.RunRecipe("recipe.hooks.postbuild", ".pattern", true); err != nil { + return err + } + b.Progress.CompleteStep() + b.Progress.PushProgress() + + if b.compilationDatabase != nil { + b.compilationDatabase.SaveToFile() + } + return nil +} diff --git a/arduino/builder/export_cmake.go b/arduino/builder/export_cmake.go index de7bdf6db88..023e34f89c5 100644 --- a/arduino/builder/export_cmake.go +++ b/arduino/builder/export_cmake.go @@ -35,11 +35,7 @@ import ( var lineMatcher = regexp.MustCompile(`^#line\s\d+\s"`) // ExportProjectCMake fixdoc -func (b *Builder) ExportProjectCMake( - sketchError bool, // Was there an error while compiling the sketch? - importedLibraries libraries.List, - includeFolders paths.PathList, -) error { +func (b *Builder) ExportProjectCMake(importedLibraries libraries.List, includeFolders paths.PathList) error { // copies the contents of the file named src to the file named // by dst. The file will be created if it does not already exist. If the // destination file exists, all it's contents will be replaced by the contents @@ -175,8 +171,8 @@ func (b *Builder) ExportProjectCMake( } var validStaticLibExtensions = []string{".a"} - // If sketch error or cannot export Cmake project - if sketchError || b.buildProperties.Get("compiler.export_cmake") == "" { + // If cannot export Cmake project + if b.buildProperties.Get("compiler.export_cmake") == "" { return nil } diff --git a/arduino/builder/sizer.go b/arduino/builder/sizer.go index 7f461f8292e..e85164f7f34 100644 --- a/arduino/builder/sizer.go +++ b/arduino/builder/sizer.go @@ -51,8 +51,8 @@ func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.Execut } // Size fixdoc -func (b *Builder) Size(sketchError bool) error { - if b.onlyUpdateCompilationDatabase || sketchError { +func (b *Builder) Size() error { + if b.onlyUpdateCompilationDatabase { return nil } diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 5dcd028c34c..7b0462926db 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -24,7 +24,7 @@ import ( "strings" "github.com/arduino/arduino-cli/arduino" - bldr "github.com/arduino/arduino-cli/arduino/builder" + "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/arduino/builder/detector" "github.com/arduino/arduino-cli/arduino/builder/logger" "github.com/arduino/arduino-cli/arduino/builder/progress" @@ -37,8 +37,6 @@ import ( "github.com/arduino/arduino-cli/configuration" "github.com/arduino/arduino-cli/i18n" "github.com/arduino/arduino-cli/internal/inventory" - "github.com/arduino/arduino-cli/legacy/builder" - "github.com/arduino/arduino-cli/legacy/builder/types" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" paths "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" @@ -174,16 +172,14 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream return nil, err } - builderCtx := &types.Context{} actualPlatform := buildPlatform builtinLibrariesDir := configuration.IDEBuiltinLibrariesDir(configuration.Settings) otherLibrariesDirs := paths.NewPathList(req.GetLibraries()...) otherLibrariesDirs.Add(configuration.LibrariesDir(configuration.Settings)) builderLogger := logger.New(outStream, errStream, req.GetVerbose(), req.GetWarnings()) - builderCtx.BuilderLogger = builderLogger - sketchBuilder, err := bldr.NewBuilder( + sketchBuilder, err := builder.NewBuilder( sk, boardBuildProperties, buildPath, @@ -207,14 +203,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream if strings.Contains(err.Error(), "invalid build properties") { return nil, &arduino.InvalidArgumentError{Message: tr("Invalid build properties"), Cause: err} } - if errors.Is(err, bldr.ErrSketchCannotBeLocatedInBuildPath) { + if errors.Is(err, builder.ErrSketchCannotBeLocatedInBuildPath) { return r, &arduino.CompileFailedError{ Message: tr("Sketch cannot be located in build path. Please specify a different build path"), } } return r, &arduino.CompileFailedError{Message: err.Error()} } - builderCtx.Builder = sketchBuilder var libsManager *librariesmanager.LibrariesManager if pme.GetProfile() != nil { @@ -235,7 +230,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream builderLogger.Warn(string(verboseOut)) } - builderCtx.SketchLibrariesDetector = detector.NewSketchLibrariesDetector( + sketchLibrariesDetector := detector.NewSketchLibrariesDetector( libsManager, libsResolver, useCachedLibrariesResolution, req.GetCreateCompilationDatabaseOnly(), @@ -270,7 +265,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream if req.GetPreprocess() { // Just output preprocessed source code and exit - compileErr := builder.RunPreprocess(builderCtx) + compileErr := sketchBuilder.Preprocess(sketchLibrariesDetector) if compileErr != nil { compileErr = &arduino.CompileFailedError{Message: compileErr.Error()} } @@ -279,7 +274,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream defer func() { importedLibs := []*rpc.Library{} - for _, lib := range builderCtx.SketchLibrariesDetector.ImportedLibraries() { + for _, lib := range sketchLibrariesDetector.ImportedLibraries() { rpcLib, err := lib.ToRPCLibrary() if err != nil { msg := tr("Error getting information for library %s", lib.Name) + ": " + err.Error() + "\n" @@ -315,7 +310,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream targetBoard.String(), "'build.board'", sketchBuilder.GetBuildProperties().Get("build.board")) + "\n")) } - if err := builder.RunBuilder(builderCtx); err != nil { + if err := sketchBuilder.Build(sketchLibrariesDetector); err != nil { return r, &arduino.CompileFailedError{Message: err.Error()} } diff --git a/internal/integrationtest/daemon/daemon_test.go b/internal/integrationtest/daemon/daemon_test.go index cbb227293c4..d550ea2ed09 100644 --- a/internal/integrationtest/daemon/daemon_test.go +++ b/internal/integrationtest/daemon/daemon_test.go @@ -187,7 +187,7 @@ func TestDaemonCompileOptions(t *testing.T) { // https://github.com/arduino/arduino-cli/issues/2016 // assert that the task progress is increasing and doesn't contain multiple 100% values results := analyzer.Results[""] - require.True(t, results[len(results)-1].Completed) + require.True(t, results[len(results)-1].Completed, fmt.Sprintf("latest percent value: %v", results[len(results)-1].Percent)) require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent)) } diff --git a/legacy/builder/.gitignore b/legacy/builder/.gitignore deleted file mode 100644 index 0df12e548b2..00000000000 --- a/legacy/builder/.gitignore +++ /dev/null @@ -1,81 +0,0 @@ -bin -src/github.com -src/golang.org -./arduino-builder - -# Created by .ignore support plugin (hsz.mobi) -### Go template -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof - - - -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm - -*.iml - -## Directory-based project format: -.idea/ -# if you remove the above rule, at least ignore the following: - -# User-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# .idea/dictionaries - -# Sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml -# .idea/uiDesigner.xml - -# Gradle: -# .idea/gradle.xml -# .idea/libraries - -# Mongo Explorer plugin: -# .idea/mongoSettings.xml - -## File-based project format: -*.ipr -*.iws - -## Plugin-specific files: - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go deleted file mode 100644 index e7fa77fc7f4..00000000000 --- a/legacy/builder/builder.go +++ /dev/null @@ -1,311 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package builder - -import ( - "reflect" - "time" - - "github.com/arduino/arduino-cli/i18n" - "github.com/arduino/arduino-cli/legacy/builder/types" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -var tr = i18n.Tr - -type Builder struct{} - -func (s *Builder) Run(ctx *types.Context) error { - if err := ctx.Builder.GetBuildPath().MkdirAll(); err != nil { - return err - } - - var mainErr error - commands := []types.Command{ - containerBuildOptions(ctx), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.prebuild", ".pattern", false) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.PrepareSketchBuildPath() - }), - - logIfVerbose(false, tr("Detecting libraries used...")), - findIncludes(ctx), - - warnAboutArchIncompatibleLibraries(ctx), - - logIfVerbose(false, tr("Generating function prototypes...")), - preprocessSketchCommand(ctx), - - logIfVerbose(false, tr("Compiling sketch...")), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.sketch.prebuild", ".pattern", false) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.BuildSketch(ctx.SketchLibrariesDetector.IncludeFolders()) - }), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.sketch.postbuild", ".pattern", true) - }), - - logIfVerbose(false, tr("Compiling libraries...")), - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.libraries.prebuild", ".pattern", false) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.RemoveUnusedCompiledLibraries( - ctx.SketchLibrariesDetector.ImportedLibraries(), - ) - }), - - types.BareCommand(func(ctx *types.Context) error { - 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) - }), - - logIfVerbose(false, tr("Compiling core...")), - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.core.prebuild", ".pattern", false) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.BuildCore() - }), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.core.postbuild", ".pattern", true) - }), - - logIfVerbose(false, tr("Linking everything together...")), - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.linking.prelink", ".pattern", false) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.Link() - }), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.linking.postlink", ".pattern", true) - }), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.objcopy.preobjcopy", ".pattern", false) - }), - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.objcopy.", ".pattern", true) - }), - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.objcopy.postobjcopy", ".pattern", true) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.MergeSketchWithBootloader() - }), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.postbuild", ".pattern", true) - }), - } - - ctx.Builder.Progress.AddSubSteps(len(commands) + 5) - defer ctx.Builder.Progress.RemoveSubSteps() - - for _, command := range commands { - PrintRingNameIfDebug(ctx, command) - err := command.Run(ctx) - if err != nil { - mainErr = errors.WithStack(err) - break - } - ctx.Builder.Progress.CompleteStep() - ctx.Builder.Progress.PushProgress() - } - - ctx.Builder.SaveCompilationDatabase() - - var otherErr error - commands = []types.Command{ - types.BareCommand(func(ctx *types.Context) error { - ctx.SketchLibrariesDetector.PrintUsedAndNotUsedLibraries(mainErr != nil) - return nil - }), - - types.BareCommand(func(ctx *types.Context) error { - ctx.Builder.PrintUsedLibraries(ctx.SketchLibrariesDetector.ImportedLibraries()) - return nil - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.ExportProjectCMake( - mainErr != nil, - ctx.SketchLibrariesDetector.ImportedLibraries(), - ctx.SketchLibrariesDetector.IncludeFolders(), - ) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.Size(mainErr != nil) - }), - } - for _, command := range commands { - PrintRingNameIfDebug(ctx, command) - err := command.Run(ctx) - if err != nil { - otherErr = errors.WithStack(err) - break - } - ctx.Builder.Progress.CompleteStep() - ctx.Builder.Progress.PushProgress() - } - - if mainErr != nil { - return mainErr - } - - return otherErr -} - -func preprocessSketchCommand(ctx *types.Context) types.BareCommand { - return func(ctx *types.Context) error { - return ctx.Builder.PreprocessSketch(ctx.SketchLibrariesDetector.IncludeFolders()) - } -} - -type Preprocess struct{} - -func (s *Preprocess) Run(ctx *types.Context) error { - if err := ctx.Builder.GetBuildPath().MkdirAll(); err != nil { - return err - } - - commands := []types.Command{ - containerBuildOptions(ctx), - - types.BareCommand(func(ctx *types.Context) error { - return recipeByPrefixSuffixRunner(ctx, "recipe.hooks.prebuild", ".pattern", false) - }), - - types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.PrepareSketchBuildPath() - }), - - findIncludes(ctx), - - warnAboutArchIncompatibleLibraries(ctx), - - preprocessSketchCommand(ctx), - } - - if err := runCommands(ctx, commands); err != nil { - return err - } - - // Output arduino-preprocessed source - preprocessedSketch, err := ctx.Builder.GetSketchBuildPath().Join(ctx.Builder.Sketch().MainFile.Base() + ".cpp").ReadFile() - if err != nil { - return err - } - ctx.BuilderLogger.WriteStdout(preprocessedSketch) - return nil -} - -func runCommands(ctx *types.Context, commands []types.Command) error { - ctx.Builder.Progress.AddSubSteps(len(commands)) - defer ctx.Builder.Progress.RemoveSubSteps() - - for _, command := range commands { - PrintRingNameIfDebug(ctx, command) - err := command.Run(ctx) - if err != nil { - return errors.WithStack(err) - } - ctx.Builder.Progress.CompleteStep() - ctx.Builder.Progress.PushProgress() - } - return nil -} - -func PrintRingNameIfDebug(ctx *types.Context, command types.Command) { - logrus.Debugf("Ts: %d - Running: %s", time.Now().Unix(), reflect.Indirect(reflect.ValueOf(command)).Type().Name()) -} - -func RunBuilder(ctx *types.Context) error { - return runCommands(ctx, []types.Command{&Builder{}}) -} - -func RunPreprocess(ctx *types.Context) error { - command := Preprocess{} - return command.Run(ctx) -} - -func findIncludes(ctx *types.Context) types.BareCommand { - return types.BareCommand(func(ctx *types.Context) error { - return ctx.SketchLibrariesDetector.FindIncludes( - ctx.Builder.GetBuildPath(), - ctx.Builder.GetBuildProperties().GetPath("build.core.path"), - ctx.Builder.GetBuildProperties().GetPath("build.variant.path"), - ctx.Builder.GetSketchBuildPath(), - ctx.Builder.Sketch(), - ctx.Builder.GetLibrariesBuildPath(), - ctx.Builder.GetBuildProperties(), - ctx.Builder.TargetPlatform().Platform.Architecture, - ) - }) -} - -func logIfVerbose(warn bool, msg string) types.BareCommand { - return types.BareCommand(func(ctx *types.Context) error { - if !ctx.BuilderLogger.Verbose() { - return nil - } - if warn { - ctx.BuilderLogger.Warn(msg) - } else { - ctx.BuilderLogger.Info(msg) - } - return nil - }) -} - -func recipeByPrefixSuffixRunner(ctx *types.Context, prefix, suffix string, skipIfOnlyUpdatingCompilationDatabase bool) error { - return ctx.Builder.RunRecipe(prefix, suffix, skipIfOnlyUpdatingCompilationDatabase) -} - -func containerBuildOptions(ctx *types.Context) types.BareCommand { - return types.BareCommand(func(ctx *types.Context) error { - return ctx.Builder.BuildOptionsManager.WipeBuildPath() - }) -} - -func warnAboutArchIncompatibleLibraries(ctx *types.Context) types.BareCommand { - return types.BareCommand(func(ctx *types.Context) error { - ctx.Builder.WarnAboutArchIncompatibleLibraries( - ctx.SketchLibrariesDetector.ImportedLibraries(), - ) - return nil - }) -} diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go deleted file mode 100644 index 64b85c93fe2..00000000000 --- a/legacy/builder/types/context.go +++ /dev/null @@ -1,29 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package types - -import ( - "github.com/arduino/arduino-cli/arduino/builder" - "github.com/arduino/arduino-cli/arduino/builder/detector" - "github.com/arduino/arduino-cli/arduino/builder/logger" -) - -// Context structure -type Context struct { - Builder *builder.Builder - SketchLibrariesDetector *detector.SketchLibrariesDetector - BuilderLogger *logger.BuilderLogger -} diff --git a/legacy/builder/types/types.go b/legacy/builder/types/types.go deleted file mode 100644 index 8678fd2fe51..00000000000 --- a/legacy/builder/types/types.go +++ /dev/null @@ -1,26 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package types - -type Command interface { - Run(ctx *Context) error -} - -type BareCommand func(ctx *Context) error - -func (cmd BareCommand) Run(ctx *Context) error { - return cmd(ctx) -}