Skip to content

Commit 1de6f43

Browse files
cmaglieumbynos
authored andcommitted
[skip-changelog] Increased resilience of compile --only-compilation-database (#1552)
* Compilation database: Do not give-up if prototype generation fails * Added tests * Compilation database: Do not give up after failing detection of libraries
1 parent bb54925 commit 1de6f43

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

Diff for: legacy/builder/container_add_prototypes.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error {
3434
// Run preprocessor
3535
sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp")
3636
if err := GCCPreprocRunner(ctx, sourceFile, targetFilePath, ctx.IncludeFolders); err != nil {
37-
return errors.WithStack(err)
37+
if !ctx.OnlyUpdateCompilationDatabase {
38+
return errors.WithStack(err)
39+
}
40+
41+
// Do not bail out if we are generating the compile commands database
42+
ctx.GetLogger().Println("info", "%s: %s", tr("An error occurred adding prototypes"), tr("the compilation database may be incomplete or inaccurate"))
43+
if err := sourceFile.CopyTo(targetFilePath); err != nil {
44+
return errors.WithStack(err)
45+
}
3846
}
3947

4048
commands := []types.Command{

Diff for: legacy/builder/container_find_includes.go

+9
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ import (
110110
type ContainerFindIncludes struct{}
111111

112112
func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
113+
err := s.findIncludes(ctx)
114+
if err != nil && ctx.OnlyUpdateCompilationDatabase {
115+
ctx.GetLogger().Println("info", "%s: %s", tr("An error occurred detecting libraries"), tr("the compilation database may be incomplete or inaccurate"))
116+
return nil
117+
}
118+
return err
119+
}
120+
121+
func (s *ContainerFindIncludes) findIncludes(ctx *types.Context) error {
113122
cachePath := ctx.BuildPath.Join("includes.cache")
114123
cache := readCache(cachePath)
115124

Diff for: test/test_compile_part_4.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,21 @@ def test_compile_with_esp8266_bundled_libraries(run_command, data_dir, copy_sket
292292
assert "\n".join(expected_output) not in res.stdout
293293

294294

295-
def test_generate_compile_commands_json_with_esp32(run_command, data_dir, copy_sketch):
296-
# https://github.com/arduino/arduino-cli/issues/1547
295+
def test_generate_compile_commands_json_resilience(run_command, data_dir, copy_sketch):
297296
assert run_command(["update"])
298297

299-
# Update index with esp32 core and install it
298+
# check it didn't fail with [email protected] that has a prebuild hook that must run:
299+
# https://github.com/arduino/arduino-cli/issues/1547
300300
url = "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json"
301301
assert run_command(["core", "update-index", f"--additional-urls={url}"])
302302
assert run_command(["core", "install", "esp32:[email protected]", f"--additional-urls={url}"])
303-
304303
sketch_path = copy_sketch("sketch_simple")
305304
assert run_command(["compile", "-b", "esp32:esp32:featheresp32", "--only-compilation-database", sketch_path])
306305

306+
# check it didn't fail on a sketch with a missing include
307+
sketch_path = copy_sketch("sketch_with_missing_include")
308+
assert run_command(["compile", "-b", "esp32:esp32:featheresp32", "--only-compilation-database", sketch_path])
309+
307310

308311
def test_compile_sketch_with_tpp_file_include(run_command, copy_sketch):
309312
assert run_command(["update"])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "akdshfgdfkgweriuweriyuiqwuegdhsgfsdkfgyuawetrkdshfdsufg.h"

0 commit comments

Comments
 (0)