Skip to content

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

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
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
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()