Skip to content
Open
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
5 changes: 3 additions & 2 deletions cmd/gendoc/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,9 @@ Contains a JSON object with the details of an error.
Method: http.MethodDelete,
Path: "/v1/apps/{appID}/sketch/libraries/{libRef}",
Parameters: (*struct {
ID string `path:"appID" description:"application identifier."`
LibRef string `path:"libRef" description:"library reference (\"LibraryName\" or \"LibraryName@Version\")."`
ID string `path:"appID" description:"application identifier."`
LibRef string `path:"libRef" description:"library reference (\"LibraryName\" or \"LibraryName@Version\")."`
RemoveDependencies string `query:"remove_deps" description:"if set to \"true\", the library's dependencies will be removed as well if not needed anymore."`
})(nil),
CustomSuccessResponse: &CustomResponseDef{
ContentType: "application/json",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ replace (
)

// Required until https://github.com/arduino/arduino-cli/pull/3019 is merged and released
replace github.com/arduino/arduino-cli => github.com/cmaglie/arduino-cli v0.0.0-20251006122726-27fe68b0a18a
replace github.com/arduino/arduino-cli => github.com/cmaglie/arduino-cli v0.0.0-20251029100020-2327b357349d

require (
github.com/Andrew-M-C/go.emoji v1.1.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/cmaglie/arduino-cli v0.0.0-20251006122726-27fe68b0a18a h1:xjGwmLNEUTb+QWUmUxwrb24Awbt4/rdpFG7lVUR3skI=
github.com/cmaglie/arduino-cli v0.0.0-20251006122726-27fe68b0a18a/go.mod h1:aH/Lfub80ymf3vpF0gUWx/sckVUNB0gDoPlABAx97SE=
github.com/cmaglie/arduino-cli v0.0.0-20251029100020-2327b357349d h1:Hpm/DaAji25rxW1JPr1DK7A1wnUygOw0ftAs6UiHAq0=
github.com/cmaglie/arduino-cli v0.0.0-20251029100020-2327b357349d/go.mod h1:aH/Lfub80ymf3vpF0gUWx/sckVUNB0gDoPlABAx97SE=
github.com/cmaglie/pb v1.0.27 h1:ynGj8vBXR+dtj4B7Q/W/qGt31771Ux5iFfRQBnwdQiA=
github.com/cmaglie/pb v1.0.27/go.mod h1:GilkKZMXYjBA4NxItWFfO+lwkp59PLHQ+IOW/b/kmZI=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
Expand Down
8 changes: 8 additions & 0 deletions internal/api/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ paths:
from the sketch project file.
operationId: appSketchRemoveLibrary
parameters:
- description: if set to "true", the library's dependencies will be removed
as well if not needed anymore.
in: query
name: remove_deps
schema:
description: if set to "true", the library's dependencies will be removed
as well if not needed anymore.
type: string
- description: application identifier.
in: path
name: appID
Expand Down
6 changes: 4 additions & 2 deletions internal/api/handlers/app_sketch_libs.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ func HandleSketchRemoveLibrary(idProvider *app.IDProvider) http.HandlerFunc {
return
}

if removedLib, err := orchestrator.RemoveSketchLibrary(r.Context(), app, libRef); err != nil {
// Get query param addDeps (default false)
removeDeps, _ := strconv.ParseBool(r.URL.Query().Get("remove_deps"))
if removedLibs, err := orchestrator.RemoveSketchLibrary(r.Context(), app, libRef, removeDeps); err != nil {
render.EncodeResponse(w, http.StatusInternalServerError, models.ErrorResponse{Details: "unable to remove sketch library"})
return
} else {
render.EncodeResponse(w, http.StatusOK, SketchRemoveLibraryResponse{
RemovedLibraries: []orchestrator.LibraryReleaseID{removedLib},
RemovedLibraries: removedLibs,
})
return
}
Expand Down
44 changes: 22 additions & 22 deletions internal/orchestrator/sketch_libs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel
resp, err := srv.ProfileLibAdd(ctx, &rpc.ProfileLibAddRequest{
Instance: inst,
SketchPath: app.MainSketchPath.String(),
Library: &rpc.SketchProfileLibraryReference{
Library: &rpc.SketchProfileLibraryReference_IndexLibrary_{
IndexLibrary: &rpc.SketchProfileLibraryReference_IndexLibrary{
Library: &rpc.ProfileLibraryReference{
Library: &rpc.ProfileLibraryReference_IndexLibrary_{
IndexLibrary: &rpc.ProfileLibraryReference_IndexLibrary{
Name: libRef.Name,
Version: libRef.Version,
},
Expand All @@ -62,11 +62,11 @@ func AddSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryRel
return f.Map(resp.GetAddedLibraries(), rpcProfileLibReferenceToLibReleaseID), nil
}

func RemoveSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryReleaseID) (LibraryReleaseID, error) {
func RemoveSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef LibraryReleaseID, removeDeps bool) ([]LibraryReleaseID, error) {
srv := commands.NewArduinoCoreServer()
var inst *rpc.Instance
if res, err := srv.Create(ctx, &rpc.CreateRequest{}); err != nil {
return LibraryReleaseID{}, err
return nil, err
} else {
inst = res.Instance
}
Expand All @@ -77,23 +77,25 @@ func RemoveSketchLibrary(ctx context.Context, app app.ArduinoApp, libRef Library
// TODO: LOG progress/error?
return nil
})); err != nil {
return LibraryReleaseID{}, err
return nil, err
}

resp, err := srv.ProfileLibRemove(ctx, &rpc.ProfileLibRemoveRequest{
Library: &rpc.SketchProfileLibraryReference{
Library: &rpc.SketchProfileLibraryReference_IndexLibrary_{
IndexLibrary: &rpc.SketchProfileLibraryReference_IndexLibrary{
Instance: inst,
Library: &rpc.ProfileLibraryReference{
Library: &rpc.ProfileLibraryReference_IndexLibrary_{
IndexLibrary: &rpc.ProfileLibraryReference_IndexLibrary{
Name: libRef.Name,
},
},
},
SketchPath: app.MainSketchPath.String(),
SketchPath: app.MainSketchPath.String(),
RemoveDependencies: &removeDeps,
})
if err != nil {
return LibraryReleaseID{}, err
return nil, err
}
return rpcProfileLibReferenceToLibReleaseID(resp.GetLibrary()), nil
return f.Map(resp.GetRemovedLibraries(), rpcProfileLibReferenceToLibReleaseID), nil
}

func ListSketchLibraries(ctx context.Context, app app.ArduinoApp) ([]LibraryReleaseID, error) {
Expand All @@ -107,19 +109,17 @@ func ListSketchLibraries(ctx context.Context, app app.ArduinoApp) ([]LibraryRele
}

// Keep only index libraries
libs := f.Filter(resp.Libraries, func(l *rpc.SketchProfileLibraryReference) bool {
libs := f.Filter(resp.Libraries, func(l *rpc.ProfileLibraryReference) bool {
return l.GetIndexLibrary() != nil
})
res := f.Map(libs, func(l *rpc.SketchProfileLibraryReference) LibraryReleaseID {
return LibraryReleaseID{
Name: l.GetIndexLibrary().GetName(),
Version: l.GetIndexLibrary().GetVersion(),
}
})
return res, nil
return f.Map(libs, rpcProfileLibReferenceToLibReleaseID), nil
}

func rpcProfileLibReferenceToLibReleaseID(ref *rpc.SketchProfileLibraryReference) LibraryReleaseID {
func rpcProfileLibReferenceToLibReleaseID(ref *rpc.ProfileLibraryReference) LibraryReleaseID {
l := ref.GetIndexLibrary()
return NewLibraryReleaseID(l.GetName(), l.GetVersion())
return LibraryReleaseID{
Name: l.GetName(),
Version: l.GetVersion(),
IsDependency: l.GetIsDependency(),
}
}
5 changes: 3 additions & 2 deletions internal/orchestrator/sketch_libs_release_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
// - name[@version]
// Version is optional, if not provided, the latest version available will be used.
type LibraryReleaseID struct {
Name string
Version string
Name string
Version string
IsDependency bool
}

func NewLibraryReleaseID(name string, version string) LibraryReleaseID {
Expand Down