Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c7d0cb4
Added gRPC functions to manage libraries in profiles
cmaglie Oct 3, 2025
92cf64f
Removed ProfileDump gRPC command.
cmaglie Oct 6, 2025
ed5d6a2
Moved SketchProfileLibraryReference in the proper commono.proto file
cmaglie Oct 6, 2025
c74f073
linter: removed unneeded type specification
cmaglie Oct 6, 2025
34c378c
Renamed SketchProfileLibraryReference -> ProfileLibraryReference
cmaglie Oct 22, 2025
0c78b3f
Renamed InitProfile -> ProfileCreate
cmaglie Oct 22, 2025
3c5a3c9
Small refactoring, no code change
cmaglie Oct 23, 2025
4d78f7f
Fixed error messages
cmaglie Oct 23, 2025
d4cbad2
Removed unnecessary type specifier
cmaglie Oct 24, 2025
140c069
Refactored libraryResolveDependencies.
cmaglie Oct 27, 2025
5ac03d8
Added support for 'dependency:' field in profiles libraries
cmaglie Oct 29, 2025
e17724b
ProfileLibAdd and ProfileLibRemove can now cleanup unneeded dependencies
cmaglie Oct 29, 2025
4bb86e7
Better error messages
cmaglie Nov 21, 2025
f520cb9
Simplified Profile.RemoveLibrary(...) method.
cmaglie Nov 21, 2025
4e80e73
Fixed algorithm for determination of required deps
cmaglie Nov 21, 2025
dbafbe6
Updated docs
cmaglie Nov 25, 2025
4f527c0
Rename DuplicateProfileError -> ProfileAlreadyExitsError
cmaglie Nov 26, 2025
1909ab7
Removed useless field in gRPC ProfileCreateResponse
cmaglie Nov 26, 2025
8b4b3a5
fix: ProfileCreate sets the new profile as default only if asked to d…
cmaglie Nov 26, 2025
ad5d941
Improved docs
cmaglie Dec 1, 2025
3a14601
Applied code review suggestion
cmaglie Dec 1, 2025
2aa7e32
Using cmp.Or helper
cmaglie Dec 1, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed algorithm for determination of required deps
  • Loading branch information
cmaglie committed Nov 25, 2025
commit 4e80e73ce832f71a706b17846f5ac680d864f0e9
16 changes: 6 additions & 10 deletions commands/service_profile_lib_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (s *arduinoCoreServerImpl) ProfileLibRemove(ctx context.Context, req *rpc.P

// Get all the dependencies required by the profile excluding the removed library
requiredDeps := map[string]bool{}
requiredDeps[libToRemove.String()] = true
for _, profLib := range profile.Libraries {
if profLib.IsDependency {
continue
Expand All @@ -95,24 +94,21 @@ func (s *arduinoCoreServerImpl) ProfileLibRemove(ctx context.Context, req *rpc.P
return nil, &cmderrors.InvalidArgumentError{Cause: err, Message: "cannot resolve dependencies for installed libraries"}
}
for _, dep := range deps {
requiredDeps[dep.String()] = true
requiredDeps[dep.Library.Name] = true
}
}

depsOfLibToRemove, err := libraryResolveDependencies(li, libToRemove.Library, libToRemove.Version.String(), nil)
candidateDepsToRemove, err := libraryResolveDependencies(li, libToRemove.Library, libToRemove.Version.String(), nil)
if err != nil {
return nil, &cmderrors.InvalidArgumentError{Cause: err, Message: "cannot resolve dependencies for installed libraries"}
}
// sort to make the output order deterministic
slices.SortFunc(depsOfLibToRemove, librariesindex.ReleaseCompare)
// deps contains the main library as well, so we skip it when removing dependencies
for _, depToRemove := range depsOfLibToRemove {
if requiredDeps[depToRemove.String()] {
slices.SortFunc(candidateDepsToRemove, librariesindex.ReleaseCompare)
for _, depToRemove := range candidateDepsToRemove {
if requiredDeps[depToRemove.Library.Name] {
continue
}
if err := remove(&sketch.ProfileLibraryReference{Library: depToRemove.Library.Name, Version: depToRemove.Version}); err != nil {
return nil, err
}
_ = remove(&sketch.ProfileLibraryReference{Library: depToRemove.Library.Name, Version: depToRemove.Version})
}
}

Expand Down
172 changes: 172 additions & 0 deletions internal/integrationtest/daemon/profile_lib_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,175 @@ default_profile: test
`)
}
}

func TestProfileLibRemoveWithDeps(t *testing.T) {
env, cli := integrationtest.CreateEnvForDaemon(t)
t.Cleanup(env.CleanUp)

_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)
_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)

tmp, err := paths.MkTempDir("", "")
require.NoError(t, err)
t.Cleanup(func() { tmp.RemoveAll() })
sk := tmp.Join("sketch")

// Create a new sketch
_, _, err = cli.Run("sketch", "new", sk.String())
require.NoError(t, err)

grpcInst := cli.Create()
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
fmt.Printf("INIT> %v\n", ir.GetMessage())
}))

// Create a new profile
resp, err := grpcInst.ProfileCreate(t.Context(), "test", sk.String(), "arduino:avr:uno", true)
require.NoError(t, err)
projectFile := paths.New(resp.GetProjectFilePath())

expect := func(expected string) {
p, _ := projectFile.ReadFile()
require.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(p)))
}
expect(`
profiles:
test:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.6)

default_profile: test
`)

// Add a library to the profile
{
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("Arduino_RouterBridge", "0.2.2"), true, false)
require.NoError(t, err)
require.Equal(t, indexLibArray(
indexLib("Arduino_RPClite", "0.2.0", true),
indexLib("Arduino_RouterBridge", "0.2.2"),
indexLib("ArxContainer", "0.7.0", true),
indexLib("ArxTypeTraits", "0.3.2", true),
indexLib("DebugLog", "0.8.4", true),
indexLib("MsgPack", "0.4.2", true),
), addresp.GetAddedLibraries())
expect(`
profiles:
test:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.6)
libraries:
- dependency: Arduino_RPClite (0.2.0)
- Arduino_RouterBridge (0.2.2)
- dependency: ArxContainer (0.7.0)
- dependency: ArxTypeTraits (0.3.2)
- dependency: DebugLog (0.8.4)
- dependency: MsgPack (0.4.2)

default_profile: test
`)
}

// Remove the library (without indicating the version) and the dependencies
{
remresp, err := grpcInst.ProfileLibRemove(t.Context(), sk.String(), "test", indexLib("Arduino_RouterBridge", ""), true)
require.NoError(t, err)
require.Equal(t, indexLibArray(
indexLib("Arduino_RouterBridge", "0.2.2"),
indexLib("Arduino_RPClite", "0.2.0", true),
indexLib("ArxContainer", "0.7.0", true),
indexLib("ArxTypeTraits", "0.3.2", true),
indexLib("DebugLog", "0.8.4", true),
indexLib("MsgPack", "0.4.2", true),
), remresp.GetRemovedLibraries())
expect(`
profiles:
test:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.6)

default_profile: test
`)
}

// Re-add the library to the profile
{
addresp, err := grpcInst.ProfileLibAdd(t.Context(), sk.String(), "test", indexLib("Arduino_RouterBridge", "0.2.2"), true, false)
require.NoError(t, err)
require.Equal(t, indexLibArray(
indexLib("Arduino_RPClite", "0.2.0", true),
indexLib("Arduino_RouterBridge", "0.2.2"),
indexLib("ArxContainer", "0.7.0", true),
indexLib("ArxTypeTraits", "0.3.2", true),
indexLib("DebugLog", "0.8.4", true),
indexLib("MsgPack", "0.4.2", true),
), addresp.GetAddedLibraries())
expect(`
profiles:
test:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.6)
libraries:
- dependency: Arduino_RPClite (0.2.0)
- Arduino_RouterBridge (0.2.2)
- dependency: ArxContainer (0.7.0)
- dependency: ArxTypeTraits (0.3.2)
- dependency: DebugLog (0.8.4)
- dependency: MsgPack (0.4.2)

default_profile: test
`)
}

// Remove one dep library (without indicating the version)
{
_, err := grpcInst.ProfileLibRemove(t.Context(), sk.String(), "test", indexLib("Arduino_RPClite", ""), true)
require.NoError(t, err)
// require.Equal(t, indexLibArray(
// indexLib("Arduino_RPClite", "0.2.0", true),
// ), remresp.GetRemovedLibraries())
expect(`
profiles:
test:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.6)
libraries:
- Arduino_RouterBridge (0.2.2)
- dependency: ArxContainer (0.7.0)
- dependency: ArxTypeTraits (0.3.2)
- dependency: DebugLog (0.8.4)
- dependency: MsgPack (0.4.2)

default_profile: test
`)
}

// Remove the library (without indicating the version) and all the dependencies
{
remresp, err := grpcInst.ProfileLibRemove(t.Context(), sk.String(), "test", indexLib("Arduino_RouterBridge", ""), true)
require.NoError(t, err)
require.Equal(t, indexLibArray(
indexLib("Arduino_RouterBridge", "0.2.2"),
indexLib("ArxContainer", "0.7.0", true),
indexLib("ArxTypeTraits", "0.3.2", true),
indexLib("DebugLog", "0.8.4", true),
indexLib("MsgPack", "0.4.2", true),
), remresp.GetRemovedLibraries())
expect(`
profiles:
test:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.6)

default_profile: test
`)
}
}