@@ -20,7 +20,6 @@ import (
20
20
21
21
"github.com/arduino/arduino-cli/arduino/builder/compilation"
22
22
"github.com/arduino/arduino-cli/arduino/builder/cpp"
23
- "github.com/arduino/arduino-cli/arduino/builder/logger"
24
23
"github.com/arduino/arduino-cli/arduino/builder/progress"
25
24
"github.com/arduino/arduino-cli/arduino/builder/utils"
26
25
"github.com/arduino/arduino-cli/arduino/libraries"
@@ -37,31 +36,25 @@ var (
37
36
FpuCflag = "fpu"
38
37
)
39
38
40
- // LibrariesBuilder fixdoc
41
- func LibrariesBuilder (
42
- librariesBuildPath * paths.Path ,
43
- buildProperties * properties.Map ,
39
+ // BuildLibraries fixdoc
40
+ func (b * Builder ) BuildLibraries (
44
41
includesFolders paths.PathList ,
45
42
importedLibraries libraries.List ,
46
43
onlyUpdateCompilationDatabase bool ,
47
44
compilationDatabase * compilation.Database ,
48
- jobs int ,
49
- builderLogger * logger.BuilderLogger ,
50
45
progress * progress.Struct , progressCB rpc.TaskProgressCB ,
51
46
) (paths.PathList , error ) {
52
47
includes := f .Map (includesFolders .AsStrings (), cpp .WrapWithHyphenI )
53
48
libs := importedLibraries
54
49
55
- if err := librariesBuildPath .MkdirAll (); err != nil {
50
+ if err := b . librariesBuildPath .MkdirAll (); err != nil {
56
51
return nil , errors .WithStack (err )
57
52
}
58
53
59
- librariesObjectFiles , err := compileLibraries (
60
- libs , librariesBuildPath , buildProperties , includes ,
54
+ librariesObjectFiles , err := b . compileLibraries (
55
+ libs , includes ,
61
56
onlyUpdateCompilationDatabase ,
62
57
compilationDatabase ,
63
- jobs ,
64
- builderLogger ,
65
58
progress , progressCB ,
66
59
)
67
60
if err != nil {
@@ -79,10 +72,9 @@ func directoryContainsFile(folder *paths.Path) bool {
79
72
return false
80
73
}
81
74
82
- func findExpectedPrecompiledLibFolder (
75
+ func ( b * Builder ) findExpectedPrecompiledLibFolder (
83
76
library * libraries.Library ,
84
77
buildProperties * properties.Map ,
85
- builderLogger * logger.BuilderLogger ,
86
78
) * paths.Path {
87
79
mcu := buildProperties .Get ("build.mcu" )
88
80
// Add fpu specifications if they exist
@@ -109,47 +101,43 @@ func findExpectedPrecompiledLibFolder(
109
101
}
110
102
}
111
103
112
- builderLogger .Info (tr ("Library %[1]s has been declared precompiled:" , library .Name ))
104
+ b . logger .Info (tr ("Library %[1]s has been declared precompiled:" , library .Name ))
113
105
114
106
// Try directory with full fpuSpecs first, if available
115
107
if len (fpuSpecs ) > 0 {
116
108
fpuSpecs = strings .TrimRight (fpuSpecs , "-" )
117
109
fullPrecompDir := library .SourceDir .Join (mcu ).Join (fpuSpecs )
118
110
if fullPrecompDir .Exist () && directoryContainsFile (fullPrecompDir ) {
119
- builderLogger .Info (tr ("Using precompiled library in %[1]s" , fullPrecompDir ))
111
+ b . logger .Info (tr ("Using precompiled library in %[1]s" , fullPrecompDir ))
120
112
return fullPrecompDir
121
113
}
122
- builderLogger .Info (tr (`Precompiled library in "%[1]s" not found` , fullPrecompDir ))
114
+ b . logger .Info (tr (`Precompiled library in "%[1]s" not found` , fullPrecompDir ))
123
115
}
124
116
125
117
precompDir := library .SourceDir .Join (mcu )
126
118
if precompDir .Exist () && directoryContainsFile (precompDir ) {
127
- builderLogger .Info (tr ("Using precompiled library in %[1]s" , precompDir ))
119
+ b . logger .Info (tr ("Using precompiled library in %[1]s" , precompDir ))
128
120
return precompDir
129
121
}
130
- builderLogger .Info (tr (`Precompiled library in "%[1]s" not found` , precompDir ))
122
+ b . logger .Info (tr (`Precompiled library in "%[1]s" not found` , precompDir ))
131
123
return nil
132
124
}
133
125
134
- func compileLibraries (
135
- libraries libraries.List , buildPath * paths. Path , buildProperties * properties. Map , includes []string ,
126
+ func ( b * Builder ) compileLibraries (
127
+ libraries libraries.List , includes []string ,
136
128
onlyUpdateCompilationDatabase bool ,
137
129
compilationDatabase * compilation.Database ,
138
- jobs int ,
139
- builderLogger * logger.BuilderLogger ,
140
130
progress * progress.Struct , progressCB rpc.TaskProgressCB ,
141
131
) (paths.PathList , error ) {
142
132
progress .AddSubSteps (len (libraries ))
143
133
defer progress .RemoveSubSteps ()
144
134
145
135
objectFiles := paths .NewPathList ()
146
136
for _ , library := range libraries {
147
- libraryObjectFiles , err := compileLibrary (
148
- library , buildPath , buildProperties , includes ,
137
+ libraryObjectFiles , err := b . compileLibrary (
138
+ library , includes ,
149
139
onlyUpdateCompilationDatabase ,
150
140
compilationDatabase ,
151
- jobs ,
152
- builderLogger ,
153
141
progress , progressCB ,
154
142
)
155
143
if err != nil {
@@ -170,18 +158,16 @@ func compileLibraries(
170
158
return objectFiles , nil
171
159
}
172
160
173
- func compileLibrary (
174
- library * libraries.Library , buildPath * paths. Path , buildProperties * properties. Map , includes []string ,
161
+ func ( b * Builder ) compileLibrary (
162
+ library * libraries.Library , includes []string ,
175
163
onlyUpdateCompilationDatabase bool ,
176
164
compilationDatabase * compilation.Database ,
177
- jobs int ,
178
- builderLogger * logger.BuilderLogger ,
179
165
progress * progress.Struct , progressCB rpc.TaskProgressCB ,
180
166
) (paths.PathList , error ) {
181
- if builderLogger .Verbose () {
182
- builderLogger .Info (tr (`Compiling library "%[1]s"` , library .Name ))
167
+ if b . logger .Verbose () {
168
+ b . logger .Info (tr (`Compiling library "%[1]s"` , library .Name ))
183
169
}
184
- libraryBuildPath := buildPath .Join (library .DirName )
170
+ libraryBuildPath := b . librariesBuildPath .Join (library .DirName )
185
171
186
172
if err := libraryBuildPath .MkdirAll (); err != nil {
187
173
return nil , errors .WithStack (err )
@@ -190,15 +176,14 @@ func compileLibrary(
190
176
objectFiles := paths .NewPathList ()
191
177
192
178
if library .Precompiled {
193
- coreSupportPrecompiled := buildProperties .ContainsKey ("compiler.libraries.ldflags" )
194
- precompiledPath := findExpectedPrecompiledLibFolder (
179
+ coreSupportPrecompiled := b . buildProperties .ContainsKey ("compiler.libraries.ldflags" )
180
+ precompiledPath := b . findExpectedPrecompiledLibFolder (
195
181
library ,
196
- buildProperties ,
197
- builderLogger ,
182
+ b .buildProperties ,
198
183
)
199
184
200
185
if ! coreSupportPrecompiled {
201
- builderLogger .Info (tr ("The platform does not support '%[1]s' for precompiled libraries." , "compiler.libraries.ldflags" ))
186
+ b . logger .Info (tr ("The platform does not support '%[1]s' for precompiled libraries." , "compiler.libraries.ldflags" ))
202
187
} else if precompiledPath != nil {
203
188
// Find all libraries in precompiledPath
204
189
libs , err := precompiledPath .ReadDir ()
@@ -217,8 +202,8 @@ func compileLibrary(
217
202
}
218
203
}
219
204
220
- currLDFlags := buildProperties .Get ("compiler.libraries.ldflags" )
221
- buildProperties .Set ("compiler.libraries.ldflags" , currLDFlags + " \" -L" + precompiledPath .String ()+ "\" " + libsCmd + " " )
205
+ currLDFlags := b . buildProperties .Get ("compiler.libraries.ldflags" )
206
+ b . buildProperties .Set ("compiler.libraries.ldflags" , currLDFlags + " \" -L" + precompiledPath .String ()+ "\" " + libsCmd + " " )
222
207
223
208
// TODO: This codepath is just taken for .a with unusual names that would
224
209
// be ignored by -L / -l methods.
@@ -239,24 +224,24 @@ func compileLibrary(
239
224
240
225
if library .Layout == libraries .RecursiveLayout {
241
226
libObjectFiles , err := utils .CompileFilesRecursive (
242
- library .SourceDir , libraryBuildPath , buildProperties , includes ,
227
+ library .SourceDir , libraryBuildPath , b . buildProperties , includes ,
243
228
onlyUpdateCompilationDatabase ,
244
229
compilationDatabase ,
245
- jobs ,
246
- builderLogger ,
230
+ b . jobs ,
231
+ b . logger ,
247
232
progress , progressCB ,
248
233
)
249
234
if err != nil {
250
235
return nil , errors .WithStack (err )
251
236
}
252
237
if library .DotALinkage {
253
238
archiveFile , verboseInfo , err := utils .ArchiveCompiledFiles (
254
- libraryBuildPath , paths .New (library .DirName + ".a" ), libObjectFiles , buildProperties ,
255
- onlyUpdateCompilationDatabase , builderLogger .Verbose (),
256
- builderLogger . Stdout (), builderLogger .Stderr (),
239
+ libraryBuildPath , paths .New (library .DirName + ".a" ), libObjectFiles , b . buildProperties ,
240
+ onlyUpdateCompilationDatabase , b . logger .Verbose (),
241
+ b . logger . Stdout (), b . logger .Stderr (),
257
242
)
258
- if builderLogger .Verbose () {
259
- builderLogger .Info (string (verboseInfo ))
243
+ if b . logger .Verbose () {
244
+ b . logger .Info (string (verboseInfo ))
260
245
}
261
246
if err != nil {
262
247
return nil , errors .WithStack (err )
@@ -270,11 +255,11 @@ func compileLibrary(
270
255
includes = append (includes , cpp .WrapWithHyphenI (library .UtilityDir .String ()))
271
256
}
272
257
libObjectFiles , err := utils .CompileFiles (
273
- library .SourceDir , libraryBuildPath , buildProperties , includes ,
258
+ library .SourceDir , libraryBuildPath , b . buildProperties , includes ,
274
259
onlyUpdateCompilationDatabase ,
275
260
compilationDatabase ,
276
- jobs ,
277
- builderLogger ,
261
+ b . jobs ,
262
+ b . logger ,
278
263
progress , progressCB ,
279
264
)
280
265
if err != nil {
@@ -285,11 +270,11 @@ func compileLibrary(
285
270
if library .UtilityDir != nil {
286
271
utilityBuildPath := libraryBuildPath .Join ("utility" )
287
272
utilityObjectFiles , err := utils .CompileFiles (
288
- library .UtilityDir , utilityBuildPath , buildProperties , includes ,
273
+ library .UtilityDir , utilityBuildPath , b . buildProperties , includes ,
289
274
onlyUpdateCompilationDatabase ,
290
275
compilationDatabase ,
291
- jobs ,
292
- builderLogger ,
276
+ b . jobs ,
277
+ b . logger ,
293
278
progress , progressCB ,
294
279
)
295
280
if err != nil {
0 commit comments