@@ -17,7 +17,6 @@ package phases
17
17
18
18
import (
19
19
"os"
20
- "path/filepath"
21
20
"strings"
22
21
23
22
"github.com/arduino/arduino-cli/arduino/libraries"
@@ -137,25 +136,20 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
137
136
138
137
if library .Precompiled {
139
138
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
+ }
144
144
145
145
// Add required LD flags
146
-
147
- // find all library names in the folder and prepend -l
148
- dynAndStaticLibs := []string {}
149
146
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" )
153
149
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 ())
156
151
if strings .HasPrefix (name , "lib" ) {
157
- name = strings .Replace (name , "lib" , "" , 1 )
158
- libsCmd += "-l" + name + " "
152
+ libsCmd += "-l" + name [3 :] + " "
159
153
}
160
154
}
161
155
@@ -171,13 +165,11 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
171
165
// TODO: This codepath is just taken for .a with unusual names that would
172
166
// be ignored by -L / -l methods.
173
167
// 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 )
181
173
}
182
174
}
183
175
return objectFiles , nil
0 commit comments