Skip to content

Commit

Permalink
Skip dependency detection if library is fully precompiled (#1139)
Browse files Browse the repository at this point in the history
* 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 arduino/ArduinoCore-mbed#119

* Add output when skipping deps detection for precompiled libs

Co-authored-by: Silvano Cerza <silvanocerza@gmail.com>
  • Loading branch information
facchinm and silvanocerza committed Jan 26, 2021
1 parent 079bb6c commit 283036f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions legacy/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}\""
Expand Down
13 changes: 13 additions & 0 deletions legacy/builder/container_find_includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,21 @@ 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 && 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
}
}

var preproc_err error
var preproc_stderr []byte

if unchanged && cache.valid {
include = cache.Next().Include
if first && ctx.Verbose {
Expand Down
39 changes: 39 additions & 0 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 283036f

Please sign in to comment.