File tree Expand file tree Collapse file tree 6 files changed +159
-113
lines changed Expand file tree Collapse file tree 6 files changed +159
-113
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ package libraries
1818import (
1919 "encoding/json"
2020 "fmt"
21+
22+ rpc "github.com/arduino/arduino-cli/rpc/commands"
2123)
2224
2325// LibraryLayout represents how the library source code is laid out in the library
@@ -65,3 +67,14 @@ func (d *LibraryLayout) UnmarshalJSON(b []byte) error {
6567 }
6668 return fmt .Errorf ("invalid library layout: %s" , s )
6769}
70+
71+ // ToRPCLibraryLayout converts this LibraryLayout to rpc.LibraryLayout
72+ func (d * LibraryLayout ) ToRPCLibraryLayout () rpc.LibraryLayout {
73+ switch * d {
74+ case FlatLayout :
75+ return rpc .LibraryLayout_flat_layout
76+ case RecursiveLayout :
77+ return rpc .LibraryLayout_recursive_layout
78+ }
79+ panic (fmt .Sprintf ("invalid LibraryLayout value %d" , * d ))
80+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ package libraries
1818import (
1919 "encoding/json"
2020 "fmt"
21+
22+ rpc "github.com/arduino/arduino-cli/rpc/commands"
2123)
2224
2325// LibraryLocation represents where the library is installed
@@ -82,3 +84,33 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
8284 }
8385 return fmt .Errorf ("invalid library location: %s" , s )
8486}
87+
88+ // ToRPCLibraryLocation converts this LibraryLocation to rpc.LibraryLocation
89+ func (d * LibraryLocation ) ToRPCLibraryLocation () rpc.LibraryLocation {
90+ switch * d {
91+ case IDEBuiltIn :
92+ return rpc .LibraryLocation_ide_builtin
93+ case PlatformBuiltIn :
94+ return rpc .LibraryLocation_platform_builtin
95+ case ReferencedPlatformBuiltIn :
96+ return rpc .LibraryLocation_referenced_platform_builtin
97+ case User :
98+ return rpc .LibraryLocation_user
99+ }
100+ panic (fmt .Sprintf ("invalid LibraryLocation value %d" , * d ))
101+ }
102+
103+ // FromRPCLibraryLocation converts a rpc.LibraryLocation to a LibraryLocation
104+ func FromRPCLibraryLocation (l rpc.LibraryLocation ) LibraryLocation {
105+ switch l {
106+ case rpc .LibraryLocation_ide_builtin :
107+ return IDEBuiltIn
108+ case rpc .LibraryLocation_platform_builtin :
109+ return PlatformBuiltIn
110+ case rpc .LibraryLocation_referenced_platform_builtin :
111+ return ReferencedPlatformBuiltIn
112+ case rpc .LibraryLocation_user :
113+ return User
114+ }
115+ panic (fmt .Sprintf ("invalid rpc.LibraryLocation value %d" , l ))
116+ }
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ func (ir installedResult) String() string {
102102 lastName = name
103103 }
104104
105- location := lib .GetLocation ()
105+ location := lib .GetLocation (). String ()
106106 if lib .ContainerPlatform != "" {
107107 location = lib .GetContainerPlatform ()
108108 }
Original file line number Diff line number Diff line change @@ -107,9 +107,9 @@ func GetOutputLibrary(lib *libraries.Library) *rpc.Library {
107107 InstallDir : insdir ,
108108 SourceDir : srcdir ,
109109 UtilityDir : utldir ,
110- Location : lib .Location .String (),
110+ Location : lib .Location .ToRPCLibraryLocation (),
111111 ContainerPlatform : cntplat ,
112- Layout : lib .Layout .String (),
112+ Layout : lib .Layout .ToRPCLibraryLayout (),
113113 RealName : lib .RealName ,
114114 DotALinkage : lib .DotALinkage ,
115115 Precompiled : lib .Precompiled ,
You can’t perform that action at this time.
0 commit comments