From 0ee1c67ddfaf4709cb8adc898e53911526eab481 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 17 Nov 2021 15:10:54 +0100 Subject: [PATCH 1/3] Compilation database: Do not give-up if prototype generation fails --- legacy/builder/container_add_prototypes.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/legacy/builder/container_add_prototypes.go b/legacy/builder/container_add_prototypes.go index 222661ef07b..cc3a77ab407 100644 --- a/legacy/builder/container_add_prototypes.go +++ b/legacy/builder/container_add_prototypes.go @@ -34,7 +34,15 @@ func (s *ContainerAddPrototypes) Run(ctx *types.Context) error { // Run preprocessor sourceFile := ctx.SketchBuildPath.Join(ctx.Sketch.MainFile.Base() + ".cpp") if err := GCCPreprocRunner(ctx, sourceFile, targetFilePath, ctx.IncludeFolders); err != nil { - return errors.WithStack(err) + if !ctx.OnlyUpdateCompilationDatabase { + return errors.WithStack(err) + } + + // Do not bail out if we are generating the compile commands database + ctx.GetLogger().Println("info", "%s: %s", tr("An error occurred adding prototypes"), tr("the compilation database may be incomplete or inaccurate")) + if err := sourceFile.CopyTo(targetFilePath); err != nil { + return errors.WithStack(err) + } } commands := []types.Command{ From 6e375d8e5ff0d992f386a1df58f146c40d4f33b6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 22 Nov 2021 19:25:41 +0100 Subject: [PATCH 2/3] Added tests --- test/test_compile_part_4.py | 11 +++++++---- .../sketch_with_missing_include.ino | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 test/testdata/sketch_with_missing_include/sketch_with_missing_include.ino diff --git a/test/test_compile_part_4.py b/test/test_compile_part_4.py index 8eeaa76e929..62c6074aecb 100644 --- a/test/test_compile_part_4.py +++ b/test/test_compile_part_4.py @@ -292,18 +292,21 @@ def test_compile_with_esp8266_bundled_libraries(run_command, data_dir, copy_sket assert "\n".join(expected_output) not in res.stdout -def test_generate_compile_commands_json_with_esp32(run_command, data_dir, copy_sketch): - # https://github.com/arduino/arduino-cli/issues/1547 +def test_generate_compile_commands_json_resilience(run_command, data_dir, copy_sketch): assert run_command(["update"]) - # Update index with esp32 core and install it + # check it didn't fail with esp32@2.0.1 that has a prebuild hook that must run: + # https://github.com/arduino/arduino-cli/issues/1547 url = "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" assert run_command(["core", "update-index", f"--additional-urls={url}"]) assert run_command(["core", "install", "esp32:esp32@2.0.1", f"--additional-urls={url}"]) - sketch_path = copy_sketch("sketch_simple") assert run_command(["compile", "-b", "esp32:esp32:featheresp32", "--only-compilation-database", sketch_path]) + # check it didn't fail on a sketch with a missing include + sketch_path = copy_sketch("sketch_with_missing_include") + assert run_command(["compile", "-b", "esp32:esp32:featheresp32", "--only-compilation-database", sketch_path]) + def test_compile_sketch_with_tpp_file_include(run_command, copy_sketch): assert run_command(["update"]) diff --git a/test/testdata/sketch_with_missing_include/sketch_with_missing_include.ino b/test/testdata/sketch_with_missing_include/sketch_with_missing_include.ino new file mode 100644 index 00000000000..3236d8c8b4b --- /dev/null +++ b/test/testdata/sketch_with_missing_include/sketch_with_missing_include.ino @@ -0,0 +1 @@ +#include "akdshfgdfkgweriuweriyuiqwuegdhsgfsdkfgyuawetrkdshfdsufg.h" From 20cfba0a74a00334591217213819fdd713d94189 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 22 Nov 2021 19:26:27 +0100 Subject: [PATCH 3/3] Compilation database: Do not give up after failing detection of libraries --- legacy/builder/container_find_includes.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 163e2ec67d1..19b587921e9 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -110,6 +110,15 @@ import ( type ContainerFindIncludes struct{} func (s *ContainerFindIncludes) Run(ctx *types.Context) error { + err := s.findIncludes(ctx) + if err != nil && ctx.OnlyUpdateCompilationDatabase { + ctx.GetLogger().Println("info", "%s: %s", tr("An error occurred detecting libraries"), tr("the compilation database may be incomplete or inaccurate")) + return nil + } + return err +} + +func (s *ContainerFindIncludes) findIncludes(ctx *types.Context) error { cachePath := ctx.BuildPath.Join("includes.cache") cache := readCache(cachePath)