@@ -117,7 +117,8 @@ func StartApp(ctx context.Context, docker *dockerClient.Client, app parser.App)
117117 })
118118
119119 if app .MainSketchFile != nil {
120- if err := compileUploadSketch (ctx , app .MainSketchFile .String (), callbackWriter ); err != nil {
120+ buildPath := app .FullPath .Join (".cache" , "sketch" ).String ()
121+ if err := compileUploadSketch (ctx , app .MainSketchFile .String (), buildPath , callbackWriter ); err != nil {
121122 yield (StreamMessage {error : err })
122123 return
123124 }
@@ -171,9 +172,11 @@ func StopApp(ctx context.Context, app parser.App) iter.Seq[StreamMessage] {
171172 }
172173 })
173174 if app .MainSketchFile != nil {
174- // Flash empty sketch to stop the microcontroller.
175175 // TODO: check that the app sketch is running before attempting to stop it.
176- if err := compileUploadSketch (ctx , getEmptySketch (), callbackWriter ); err != nil {
176+
177+ // Flash empty sketch to stop the microcontroller.
178+ buildPath := "" // the empty sketch' build path must be in the default temporary directory.
179+ if err := compileUploadSketch (ctx , getEmptySketch (), buildPath , callbackWriter ); err != nil {
177180 panic (err )
178181 }
179182 }
@@ -521,7 +524,7 @@ func getDevices() []string {
521524 return deviceList .AsStrings ()
522525}
523526
524- func compileUploadSketch (ctx context.Context , path string , w io.Writer ) error {
527+ func compileUploadSketch (ctx context.Context , sketchPath , buildPath string , w io.Writer ) error {
525528 logrus .SetLevel (logrus .ErrorLevel )
526529 srv := commands .NewArduinoCoreServer ()
527530
@@ -536,12 +539,12 @@ func compileUploadSketch(ctx context.Context, path string, w io.Writer) error {
536539 _ , _ = srv .Destroy (ctx , & rpc.DestroyRequest {Instance : inst })
537540 }()
538541
539- sketchResp , err := srv .LoadSketch (ctx , & rpc.LoadSketchRequest {SketchPath : path })
542+ sketchResp , err := srv .LoadSketch (ctx , & rpc.LoadSketchRequest {SketchPath : sketchPath })
540543 if err != nil {
541544 return err
542545 }
543546 sketch := sketchResp .GetSketch ()
544- initReq := & rpc.InitRequest {Instance : inst , SketchPath : path }
547+ initReq := & rpc.InitRequest {Instance : inst , SketchPath : sketchPath }
545548 if profile := sketch .GetDefaultProfile ().GetName (); profile != "" {
546549 initReq .Profile = profile
547550 }
@@ -583,7 +586,8 @@ func compileUploadSketch(ctx context.Context, path string, w io.Writer) error {
583586 err = srv .Compile (& rpc.CompileRequest {
584587 Instance : inst ,
585588 Fqbn : fqbn ,
586- SketchPath : path ,
589+ SketchPath : sketchPath ,
590+ BuildPath : buildPath ,
587591 }, server )
588592 if err != nil {
589593 return err
@@ -593,7 +597,7 @@ func compileUploadSketch(ctx context.Context, path string, w io.Writer) error {
593597 err = srv .Upload (& rpc.UploadRequest {
594598 Instance : inst ,
595599 Fqbn : fqbn ,
596- SketchPath : path ,
600+ SketchPath : sketchPath ,
597601 Port : port ,
598602 }, stream )
599603 if err != nil {
0 commit comments