From a27b2f45cf938480d155e23f83289fc913b07275 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 14 Jan 2021 18:53:00 +0100 Subject: [PATCH 1/2] Skip dependency detection if library is fully precompiled Precompiled bits of a library should not depend on any link time dependency (we cannot assure ABI stability). Fixes https://github.com/arduino/ArduinoCore-mbed/issues/119 --- legacy/builder/container_find_includes.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index 2d980aca4ec..a66734b111b 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -316,8 +316,18 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t if library, ok := sourceFile.Origin.(*libraries.Library); ok && library.UtilityDir != nil { includes = append(includes, library.UtilityDir) } + + if library, ok := sourceFile.Origin.(*libraries.Library); ok { + if library.Precompiled == true && library.PrecompiledWithSources == true { + // Fully precompiled libraries should have no dependencies + // to avoid ABI breakage + return nil + } + } + var preproc_err error var preproc_stderr []byte + if unchanged && cache.valid { include = cache.Next().Include if first && ctx.Verbose { From 4fba67bf6128d8d241a5a97afe8eeb1a616719f9 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Tue, 26 Jan 2021 16:17:45 +0100 Subject: [PATCH 2/2] Add output when skipping deps detection for precompiled libs --- legacy/builder/constants/constants.go | 1 + legacy/builder/container_find_includes.go | 5 ++- test/test_compile.py | 39 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/legacy/builder/constants/constants.go b/legacy/builder/constants/constants.go index c0bde3c7a85..bb1c60bb483 100644 --- a/legacy/builder/constants/constants.go +++ b/legacy/builder/constants/constants.go @@ -89,6 +89,7 @@ const MSG_BOOTLOADER_FILE_MISSING = "Bootloader file specified but missing: {0}" const MSG_BUILD_OPTIONS_CHANGED = "Build options changed, rebuilding all" const MSG_CANT_FIND_SKETCH_IN_PATH = "Unable to find {0} in {1}" const MSG_FQBN_INVALID = "{0} is not a valid fully qualified board name. Required format is targetPackageName:targetPlatformName:targetBoardName." +const MSG_SKIP_PRECOMPILED_LIBRARY = "Skipping dependencies detection for precompiled library {0}" const MSG_FIND_INCLUDES_FAILED = "Error while detecting libraries included by {0}" const MSG_LIB_LEGACY = "(legacy)" const MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR = "Multiple libraries were found for \"{0}\"" diff --git a/legacy/builder/container_find_includes.go b/legacy/builder/container_find_includes.go index a66734b111b..6477a5351ed 100644 --- a/legacy/builder/container_find_includes.go +++ b/legacy/builder/container_find_includes.go @@ -318,9 +318,12 @@ func findIncludesUntilDone(ctx *types.Context, cache *includeCache, sourceFile t } if library, ok := sourceFile.Origin.(*libraries.Library); ok { - if library.Precompiled == true && library.PrecompiledWithSources == true { + if library.Precompiled && library.PrecompiledWithSources { // Fully precompiled libraries should have no dependencies // to avoid ABI breakage + if ctx.Verbose { + ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_SKIP_PRECOMPILED_LIBRARY, library.Name) + } return nil } } diff --git a/test/test_compile.py b/test/test_compile.py index 6bd1bd5efe4..8b5337e02cf 100644 --- a/test/test_compile.py +++ b/test/test_compile.py @@ -590,3 +590,42 @@ def test_compile_with_archives_and_long_paths(run_command): sketch_path = Path(lib_output[0]["library"]["install_dir"], "examples", "ArduinoIoTCloud-Advanced") assert run_command(f"compile -b esp8266:esp8266:huzzah {sketch_path}") + + +def test_compile_with_precompiled_library(run_command, data_dir): + assert run_command("update") + + assert run_command("core install arduino:samd@1.8.11") + fqbn = "arduino:samd:mkrzero" + + # Install precompiled library + # For more information see: + # https://arduino.github.io/arduino-cli/latest/library-specification/#precompiled-binaries + assert run_command('lib install "BSEC Software Library@1.5.1474"') + sketch_folder = Path(data_dir, "libraries", "BSEC_Software_Library", "examples", "basic") + + # Compile and verify dependencies detection for fully precompiled library is not skipped + result = run_command(f"compile -b {fqbn} {sketch_folder} -v") + assert result.ok + assert "Skipping dependencies detection for precompiled library BSEC Software Library" not in result.stdout + + +def test_compile_with_fully_precompiled_library(run_command, data_dir): + assert run_command("update") + + assert run_command("core install arduino:mbed@1.3.1") + fqbn = "arduino:mbed:nano33ble" + + # Install fully precompiled library + # For more information see: + # https://arduino.github.io/arduino-cli/latest/library-specification/#precompiled-binaries + assert run_command("lib install Arduino_TensorFlowLite@2.1.1-ALPHA-precompiled") + sketch_folder = Path(data_dir, "libraries", "Arduino_TensorFlowLite", "examples", "hello_world") + + # Install example dependency + # assert run_command("lib install Arduino_LSM9DS1") + + # Compile and verify dependencies detection for fully precompiled library is skipped + result = run_command(f"compile -b {fqbn} {sketch_folder} -v") + assert result.ok + assert "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite" in result.stdout