-
-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library update/install with
--no-overwrite
will perform the update …
…if it's possible to keep already installed dependencies at their current version (#2431) * Updated semver library * Improved behaviour of 'lib install --no-overwrite' flag Previously the --no-overwrite flag would fail to install if a library dependency was already installed but not at the latest version. After this change the already present library may be accepted as a dependency if it match the version constraints of the installed library. * Fixed integration test * Added integration test * Always use 'installed' version if available * Allow a bit more time for slow CI
- Loading branch information
Showing
14 changed files
with
423 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ func TestIndexer(t *testing.T) { | |
rtcInexistent2 := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero-blah", Version: semver.MustParse("1.0.0")}) | ||
require.Nil(t, rtcInexistent2) | ||
|
||
resolve1 := index.ResolveDependencies(alp.Releases["1.2.1"]) | ||
resolve1 := index.ResolveDependencies(alp.Releases["1.2.1"], nil) | ||
require.Len(t, resolve1, 2) | ||
require.Contains(t, resolve1, alp.Releases["1.2.1"]) | ||
require.Contains(t, resolve1, rtc.Releases["1.6.0"]) | ||
|
@@ -108,7 +108,7 @@ func TestIndexer(t *testing.T) { | |
require.NotNil(t, http040) | ||
require.Equal(t, "[email protected]", http040.String()) | ||
|
||
resolve2 := index.ResolveDependencies(oauth010) | ||
resolve2 := index.ResolveDependencies(oauth010, nil) | ||
require.Len(t, resolve2, 4) | ||
require.Contains(t, resolve2, oauth010) | ||
require.Contains(t, resolve2, eccx135) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import ( | |
) | ||
|
||
func initDepsCommand() *cobra.Command { | ||
var noOverwrite bool | ||
depsCommand := &cobra.Command{ | ||
Use: fmt.Sprintf("deps %s[@%s]...", tr("LIBRARY"), tr("VERSION_NUMBER")), | ||
Short: tr("Check dependencies status for the specified library."), | ||
|
@@ -41,15 +42,18 @@ func initDepsCommand() *cobra.Command { | |
" " + os.Args[0] + " lib deps AudioZero # " + tr("for the latest version.") + "\n" + | ||
" " + os.Args[0] + " lib deps [email protected] # " + tr("for the specific version."), | ||
Args: cobra.ExactArgs(1), | ||
Run: runDepsCommand, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runDepsCommand(args, noOverwrite) | ||
}, | ||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return arguments.GetInstalledLibraries(), cobra.ShellCompDirectiveDefault | ||
}, | ||
} | ||
depsCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, tr("Do not try to update library dependencies if already installed.")) | ||
return depsCommand | ||
} | ||
|
||
func runDepsCommand(cmd *cobra.Command, args []string) { | ||
func runDepsCommand(args []string, noOverwrite bool) { | ||
instance := instance.CreateAndInit() | ||
logrus.Info("Executing `arduino-cli lib deps`") | ||
libRef, err := ParseLibraryReferenceArgAndAdjustCase(instance, args[0]) | ||
|
@@ -58,9 +62,10 @@ func runDepsCommand(cmd *cobra.Command, args []string) { | |
} | ||
|
||
deps, err := lib.LibraryResolveDependencies(context.Background(), &rpc.LibraryResolveDependenciesRequest{ | ||
Instance: instance, | ||
Name: libRef.Name, | ||
Version: libRef.Version, | ||
Instance: instance, | ||
Name: libRef.Name, | ||
Version: libRef.Version, | ||
DoNotUpdateInstalledLibraries: noOverwrite, | ||
}) | ||
if err != nil { | ||
feedback.Fatal(tr("Error resolving dependencies for %[1]s: %[2]s", libRef, err), feedback.ErrGeneric) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,8 +589,10 @@ func TestInstallLibraryWithDependencies(t *testing.T) { | |
require.NoError(t, err) | ||
_, _, err = cli.Run("lib", "install", "[email protected]") | ||
require.NoError(t, err) | ||
_, _, err = cli.Run("lib", "install", "Arduino_Builtin", "--no-overwrite") | ||
require.Error(t, err) | ||
// This time it should accept the installation with the currently installed SD 1.2.3 | ||
out, _, err := cli.Run("lib", "install", "Arduino_Builtin", "--no-overwrite") | ||
require.NoError(t, err) | ||
require.Contains(t, string(out), "Already installed [email protected]") | ||
} | ||
|
||
func TestInstallNoDeps(t *testing.T) { | ||
|
@@ -1653,9 +1655,6 @@ func TestDependencyResolver(t *testing.T) { | |
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) | ||
defer env.CleanUp() | ||
|
||
_, _, err := cli.Run("lib", "update-index") | ||
require.NoError(t, err) | ||
|
||
done := make(chan bool) | ||
go func() { | ||
_, _, err := cli.Run("lib", "install", "NTPClient_Generic") | ||
|
@@ -1665,7 +1664,54 @@ func TestDependencyResolver(t *testing.T) { | |
|
||
select { | ||
case <-done: | ||
case <-time.After(time.Second * 2): | ||
case <-time.After(time.Second * 10): | ||
require.FailNow(t, "The install command didn't complete in the allocated time") | ||
} | ||
} | ||
|
||
func TestDependencyResolverNoOverwrite(t *testing.T) { | ||
// https://github.com/arduino/arduino-cli/issues/1799 | ||
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) | ||
defer env.CleanUp() | ||
|
||
_, _, err := cli.Run("lib", "install", "[email protected]") | ||
require.NoError(t, err) | ||
|
||
out, _, err := cli.Run("lib", "deps", "[email protected]", "--format", "json") | ||
require.NoError(t, err) | ||
outjson := requirejson.Parse(t, out) | ||
outjson.MustContain(`{ | ||
"dependencies": [ | ||
{ | ||
"name": "Bounce2", | ||
"version_installed": "2.53" | ||
}, | ||
{ | ||
"name": "EncoderTool", | ||
"version_required": "2.2.0" | ||
} | ||
] | ||
}`) | ||
require.NotEqual(t, outjson.Query("dependencies[0].version_required").String(), `"2.53.0"`) | ||
require.NotEqual(t, outjson.Query("dependencies[0].version_required").String(), `"2.53"`) | ||
|
||
out, _, err = cli.Run("lib", "deps", "[email protected]", "--no-overwrite", "--format", "json") | ||
require.NoError(t, err) | ||
outjson = requirejson.Parse(t, out) | ||
outjson.MustContain(`{ | ||
"dependencies": [ | ||
{ | ||
"name": "Bounce2", | ||
"version_required": "2.53", | ||
"version_installed": "2.53" | ||
}, | ||
{ | ||
"name": "EncoderTool", | ||
"version_required": "2.2.0" | ||
} | ||
] | ||
}`) | ||
|
||
_, _, err = cli.Run("lib", "install", "[email protected]", "--no-overwrite") | ||
require.NoError(t, err) | ||
} |
Oops, something went wrong.