@@ -196,59 +196,61 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
196196 return nil , err
197197 }
198198
199- // FIXME: Make a function to obtain these info...
200- outputPath := paths .New (
201- builderCtx .BuildProperties .ExpandPropsInString ("{build.path}/{recipe.output.tmp_file}" )) // "/build/path/sketch.ino.bin"
202- ext := outputPath .Ext () // ".hex" | ".bin"
203- base := outputPath .Base () // "sketch.ino.hex"
204- base = base [:len (base )- len (ext )] // "sketch.ino"
205-
206- // FIXME: Make a function to produce a better name...
207- // Make the filename without the FQBN configs part
208- fqbn .Configs = properties .NewMap ()
209- fqbnSuffix := strings .Replace (fqbn .String (), ":" , "." , - 1 )
210-
211- var exportPath * paths.Path
212- var exportFile string
213- if req .GetExportFile () == "" {
214- if sketch .FullPath .IsDir () {
215- exportPath = sketch .FullPath
199+ if ! req .GetDryRun () {
200+ // FIXME: Make a function to obtain these info...
201+ outputPath := paths .New (
202+ builderCtx .BuildProperties .ExpandPropsInString ("{build.path}/{recipe.output.tmp_file}" )) // "/build/path/sketch.ino.bin"
203+ ext := outputPath .Ext () // ".hex" | ".bin"
204+ base := outputPath .Base () // "sketch.ino.hex"
205+ base = base [:len (base )- len (ext )] // "sketch.ino"
206+
207+ // FIXME: Make a function to produce a better name...
208+ // Make the filename without the FQBN configs part
209+ fqbn .Configs = properties .NewMap ()
210+ fqbnSuffix := strings .Replace (fqbn .String (), ":" , "." , - 1 )
211+
212+ var exportPath * paths.Path
213+ var exportFile string
214+ if req .GetExportFile () == "" {
215+ if sketch .FullPath .IsDir () {
216+ exportPath = sketch .FullPath
217+ } else {
218+ exportPath = sketch .FullPath .Parent ()
219+ }
220+ exportFile = sketch .Name + "." + fqbnSuffix // "sketch.arduino.avr.uno"
216221 } else {
217- exportPath = sketch .FullPath .Parent ()
218- }
219- exportFile = sketch .Name + "." + fqbnSuffix // "sketch.arduino.avr.uno"
220- } else {
221- exportPath = paths .New (req .GetExportFile ()).Parent ()
222- exportFile = paths .New (req .GetExportFile ()).Base ()
223- if strings .HasSuffix (exportFile , ext ) {
224- exportFile = exportFile [:len (exportFile )- len (ext )]
222+ exportPath = paths .New (req .GetExportFile ()).Parent ()
223+ exportFile = paths .New (req .GetExportFile ()).Base ()
224+ if strings .HasSuffix (exportFile , ext ) {
225+ exportFile = exportFile [:len (exportFile )- len (ext )]
226+ }
225227 }
226- }
227228
228- // Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
229- srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
230- if err != nil {
231- return nil , fmt .Errorf ("reading build directory: %s" , err )
232- }
233- srcDir .FilterPrefix (base + "." )
234- srcDir .FilterSuffix (ext )
235- for _ , srcOutput := range srcDir {
236- srcFilename := srcOutput .Base () // "sketch.ino.*.bin"
237- srcFilename = srcFilename [len (base ):] // ".*.bin"
238- dstOutput := exportPath .Join (exportFile + srcFilename )
239- logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
240- if err = srcOutput .CopyTo (dstOutput ); err != nil {
241- return nil , fmt .Errorf ("copying output file: %s" , err )
229+ // Copy "sketch.ino.*.hex" / "sketch.ino.*.bin" artifacts to sketch directory
230+ srcDir , err := outputPath .Parent ().ReadDir () // read "/build/path/*"
231+ if err != nil {
232+ return nil , fmt .Errorf ("reading build directory: %s" , err )
233+ }
234+ srcDir .FilterPrefix (base + "." )
235+ srcDir .FilterSuffix (ext )
236+ for _ , srcOutput := range srcDir {
237+ srcFilename := srcOutput .Base () // "sketch.ino.*.bin"
238+ srcFilename = srcFilename [len (base ):] // ".*.bin"
239+ dstOutput := exportPath .Join (exportFile + srcFilename )
240+ logrus .WithField ("from" , srcOutput ).WithField ("to" , dstOutput ).Debug ("copying sketch build output" )
241+ if err = srcOutput .CopyTo (dstOutput ); err != nil {
242+ return nil , fmt .Errorf ("copying output file: %s" , err )
243+ }
242244 }
243- }
244245
245- // Copy .elf file to sketch directory
246- srcElf := outputPath .Parent ().Join (base + ".elf" )
247- if srcElf .Exist () {
248- dstElf := exportPath .Join (exportFile + ".elf" )
249- logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
250- if err = srcElf .CopyTo (dstElf ); err != nil {
251- return nil , fmt .Errorf ("copying elf file: %s" , err )
246+ // Copy .elf file to sketch directory
247+ srcElf := outputPath .Parent ().Join (base + ".elf" )
248+ if srcElf .Exist () {
249+ dstElf := exportPath .Join (exportFile + ".elf" )
250+ logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Debug ("copying sketch build output" )
251+ if err = srcElf .CopyTo (dstElf ); err != nil {
252+ return nil , fmt .Errorf ("copying elf file: %s" , err )
253+ }
252254 }
253255 }
254256
0 commit comments