@@ -174,8 +174,11 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
174174 }
175175
176176 // FIXME: Make a function to obtain these info...
177- outputPath := builderCtx .BuildProperties .ExpandPropsInString ("{build.path}/{recipe.output.tmp_file}" )
178- ext := filepath .Ext (outputPath )
177+ outputPath := paths .New (
178+ builderCtx .BuildProperties .ExpandPropsInString ("{build.path}/{recipe.output.tmp_file}" )) // "/build/path/sketch.ino.bin"
179+ ext := outputPath .Ext () // ".hex" | ".bin"
180+ base := outputPath .Base () // "sketch.ino.hex"
181+ base = base [:len (base )- len (ext )] // "sketch.ino"
179182
180183 // FIXME: Make a function to produce a better name...
181184 // Make the filename without the FQBN configs part
@@ -190,7 +193,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
190193 } else {
191194 exportPath = sketch .FullPath .Parent ()
192195 }
193- exportFile = sketch .Name + "." + fqbnSuffix
196+ exportFile = sketch .Name + "." + fqbnSuffix // "sketch.arduino.avr.uno"
194197 } else {
195198 exportPath = paths .New (req .GetExportFile ()).Parent ()
196199 exportFile = paths .New (req .GetExportFile ()).Base ()
@@ -199,16 +202,25 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
199202 }
200203 }
201204
202- // Copy .hex file to sketch directory
203- srcHex := paths .New (outputPath )
204- dstHex := exportPath .Join (exportFile + ext )
205- logrus .WithField ("from" , srcHex ).WithField ("to" , dstHex ).Debug ("copying sketch build output" )
206- if err = srcHex .CopyTo (dstHex ); err != nil {
207- return nil , fmt .Errorf ("copying output file: %s" , err )
205+ // Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
206+ srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
207+ if err != nil {
208+ return nil , fmt .Errorf ("reading build directory: %s" , err )
209+ }
210+ srcDir .FilterPrefix (base + "." )
211+ srcDir .FilterSuffix (ext )
212+ for _ , srcOutput := range srcDir {
213+ srcFilename := srcOutput .Base () // "sketch.ino.*.bin"
214+ srcFilename = srcFilename [len (base ):] // ".*.bin"
215+ dstOutput := exportPath .Join (exportFile + srcFilename )
216+ logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
217+ if err = srcOutput .CopyTo (dstOutput ); err != nil {
218+ return nil , fmt .Errorf ("copying output file: %s" , err )
219+ }
208220 }
209221
210222 // Copy .elf file to sketch directory
211- srcElf := paths . New ( outputPath [: len ( outputPath ) - 3 ] + "elf" )
223+ srcElf := outputPath . Parent (). Join ( base + ". elf" )
212224 if srcElf .Exist () {
213225 dstElf := exportPath .Join (exportFile + ".elf" )
214226 logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
0 commit comments