Skip to content

Commit

Permalink
Add multiple libraries installation when using --git-url or --zip-pat…
Browse files Browse the repository at this point in the history
…h flags (#1146)
  • Loading branch information
silvanocerza committed Jan 22, 2021
1 parent 6328430 commit 7e55f9e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 23 deletions.
51 changes: 28 additions & 23 deletions cli/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func initInstallCommand() *cobra.Command {
Long: "Installs one or more specified libraries into the system.",
Example: "" +
" " + os.Args[0] + " lib install AudioZero # for the latest version.\n" +
" " + os.Args[0] + " lib install AudioZero@1.0.0 # for the specific version.",
" " + os.Args[0] + " lib install AudioZero@1.0.0 # for the specific version.\n" +
" " + os.Args[0] + " lib install --git-url https://github.com/arduino-libraries/WiFi101.git https://github.com/arduino-libraries/ArduinoBLE.git\n" +
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
Args: cobra.MinimumNArgs(1),
Run: runInstallCommand,
}
Expand Down Expand Up @@ -73,36 +75,39 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
}

if installFlags.zipPath {
ziplibraryInstallReq := &rpc.ZipLibraryInstallReq{
Instance: instance,
Path: args[0],
}
err := lib.ZipLibraryInstall(context.Background(), ziplibraryInstallReq, output.TaskProgress())
if err != nil {
feedback.Errorf("Error installing Zip Library: %v", err)
os.Exit(errorcodes.ErrGeneric)
for _, path := range args {
ziplibraryInstallReq := &rpc.ZipLibraryInstallReq{
Instance: instance,
Path: path,
}
err := lib.ZipLibraryInstall(context.Background(), ziplibraryInstallReq, output.TaskProgress())
if err != nil {
feedback.Errorf("Error installing Zip Library: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
}
return
}

if installFlags.gitURL {
url := args[0]
if url == "." {
wd, err := paths.Getwd()
for _, url := range args {
if url == "." {
wd, err := paths.Getwd()
if err != nil {
feedback.Errorf("Couldn't get current working directory: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
url = wd.String()
}
gitlibraryInstallReq := &rpc.GitLibraryInstallReq{
Instance: instance,
Url: url,
}
err := lib.GitLibraryInstall(context.Background(), gitlibraryInstallReq, output.TaskProgress())
if err != nil {
feedback.Errorf("Couldn't get current working directory: %v", err)
feedback.Errorf("Error installing Git Library: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
url = wd.String()
}
gitlibraryInstallReq := &rpc.GitLibraryInstallReq{
Instance: instance,
Url: url,
}
err := lib.GitLibraryInstall(context.Background(), gitlibraryInstallReq, output.TaskProgress())
if err != nil {
feedback.Errorf("Error installing Git Library: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
return
}
Expand Down
55 changes: 55 additions & 0 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,58 @@ def test_install_with_git_url_does_not_create_git_repo(run_command, downloads_di

# Verifies installed library is not a git repository
assert not Path(lib_install_dir, ".git").exists()


def test_install_with_git_url_multiple_libraries(run_command, downloads_dir, data_dir):
assert run_command("update")

env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}

wifi_install_dir = Path(data_dir, "libraries", "WiFi101")
ble_install_dir = Path(data_dir, "libraries", "ArduinoBLE")
# Verifies libraries are not installed
assert not wifi_install_dir.exists()
assert not ble_install_dir.exists()

wifi_url = "https://github.com/arduino-libraries/WiFi101.git"
ble_url = "https://github.com/arduino-libraries/ArduinoBLE.git"

assert run_command(f"lib install --git-url {wifi_url} {ble_url}", custom_env=env)

# Verifies library are installed
assert wifi_install_dir.exists()
assert ble_install_dir.exists()


def test_install_with_zip_path_multiple_libraries(run_command, downloads_dir, data_dir):
assert run_command("update")

env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}

# Downloads zip to be installed later
assert run_command("lib download WiFi101@0.16.1")
assert run_command("lib download ArduinoBLE@1.1.3")
wifi_zip_path = Path(downloads_dir, "libraries", "WiFi101-0.16.1.zip")
ble_zip_path = Path(downloads_dir, "libraries", "ArduinoBLE-1.1.3.zip")

wifi_install_dir = Path(data_dir, "libraries", "WiFi101-0.16.1")
ble_install_dir = Path(data_dir, "libraries", "ArduinoBLE-1.1.3")
# Verifies libraries are not installed
assert not wifi_install_dir.exists()
assert not ble_install_dir.exists()

assert run_command(f"lib install --zip-path {wifi_zip_path} {ble_zip_path}", custom_env=env)

# Verifies library are installed
assert wifi_install_dir.exists()
assert ble_install_dir.exists()

0 comments on commit 7e55f9e

Please sign in to comment.