Skip to content

Precompiled libraries: only select a folder if it contains files #1134

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
Show file tree
Hide file tree
Changes from 2 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
16 changes: 14 additions & 2 deletions legacy/builder/phases/libraries_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
return nil
}

func containsFile(folder *paths.Path) bool {
res, _ := folder.ReadDir()
hasfiles := false
for _, el := range res {
if !el.IsDir() {
hasfiles = true
break
}
}
return hasfiles
}

func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Library) *paths.Path {
mcu := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_BUILD_MCU)
// Add fpu specifications if they exist
Expand Down Expand Up @@ -86,15 +98,15 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
if len(fpuSpecs) > 0 {
fpuSpecs = strings.TrimRight(fpuSpecs, "-")
fullPrecompDir := library.SourceDir.Join(mcu).Join(fpuSpecs)
if fullPrecompDir.Exist() {
if fullPrecompDir.Exist() && containsFile(fullPrecompDir) {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "Using precompiled library in {0}", fullPrecompDir)
return fullPrecompDir
}
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "Precompiled library in \"{0}\" not found", fullPrecompDir)
}

precompDir := library.SourceDir.Join(mcu)
if precompDir.Exist() {
if precompDir.Exist() && containsFile(precompDir) {
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "Using precompiled library in {0}", precompDir)
return precompDir
}
Expand Down
23 changes: 11 additions & 12 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,33 +181,26 @@ def test_compile_blacklisted_sketchname(run_command, data_dir):
assert result.ok


@pytest.mark.skip()
def test_compile_without_precompiled_libraries(run_command, data_dir):
# Init the environment explicitly
url = "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
result = run_command("core update-index --additional-urls={}".format(url))
assert result.ok
# arduino:mbed 1.1.5 is incompatible with the Arduino_TensorFlowLite library
# see: https://github.com/arduino/ArduinoCore-nRF528x-mbedos/issues/93
result = run_command("core install arduino:[email protected] --additional-urls={}".format(url))
result = run_command("core install arduino:[email protected] --additional-urls={}".format(url))
assert result.ok
result = run_command("core install arduino:[email protected] --additional-urls={}".format(url))
assert result.ok
result = run_command("core install adafruit:[email protected] --additional-urls={}".format(url))
assert result.ok

# Install pre-release version of Arduino_TensorFlowLite (will be officially released
# via lib manager after https://github.com/arduino/arduino-builder/issues/353 is in)
import zipfile

with zipfile.ZipFile("test/testdata/Arduino_TensorFlowLite.zip", "r") as zip_ref:
zip_ref.extractall("{}/libraries/".format(data_dir))
result = run_command("lib install [email protected]")
# Precompiled version of Arduino_TensorflowLite
result = run_command("lib install [email protected]")
assert result.ok
result = run_command(
"compile -b arduino:mbed:nano33ble {}/libraries/Arduino_TensorFlowLite/examples/magic_wand/".format(data_dir)
)
assert result.ok
# should work on adafruit too after https://github.com/arduino/arduino-cli/pull/1134
result = run_command(
"compile -b adafruit:samd:adafruit_feather_m4 {}/libraries/Arduino_TensorFlowLite/examples/magic_wand/".format(
data_dir
Expand All @@ -216,7 +209,7 @@ def test_compile_without_precompiled_libraries(run_command, data_dir):
assert result.ok

# Non-precompiled version of Arduino_TensorflowLite
result = run_command("lib install Arduino_TensorflowLite@1.15.0-ALPHA")
result = run_command("lib install Arduino_TensorflowLite@2.1.0-ALPHA")
assert result.ok
result = run_command(
"compile -b arduino:mbed:nano33ble {}/libraries/Arduino_TensorFlowLite/examples/magic_wand/".format(data_dir)
Expand All @@ -241,6 +234,12 @@ def test_compile_without_precompiled_libraries(run_command, data_dir):
)
assert result.ok

# USBBlaster library
result = run_command('lib install "[email protected]"')
assert result.ok
result = run_command(
"compile -b arduino:samd:mkrvidor4000 {}/libraries/USBBlaster/examples/USB_Blaster/".format(data_dir)
)

def test_compile_with_build_properties_flag(run_command, data_dir, copy_sketch):
# Init the environment explicitly
Expand Down