11import os
2+ from pathlib import Path
23import stat
34from collections .abc import Mapping
4- from typing import Any , Dict , List
5+ from typing import Any , Dict , Generator , List
56
67from tests .util import *
78from jinja2 import Template
@@ -94,16 +95,16 @@ def render_script(template: str, out_path: str, params: Dict):
9495 os .chmod (out_path , stat .S_IREAD | stat .S_IWRITE | stat .S_IEXEC )
9596
9697
97- def autogen_cargo (conf_file , yaml : Dict ):
98- def render_stage (stage_conf : Mapping [str , Any ] | None , filename : str ) -> bool :
98+ def autogen_cargo (conf_file , yaml : Dict ) -> Generator [ Path ] :
99+ def render_stage (stage_conf : Mapping [str , Any ] | None , filename : str ) -> Generator [ Path ] :
99100 if not isinstance (stage_conf , Mapping ):
100- return False
101+ return
101102 if not stage_conf :
102- return False
103+ return
103104
104105 ag = stage_conf .get ("autogen" )
105106 if not (ag and isinstance (ag , bool )):
106- return False
107+ return
107108
108109 params : Dict [str , str ] = {}
109110 rustflags = stage_conf .get ("rustflags" )
@@ -115,16 +116,16 @@ def render_stage(stage_conf: Mapping[str, Any] | None, filename: str) -> bool:
115116 filename
116117 )
117118 render_script (CARGO_SH , out_path , params )
118- return True
119+ yield Path ( out_path )
119120
120121 for key , fname in (
121122 ("cargo.transpile" , "cargo.transpile.gen.sh" ),
122123 ("cargo.refactor" , "cargo.refactor.gen.sh" ),
123124 ):
124- render_stage (yaml .get (key ), fname )
125+ yield from render_stage (yaml .get (key ), fname )
125126
126127
127- def autogen_refactor (conf_file , yaml : Dict ):
128+ def autogen_refactor (conf_file , yaml : Dict ) -> Generator [ str ] :
128129 refactor = yaml .get ("refactor" )
129130 if refactor and isinstance (refactor , Dict ):
130131 ag = refactor .get ("autogen" )
@@ -149,9 +150,10 @@ def autogen_refactor(conf_file, yaml: Dict):
149150 "refactor.gen.sh"
150151 )
151152 render_script (REFACTOR_SH , out_path , params )
153+ yield Path (out_path )
152154
153155
154- def autogen_transpile (conf_file , yaml : Dict ):
156+ def autogen_transpile (conf_file , yaml : Dict ) -> Generator [ Path ] :
155157 transpile = yaml .get ("transpile" )
156158 if transpile and isinstance (transpile , Dict ):
157159 ag = transpile .get ("autogen" )
@@ -180,10 +182,11 @@ def autogen_transpile(conf_file, yaml: Dict):
180182 "transpile.gen.sh"
181183 )
182184 render_script (TRANSPILE_SH , out_path , params )
185+ yield Path (out_path )
183186
184187
185- def autogen (conf : Config ):
188+ def autogen (conf : Config ) -> Generator [ Path ] :
186189 for (cf , yaml ) in conf .project_conf .items ():
187- autogen_transpile (cf , yaml )
188- autogen_refactor (cf , yaml )
189- autogen_cargo (cf , yaml )
190+ yield from autogen_transpile (cf , yaml )
191+ yield from autogen_refactor (cf , yaml )
192+ yield from autogen_cargo (cf , yaml )
0 commit comments