@@ -18,17 +18,18 @@ package debug
1818import (
1919 "context"
2020 "fmt"
21+ "io"
22+ "os"
23+ "path/filepath"
24+ "strings"
25+ "time"
26+
2127 "github.com/arduino/arduino-cli/arduino/cores"
2228 "github.com/arduino/arduino-cli/arduino/sketches"
2329 "github.com/arduino/arduino-cli/commands"
2430 "github.com/arduino/go-paths-helper"
2531 "github.com/arduino/go-properties-orderedmap"
2632 "github.com/sirupsen/logrus"
27- "io"
28- "os"
29- "path/filepath"
30- "strings"
31- "time"
3233
3334 "github.com/arduino/arduino-cli/executils"
3435 dbg "github.com/arduino/arduino-cli/rpc/debug"
@@ -75,17 +76,17 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream dbg.Debug_Debu
7576 }
7677
7778 // Load programmer tool
78- uploadToolPattern , have := boardProperties .GetOk ("debug.tool" )
79- if ! have || uploadToolPattern == "" {
79+ toolName , have := boardProperties .GetOk ("debug.tool" )
80+ if ! have || toolName == "" {
8081 return nil , fmt .Errorf ("cannot get programmer tool: undefined 'debug.tool' property" )
8182 }
8283
8384 var referencedPlatformRelease * cores.PlatformRelease
84- if split := strings .Split (uploadToolPattern , ":" ); len (split ) > 2 {
85- return nil , fmt .Errorf ("invalid 'debug.tool' property: %s" , uploadToolPattern )
85+ if split := strings .Split (toolName , ":" ); len (split ) > 2 {
86+ return nil , fmt .Errorf ("invalid 'debug.tool' property: %s" , toolName )
8687 } else if len (split ) == 2 {
8788 referencedPackageName := split [0 ]
88- uploadToolPattern = split [1 ]
89+ toolName = split [1 ]
8990 architecture := board .PlatformRelease .Platform .Architecture
9091
9192 if referencedPackage := pm .Packages [referencedPackageName ]; referencedPackage == nil {
@@ -98,33 +99,33 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream dbg.Debug_Debu
9899 }
99100
100101 // Build configuration for upload
101- debugProperties := properties .NewMap ()
102+ toolProperties := properties .NewMap ()
102103 if referencedPlatformRelease != nil {
103- debugProperties .Merge (referencedPlatformRelease .Properties )
104+ toolProperties .Merge (referencedPlatformRelease .Properties )
104105 }
105- debugProperties .Merge (board .PlatformRelease .Properties )
106- debugProperties .Merge (board .PlatformRelease .RuntimeProperties ())
107- debugProperties .Merge (boardProperties )
106+ toolProperties .Merge (board .PlatformRelease .Properties )
107+ toolProperties .Merge (board .PlatformRelease .RuntimeProperties ())
108+ toolProperties .Merge (boardProperties )
108109
109- uploadToolProperties := debugProperties .SubTree ("tools." + uploadToolPattern )
110- debugProperties .Merge (uploadToolProperties )
110+ requestedToolProperties := toolProperties .SubTree ("tools." + toolName )
111+ toolProperties .Merge (requestedToolProperties )
111112
112113 if requiredTools , err := pm .FindToolsRequiredForBoard (board ); err == nil {
113114 for _ , requiredTool := range requiredTools {
114115 logrus .WithField ("tool" , requiredTool ).Info ("Tool required for upload" )
115- debugProperties .Merge (requiredTool .RuntimeProperties ())
116+ toolProperties .Merge (requiredTool .RuntimeProperties ())
116117 }
117118 }
118119
119120 // Set properties for verbose upload
120- Verbose := req .GetVerbose ()
121- if Verbose {
122- if v , ok := debugProperties .GetOk ("debug.params.verbose" ); ok {
123- debugProperties .Set ("debug.verbose" , v )
121+ verbose := req .GetVerbose ()
122+ if verbose {
123+ if v , ok := toolProperties .GetOk ("debug.params.verbose" ); ok {
124+ toolProperties .Set ("debug.verbose" , v )
124125 }
125126 } else {
126- if v , ok := debugProperties .GetOk ("debug.params.quiet" ); ok {
127- debugProperties .Set ("debug.verbose" , v )
127+ if v , ok := toolProperties .GetOk ("debug.params.quiet" ); ok {
128+ toolProperties .Set ("debug.verbose" , v )
128129 }
129130 }
130131
@@ -143,8 +144,8 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream dbg.Debug_Debu
143144 importFile = paths .New (req .GetImportFile ()).Base ()
144145 }
145146
146- outputTmpFile , ok := debugProperties .GetOk ("recipe.output.tmp_file" )
147- outputTmpFile = debugProperties .ExpandPropsInString (outputTmpFile )
147+ outputTmpFile , ok := toolProperties .GetOk ("recipe.output.tmp_file" )
148+ outputTmpFile = toolProperties .ExpandPropsInString (outputTmpFile )
148149 if ! ok {
149150 return nil , fmt .Errorf ("property 'recipe.output.tmp_file' not defined" )
150151 }
@@ -153,8 +154,8 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream dbg.Debug_Debu
153154 importFile = importFile [:len (importFile )- len (ext )]
154155 }
155156
156- debugProperties .SetPath ("build.path" , importPath )
157- debugProperties .Set ("build.project_name" , importFile )
157+ toolProperties .SetPath ("build.path" , importPath )
158+ toolProperties .Set ("build.project_name" , importFile )
158159 uploadFile := importPath .Join (importFile + ext )
159160 if _ , err := uploadFile .Stat (); err != nil {
160161 if os .IsNotExist (err ) {
@@ -163,22 +164,27 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream dbg.Debug_Debu
163164 return nil , fmt .Errorf ("cannot open sketch: %s" , err )
164165 }
165166
166- // Set serial port property
167- debugProperties .Set ("serial .port" , port )
167+ // Set debug port property
168+ toolProperties .Set ("debug .port" , port )
168169 if strings .HasPrefix (port , "/dev/" ) {
169- debugProperties .Set ("serial .port.file" , port [5 :])
170+ toolProperties .Set ("debug .port.file" , port [5 :])
170171 } else {
171- debugProperties .Set ("serial .port.file" , port )
172+ toolProperties .Set ("debug .port.file" , port )
172173 }
173174
174- // Build recipe for upload
175- recipe := debugProperties .Get ("debug.pattern" )
176- cmdLine := debugProperties .ExpandPropsInString (recipe )
175+ // Build recipe for tool
176+ recipe := toolProperties .Get ("debug.pattern" )
177+ cmdLine := toolProperties .ExpandPropsInString (recipe )
177178 cmdArgs , err := properties .SplitQuotedString (cmdLine , `"'` , false )
178179 if err != nil {
179180 return nil , fmt .Errorf ("invalid recipe '%s': %s" , recipe , err )
180181 }
181182
183+ // for _, arg := range cmdArgs {
184+ // fmt.Println(">>", arg)
185+ // }
186+ // time.Sleep(time.Hour)
187+
182188 // Run Tool
183189 cmd , err := executils .Command (cmdArgs )
184190 if err != nil {
@@ -193,6 +199,7 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream dbg.Debug_Debu
193199 defer in .Close ()
194200
195201 cmd .Stdout = out
202+ cmd .Stderr = out
196203
197204 if err := cmd .Start (); err != nil {
198205 fmt .Printf ("%v\n " , err )
0 commit comments