@@ -17,13 +17,14 @@ package compile
1717
1818import (
1919 "context"
20- "errors "
20+ "fmt "
2121 "io"
2222 "path/filepath"
2323 "sort"
2424 "strconv"
2525 "strings"
2626
27+ "github.com/arduino/arduino-cli/arduino"
2728 bldr "github.com/arduino/arduino-cli/arduino/builder"
2829 "github.com/arduino/arduino-cli/arduino/cores"
2930 "github.com/arduino/arduino-cli/arduino/cores/packagemanager"
@@ -89,29 +90,29 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
8990
9091 pm := commands .GetPackageManager (req .GetInstance ().GetId ())
9192 if pm == nil {
92- return nil , & commands .InvalidInstanceError {}
93+ return nil , & arduino .InvalidInstanceError {}
9394 }
9495
9596 logrus .Tracef ("Compile %s for %s started" , req .GetSketchPath (), req .GetFqbn ())
9697 if req .GetSketchPath () == "" {
97- return nil , & commands .MissingSketchPathError {}
98+ return nil , & arduino .MissingSketchPathError {}
9899 }
99100 sketchPath := paths .New (req .GetSketchPath ())
100101 sk , err := sketch .New (sketchPath )
101102 if err != nil {
102- return nil , & commands .CantOpenSketchError {Cause : err }
103+ return nil , & arduino .CantOpenSketchError {Cause : err }
103104 }
104105
105106 fqbnIn := req .GetFqbn ()
106107 if fqbnIn == "" && sk != nil && sk .Metadata != nil {
107108 fqbnIn = sk .Metadata .CPU .Fqbn
108109 }
109110 if fqbnIn == "" {
110- return nil , & commands .MissingFQBNError {}
111+ return nil , & arduino .MissingFQBNError {}
111112 }
112113 fqbn , err := cores .ParseFQBN (fqbnIn )
113114 if err != nil {
114- return nil , & commands .InvalidFQBNError {Cause : err }
115+ return nil , & arduino .InvalidFQBNError {Cause : err }
115116 }
116117
117118 targetPlatform := pm .FindPlatform (& packagemanager.PlatformReference {
@@ -124,7 +125,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
124125 // "\"%[1]s:%[2]s\" platform is not installed, please install it by running \""+
125126 // version.GetAppName()+" core install %[1]s:%[2]s\".", fqbn.Package, fqbn.PlatformArch)
126127 // feedback.Error(errorMessage)
127- return nil , & commands .PlatformNotFound {Platform : targetPlatform .String (), Cause : errors . New (tr ("platform not installed" ))}
128+ return nil , & arduino .PlatformNotFound {Platform : targetPlatform .String (), Cause : fmt . Errorf (tr ("platform not installed" ))}
128129 }
129130
130131 builderCtx := & types.Context {}
@@ -147,7 +148,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
147148 builderCtx .BuildPath = paths .New (req .GetBuildPath ()).Canonical ()
148149 }
149150 if err = builderCtx .BuildPath .MkdirAll (); err != nil {
150- return nil , & commands .PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
151+ return nil , & arduino .PermissionDeniedError {Message : tr ("Cannot create build directory" ), Cause : err }
151152 }
152153 builderCtx .CompilationDatabase = bldr .NewCompilationDatabase (
153154 builderCtx .BuildPath .Join ("compile_commands.json" ),
@@ -177,7 +178,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
177178 builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
178179 err = builderCtx .BuildCachePath .MkdirAll ()
179180 if err != nil {
180- return nil , & commands .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
181+ return nil , & arduino .PermissionDeniedError {Message : tr ("Cannot create build cache directory" ), Cause : err }
181182 }
182183 }
183184
@@ -222,20 +223,20 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
222223 if req .GetShowProperties () {
223224 compileErr := builder .RunParseHardwareAndDumpBuildProperties (builderCtx )
224225 if compileErr != nil {
225- compileErr = & commands .CompileFailedError {Message : err .Error ()}
226+ compileErr = & arduino .CompileFailedError {Message : err .Error ()}
226227 }
227228 return r , compileErr
228229 } else if req .GetPreprocess () {
229230 compileErr := builder .RunPreprocess (builderCtx )
230231 if compileErr != nil {
231- compileErr = & commands .CompileFailedError {Message : err .Error ()}
232+ compileErr = & arduino .CompileFailedError {Message : err .Error ()}
232233 }
233234 return r , compileErr
234235 }
235236
236237 // if it's a regular build, go on...
237238 if err := builder .RunBuilder (builderCtx ); err != nil {
238- return r , & commands .CompileFailedError {Message : err .Error ()}
239+ return r , & arduino .CompileFailedError {Message : err .Error ()}
239240 }
240241
241242 // If the export directory is set we assume you want to export the binaries
@@ -257,17 +258,17 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
257258 }
258259 logrus .WithField ("path" , exportPath ).Trace ("Saving sketch to export path." )
259260 if err := exportPath .MkdirAll (); err != nil {
260- return r , & commands .PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
261+ return r , & arduino .PermissionDeniedError {Message : tr ("Error creating output dir" ), Cause : err }
261262 }
262263
263264 // Copy all "sketch.ino.*" artifacts to the export directory
264265 baseName , ok := builderCtx .BuildProperties .GetOk ("build.project_name" ) // == "sketch.ino"
265266 if ! ok {
266- return r , & commands .MissingPlatformPropertyError {Property : "build.project_name" }
267+ return r , & arduino .MissingPlatformPropertyError {Property : "build.project_name" }
267268 }
268269 buildFiles , err := builderCtx .BuildPath .ReadDir ()
269270 if err != nil {
270- return r , & commands .PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
271+ return r , & arduino .PermissionDeniedError {Message : tr ("Error reading build directory" ), Cause : err }
271272 }
272273 buildFiles .FilterPrefix (baseName )
273274 for _ , buildFile := range buildFiles {
@@ -277,7 +278,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
277278 WithField ("dest" , exportedFile ).
278279 Trace ("Copying artifact." )
279280 if err = buildFile .CopyTo (exportedFile ); err != nil {
280- return r , & commands .PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
281+ return r , & arduino .PermissionDeniedError {Message : tr ("Error copying output file %s" , buildFile ), Cause : err }
281282 }
282283 }
283284 }
@@ -286,7 +287,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
286287 for _ , lib := range builderCtx .ImportedLibraries {
287288 rpcLib , err := lib .ToRPCLibrary ()
288289 if err != nil {
289- return r , & commands .PermissionDeniedError {Message : tr ("Error getting information for library %s" , lib .Name ), Cause : err }
290+ return r , & arduino .PermissionDeniedError {Message : tr ("Error getting information for library %s" , lib .Name ), Cause : err }
290291 }
291292 importedLibs = append (importedLibs , rpcLib )
292293 }
0 commit comments