@@ -6,12 +6,10 @@ import (
66 "fmt"
77 "io"
88 "iter"
9- "log"
109 "log/slog"
1110 "net"
1211 "os"
1312 "os/user"
14- "path/filepath"
1513 "runtime"
1614 "slices"
1715 "strings"
@@ -124,8 +122,7 @@ func StartApp(ctx context.Context, docker *dockerClient.Client, provisioner *Pro
124122 })
125123
126124 if app .MainSketchPath != nil {
127- buildPath := app .FullPath .Join (".cache" , "sketch" ).String ()
128- if err := compileUploadSketch (ctx , app .MainSketchPath .String (), buildPath , callbackWriter ); err != nil {
125+ if err := compileUploadSketch (ctx , & app , callbackWriter ); err != nil {
129126 yield (StreamMessage {error : err })
130127 return
131128 }
@@ -208,17 +205,6 @@ func StopApp(ctx context.Context, app app.ArduinoApp) iter.Seq[StreamMessage] {
208205 yield (StreamMessage {error : err })
209206 return
210207 }
211- } else {
212- // Flash empty sketch to stop the microcontroller.
213- buildPath := "" // the empty sketch' build path must be in the default temporary directory.
214-
215- // TODO: probably we don't need this branch as the code is always executed on the UnoQ, expect
216- // during dev-env
217- noOpCallbackWriter := NewCallbackWriter (func (line string ) {})
218- if err := compileUploadSketch (ctx , getEmptySketch (), buildPath , noOpCallbackWriter ); err != nil {
219- yield (StreamMessage {error : err })
220- return
221- }
222208 }
223209 }
224210
@@ -860,7 +846,7 @@ func disconnectSerialFromRPCRouter(ctx context.Context, portAddress string) func
860846 }
861847}
862848
863- func compileUploadSketch (ctx context.Context , sketchPath , buildPath string , w io.Writer ) error {
849+ func compileUploadSketch (ctx context.Context , arduinoApp * app. ArduinoApp , w io.Writer ) error {
864850 logrus .SetLevel (logrus .ErrorLevel ) // Reduce the log level of arduino-cli
865851 srv := commands .NewArduinoCoreServer ()
866852
@@ -874,7 +860,8 @@ func compileUploadSketch(ctx context.Context, sketchPath, buildPath string, w io
874860 defer func () {
875861 _ , _ = srv .Destroy (ctx , & rpc.DestroyRequest {Instance : inst })
876862 }()
877-
863+ sketchPath := arduinoApp .MainSketchPath .String ()
864+ buildPath := arduinoApp .SketchBuildPath ().String ()
878865 sketchResp , err := srv .LoadSketch (ctx , & rpc.LoadSketchRequest {SketchPath : sketchPath })
879866 if err != nil {
880867 return err
@@ -988,19 +975,3 @@ func compileUploadSketch(ctx context.Context, sketchPath, buildPath string, w io
988975 ImportDir : buildPath ,
989976 }, stream )
990977}
991-
992- func getEmptySketch () string {
993- const emptySketch = `void setup() {}
994- void loop() {}
995- `
996- dir := filepath .Join (os .TempDir (), "empty_sketch" )
997- if err := os .MkdirAll (dir , 0700 ); err != nil {
998- log .Panic (err )
999- }
1000- ino := filepath .Join (dir , "empty_sketch.ino" )
1001- err := os .WriteFile (ino , []byte (emptySketch ), 0600 )
1002- if err != nil {
1003- panic (err )
1004- }
1005- return ino
1006- }
0 commit comments