@@ -73,11 +73,14 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
73
73
return nil , & arduino.MissingSketchPathError {}
74
74
}
75
75
sketchPath := paths .New (req .GetSketchPath ())
76
- sk , err := sketch .New (sketchPath )
77
- if err != nil {
78
- return nil , & arduino.CantOpenSketchError {Cause : err }
76
+ builderCtx := & types.Context {}
77
+ builderCtx .PackageManager = pme
78
+ if pme .GetProfile () != nil {
79
+ builderCtx .LibrariesManager = lm
79
80
}
80
81
82
+ sk , newSketchErr := sketch .New (sketchPath )
83
+
81
84
fqbnIn := req .GetFqbn ()
82
85
if fqbnIn == "" && sk != nil {
83
86
fqbnIn = sk .GetDefaultFQBN ()
@@ -111,13 +114,23 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
111
114
securityKeysOverride = append (securityKeysOverride , "build.keys.keychain=" + req .KeysKeychain , "build.keys.sign_key=" + req .GetSignKey (), "build.keys.encrypt_key=" + req .EncryptKey )
112
115
}
113
116
114
- builderCtx := & types.Context {}
115
- builderCtx .PackageManager = pme
116
- if pme .GetProfile () != nil {
117
- builderCtx .LibrariesManager = lm
118
- }
119
117
builderCtx .UseCachedLibrariesResolution = req .GetSkipLibrariesDiscovery ()
120
118
builderCtx .FQBN = fqbn
119
+ defer func () {
120
+ appendBuildProperties (r , builderCtx )
121
+ }()
122
+ r = & rpc.CompileResponse {}
123
+ if newSketchErr != nil {
124
+ if req .GetShowProperties () {
125
+ // Just get build properties and exit
126
+ compileErr := builder .RunParseHardware (builderCtx )
127
+ if compileErr != nil {
128
+ compileErr = & arduino.CompileFailedError {Message : compileErr .Error ()}
129
+ }
130
+ return r , compileErr
131
+ }
132
+ return nil , & arduino.CantOpenSketchError {Cause : err }
133
+ }
121
134
builderCtx .Sketch = sk
122
135
builderCtx .ProgressCB = progressCB
123
136
@@ -187,7 +200,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
187
200
builderCtx .OnlyUpdateCompilationDatabase = req .GetCreateCompilationDatabaseOnly ()
188
201
builderCtx .SourceOverride = req .GetSourceOverride ()
189
202
190
- r = & rpc.CompileResponse {}
191
203
defer func () {
192
204
if p := builderCtx .BuildPath ; p != nil {
193
205
r .BuildPath = p .String ()
@@ -200,18 +212,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
200
212
}
201
213
}()
202
214
203
- defer func () {
204
- buildProperties := builderCtx .BuildProperties
205
- if buildProperties == nil {
206
- return
207
- }
208
- keys := buildProperties .Keys ()
209
- sort .Strings (keys )
210
- for _ , key := range keys {
211
- r .BuildProperties = append (r .BuildProperties , key + "=" + buildProperties .Get (key ))
212
- }
213
- }()
214
-
215
215
if req .GetShowProperties () {
216
216
// Just get build properties and exit
217
217
compileErr := builder .RunParseHardware (builderCtx )
@@ -231,16 +231,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
231
231
}
232
232
233
233
defer func () {
234
- importedLibs := []* rpc.Library {}
235
- for _ , lib := range builderCtx .ImportedLibraries {
236
- rpcLib , err := lib .ToRPCLibrary ()
237
- if err != nil {
238
- msg := tr ("Error getting information for library %s" , lib .Name ) + ": " + err .Error () + "\n "
239
- errStream .Write ([]byte (msg ))
240
- }
241
- importedLibs = append (importedLibs , rpcLib )
242
- }
243
- r .UsedLibraries = importedLibs
234
+ appendUserLibraries (r , builderCtx , errStream )
244
235
}()
245
236
246
237
// if it's a regular build, go on...
@@ -309,6 +300,32 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
309
300
return r , nil
310
301
}
311
302
303
+ func appendUserLibraries (r * rpc.CompileResponse , builderCtx * types.Context , errStream io.Writer ) {
304
+ importedLibs := []* rpc.Library {}
305
+ for _ , lib := range builderCtx .ImportedLibraries {
306
+ rpcLib , err := lib .ToRPCLibrary ()
307
+ if err != nil {
308
+ msg := tr ("Error getting information for library %s" , lib .Name ) + ": " + err .Error () + "\n "
309
+ errStream .Write ([]byte (msg ))
310
+ }
311
+ importedLibs = append (importedLibs , rpcLib )
312
+ }
313
+ r .UsedLibraries = importedLibs
314
+ }
315
+
316
+ func appendBuildProperties (r * rpc.CompileResponse , builderCtx * types.Context ) bool {
317
+ buildProperties := builderCtx .BuildProperties
318
+ if buildProperties == nil {
319
+ return true
320
+ }
321
+ keys := buildProperties .Keys ()
322
+ sort .Strings (keys )
323
+ for _ , key := range keys {
324
+ r .BuildProperties = append (r .BuildProperties , key + "=" + buildProperties .Get (key ))
325
+ }
326
+ return false
327
+ }
328
+
312
329
// maybePurgeBuildCache runs the build files cache purge if the policy conditions are met.
313
330
func maybePurgeBuildCache () {
314
331
0 commit comments