6
6
import os
7
7
from packaging import version
8
8
from pathlib import Path
9
+ import random
9
10
import re
10
11
import subprocess
11
12
import sys
@@ -725,6 +726,11 @@ def build_config(sketch, boardSkipped):
725
726
def build_all ():
726
727
create_output_log_tree ()
727
728
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
728
734
729
735
for sketch_nb , sketch in enumerate (sketch_list , start = 1 ):
730
736
boardKo = []
@@ -756,7 +762,7 @@ def build_all():
756
762
757
763
758
764
# Run arduino-cli command
759
- def build (build_conf ):
765
+ def real_build (build_conf ):
760
766
cmd = build_conf [4 ]
761
767
status = [time .monotonic ()]
762
768
with open (build_conf [3 ] / f"{ cmd [- 1 ].name } .log" , "w" ) as stdout :
@@ -767,6 +773,23 @@ def build(build_conf):
767
773
return status
768
774
769
775
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
+
770
793
# Parser
771
794
parser = argparse .ArgumentParser (
772
795
description = "Manage arduino-cli to build sketche(s) for STM32 boards."
@@ -795,6 +818,11 @@ def build(build_conf):
795
818
parser .add_argument (
796
819
"-c" , "--clean" , help = "clean output directory." , action = "store_true"
797
820
)
821
+
822
+ parser .add_argument (
823
+ "-d" , "--dry" , help = "perform a dry run (no build)" , action = "store_true"
824
+ )
825
+
798
826
parser .add_argument (
799
827
"--arch" ,
800
828
metavar = "architecture" ,
0 commit comments