@@ -50,57 +50,67 @@ func LibraryList(ctx context.Context, req *rpc.LibraryListReq) (*rpc.LibraryList
5050
5151	instaledLib  :=  []* rpc.InstalledLibrary {}
5252	res  :=  listLibraries (lm , req .GetUpdatable (), req .GetAll ())
53- 	if  len (res ) >  0  {
54- 		if  f  :=  req .GetFqbn (); f  !=  ""  {
55- 			fqbn , err  :=  cores .ParseFQBN (req .GetFqbn ())
56- 			if  err  !=  nil  {
57- 				return  nil , fmt .Errorf ("parsing fqbn: %s" , err )
58- 			}
59- 			_ , boardPlatform , _ , _ , refBoardPlatform , err  :=  pm .ResolveFQBN (fqbn )
60- 			if  err  !=  nil  {
61- 				return  nil , fmt .Errorf ("loading board data: %s" , err )
62- 			}
53+ 	if  f  :=  req .GetFqbn (); f  !=  ""  {
54+ 		fqbn , err  :=  cores .ParseFQBN (req .GetFqbn ())
55+ 		if  err  !=  nil  {
56+ 			return  nil , fmt .Errorf ("parsing fqbn: %s" , err )
57+ 		}
58+ 		_ , boardPlatform , _ , _ , refBoardPlatform , err  :=  pm .ResolveFQBN (fqbn )
59+ 		if  err  !=  nil  {
60+ 			return  nil , fmt .Errorf ("loading board data: %s" , err )
61+ 		}
6362
64- 			filteredRes  :=  map [string ]* installedLib {}
65- 			for  _ , lib  :=  range  res  {
66- 				if  cp  :=  lib .Library .ContainerPlatform ; cp  !=  nil  {
67- 					if  cp  !=  boardPlatform  &&  cp  !=  refBoardPlatform  {
68- 						// Filter all libraries from extraneous platforms 
69- 						continue 
70- 					}
63+ 		filteredRes  :=  map [string ]* installedLib {}
64+ 		for  _ , lib  :=  range  res  {
65+ 			if  cp  :=  lib .Library .ContainerPlatform ; cp  !=  nil  {
66+ 				if  cp  !=  boardPlatform  &&  cp  !=  refBoardPlatform  {
67+ 					// Filter all libraries from extraneous platforms 
68+ 					continue 
7169				}
72- 				 if   latest ,  has   :=   filteredRes [ lib . Library . Name ];  has  { 
73- 					 if  latest . Library . LocationPriorityFor ( boardPlatform ,  refBoardPlatform )  >=   lib .Library .LocationPriorityFor ( boardPlatform ,  refBoardPlatform )  {
74- 						 continue 
75- 					} 
70+ 			} 
71+ 			if  latest ,  has   :=   filteredRes [ lib .Library .Name ];  has  {
72+ 				if   latest . Library . LocationPriorityFor ( boardPlatform ,  refBoardPlatform )  >=   lib . Library . LocationPriorityFor ( boardPlatform ,  refBoardPlatform ) { 
73+ 					continue 
7674				}
77- 				filteredRes [lib .Library .Name ] =  lib 
7875			}
7976
80- 			res  =  []* installedLib {}
81- 			for  _ , lib  :=  range  filteredRes  {
82- 				res  =  append (res , lib )
77+ 			// Check if library is compatible with board specified by FBQN 
78+ 			compatible  :=  false 
79+ 			for  _ , arch  :=  range  lib .Library .Architectures  {
80+ 				compatible  =  (arch  ==  fqbn .PlatformArch  ||  arch  ==  "*" )
81+ 				if  compatible  {
82+ 					break 
83+ 				}
84+ 			}
85+ 			lib .Library .CompatibleWith  =  map [string ]bool {
86+ 				f : compatible ,
8387			}
88+ 
89+ 			filteredRes [lib .Library .Name ] =  lib 
8490		}
8591
86- 		for  _ , lib  :=  range  res  {
87- 			if  nameFilter  !=  ""  &&  strings .ToLower (lib .Library .Name ) !=  nameFilter  {
88- 				continue 
89- 			}
90- 			libtmp , err  :=  GetOutputLibrary (lib .Library )
91- 			if  err  !=  nil  {
92- 				return  nil , err 
93- 			}
94- 			release  :=  GetOutputRelease (lib .Available )
95- 			instaledLib  =  append (instaledLib , & rpc.InstalledLibrary {
96- 				Library : libtmp ,
97- 				Release : release ,
98- 			})
92+ 		res  =  []* installedLib {}
93+ 		for  _ , lib  :=  range  filteredRes  {
94+ 			res  =  append (res , lib )
9995		}
96+ 	}
10097
101- 		return  & rpc.LibraryListResp {InstalledLibrary : instaledLib }, nil 
98+ 	for  _ , lib  :=  range  res  {
99+ 		if  nameFilter  !=  ""  &&  strings .ToLower (lib .Library .Name ) !=  nameFilter  {
100+ 			continue 
101+ 		}
102+ 		libtmp , err  :=  GetOutputLibrary (lib .Library )
103+ 		if  err  !=  nil  {
104+ 			return  nil , err 
105+ 		}
106+ 		release  :=  GetOutputRelease (lib .Available )
107+ 		instaledLib  =  append (instaledLib , & rpc.InstalledLibrary {
108+ 			Library : libtmp ,
109+ 			Release : release ,
110+ 		})
102111	}
103- 	return  & rpc.LibraryListResp {}, nil 
112+ 
113+ 	return  & rpc.LibraryListResp {InstalledLibrary : instaledLib }, nil 
104114}
105115
106116// listLibraries returns the list of installed libraries. If updatable is true it 
@@ -171,6 +181,7 @@ func GetOutputLibrary(lib *libraries.Library) (*rpc.Library, error) {
171181		License :           lib .License ,
172182		Examples :          lib .Examples .AsStrings (),
173183		ProvidesIncludes :  lib .DeclaredHeaders (),
184+ 		CompatibleWith :    lib .CompatibleWith ,
174185	}, nil 
175186}
176187
0 commit comments