66import os
77from packaging import version
88from pathlib import Path
9+ import random
910import re
1011import subprocess
1112import sys
@@ -725,6 +726,11 @@ def build_config(sketch, boardSkipped):
725726def build_all ():
726727 create_output_log_tree ()
727728 wrapper = textwrap .TextWrapper (width = 76 )
729+ if args .dry :
730+ print ("Performing a dry run (no build)" )
731+ build = dry_build
732+ else :
733+ build = real_build
728734
729735 for sketch_nb , sketch in enumerate (sketch_list , start = 1 ):
730736 boardKo = []
@@ -756,7 +762,7 @@ def build_all():
756762
757763
758764# Run arduino-cli command
759- def build (build_conf ):
765+ def real_build (build_conf ):
760766 cmd = build_conf [4 ]
761767 status = [time .monotonic ()]
762768 with open (build_conf [3 ] / f"{ cmd [- 1 ].name } .log" , "w" ) as stdout :
@@ -767,6 +773,23 @@ def build(build_conf):
767773 return status
768774
769775
776+ # Run arduino-cli command
777+ def dry_build (build_conf ):
778+ # cmd = build_conf[4]
779+ status = [random .random () * 10 , random .randint (0 , 1 )]
780+ if status [1 ] == 1 :
781+ # Create dummy log file
782+ logFile = build_conf [3 ] / f"{ build_conf [4 ][- 1 ].name } .log"
783+ # random failed
784+ dummy = open (logFile , "w" )
785+ if random .randint (0 , 1 ) == 1 :
786+ dummy .writelines ("region `FLASH' overflowed by 5612 bytes" )
787+ else :
788+ dummy .writelines ("Error:" )
789+ dummy .close ()
790+ return status
791+
792+
770793# Parser
771794parser = argparse .ArgumentParser (
772795 description = "Manage arduino-cli to build sketche(s) for STM32 boards."
@@ -795,6 +818,11 @@ def build(build_conf):
795818parser .add_argument (
796819 "-c" , "--clean" , help = "clean output directory." , action = "store_true"
797820)
821+
822+ parser .add_argument (
823+ "-d" , "--dry" , help = "perform a dry run (no build)" , action = "store_true"
824+ )
825+
798826parser .add_argument (
799827 "--arch" ,
800828 metavar = "architecture" ,
0 commit comments