Skip to content

Commit fb30f2d

Browse files
Do not try to export binaries if --only-compilation-database is set (arduino#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 <silvanocerza@gmail.com>
1 parent 0e6bb9e commit fb30f2d

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

commands/compile/compile.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,21 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
227227
}
228228

229229
// If the export directory is set we assume you want to export the binaries
230-
if exportBinaries || req.GetExportDir() != "" {
230+
if req.GetExportDir() != "" {
231+
exportBinaries = true
232+
}
233+
// If CreateCompilationDatabaseOnly is set, we do not need to export anything
234+
if req.GetCreateCompilationDatabaseOnly() {
235+
exportBinaries = false
236+
}
237+
if exportBinaries {
231238
var exportPath *paths.Path
232239
if exportDir := req.GetExportDir(); exportDir != "" {
233240
exportPath = paths.New(exportDir)
234241
} else {
235-
exportPath = sketch.FullPath
236242
// Add FQBN (without configs part) to export path
237243
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
238-
exportPath = exportPath.Join("build").Join(fqbnSuffix)
244+
exportPath = sketch.FullPath.Join("build", fqbnSuffix)
239245
}
240246
logrus.WithField("path", exportPath).Trace("Saving sketch to export path.")
241247
if err := exportPath.MkdirAll(); err != nil {

test/test_compile.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,3 +726,35 @@ def test_compile_sketch_case_mismatch_fails(run_command, data_dir):
726726
res = run_command(f"compile --clean -b {fqbn}", custom_working_dir=sketch_path)
727727
assert res.failed
728728
assert "Error during build: opening sketch: no valid sketch found" in res.stderr
729+
730+
731+
def test_compile_with_only_compilation_database_flag(run_command, data_dir):
732+
assert run_command("update")
733+
734+
assert run_command("core install arduino:avr@1.8.3")
735+
736+
sketch_name = "CompileSketchOnlyCompilationDatabaseFlag"
737+
sketch_path = Path(data_dir, sketch_name)
738+
fqbn = "arduino:avr:uno"
739+
740+
assert run_command(f"sketch new {sketch_path}")
741+
742+
# Verifies no binaries exist
743+
build_path = Path(sketch_path, "build")
744+
assert not build_path.exists()
745+
746+
# Compile with both --export-binaries and --only-compilation-database flags
747+
assert run_command(f"compile --export-binaries --only-compilation-database --clean -b {fqbn} {sketch_path}")
748+
749+
# Verifies no binaries are exported
750+
assert not build_path.exists()
751+
752+
# Verifies no binaries exist
753+
build_path = Path(data_dir, "export-dir")
754+
assert not build_path.exists()
755+
756+
# Compile by setting the --output-dir flag and --only-compilation-database flags
757+
assert run_command(f"compile --output-dir {build_path} --only-compilation-database --clean -b {fqbn} {sketch_path}")
758+
759+
# Verifies no binaries are exported
760+
assert not build_path.exists()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy