3737# the Registry has been imported. Yes this is awkward, but it was the least awkward way to make --verify work.
3838generators = {}
3939
40- def RunGenerators (api : str , registry : str , directory : str , styleFile : str , targetFilter : str , caching : bool ):
40+ def RunGenerators (api : str , registry : str , directory : str , styleFile : str , targetFilter : str , flatOutput : bool ):
4141
4242 try :
4343 common_codegen .RunShellCmd (f'clang-format --version' )
@@ -130,7 +130,12 @@ def RunGenerators(api: str, registry: str, directory: str, styleFile: str, targe
130130 else :
131131 SetMergedApiNames (None )
132132
133- outDirectory = os .path .abspath (os .path .join (directory , generators [target ]['directory' ]))
133+ # For people who want to generate all the files in a single director
134+ if flatOutput :
135+ outDirectory = os .path .abspath (os .path .join (directory ))
136+ else :
137+ outDirectory = os .path .abspath (os .path .join (directory , generators [target ]['directory' ]))
138+
134139 options = BaseGeneratorOptions (
135140 customFileName = target ,
136141 customDirectory = outDirectory )
@@ -155,7 +160,7 @@ def RunGenerators(api: str, registry: str, directory: str, styleFile: str, targe
155160 reg .apiGen ()
156161
157162 # Run clang-format on the file
158- if has_clang_format :
163+ if has_clang_format and styleFile :
159164 common_codegen .RunShellCmd (f'clang-format -i --style=file:{ styleFile } { os .path .join (outDirectory , target )} ' )
160165
161166
@@ -182,7 +187,7 @@ def main(argv):
182187 group .add_argument ('--target' , nargs = '+' , help = 'only generate file names passed in' )
183188 group .add_argument ('-i' , '--incremental' , action = 'store_true' , help = 'only update repo files that change' )
184189 group .add_argument ('-v' , '--verify' , action = 'store_true' , help = 'verify repo files match generator output' )
185- group .add_argument ('--no-caching ' , action = 'store_true ' , help = 'Do not try to cache generator objects ' )
190+ group .add_argument ('-o ' , action = 'store ' , dest = 'directory' , help = 'Create target and related files in specified directory ' )
186191 args = parser .parse_args (argv )
187192
188193 repo_dir = common_codegen .repo_relative ('.' )
@@ -210,12 +215,13 @@ def main(argv):
210215 temp_obj = tempfile .TemporaryDirectory (prefix = 'loader_codegen_' )
211216 temp_dir = temp_obj .name
212217 gen_dir = temp_dir
218+ elif args .directory :
219+ gen_dir = args .directory
213220 else :
214221 # generate directly in the repo
215222 gen_dir = repo_dir
216223
217- caching = not args .no_caching
218- RunGenerators (api = args .api ,registry = registry , directory = gen_dir , styleFile = style_file , targetFilter = args .target , caching = caching )
224+ RunGenerators (api = args .api ,registry = registry , directory = gen_dir , styleFile = style_file , targetFilter = args .target , flatOutput = False )
219225
220226 # optional post-generation steps
221227 if args .verify :
0 commit comments