Skip to content

Add multiple libraries installation when using --git-url or --zip-path flags #1146

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 1 commit into from
Jan 22, 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
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 [email protected] # for the specific version.",
" " + os.Args[0] + " lib install [email protected] # 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 [email protected]")
assert run_command("lib download [email protected]")
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()