Unverified Commit fbd35df6 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Added dry-run mode in Compile command (#619)

* Added dry-run mode in Compile command

* Update cli/compile/compile.go
Co-Authored-By: default avatarRoberto Sora <r.sora@arduino.cc>
Co-authored-by: default avatarRoberto Sora <r.sora@arduino.cc>
parent f855feaa
...@@ -47,6 +47,7 @@ var ( ...@@ -47,6 +47,7 @@ var (
port string // Upload port, e.g.: COM10 or /dev/ttyACM0. port string // Upload port, e.g.: COM10 or /dev/ttyACM0.
verify bool // Upload, verify uploaded binary after the upload. verify bool // Upload, verify uploaded binary after the upload.
exportFile string // The compiled binary is written to this file exportFile string // The compiled binary is written to this file
dryRun bool // Use this flag to now write the output file
libraries []string // List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths. 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 optimizeForDebug bool // Optimize compile output for debug, not for release
) )
...@@ -67,6 +68,7 @@ func NewCommand() *cobra.Command { ...@@ -67,6 +68,7 @@ func NewCommand() *cobra.Command {
command.Flags().BoolVar(&preprocess, "preprocess", false, "Print preprocessed code to stdout instead of compiling.") command.Flags().BoolVar(&preprocess, "preprocess", false, "Print preprocessed code to stdout instead of compiling.")
command.Flags().StringVar(&buildCachePath, "build-cache-path", "", "Builds of 'core.a' are saved into this path to be cached and reused.") command.Flags().StringVar(&buildCachePath, "build-cache-path", "", "Builds of 'core.a' are saved into this path to be cached and reused.")
command.Flags().StringVarP(&exportFile, "output", "o", "", "Filename of the compile output.") command.Flags().StringVarP(&exportFile, "output", "o", "", "Filename of the compile output.")
command.Flags().BoolVarP(&dryRun, "dry-run", "n", false, "Perform the build but do not copy the compile output file.")
command.Flags().StringVar(&buildPath, "build-path", "", command.Flags().StringVar(&buildPath, "build-path", "",
"Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.") "Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.")
command.Flags().StringSliceVar(&buildProperties, "build-properties", []string{}, command.Flags().StringSliceVar(&buildProperties, "build-properties", []string{},
...@@ -114,6 +116,7 @@ func run(cmd *cobra.Command, args []string) { ...@@ -114,6 +116,7 @@ func run(cmd *cobra.Command, args []string) {
Quiet: quiet, Quiet: quiet,
VidPid: vidPid, VidPid: vidPid,
ExportFile: exportFile, ExportFile: exportFile,
DryRun: dryRun,
Libraries: libraries, Libraries: libraries,
OptimizeForDebug: optimizeForDebug, OptimizeForDebug: optimizeForDebug,
}, os.Stdout, os.Stderr, viper.GetString("logging.level") == "debug") }, os.Stdout, os.Stderr, viper.GetString("logging.level") == "debug")
......
...@@ -196,59 +196,61 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W ...@@ -196,59 +196,61 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
return nil, err return nil, err
} }
// FIXME: Make a function to obtain these info... if !req.GetDryRun() {
outputPath := paths.New( // FIXME: Make a function to obtain these info...
builderCtx.BuildProperties.ExpandPropsInString("{build.path}/{recipe.output.tmp_file}")) // "/build/path/sketch.ino.bin" outputPath := paths.New(
ext := outputPath.Ext() // ".hex" | ".bin" builderCtx.BuildProperties.ExpandPropsInString("{build.path}/{recipe.output.tmp_file}")) // "/build/path/sketch.ino.bin"
base := outputPath.Base() // "sketch.ino.hex" ext := outputPath.Ext() // ".hex" | ".bin"
base = base[:len(base)-len(ext)] // "sketch.ino" base := outputPath.Base() // "sketch.ino.hex"
base = base[:len(base)-len(ext)] // "sketch.ino"
// FIXME: Make a function to produce a better name...
// Make the filename without the FQBN configs part // FIXME: Make a function to produce a better name...
fqbn.Configs = properties.NewMap() // Make the filename without the FQBN configs part
fqbnSuffix := strings.Replace(fqbn.String(), ":", ".", -1) fqbn.Configs = properties.NewMap()
fqbnSuffix := strings.Replace(fqbn.String(), ":", ".", -1)
var exportPath *paths.Path
var exportFile string var exportPath *paths.Path
if req.GetExportFile() == "" { var exportFile string
if sketch.FullPath.IsDir() { if req.GetExportFile() == "" {
exportPath = sketch.FullPath if sketch.FullPath.IsDir() {
exportPath = sketch.FullPath
} else {
exportPath = sketch.FullPath.Parent()
}
exportFile = sketch.Name + "." + fqbnSuffix // "sketch.arduino.avr.uno"
} else { } else {
exportPath = sketch.FullPath.Parent() exportPath = paths.New(req.GetExportFile()).Parent()
} exportFile = paths.New(req.GetExportFile()).Base()
exportFile = sketch.Name + "." + fqbnSuffix // "sketch.arduino.avr.uno" if strings.HasSuffix(exportFile, ext) {
} else { exportFile = exportFile[:len(exportFile)-len(ext)]
exportPath = paths.New(req.GetExportFile()).Parent() }
exportFile = paths.New(req.GetExportFile()).Base()
if strings.HasSuffix(exportFile, ext) {
exportFile = exportFile[:len(exportFile)-len(ext)]
} }
}
// Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory // Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
srcDir, err := outputPath.Parent().ReadDir() // read "/build/path/*" srcDir, err := outputPath.Parent().ReadDir() // read "/build/path/*"
if err != nil { if err != nil {
return nil, fmt.Errorf("reading build directory: %s", err) return nil, fmt.Errorf("reading build directory: %s", err)
} }
srcDir.FilterPrefix(base + ".") srcDir.FilterPrefix(base + ".")
srcDir.FilterSuffix(ext) srcDir.FilterSuffix(ext)
for _, srcOutput := range srcDir { for _, srcOutput := range srcDir {
srcFilename := srcOutput.Base() // "sketch.ino.*.bin" srcFilename := srcOutput.Base() // "sketch.ino.*.bin"
srcFilename = srcFilename[len(base):] // ".*.bin" srcFilename = srcFilename[len(base):] // ".*.bin"
dstOutput := exportPath.Join(exportFile + srcFilename) dstOutput := exportPath.Join(exportFile + srcFilename)
logrus.WithField("from", srcOutput).WithField("to", dstOutput).Debug("copying sketch build output") logrus.WithField("from", srcOutput).WithField("to", dstOutput).Debug("copying sketch build output")
if err = srcOutput.CopyTo(dstOutput); err != nil { if err = srcOutput.CopyTo(dstOutput); err != nil {
return nil, fmt.Errorf("copying output file: %s", err) return nil, fmt.Errorf("copying output file: %s", err)
}
} }
}
// Copy .elf file to sketch directory // Copy .elf file to sketch directory
srcElf := outputPath.Parent().Join(base + ".elf") srcElf := outputPath.Parent().Join(base + ".elf")
if srcElf.Exist() { if srcElf.Exist() {
dstElf := exportPath.Join(exportFile + ".elf") dstElf := exportPath.Join(exportFile + ".elf")
logrus.WithField("from", srcElf).WithField("to", dstElf).Debug("copying sketch build output") logrus.WithField("from", srcElf).WithField("to", dstElf).Debug("copying sketch build output")
if err = srcElf.CopyTo(dstElf); err != nil { if err = srcElf.CopyTo(dstElf); err != nil {
return nil, fmt.Errorf("copying elf file: %s", err) return nil, fmt.Errorf("copying elf file: %s", err)
}
} }
} }
......
...@@ -37,6 +37,7 @@ type CompileReq struct { ...@@ -37,6 +37,7 @@ type CompileReq struct {
Jobs int32 `protobuf:"varint,14,opt,name=jobs,proto3" json:"jobs,omitempty"` Jobs int32 `protobuf:"varint,14,opt,name=jobs,proto3" json:"jobs,omitempty"`
Libraries []string `protobuf:"bytes,15,rep,name=libraries,proto3" json:"libraries,omitempty"` Libraries []string `protobuf:"bytes,15,rep,name=libraries,proto3" json:"libraries,omitempty"`
OptimizeForDebug bool `protobuf:"varint,16,opt,name=optimizeForDebug,proto3" json:"optimizeForDebug,omitempty"` OptimizeForDebug bool `protobuf:"varint,16,opt,name=optimizeForDebug,proto3" json:"optimizeForDebug,omitempty"`
DryRun bool `protobuf:"varint,17,opt,name=dryRun,proto3" json:"dryRun,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
...@@ -179,6 +180,13 @@ func (m *CompileReq) GetOptimizeForDebug() bool { ...@@ -179,6 +180,13 @@ func (m *CompileReq) GetOptimizeForDebug() bool {
return false return false
} }
func (m *CompileReq) GetDryRun() bool {
if m != nil {
return m.DryRun
}
return false
}
type CompileResp struct { type CompileResp struct {
OutStream []byte `protobuf:"bytes,1,opt,name=out_stream,json=outStream,proto3" json:"out_stream,omitempty"` OutStream []byte `protobuf:"bytes,1,opt,name=out_stream,json=outStream,proto3" json:"out_stream,omitempty"`
ErrStream []byte `protobuf:"bytes,2,opt,name=err_stream,json=errStream,proto3" json:"err_stream,omitempty"` ErrStream []byte `protobuf:"bytes,2,opt,name=err_stream,json=errStream,proto3" json:"err_stream,omitempty"`
...@@ -234,32 +242,33 @@ func init() { ...@@ -234,32 +242,33 @@ func init() {
func init() { proto.RegisterFile("commands/compile.proto", fileDescriptor_86bc582849c76c3d) } func init() { proto.RegisterFile("commands/compile.proto", fileDescriptor_86bc582849c76c3d) }
var fileDescriptor_86bc582849c76c3d = []byte{ var fileDescriptor_86bc582849c76c3d = []byte{
// 426 bytes of a gzipped FileDescriptorProto // 437 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xc1, 0x6f, 0xd3, 0x30, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xc1, 0x6f, 0xd3, 0x30,
0x14, 0xc6, 0x95, 0xad, 0xed, 0x9a, 0xd7, 0xb1, 0x4d, 0x16, 0x0c, 0x6b, 0x02, 0x14, 0x76, 0x40, 0x14, 0xc6, 0x95, 0xad, 0xed, 0x9a, 0xd7, 0xb1, 0x0d, 0x0b, 0x86, 0x35, 0x01, 0x0a, 0x3b, 0xa0,
0x11, 0x68, 0xa9, 0x04, 0x67, 0x2e, 0x0c, 0x4d, 0x42, 0x5c, 0xaa, 0x70, 0xe3, 0x82, 0x12, 0xe7, 0x08, 0xb4, 0x54, 0x82, 0x33, 0x17, 0x86, 0x26, 0x21, 0x2e, 0x55, 0xb8, 0x71, 0x41, 0x89, 0xf3,
0xd1, 0x18, 0x92, 0xd8, 0x7d, 0x76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 0xf6, 0xe8, 0x02, 0x00, 0x00, 0xf9, 0x10, 0xba, 0x7c, 0xc2, 0xb1, 0x7d, 0xfb, 0x37, 0x00, 0x00, 0xff, 0xff, 0xda, 0x5b, 0x4b,
0x18, 0x00, 0x03, 0x00, 0x00,
} }
...@@ -38,6 +38,7 @@ message CompileReq { ...@@ -38,6 +38,7 @@ message CompileReq {
int32 jobs = 14; // The max number of concurrent compiler instances to run (as make -jx) int32 jobs = 14; // The max number of concurrent compiler instances to run (as make -jx)
repeated string libraries = 15; // List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths. repeated string libraries = 15; // List of custom libraries paths separated by commas. Or can be used multiple times for multiple libraries paths.
bool optimizeForDebug = 16; // Optimize compile output for debug, not for release 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
} }
message CompileResp { 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