Commit 1de6f437 authored by Cristian Maglie's avatar Cristian Maglie Committed by umbynos

[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
parent bb549253
......@@ -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{
......
......@@ -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)
......
......@@ -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"])
......
#include "akdshfgdfkgweriuweriyuiqwuegdhsgfsdkfgyuawetrkdshfdsufg.h"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment