Skip to content

Binaries export must now be explicitly specified #1042

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 4 commits into from
Nov 2, 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
10 changes: 6 additions & 4 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ var (
port string // Upload port, e.g.: COM10 or /dev/ttyACM0.
verify bool // Upload, verify uploaded binary after the upload.
exportDir 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.
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
exportBinaries bool // Copies compiled binaries to sketch folder when true
)

// NewCommand created a new `compile` command
Expand All @@ -70,7 +70,6 @@ func NewCommand() *cobra.Command {
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().StringVarP(&exportDir, "output-dir", "", "", "Save build artifacts in this directory.")
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", "",
"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{},
Expand All @@ -88,6 +87,9 @@ func NewCommand() *cobra.Command {
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.")
command.Flags().BoolVarP(&exportBinaries, "export-binaries", "e", false, "If set built binaries will be exported to the sketch folder.")

configuration.Settings.BindPFlag("sketch.always_export_binaries", command.Flags().Lookup("export-binaries"))

return command
}
Expand Down Expand Up @@ -120,10 +122,10 @@ func run(cmd *cobra.Command, args []string) {
Quiet: quiet,
VidPid: vidPid,
ExportDir: exportDir,
DryRun: dryRun,
Libraries: libraries,
OptimizeForDebug: optimizeForDebug,
Clean: clean,
ExportBinaries: exportBinaries,
}, os.Stdout, os.Stderr, configuration.Settings.GetString("logging.level") == "debug")

if err != nil {
Expand All @@ -139,7 +141,7 @@ func run(cmd *cobra.Command, args []string) {
Port: port,
Verbose: verbose,
Verify: verify,
ImportDir: exportDir,
ImportDir: buildPath,
Programmer: programmer,
}, os.Stdout, os.Stderr)

Expand Down
22 changes: 11 additions & 11 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"

bldr "github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/sketches"
Expand Down Expand Up @@ -54,15 +55,11 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
"verbose": strconv.FormatBool(req.Verbose),
"quiet": strconv.FormatBool(req.Quiet),
"vidPid": req.VidPid,
"exportFile": telemetry.Sanitize(req.ExportFile), // deprecated
"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() != "" {
outStream.Write([]byte(fmt.Sprintln("Compile.ExportFile has been deprecated. The ExportFile parameter will be ignored, use ExportDir instead.")))
"exportBinaries": strconv.FormatBool(req.GetExportBinaries()),
}

// Use defer func() to evaluate tags map when function returns
Expand Down Expand Up @@ -127,12 +124,14 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
builderCtx.OtherLibrariesDirs = paths.NewPathList(req.GetLibraries()...)
builderCtx.OtherLibrariesDirs.Add(configuration.LibrariesDir(configuration.Settings))

if req.GetBuildPath() != "" {
if req.GetBuildPath() == "" {
builderCtx.BuildPath = bldr.GenBuildPath(sketch.FullPath)
} else {
builderCtx.BuildPath = paths.New(req.GetBuildPath())
err = builderCtx.BuildPath.MkdirAll()
if err != nil {
return nil, fmt.Errorf("cannot create build directory: %s", err)
}
}

if err = builderCtx.BuildPath.MkdirAll(); err != nil {
return nil, fmt.Errorf("cannot create build directory: %s", err)
}

builderCtx.Verbose = req.GetVerbose()
Expand Down Expand Up @@ -202,7 +201,8 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
return nil, err
}

if !req.GetDryRun() {
// If the export directory is set we assume you want to export the binaries
if req.GetExportBinaries() || req.GetExportDir() != "" {
var exportPath *paths.Path
if exportDir := req.GetExportDir(); exportDir != "" {
exportPath = paths.New(exportDir)
Expand Down
12 changes: 3 additions & 9 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"strings"

bldr "github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/serialutils"
Expand Down Expand Up @@ -425,16 +426,9 @@ func determineBuildPathAndSketchName(importFile, importDir string, sketch *sketc
return nil, "", fmt.Errorf("no sketch or build directory/file specified")
}

// Case 4: only sketch specified. In this case we use the default sketch build path
// Case 4: only sketch specified. In this case we use the generated build path
// and the given sketch name.

// TODO: Create a function to obtain importPath from sketch
// Add FQBN (without configs part) to export path
if fqbn == nil {
return nil, "", fmt.Errorf("missing FQBN")
}
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
return sketch.FullPath.Join("build").Join(fqbnSuffix), sketch.Name + ".ino", nil
return bldr.GenBuildPath(sketch.FullPath), sketch.Name + ".ino", nil
}

func detectSketchNameFromBuildPath(buildPath *paths.Path) (string, error) {
Expand Down
9 changes: 4 additions & 5 deletions commands/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"testing"

"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/sketches"
Expand Down Expand Up @@ -76,15 +77,14 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
{"", "testdata/build_path_2", nil, nil, "testdata/build_path_2", "Blink.ino"},
// 03: error: used both importPath and importFile
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", nil, nil, "<nil>", ""},
// 04: error: only sketch without FQBN
{"", "", blonk, nil, "<nil>", ""},
// 04: only sketch without FQBN
{"", "", blonk, nil, builder.GenBuildPath(blonk.FullPath).String(), "Blonk.ino"},
// 05: use importFile to detect build.path and project_name, sketch is ignored.
{"testdata/build_path_2/Blink.ino.hex", "", blonk, nil, "testdata/build_path_2", "Blink.ino"},
// 06: use importPath as build.path and Blink as project name, ignore the sketch Blonk
{"", "testdata/build_path_2", blonk, nil, "testdata/build_path_2", "Blink.ino"},
// 07: error: used both importPath and importFile
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, nil, "<nil>", ""},

// 08: error: no data passed in
{"", "", nil, fqbn, "<nil>", ""},
// 09: use importFile to detect build.path and project_name, fqbn ignored
Expand All @@ -94,14 +94,13 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
// 11: error: used both importPath and importFile
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", nil, fqbn, "<nil>", ""},
// 12: use sketch to determine project name and sketch+fqbn to determine build path
{"", "", blonk, fqbn, "testdata/Blonk/build/arduino.samd.mkr1000", "Blonk.ino"},
{"", "", blonk, fqbn, builder.GenBuildPath(blonk.FullPath).String(), "Blonk.ino"},
// 13: use importFile to detect build.path and project_name, sketch+fqbn is ignored.
{"testdata/build_path_2/Blink.ino.hex", "", blonk, fqbn, "testdata/build_path_2", "Blink.ino"},
// 14: use importPath as build.path and Blink as project name, ignore the sketch Blonk, ignore fqbn
{"", "testdata/build_path_2", blonk, fqbn, "testdata/build_path_2", "Blink.ino"},
// 15: error: used both importPath and importFile
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, fqbn, "<nil>", ""},

// 16: importPath containing multiple firmwares, but one has the same name as the containing folder
{"", "testdata/firmware", nil, fqbn, "testdata/firmware", "firmware.ino"},
// 17: importFile among multiple firmwares
Expand Down
4 changes: 4 additions & 0 deletions configuration/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func SetDefaults(settings *viper.Viper) {
settings.SetDefault("directories.Downloads", filepath.Join(getDefaultArduinoDataDir(), "staging"))
settings.SetDefault("directories.User", getDefaultUserDir())

// Sketch compilation
settings.SetDefault("sketch.always_export_binaries", false)

// daemon settings
settings.SetDefault("daemon.port", "50051")

Expand All @@ -52,4 +55,5 @@ func SetDefaults(settings *viper.Viper) {
settings.BindEnv("directories.User", "ARDUINO_SKETCHBOOK_DIR")
settings.BindEnv("directories.Downloads", "ARDUINO_DOWNLOADS_DIR")
settings.BindEnv("directories.Data", "ARDUINO_DATA_DIR")
settings.BindEnv("sketch.always_export_binaries", "ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES")
}
4 changes: 0 additions & 4 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ const DEFAULT_SOFTWARE = "ARDUINO"
type Builder struct{}

func (s *Builder) Run(ctx *types.Context) error {
if ctx.BuildPath == nil {
ctx.BuildPath = bldr.GenBuildPath(ctx.SketchLocation)
}

if err := bldr.EnsureBuildPathExists(ctx.BuildPath.String()); err != nil {
return err
}
Expand Down
Loading