@@ -174,8 +174,11 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
174
174
}
175
175
176
176
// 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"
179
182
180
183
// FIXME: Make a function to produce a better name...
181
184
// Make the filename without the FQBN configs part
@@ -190,7 +193,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
190
193
} else {
191
194
exportPath = sketch .FullPath .Parent ()
192
195
}
193
- exportFile = sketch .Name + "." + fqbnSuffix
196
+ exportFile = sketch .Name + "." + fqbnSuffix // "sketch.arduino.avr.uno"
194
197
} else {
195
198
exportPath = paths .New (req .GetExportFile ()).Parent ()
196
199
exportFile = paths .New (req .GetExportFile ()).Base ()
@@ -199,16 +202,25 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
199
202
}
200
203
}
201
204
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
+ }
208
220
}
209
221
210
222
// Copy .elf file to sketch directory
211
- srcElf := paths . New ( outputPath [: len ( outputPath ) - 3 ] + "elf" )
223
+ srcElf := outputPath . Parent (). Join ( base + ". elf" )
212
224
if srcElf .Exist () {
213
225
dstElf := exportPath .Join (exportFile + ".elf" )
214
226
logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
0 commit comments