Skip to content

Added --clean flag in 'compile' command #1019

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 1 commit into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
libraries []string // List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths.
optimizeForDebug bool // Optimize compile output for debug, not for release
programmer string // Use the specified programmer to upload
clean bool // Cleanup the build folder and do not use any cached build
)

// NewCommand created a new `compile` command
Expand Down Expand Up @@ -86,6 +87,7 @@ func NewCommand() *cobra.Command {
"List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths.")
command.Flags().BoolVar(&optimizeForDebug, "optimize-for-debug", false, "Optional, optimize compile output for debugging, rather than for release.")
command.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload.")
command.Flags().BoolVar(&clean, "clean", false, "Optional, cleanup the build folder and do not use any cached build.")

return command
}
Expand Down Expand Up @@ -121,6 +123,7 @@ func run(cmd *cobra.Command, args []string) {
DryRun: dryRun,
Libraries: libraries,
OptimizeForDebug: optimizeForDebug,
Clean: clean,
}, os.Stdout, os.Stderr, viper.GetString("logging.level") == "debug")

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
"exportDir": telemetry.Sanitize(req.GetExportDir()),
"jobs": strconv.FormatInt(int64(req.Jobs), 10),
"libraries": strings.Join(req.Libraries, ","),
"clean": strconv.FormatBool(req.GetClean()),
}

if req.GetExportFile() != "" {
Expand Down Expand Up @@ -188,6 +189,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
builderCtx.ExecStdout = outStream
builderCtx.ExecStderr = errStream
builderCtx.SetLogger(i18n.LoggerToCustomStreams{Stdout: outStream, Stderr: errStream})
builderCtx.Clean = req.GetClean()

// if --preprocess or --show-properties were passed, we can stop here
if req.GetShowProperties() {
Expand Down
2 changes: 1 addition & 1 deletion legacy/builder/phases/core_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func compileCore(ctx *types.Context, buildPath *paths.Path, buildCachePath *path
archivedCoreName := GetCachedCoreArchiveFileName(buildProperties.Get(constants.BUILD_PROPERTIES_FQBN),
buildProperties.Get("compiler.optimization_flags"), realCoreFolder)
targetArchivedCore = buildCachePath.Join(archivedCoreName)
canUseArchivedCore := !builder_utils.CoreOrReferencedCoreHasChanged(realCoreFolder, targetCoreFolder, targetArchivedCore)
canUseArchivedCore := !ctx.Clean && !builder_utils.CoreOrReferencedCoreHasChanged(realCoreFolder, targetCoreFolder, targetArchivedCore)

if canUseArchivedCore {
// use archived core
Expand Down
1 change: 1 addition & 0 deletions legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Context struct {
ArduinoAPIVersion string
FQBN *cores.FQBN
CodeCompleteAt string
Clean bool

// Build options are serialized here
BuildOptionsJson string
Expand Down
25 changes: 16 additions & 9 deletions legacy/builder/wipeout_build_path_if_build_options_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ import (

"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/gohasissues"
"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
"github.com/pkg/errors"
)

type WipeoutBuildPathIfBuildOptionsChanged struct{}

func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
if ctx.Clean {
return doCleanup(ctx.BuildPath)
}
if ctx.BuildOptionsJsonPrevious == "" {
return nil
}
Expand Down Expand Up @@ -64,18 +67,22 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
}
}

return doCleanup(ctx.BuildPath)
}

func doCleanup(buildPath *paths.Path) error {
// FIXME: this should go outside legacy and behind a `logrus` call so users can
// control when this should be printed.
// logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)

buildPath := ctx.BuildPath
files, err := gohasissues.ReadDir(buildPath.String())
if err != nil {
return errors.WithStack(err)
}
for _, file := range files {
buildPath.Join(file.Name()).RemoveAll()
if files, err := buildPath.ReadDir(); err != nil {
return errors.WithMessage(err, "cleaning build path")
} else {
for _, file := range files {
if err := file.RemoveAll(); err != nil {
return errors.WithMessage(err, "cleaning build path")
}
}
}

return nil
}
31 changes: 20 additions & 11 deletions rpc/commands/compile.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/commands/compile.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ message CompileReq {
bool optimizeForDebug = 16; // Optimize compile output for debug, not for release.
bool dryRun = 17; // When set to `true` the compiled binary will not be copied to the export directory.
string export_dir = 18; // Optional: save the build artifacts in this directory, the directory must exist.
bool clean = 19; // Optional: cleanup the build folder and do not use any previously cached build
}

message CompileResp {
Expand Down