Skip to content

Do not give-up on compile --only-compilation-database if prototypes generation fails #1552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion legacy/builder/container_add_prototypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
9 changes: 9 additions & 0 deletions legacy/builder/container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions test/test_compile_part_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] 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:[email protected]", 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"])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "akdshfgdfkgweriuweriyuiqwuegdhsgfsdkfgyuawetrkdshfdsufg.h"