77Entry point for running the parser package as a script.
88
99Usage:
10- # With codegen modules path:
11- python ... --codegen-path /path/to/codegen
12-
1310 # With output directory:
1411 python ... --output-dir /path/to/output
1512"""
@@ -73,18 +70,62 @@ def build_doxygen_config(
7370 f .write (config )
7471
7572
73+ def build_codegen (platform : str , verbose : bool = False ) -> str :
74+ react_native_dir = os .path .join (get_react_native_dir (), "packages" , "react-native" )
75+
76+ result = subprocess .run (
77+ [
78+ "node" ,
79+ "./scripts/generate-codegen-artifacts.js" ,
80+ "--path" ,
81+ "./" ,
82+ "--outputPath" ,
83+ "./api/codegen" ,
84+ "--targetPlatform" ,
85+ platform ,
86+ "--forceOutputPath" ,
87+ ],
88+ cwd = react_native_dir ,
89+ )
90+
91+ if result .returncode != 0 :
92+ if verbose :
93+ print (f"Codegen finished with error: { result .stderr } " )
94+ sys .exit (1 )
95+ else :
96+ if verbose :
97+ print ("Codegen finished successfully" )
98+
99+ return os .path .join (react_native_dir , "api" , "codegen" )
100+
101+
76102def build_snapshot_for_view (
77103 api_view : str ,
78104 react_native_dir : str ,
79105 include_directories : list [str ],
80106 exclude_patterns : list [str ],
81107 definitions : dict [str , str | int ],
82108 output_dir : str ,
109+ codegen_platform : str | None = None ,
83110 verbose : bool = True ,
84111 input_filter : str = None ,
85112) -> None :
113+ # If there is already an output directory, delete it
114+ if os .path .exists (os .path .join (react_native_dir , "api" )):
115+ if verbose :
116+ print ("Deleting existing output directory" )
117+ subprocess .run (["rm" , "-rf" , os .path .join (react_native_dir , "api" )])
118+
86119 if verbose :
87120 print (f"Generating API view: { api_view } " )
121+
122+ if codegen_platform is not None :
123+ codegen_dir = build_codegen (codegen_platform , verbose = verbose )
124+ include_directories .append (codegen_dir )
125+ elif verbose :
126+ print ("Skipping codegen" )
127+
128+ if verbose :
88129 print ("Generating Doxygen config file" )
89130
90131 build_doxygen_config (
@@ -95,12 +136,6 @@ def build_snapshot_for_view(
95136 input_filter = input_filter ,
96137 )
97138
98- # If there is already a doxygen output directory, delete it
99- if os .path .exists (os .path .join (react_native_dir , "api" )):
100- if verbose :
101- print ("Deleting existing output directory" )
102- subprocess .run (["rm" , "-rf" , os .path .join (react_native_dir , "api" )])
103-
104139 if verbose :
105140 print ("Running Doxygen" )
106141 if input_filter :
@@ -120,6 +155,7 @@ def build_snapshot_for_view(
120155 if result .returncode != 0 :
121156 if verbose :
122157 print (f"Doxygen finished with error: { result .stderr } " )
158+ sys .exit (1 )
123159 else :
124160 if verbose :
125161 print ("Doxygen finished successfully" )
@@ -152,11 +188,6 @@ def main():
152188 type = str ,
153189 help = "Output directory for the snapshot" ,
154190 )
155- parser .add_argument (
156- "--codegen-path" ,
157- type = str ,
158- help = "Path to codegen generated code" ,
159- )
160191 parser .add_argument (
161192 "--check" ,
162193 action = "store_true" ,
@@ -194,9 +225,6 @@ def main():
194225 if verbose :
195226 print (f"Running in directory: { react_native_package_dir } " )
196227
197- if verbose and args .codegen_path :
198- print (f"Codegen output path: { os .path .abspath (args .codegen_path )} " )
199-
200228 input_filter_path = os .path .join (
201229 get_react_native_dir (),
202230 "scripts" ,
@@ -216,7 +244,6 @@ def main():
216244 snapshot_configs = parse_config_file (
217245 config_path ,
218246 get_react_native_dir (),
219- codegen_path = args .codegen_path ,
220247 )
221248
222249 def build_snapshots (output_dir : str , verbose : bool ) -> None :
@@ -229,6 +256,7 @@ def build_snapshots(output_dir: str, verbose: bool) -> None:
229256 exclude_patterns = config .exclude_patterns ,
230257 definitions = config .definitions ,
231258 output_dir = output_dir ,
259+ codegen_platform = config .codegen_platform ,
232260 verbose = verbose ,
233261 input_filter = input_filter ,
234262 )
@@ -240,6 +268,7 @@ def build_snapshots(output_dir: str, verbose: bool) -> None:
240268 exclude_patterns = [],
241269 definitions = {},
242270 output_dir = output_dir ,
271+ codegen_platform = None ,
243272 verbose = verbose ,
244273 input_filter = input_filter ,
245274 )
0 commit comments