@@ -49,6 +49,54 @@ def run_cmd(cmd, output_info=True):
4949
5050 return output_str_list , res
5151
52+ def is_env_enabled (name , default = False ):
53+ value = os .getenv (name )
54+ if value is None :
55+ return default
56+
57+ return value .lower () not in ('' , '0' , 'false' , 'no' , 'off' )
58+
59+ def run_dist_build_check (bsp , scons_args = '' ):
60+ """
61+ build BSP distribution and verify that the generated project can compile.
62+ """
63+ os .chdir (rtt_root )
64+ dist_root = os .path .join (rtt_root , 'bsp' , bsp , 'dist' )
65+ dist_project = os .path .join (dist_root , 'project' )
66+ if os .path .exists (dist_root ):
67+ shutil .rmtree (dist_root )
68+
69+ old_rtt_root = None
70+ try :
71+ _ , res = run_cmd (f'scons --dist -C bsp/{ bsp } { scons_args } ' , output_info = True )
72+ if res != 0 :
73+ print (f"::error::scons --dist failed for { bsp } " )
74+ return False
75+
76+ if not os .path .exists (dist_project ):
77+ print (f"::error::dist project not found: { dist_project } " )
78+ return False
79+
80+ old_rtt_root = os .environ .pop ('RTT_ROOT' , None )
81+ _ , res = run_cmd (f'scons --pyconfig-silent -C { dist_project } ' , output_info = True )
82+ if res != 0 :
83+ print (f"::error::dist project pyconfig failed for { bsp } " )
84+ return False
85+
86+ nproc = multiprocessing .cpu_count ()
87+ _ , res = run_cmd (f'scons -C { dist_project } -j{ nproc } ' , output_info = True )
88+ if res != 0 :
89+ print (f"::error::dist project build failed for { bsp } " )
90+ return False
91+ finally :
92+ if old_rtt_root is not None :
93+ os .environ ['RTT_ROOT' ] = old_rtt_root
94+ os .chdir (rtt_root )
95+ if os .path .exists (dist_root ):
96+ shutil .rmtree (dist_root )
97+
98+ return True
99+
52100
53101def build_bsp (bsp , scons_args = '' ,name = 'default' , pre_build_commands = None , post_build_command = None ,build_check_result = None ,bsp_build_env = None ):
54102 """
@@ -115,6 +163,15 @@ def build_bsp(bsp, scons_args='',name='default', pre_build_commands=None, post_b
115163 files = glob .glob (f'{ rtt_root } /bsp/{ bsp } /{ file_type } ' )
116164 for file in files :
117165 shutil .copy (file , f'{ rtt_root } /output/bsp/{ bsp } /{ name .replace ("/" , "_" )} .{ file_type [2 :]} ' )
166+ if is_env_enabled ('RTT_CI_BUILD_DIST' ):
167+ print (f"::group::\t Checking dist project: { bsp } { name } " )
168+ dist_res = run_dist_build_check (bsp , scons_args )
169+ print ("::endgroup::" )
170+ if not dist_res :
171+ add_summary (f'\t - ❌ dist build { bsp } { name } failed.' )
172+ success = False
173+ else :
174+ add_summary (f'\t - ✅ dist build { bsp } { name } success.' )
118175
119176 os .chdir (f'{ rtt_root } /bsp/{ bsp } ' )
120177 if post_build_command is not None :
0 commit comments