Unverified Commit 1ea75180 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

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

parent 27ec1214
......@@ -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
......@@ -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
}
......@@ -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 {
......
......@@ -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() != "" {
......@@ -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() {
......
......@@ -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
......
......@@ -70,6 +70,7 @@ type Context struct {
ArduinoAPIVersion string
FQBN *cores.FQBN
CodeCompleteAt string
Clean bool
// Build options are serialized here
BuildOptionsJson string
......
......@@ -21,8 +21,8 @@ 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"
)
......@@ -30,6 +30,9 @@ import (
type WipeoutBuildPathIfBuildOptionsChanged struct{}
func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
if ctx.Clean {
return doCleanup(ctx.BuildPath)
}
if ctx.BuildOptionsJsonPrevious == "" {
return nil
}
......@@ -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
}
......@@ -64,6 +64,7 @@ type CompileReq struct {
OptimizeForDebug bool `protobuf:"varint,16,opt,name=optimizeForDebug,proto3" json:"optimizeForDebug,omitempty"` // Optimize compile output for debug, not for release.
DryRun bool `protobuf:"varint,17,opt,name=dryRun,proto3" json:"dryRun,omitempty"` // When set to `true` the compiled binary will not be copied to the export directory.
ExportDir string `protobuf:"bytes,18,opt,name=export_dir,json=exportDir,proto3" json:"export_dir,omitempty"` // Optional: save the build artifacts in this directory, the directory must exist.
Clean bool `protobuf:"varint,19,opt,name=clean,proto3" json:"clean,omitempty"` // Optional: cleanup the build folder and do not use any previously cached build
}
func (x *CompileReq) Reset() {
......@@ -225,6 +226,13 @@ func (x *CompileReq) GetExportDir() string {
return ""
}
func (x *CompileReq) GetClean() bool {
if x != nil {
return x.Clean
}
return false
}
type CompileResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
......@@ -287,7 +295,7 @@ var file_commands_compile_proto_rawDesc = []byte{
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x17, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64,
0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
0x73, 0x1a, 0x15, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x63, 0x6f, 0x6d, 0x6d,
0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd4, 0x04, 0x0a, 0x0a, 0x43, 0x6f, 0x6d,
0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xea, 0x04, 0x0a, 0x0a, 0x43, 0x6f, 0x6d,
0x70, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61,
0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61,
0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61,
......@@ -324,16 +332,17 @@ var file_commands_compile_proto_rawDesc = []byte{
0x46, 0x6f, 0x72, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, 0x79, 0x52,
0x75, 0x6e, 0x18, 0x11, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x64, 0x72, 0x79, 0x52, 0x75, 0x6e,
0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x12,
0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22,
0x4b, 0x0a, 0x0b, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d,
0x0a, 0x0a, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0c, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1d, 0x0a,
0x0a, 0x65, 0x72, 0x72, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28,
0x0c, 0x52, 0x09, 0x65, 0x72, 0x72, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x42, 0x2d, 0x5a, 0x2b,
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69,
0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72,
0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x12,
0x14, 0x0a, 0x05, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x18, 0x13, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05,
0x63, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x4b, 0x0a, 0x0b, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65,
0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65,
0x61, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x53, 0x74, 0x72,
0x65, 0x61, 0x6d, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61,
0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x65, 0x72, 0x72, 0x53, 0x74, 0x72, 0x65,
0x61, 0x6d, 0x42, 0x2d, 0x5a, 0x2b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f,
0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64,
0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
......
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment