@@ -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
@@ -183,7 +196,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
183
196
builderCtx .OnlyUpdateCompilationDatabase = req .GetCreateCompilationDatabaseOnly ()
184
197
builderCtx .SourceOverride = req .GetSourceOverride ()
185
198
186
- r = & rpc.CompileResponse {}
187
199
defer func () {
188
200
if p := builderCtx .BuildPath ; p != nil {
189
201
r .BuildPath = p .String ()
@@ -196,18 +208,6 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
196
208
}
197
209
}()
198
210
199
- defer func () {
200
- buildProperties := builderCtx .BuildProperties
201
- if buildProperties == nil {
202
- return
203
- }
204
- keys := buildProperties .Keys ()
205
- sort .Strings (keys )
206
- for _ , key := range keys {
207
- r .BuildProperties = append (r .BuildProperties , key + "=" + buildProperties .Get (key ))
208
- }
209
- }()
210
-
211
211
if req .GetShowProperties () {
212
212
// Just get build properties and exit
213
213
compileErr := builder .RunParseHardware (builderCtx )
@@ -227,16 +227,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
227
227
}
228
228
229
229
defer func () {
230
- importedLibs := []* rpc.Library {}
231
- for _ , lib := range builderCtx .ImportedLibraries {
232
- rpcLib , err := lib .ToRPCLibrary ()
233
- if err != nil {
234
- msg := tr ("Error getting information for library %s" , lib .Name ) + ": " + err .Error () + "\n "
235
- errStream .Write ([]byte (msg ))
236
- }
237
- importedLibs = append (importedLibs , rpcLib )
238
- }
239
- r .UsedLibraries = importedLibs
230
+ appendUserLibraries (r , builderCtx , errStream )
240
231
}()
241
232
242
233
// if it's a regular build, go on...
@@ -295,6 +286,32 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
295
286
return r , nil
296
287
}
297
288
289
+ func appendUserLibraries (r * rpc.CompileResponse , builderCtx * types.Context , errStream io.Writer ) {
290
+ importedLibs := []* rpc.Library {}
291
+ for _ , lib := range builderCtx .ImportedLibraries {
292
+ rpcLib , err := lib .ToRPCLibrary ()
293
+ if err != nil {
294
+ msg := tr ("Error getting information for library %s" , lib .Name ) + ": " + err .Error () + "\n "
295
+ errStream .Write ([]byte (msg ))
296
+ }
297
+ importedLibs = append (importedLibs , rpcLib )
298
+ }
299
+ r .UsedLibraries = importedLibs
300
+ }
301
+
302
+ func appendBuildProperties (r * rpc.CompileResponse , builderCtx * types.Context ) bool {
303
+ buildProperties := builderCtx .BuildProperties
304
+ if buildProperties == nil {
305
+ return true
306
+ }
307
+ keys := buildProperties .Keys ()
308
+ sort .Strings (keys )
309
+ for _ , key := range keys {
310
+ r .BuildProperties = append (r .BuildProperties , key + "=" + buildProperties .Get (key ))
311
+ }
312
+ return false
313
+ }
314
+
298
315
// maybePurgeBuildCache runs the build files cache purge if the policy conditions are met.
299
316
func maybePurgeBuildCache () {
300
317
0 commit comments