Skip to content

Commit

Permalink
Do not try to export binaries if --only-compilation-database is set (a…
Browse files Browse the repository at this point in the history
…rduino#1181)

* Do not try to export binaries if --only-compilation-database is set

otherwise an empty "build/fqbn/..." folder is created if "always-export-binaries"
option is set via config file.

* slightly simplify function call

* [skip changelog] Add integration test

Co-authored-by: Silvano Cerza <[email protected]>
  • Loading branch information
cmaglie and silvanocerza authored Feb 11, 2021
1 parent 0e6bb9e commit fb30f2d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
12 changes: 9 additions & 3 deletions commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,21 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
}

// If the export directory is set we assume you want to export the binaries
if exportBinaries || req.GetExportDir() != "" {
if req.GetExportDir() != "" {
exportBinaries = true
}
// If CreateCompilationDatabaseOnly is set, we do not need to export anything
if req.GetCreateCompilationDatabaseOnly() {
exportBinaries = false
}
if exportBinaries {
var exportPath *paths.Path
if exportDir := req.GetExportDir(); exportDir != "" {
exportPath = paths.New(exportDir)
} else {
exportPath = sketch.FullPath
// Add FQBN (without configs part) to export path
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
exportPath = exportPath.Join("build").Join(fqbnSuffix)
exportPath = sketch.FullPath.Join("build", fqbnSuffix)
}
logrus.WithField("path", exportPath).Trace("Saving sketch to export path.")
if err := exportPath.MkdirAll(); err != nil {
Expand Down
32 changes: 32 additions & 0 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,35 @@ def test_compile_sketch_case_mismatch_fails(run_command, data_dir):
res = run_command(f"compile --clean -b {fqbn}", custom_working_dir=sketch_path)
assert res.failed
assert "Error during build: opening sketch: no valid sketch found" in res.stderr


def test_compile_with_only_compilation_database_flag(run_command, data_dir):
assert run_command("update")

assert run_command("core install arduino:[email protected]")

sketch_name = "CompileSketchOnlyCompilationDatabaseFlag"
sketch_path = Path(data_dir, sketch_name)
fqbn = "arduino:avr:uno"

assert run_command(f"sketch new {sketch_path}")

# Verifies no binaries exist
build_path = Path(sketch_path, "build")
assert not build_path.exists()

# Compile with both --export-binaries and --only-compilation-database flags
assert run_command(f"compile --export-binaries --only-compilation-database --clean -b {fqbn} {sketch_path}")

# Verifies no binaries are exported
assert not build_path.exists()

# Verifies no binaries exist
build_path = Path(data_dir, "export-dir")
assert not build_path.exists()

# Compile by setting the --output-dir flag and --only-compilation-database flags
assert run_command(f"compile --output-dir {build_path} --only-compilation-database --clean -b {fqbn} {sketch_path}")

# Verifies no binaries are exported
assert not build_path.exists()

0 comments on commit fb30f2d

Please sign in to comment.