From c07d0f5de7d7ebd5abce6dfc7c609842e8348d52 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 10 Feb 2021 16:48:46 +0100 Subject: [PATCH 1/3] 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. --- commands/compile/compile.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 7003bdfb88b..38335783bce 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -227,7 +227,14 @@ 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) From f8cd723ce9fe8f1b7a9768f836a75bf35af05c38 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 10 Feb 2021 16:51:34 +0100 Subject: [PATCH 2/3] slightly simplify function call --- commands/compile/compile.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/commands/compile/compile.go b/commands/compile/compile.go index 38335783bce..09704be97d6 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -239,10 +239,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W 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 { From b74ab170f7ad95730cf84b6f5c841de9804f0af4 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Thu, 11 Feb 2021 15:25:13 +0100 Subject: [PATCH 3/3] [skip changelog] Add integration test --- test/test_compile.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/test_compile.py b/test/test_compile.py index 9fe751eea54..fa9d2fd42f0 100644 --- a/test/test_compile.py +++ b/test/test_compile.py @@ -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:avr@1.8.3") + + 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()