@@ -17,7 +17,6 @@ package phases
1717
1818import (
1919 "os"
20- "path/filepath"
2120 "strings"
2221
2322 "github.com/arduino/arduino-cli/arduino/libraries"
@@ -137,25 +136,20 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
137136
138137 if library .Precompiled {
139138 if precompiledPath := findExpectedPrecompiledLibFolder (ctx , library ); precompiledPath != nil {
140- var staticLibExts = map [string ]bool {".a" : true }
141- var dynamixLibExts = map [string ]bool {".so" : true }
142- dynAndStatic := func (ext string ) bool { return dynamixLibExts [ext ] || staticLibExts [ext ] }
143- staticOnly := func (ext string ) bool { return staticLibExts [ext ] }
139+ // Find all libraries in precompiledPath
140+ libs , err := precompiledPath .ReadDir ()
141+ if err != nil {
142+ return nil , errors .WithStack (err )
143+ }
144144
145145 // Add required LD flags
146-
147- // find all library names in the folder and prepend -l
148- dynAndStaticLibs := []string {}
149146 libsCmd := library .LDflags + " "
150- if err := utils .FindFilesInFolder (& dynAndStaticLibs , precompiledPath .String (), dynAndStatic , false ); err != nil {
151- return nil , errors .WithStack (err )
152- }
147+ dynAndStaticLibs := libs .Clone ()
148+ dynAndStaticLibs .FilterSuffix (".a" , ".so" )
153149 for _ , lib := range dynAndStaticLibs {
154- name := strings .TrimSuffix (filepath .Base (lib ), filepath .Ext (lib ))
155- // strip "lib" first occurrence
150+ name := strings .TrimSuffix (lib .Base (), lib .Ext ())
156151 if strings .HasPrefix (name , "lib" ) {
157- name = strings .Replace (name , "lib" , "" , 1 )
158- libsCmd += "-l" + name + " "
152+ libsCmd += "-l" + name [3 :] + " "
159153 }
160154 }
161155
@@ -171,13 +165,11 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
171165 // TODO: This codepath is just taken for .a with unusual names that would
172166 // be ignored by -L / -l methods.
173167 // Should we force precompiled libraries to start with "lib" ?
174- staticLibs := []string {}
175- if err := utils .FindFilesInFolder (& staticLibs , precompiledPath .String (), staticOnly , false ); err != nil {
176- return nil , errors .WithStack (err )
177- }
178- for _ , path := range staticLibs {
179- if ! strings .HasPrefix (filepath .Base (path ), "lib" ) {
180- objectFiles .Add (paths .New (path ))
168+ staticLibs := libs .Clone ()
169+ staticLibs .FilterSuffix (".a" )
170+ for _ , lib := range staticLibs {
171+ if ! strings .HasPrefix (lib .Base (), "lib" ) {
172+ objectFiles .Add (lib )
181173 }
182174 }
183175 return objectFiles , nil
0 commit comments