@@ -23,9 +23,9 @@ import (
23
23
"sort"
24
24
"strings"
25
25
26
+ "github.com/arduino/arduino-cli/commands/cmderrors"
26
27
"github.com/arduino/arduino-cli/commands/internal/instances"
27
28
"github.com/arduino/arduino-cli/i18n"
28
- "github.com/arduino/arduino-cli/internal/arduino"
29
29
"github.com/arduino/arduino-cli/internal/arduino/builder"
30
30
"github.com/arduino/arduino-cli/internal/arduino/cores"
31
31
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesmanager"
@@ -59,23 +59,23 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
59
59
60
60
pme , release := instances .GetPackageManagerExplorer (req .GetInstance ())
61
61
if pme == nil {
62
- return nil , & arduino .InvalidInstanceError {}
62
+ return nil , & cmderrors .InvalidInstanceError {}
63
63
}
64
64
defer release ()
65
65
66
66
lm := instances .GetLibraryManager (req .GetInstance ())
67
67
if lm == nil {
68
- return nil , & arduino .InvalidInstanceError {}
68
+ return nil , & cmderrors .InvalidInstanceError {}
69
69
}
70
70
71
71
logrus .Tracef ("Compile %s for %s started" , req .GetSketchPath (), req .GetFqbn ())
72
72
if req .GetSketchPath () == "" {
73
- return nil , & arduino .MissingSketchPathError {}
73
+ return nil , & cmderrors .MissingSketchPathError {}
74
74
}
75
75
sketchPath := paths .New (req .GetSketchPath ())
76
76
sk , err := sketch .New (sketchPath )
77
77
if err != nil {
78
- return nil , & arduino .CantOpenSketchError {Cause : err }
78
+ return nil , & cmderrors .CantOpenSketchError {Cause : err }
79
79
}
80
80
81
81
fqbnIn := req .GetFqbn ()
@@ -87,22 +87,22 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
87
87
}
88
88
}
89
89
if fqbnIn == "" {
90
- return nil , & arduino .MissingFQBNError {}
90
+ return nil , & cmderrors .MissingFQBNError {}
91
91
}
92
92
93
93
fqbn , err := cores .ParseFQBN (fqbnIn )
94
94
if err != nil {
95
- return nil , & arduino .InvalidFQBNError {Cause : err }
95
+ return nil , & cmderrors .InvalidFQBNError {Cause : err }
96
96
}
97
97
_ , targetPlatform , targetBoard , boardBuildProperties , buildPlatform , err := pme .ResolveFQBN (fqbn )
98
98
if err != nil {
99
99
if targetPlatform == nil {
100
- return nil , & arduino .PlatformNotFoundError {
100
+ return nil , & cmderrors .PlatformNotFoundError {
101
101
Platform : fmt .Sprintf ("%s:%s" , fqbn .Package , fqbn .PlatformArch ),
102
102
Cause : fmt .Errorf (tr ("platform not installed" )),
103
103
}
104
104
}
105
- return nil , & arduino .InvalidFQBNError {Cause : err }
105
+ return nil , & cmderrors .InvalidFQBNError {Cause : err }
106
106
}
107
107
108
108
r = & rpc.CompileResponse {}
@@ -145,7 +145,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
145
145
buildPath = sk .DefaultBuildPath ()
146
146
}
147
147
if err = buildPath .MkdirAll (); err != nil {
148
- return nil , & arduino .PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
148
+ return nil , & cmderrors .PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
149
149
}
150
150
buildcache .New (buildPath .Parent ()).GetOrCreate (buildPath .Base ())
151
151
// cache is purged after compilation to not remove entries that might be required
@@ -157,10 +157,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
157
157
} else {
158
158
buildCachePath , err := paths .New (req .GetBuildCachePath ()).Abs ()
159
159
if err != nil {
160
- return nil , & arduino .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
160
+ return nil , & cmderrors .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
161
161
}
162
162
if err := buildCachePath .MkdirAll (); err != nil {
163
- return nil , & arduino .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
163
+ return nil , & cmderrors .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
164
164
}
165
165
coreBuildCachePath = buildCachePath .Join ("core" )
166
166
}
@@ -203,14 +203,14 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
203
203
)
204
204
if err != nil {
205
205
if strings .Contains (err .Error (), "invalid build properties" ) {
206
- return nil , & arduino .InvalidArgumentError {Message : tr ("Invalid build properties" ), Cause : err }
206
+ return nil , & cmderrors .InvalidArgumentError {Message : tr ("Invalid build properties" ), Cause : err }
207
207
}
208
208
if errors .Is (err , builder .ErrSketchCannotBeLocatedInBuildPath ) {
209
- return r , & arduino .CompileFailedError {
209
+ return r , & cmderrors .CompileFailedError {
210
210
Message : tr ("Sketch cannot be located in build path. Please specify a different build path" ),
211
211
}
212
212
}
213
- return r , & arduino .CompileFailedError {Message : err .Error ()}
213
+ return r , & cmderrors .CompileFailedError {Message : err .Error ()}
214
214
}
215
215
216
216
defer func () {
@@ -247,7 +247,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
247
247
// Just output preprocessed source code and exit
248
248
preprocessedSketch , err := sketchBuilder .Preprocess ()
249
249
if err != nil {
250
- err = & arduino .CompileFailedError {Message : err .Error ()}
250
+ err = & cmderrors .CompileFailedError {Message : err .Error ()}
251
251
return r , err
252
252
}
253
253
_ , err = outStream .Write (preprocessedSketch )
@@ -293,7 +293,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
293
293
}
294
294
295
295
if err := sketchBuilder .Build (); err != nil {
296
- return r , & arduino .CompileFailedError {Message : err .Error ()}
296
+ return r , & cmderrors .CompileFailedError {Message : err .Error ()}
297
297
}
298
298
299
299
// If the export directory is set we assume you want to export the binaries
@@ -321,23 +321,23 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
321
321
if ! buildPath .EqualsTo (exportPath ) {
322
322
logrus .WithField ("path" , exportPath ).Trace ("Saving sketch to export path." )
323
323
if err := exportPath .MkdirAll (); err != nil {
324
- return r , & arduino .PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
324
+ return r , & cmderrors .PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
325
325
}
326
326
327
327
baseName , ok := sketchBuilder .GetBuildProperties ().GetOk ("build.project_name" ) // == "sketch.ino"
328
328
if ! ok {
329
- return r , & arduino .MissingPlatformPropertyError {Property : "build.project_name" }
329
+ return r , & cmderrors .MissingPlatformPropertyError {Property : "build.project_name" }
330
330
}
331
331
buildFiles , err := sketchBuilder .GetBuildPath ().ReadDir ()
332
332
if err != nil {
333
- return r , & arduino .PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
333
+ return r , & cmderrors .PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
334
334
}
335
335
buildFiles .FilterPrefix (baseName )
336
336
for _ , buildFile := range buildFiles {
337
337
exportedFile := exportPath .Join (buildFile .Base ())
338
338
logrus .WithField ("src" , buildFile ).WithField ("dest" , exportedFile ).Trace ("Copying artifact." )
339
339
if err = buildFile .CopyTo (exportedFile ); err != nil {
340
- return r , & arduino .PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
340
+ return r , & cmderrors .PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
341
341
}
342
342
}
343
343
}
0 commit comments