22
22
import subprocess
23
23
import sys
24
24
import urllib .request
25
+ from dataclasses import dataclass
26
+
27
+
28
+ @dataclass
29
+ class CmdLineArgs :
30
+ zapFile : str
31
+ zclFile : str
32
+ templateFile : str
33
+ outputDir : str
34
+ runBootstrap : bool
35
+
25
36
26
37
CHIP_ROOT_DIR = os .path .realpath (
27
38
os .path .join (os .path .dirname (__file__ ), '../../..' ))
@@ -77,7 +88,7 @@ def detectZclFile(zapFile):
77
88
return getFilePath (path )
78
89
79
90
80
- def runArgumentsParser ():
91
+ def runArgumentsParser () -> CmdLineArgs :
81
92
default_templates = 'src/app/zap-templates/app-templates.json'
82
93
default_output_dir = 'zap-generated/'
83
94
@@ -90,6 +101,8 @@ def runArgumentsParser():
90
101
help = 'Path to the zcl templates records to use for generating artifacts (default: autodetect read from zap file)' )
91
102
parser .add_argument ('-o' , '--output-dir' , default = None ,
92
103
help = 'Output directory for the generated files (default: automatically selected)' )
104
+ parser .add_argument ('--run-bootstrap' , default = None , action = 'store_true' ,
105
+ help = 'Automatically run ZAP bootstrap. By default the bootstrap is not triggered' )
93
106
args = parser .parse_args ()
94
107
95
108
# By default, this script assumes that the global CHIP template is used with
@@ -113,7 +126,7 @@ def runArgumentsParser():
113
126
templates_file = getFilePath (args .templates )
114
127
output_dir = getDirPath (output_dir )
115
128
116
- return (zap_file , zcl_file , templates_file , output_dir )
129
+ return CmdLineArgs (zap_file , zcl_file , templates_file , output_dir , args . run_bootstrap )
117
130
118
131
119
132
def extractGeneratedIdl (output_dir , zap_config_path ):
@@ -209,21 +222,26 @@ def runJavaPrettifier(templates_file, output_dir):
209
222
print ('google-java-format error:' , err )
210
223
211
224
225
+ def runBootstrap ():
226
+ subprocess .check_call (getFilePath ("scripts/tools/zap/zap_bootstrap.sh" ), shell = True )
227
+
228
+
212
229
def main ():
213
230
checkPythonVersion ()
214
-
215
- # The maximum meory usage is over 4GB (#15620)
231
+ cmdLineArgs = runArgumentsParser ()
232
+ if cmdLineArgs .runBootstrap :
233
+ runBootstrap ()
234
+ # The maximum memory usage is over 4GB (#15620)
216
235
os .environ ["NODE_OPTIONS" ] = "--max-old-space-size=8192"
217
- zap_file , zcl_file , templates_file , output_dir = runArgumentsParser ()
218
- runGeneration (zap_file , zcl_file , templates_file , output_dir )
236
+ runGeneration (cmdLineArgs .zapFile , cmdLineArgs .zclFile , cmdLineArgs .templateFile , cmdLineArgs .outputDir )
219
237
220
238
prettifiers = [
221
239
runClangPrettifier ,
222
240
runJavaPrettifier ,
223
241
]
224
242
225
243
for prettifier in prettifiers :
226
- prettifier (templates_file , output_dir )
244
+ prettifier (cmdLineArgs . templateFile , cmdLineArgs . outputDir )
227
245
228
246
229
247
if __name__ == '__main__' :
0 commit comments