midl.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. # Copyright 2017 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. from __future__ import division
  5. from __future__ import print_function
  6. import array
  7. import difflib
  8. import filecmp
  9. import io
  10. import operator
  11. import os
  12. import posixpath
  13. import re
  14. import shutil
  15. import struct
  16. import subprocess
  17. import sys
  18. import tempfile
  19. import uuid
  20. from functools import reduce
  21. def ZapTimestamp(filename):
  22. contents = open(filename, 'rb').read()
  23. # midl.exe writes timestamp 2147483647 (2^31 - 1) as creation date into its
  24. # outputs, but using the local timezone. To make the output timezone-
  25. # independent, replace that date with a fixed string of the same length.
  26. # Also blank out the minor version number.
  27. if filename.endswith('.tlb'):
  28. # See https://chromium-review.googlesource.com/c/chromium/src/+/693223 for
  29. # a fairly complete description of the .tlb binary format.
  30. # TLB files start with a 54 byte header. Offset 0x20 stores how many types
  31. # are defined in the file, and the header is followed by that many uint32s.
  32. # After that, 15 section headers appear. Each section header is 16 bytes,
  33. # starting with offset and length uint32s.
  34. # Section 12 in the file contains custom() data. custom() data has a type
  35. # (int, string, etc). Each custom data chunk starts with a uint16_t
  36. # describing its type. Type 8 is string data, consisting of a uint32_t
  37. # len, followed by that many data bytes, followed by 'W' bytes to pad to a
  38. # 4 byte boundary. Type 0x13 is uint32 data, followed by 4 data bytes,
  39. # followed by two 'W' to pad to a 4 byte boundary.
  40. # The custom block always starts with one string containing "Created by
  41. # MIDL version 8...", followed by one uint32 containing 0x7fffffff,
  42. # followed by another uint32 containing the MIDL compiler version (e.g.
  43. # 0x0801026e for v8.1.622 -- 0x26e == 622). These 3 fields take 0x54 bytes.
  44. # There might be more custom data after that, but these 3 blocks are always
  45. # there for file-level metadata.
  46. # All data is little-endian in the file.
  47. assert contents[0:8] == b'MSFT\x02\x00\x01\x00'
  48. ntypes, = struct.unpack_from('<I', contents, 0x20)
  49. custom_off, custom_len = struct.unpack_from(
  50. '<II', contents, 0x54 + 4*ntypes + 11*16)
  51. assert custom_len >= 0x54
  52. # First: Type string (0x8), followed by 0x3e characters.
  53. assert contents[custom_off:custom_off + 6] == b'\x08\x00\x3e\x00\x00\x00'
  54. assert re.match(
  55. br'Created by MIDL version 8\.\d\d\.\d{4} '
  56. br'at ... Jan 1. ..:..:.. 2038\n',
  57. contents[custom_off + 6:custom_off + 6 + 0x3e])
  58. # Second: Type uint32 (0x13) storing 0x7fffffff (followed by WW / 0x57 pad)
  59. assert contents[custom_off+6+0x3e:custom_off+6+0x3e+8] == \
  60. b'\x13\x00\xff\xff\xff\x7f\x57\x57'
  61. # Third: Type uint32 (0x13) storing MIDL compiler version.
  62. assert contents[custom_off + 6 + 0x3e + 8:custom_off + 6 + 0x3e + 8 +
  63. 2] == b'\x13\x00'
  64. # Replace "Created by" string with fixed string, and fixed MIDL version with
  65. # 8.1.622 always.
  66. contents = (
  67. contents[0:custom_off + 6] +
  68. b'Created by MIDL version 8.xx.xxxx at a redacted point in time\n' +
  69. # uint32 (0x13) val 0x7fffffff, WW, uint32 (0x13), val 0x0801026e, WW
  70. b'\x13\x00\xff\xff\xff\x7f\x57\x57\x13\x00\x6e\x02\x01\x08\x57\x57' +
  71. contents[custom_off + 0x54:])
  72. else:
  73. contents = re.sub(
  74. br'File created by MIDL compiler version 8\.\d\d\.\d{4} \*/\r\n'
  75. br'/\* at ... Jan 1. ..:..:.. 2038',
  76. br'File created by MIDL compiler version 8.xx.xxxx */\r\n'
  77. br'/* at a redacted point in time', contents)
  78. contents = re.sub(
  79. br' Oicf, W1, Zp8, env=(.....) \(32b run\), '
  80. br'target_arch=(AMD64|X86) 8\.\d\d\.\d{4}',
  81. br' Oicf, W1, Zp8, env=\1 (32b run), target_arch=\2 8.xx.xxxx',
  82. contents)
  83. # TODO(thakis): If we need more hacks than these, try to verify checked-in
  84. # outputs when we're using the hermetic toolchain.
  85. # midl.exe older than 8.1.622 omit '//' after #endif, fix that:
  86. contents = contents.replace(b'#endif !_MIDL_USE_GUIDDEF_',
  87. b'#endif // !_MIDL_USE_GUIDDEF_')
  88. # midl.exe puts the midl version into code in one place. To have
  89. # predictable output, lie about the midl version if it's not 8.1.622.
  90. # This is unfortunate, but remember that there's beauty too in imperfection.
  91. contents = contents.replace(b'0x801026c, /* MIDL Version 8.1.620 */',
  92. b'0x801026e, /* MIDL Version 8.1.622 */')
  93. open(filename, 'wb').write(contents)
  94. def get_tlb_contents(tlb_file):
  95. # See ZapTimestamp() for a short overview of the .tlb format.
  96. contents = open(tlb_file, 'rb').read()
  97. assert contents[0:8] == b'MSFT\x02\x00\x01\x00'
  98. ntypes, = struct.unpack_from('<I', contents, 0x20)
  99. type_off, type_len = struct.unpack_from('<II', contents, 0x54 + 4*ntypes)
  100. guid_off, guid_len = struct.unpack_from(
  101. '<II', contents, 0x54 + 4*ntypes + 5*16)
  102. assert guid_len % 24 == 0
  103. contents = array.array('B', contents)
  104. return contents, ntypes, type_off, guid_off, guid_len
  105. def recreate_guid_hashtable(contents, ntypes, guid_off, guid_len):
  106. # This function is called after changing guids in section 6 (the "guid"
  107. # section). This function recreates the GUID hashtable in section 5. Since the
  108. # hash table uses chaining, it's easiest to recompute it from scratch rather
  109. # than trying to patch it up.
  110. hashtab = [0xffffffff] * (0x80 // 4)
  111. for guidind in range(guid_off, guid_off + guid_len, 24):
  112. guidbytes, typeoff, nextguid = struct.unpack_from(
  113. '<16sII', contents, guidind)
  114. words = struct.unpack('<8H', guidbytes)
  115. # midl seems to use the following simple hash function for GUIDs:
  116. guidhash = reduce(operator.xor, [w for w in words]) % (0x80 // 4)
  117. nextguid = hashtab[guidhash]
  118. struct.pack_into('<I', contents, guidind + 0x14, nextguid)
  119. hashtab[guidhash] = guidind - guid_off
  120. hash_off, hash_len = struct.unpack_from(
  121. '<II', contents, 0x54 + 4*ntypes + 4*16)
  122. for i, hashval in enumerate(hashtab):
  123. struct.pack_into('<I', contents, hash_off + 4*i, hashval)
  124. def overwrite_guids_h(h_file, dynamic_guids):
  125. contents = open(h_file, 'rb').read()
  126. for key in dynamic_guids:
  127. contents = re.sub(key, dynamic_guids[key], contents, flags=re.I)
  128. open(h_file, 'wb').write(contents)
  129. def get_uuid_format(guid, prefix):
  130. formatted_uuid = b'0x%s,0x%s,0x%s,' % (guid[0:8], guid[9:13], guid[14:18])
  131. formatted_uuid += b'%s0x%s,0x%s' % (prefix, guid[19:21], guid[21:23])
  132. for i in range(24, len(guid), 2):
  133. formatted_uuid += b',0x' + guid[i:i + 2]
  134. return formatted_uuid
  135. def get_uuid_format_iid_file(guid):
  136. # Convert from "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83" to
  137. # 0xD0E1CACC,0xC63C,0x4192,0x94,0xAB,0xBF,0x8E,0xAD,0x0E,0x3B,0x83.
  138. return get_uuid_format(guid, b'')
  139. def overwrite_guids_iid(iid_file, dynamic_guids):
  140. contents = open(iid_file, 'rb').read()
  141. for key in dynamic_guids:
  142. contents = re.sub(get_uuid_format_iid_file(key),
  143. get_uuid_format_iid_file(dynamic_guids[key]),
  144. contents,
  145. flags=re.I)
  146. open(iid_file, 'wb').write(contents)
  147. def get_uuid_format_proxy_file(guid):
  148. # Convert from "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83" to
  149. # {0xD0E1CACC,0xC63C,0x4192,{0x94,0xAB,0xBF,0x8E,0xAD,0x0E,0x3B,0x83}}.
  150. return get_uuid_format(guid, b'{')
  151. def overwrite_guids_proxy(proxy_file, dynamic_guids):
  152. contents = open(proxy_file, 'rb').read()
  153. for key in dynamic_guids:
  154. contents = re.sub(get_uuid_format_proxy_file(key),
  155. get_uuid_format_proxy_file(dynamic_guids[key]),
  156. contents,
  157. flags=re.I)
  158. open(proxy_file, 'wb').write(contents)
  159. def getguid(contents, offset):
  160. # Returns a guid string of the form "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83".
  161. g0, g1, g2, g3 = struct.unpack_from('<IHH8s', contents, offset)
  162. g3 = b''.join([b'%02X' % g for g in bytearray(g3)])
  163. return b'%08X-%04X-%04X-%s-%s' % (g0, g1, g2, g3[0:4], g3[4:])
  164. def setguid(contents, offset, guid):
  165. guid = uuid.UUID(guid.decode('utf-8'))
  166. struct.pack_into('<IHH8s', contents, offset,
  167. *(guid.fields[0:3] + (guid.bytes[8:], )))
  168. def overwrite_guids_tlb(tlb_file, dynamic_guids):
  169. contents, ntypes, type_off, guid_off, guid_len = get_tlb_contents(tlb_file)
  170. for i in range(0, guid_len, 24):
  171. current_guid = getguid(contents, guid_off + i)
  172. for key in dynamic_guids:
  173. if key.lower() == current_guid.lower():
  174. setguid(contents, guid_off + i, dynamic_guids[key])
  175. recreate_guid_hashtable(contents, ntypes, guid_off, guid_len)
  176. open(tlb_file, 'wb').write(contents)
  177. # Handle multiple guid substitutions, where |dynamic_guids| is of the form
  178. # "PLACEHOLDER-GUID-158428a4-6014-4978-83ba-9fad0dabe791="
  179. # "3d852661-c795-4d20-9b95-5561e9a1d2d9,"
  180. # "PLACEHOLDER-GUID-63B8FFB1-5314-48C9-9C57-93EC8BC6184B="
  181. # "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83".
  182. #
  183. # Before specifying |dynamic_guids| in the build, the IDL file is first compiled
  184. # with "158428a4-6014-4978-83ba-9fad0dabe791" and
  185. # "63B8FFB1-5314-48C9-9C57-93EC8BC6184B". These are the "replaceable" guids,
  186. # i.e., guids that can be replaced in future builds. The resulting MIDL outputs
  187. # are copied over to src\third_party\win_build_output\.
  188. #
  189. # Then, in the future, any changes to these guids can be accomplished by
  190. # providing |dynamic_guids| of the format above in the build file. These
  191. # "dynamic" guid changes by themselves will not require the MIDL compiler and
  192. # therefore will not require copying output over to
  193. # src\third_party\win_build_output\.
  194. #
  195. # The pre-generated src\third_party\win_build_output\ files are used for
  196. # cross-compiling on other platforms, since the MIDL compiler is Windows-only.
  197. def overwrite_guids(h_file, iid_file, proxy_file, tlb_file, dynamic_guids):
  198. # Fix up GUIDs in .h, _i.c, _p.c, and .tlb.
  199. overwrite_guids_h(h_file, dynamic_guids)
  200. overwrite_guids_iid(iid_file, dynamic_guids)
  201. overwrite_guids_proxy(proxy_file, dynamic_guids)
  202. if tlb_file:
  203. overwrite_guids_tlb(tlb_file, dynamic_guids)
  204. # This function removes all occurrences of 'PLACEHOLDER-GUID-' from the
  205. # template, and if |dynamic_guids| is specified, also replaces the guids within
  206. # the file. Finally, it writes the resultant output to the |idl| file.
  207. def generate_idl_from_template(idl_template, dynamic_guids, idl):
  208. contents = open(idl_template, 'rb').read()
  209. contents = re.sub(b'PLACEHOLDER-GUID-', b'', contents, flags=re.I)
  210. if dynamic_guids:
  211. for key in dynamic_guids:
  212. contents = re.sub(key, dynamic_guids[key], contents, flags=re.I)
  213. open(idl, 'wb').write(contents)
  214. # This function runs the MIDL compiler with the provided arguments. It creates
  215. # and returns a tuple of |0,midl_output_dir| on success.
  216. def run_midl(args, env_dict):
  217. midl_output_dir = tempfile.mkdtemp()
  218. delete_midl_output_dir = True
  219. try:
  220. popen = subprocess.Popen(args + ['/out', midl_output_dir],
  221. shell=True,
  222. universal_newlines=True,
  223. env=env_dict,
  224. stdout=subprocess.PIPE,
  225. stderr=subprocess.STDOUT)
  226. out, _ = popen.communicate()
  227. # Filter junk out of stdout, and write filtered versions. Output we want
  228. # to filter is pairs of lines that look like this:
  229. # Processing C:\Program Files (x86)\Microsoft SDKs\...\include\objidl.idl
  230. # objidl.idl
  231. lines = out.splitlines()
  232. prefixes = ('Processing ', '64 bit Processing ')
  233. processing = set(
  234. os.path.basename(x) for x in lines if x.startswith(prefixes))
  235. for line in lines:
  236. if not line.startswith(prefixes) and line not in processing:
  237. print(line)
  238. if popen.returncode != 0:
  239. return popen.returncode, midl_output_dir
  240. for f in os.listdir(midl_output_dir):
  241. ZapTimestamp(os.path.join(midl_output_dir, f))
  242. delete_midl_output_dir = False
  243. finally:
  244. if os.path.exists(midl_output_dir) and delete_midl_output_dir:
  245. shutil.rmtree(midl_output_dir)
  246. return 0, midl_output_dir
  247. # This function adds support for dynamic generation of guids: when values are
  248. # specified as 'uuid5:name', this function will substitute the values with
  249. # generated dynamic guids using the uuid5 function. The uuid5 function generates
  250. # a guid based on the SHA-1 hash of a namespace identifier (which is the guid
  251. # that comes after 'PLACEHOLDER-GUID-') and a name (which is a string, such as a
  252. # version string "87.1.2.3").
  253. #
  254. # For instance, when |dynamic_guid| is of the form:
  255. # "PLACEHOLDER-GUID-158428a4-6014-4978-83ba-9fad0dabe791=uuid5:88.0.4307.0
  256. # ,"
  257. # "PLACEHOLDER-GUID-63B8FFB1-5314-48C9-9C57-93EC8BC6184B=uuid5:88.0.4307.0
  258. # "
  259. #
  260. # "PLACEHOLDER-GUID-158428a4-6014-4978-83ba-9fad0dabe791" would be substituted
  261. # with uuid5("158428a4-6014-4978-83ba-9fad0dabe791", "88.0.4307.0"), which is
  262. # "64700170-AD80-5DE3-924E-2F39D862CFD5". And
  263. # "PLACEHOLDER-GUID-63B8FFB1-5314-48C9-9C57-93EC8BC6184B" would be
  264. # substituted with uuid5("63B8FFB1-5314-48C9-9C57-93EC8BC6184B", "88.0.4307.0"),
  265. # which is "7B6E7538-3C38-5565-BC92-42BCEE268D76".
  266. def uuid5_substitutions(dynamic_guids):
  267. for key, value in dynamic_guids.items():
  268. if value.startswith('uuid5:'):
  269. name = value.split('uuid5:', 1)[1]
  270. assert name
  271. dynamic_guids[key] = str(uuid.uuid5(uuid.UUID(key), name)).upper()
  272. def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy,
  273. clang, idl, *flags):
  274. # Copy checked-in outputs to final location.
  275. source = gendir
  276. if os.path.isdir(os.path.join(source, os.path.basename(idl))):
  277. source = os.path.join(source, os.path.basename(idl))
  278. source = os.path.join(source, arch.split('.')[1]) # Append 'x86' or 'x64'.
  279. source = os.path.normpath(source)
  280. source_exists = True
  281. if not os.path.isdir(source):
  282. source_exists = False
  283. if sys.platform != 'win32':
  284. print('Directory %s needs to be populated from Windows first' % source)
  285. return 1
  286. # This is a brand new IDL file that does not have outputs under
  287. # third_party\win_build_output\midl. We create an empty directory for now.
  288. os.makedirs(source)
  289. common_files = [h, iid]
  290. if tlb != 'none':
  291. # Not all projects use tlb files.
  292. common_files += [tlb]
  293. else:
  294. tlb = None
  295. if dlldata != 'none':
  296. # Not all projects use dlldta files.
  297. common_files += [dlldata]
  298. else:
  299. dlldata = None
  300. # Not all projects use proxy files
  301. if proxy != 'none':
  302. # Not all projects use proxy files.
  303. common_files += [proxy]
  304. else:
  305. proxy = None
  306. for source_file in common_files:
  307. file_path = os.path.join(source, source_file)
  308. if not os.path.isfile(file_path):
  309. source_exists = False
  310. if sys.platform != 'win32':
  311. print('File %s needs to be generated from Windows first' % file_path)
  312. return 1
  313. # Either this is a brand new IDL file that does not have outputs under
  314. # third_party\win_build_output\midl or the file is (unexpectedly) missing.
  315. # We create an empty file for now. The rest of the machinery below will
  316. # then generate the correctly populated file using the MIDL compiler and
  317. # instruct the developer to copy that file under
  318. # third_party\win_build_output\midl.
  319. open(file_path, 'wb').close()
  320. shutil.copy(file_path, outdir)
  321. if dynamic_guids != 'none':
  322. assert '=' in dynamic_guids
  323. if dynamic_guids.startswith("ignore_proxy_stub,"):
  324. # TODO(ganesh): The custom proxy/stub file ("_p.c") is not generated
  325. # correctly for dynamic IIDs (but correctly if there are only dynamic
  326. # CLSIDs). The proxy/stub lookup functions generated by MIDL.exe within
  327. # "_p.c" rely on a sorted set of vtable lists, which we are not currently
  328. # regenerating. At the moment, no project in Chromium that uses dynamic
  329. # IIDs is relying on the custom proxy/stub file. So for now, if
  330. # |dynamic_guids| is prefixed with "ignore_proxy_stub,", we exclude the
  331. # custom proxy/stub file from the directory comparisons.
  332. common_files.remove(proxy)
  333. dynamic_guids = dynamic_guids.split("ignore_proxy_stub,", 1)[1]
  334. dynamic_guids = re.sub('PLACEHOLDER-GUID-', '', dynamic_guids, flags=re.I)
  335. dynamic_guids = dynamic_guids.split(',')
  336. dynamic_guids = dict(s.split('=') for s in dynamic_guids)
  337. uuid5_substitutions(dynamic_guids)
  338. dynamic_guids_bytes = {
  339. k.encode('utf-8'): v.encode('utf-8')
  340. for k, v in dynamic_guids.items()
  341. }
  342. if source_exists:
  343. overwrite_guids(*(os.path.join(outdir, file) if file else None
  344. for file in [h, iid, proxy, tlb]),
  345. dynamic_guids=dynamic_guids_bytes)
  346. else:
  347. dynamic_guids = None
  348. # On non-Windows, that's all we can do.
  349. if sys.platform != 'win32':
  350. return 0
  351. idl_template = None
  352. if dynamic_guids:
  353. idl_template = idl
  354. # posixpath is used here to keep the MIDL-generated files with a uniform
  355. # separator of '/' instead of mixed '/' and '\\'.
  356. idl = posixpath.join(
  357. outdir,
  358. os.path.splitext(os.path.basename(idl_template))[0] + '.idl')
  359. # |idl_template| can contain one or more occurrences of guids that are
  360. # substituted with |dynamic_guids|, and then MIDL is run on the substituted
  361. # IDL file.
  362. generate_idl_from_template(idl_template, dynamic_guids_bytes, idl)
  363. # On Windows, run midl.exe on the input and check that its outputs are
  364. # identical to the checked-in outputs (after replacing guids if
  365. # |dynamic_guids| is specified).
  366. # Read the environment block from the file. This is stored in the format used
  367. # by CreateProcess. Drop last 2 NULs, one for list terminator, one for
  368. # trailing vs. separator.
  369. env_pairs = open(arch).read()[:-2].split('\0')
  370. env_dict = dict([item.split('=', 1) for item in env_pairs])
  371. # Extract the /D options and send them to the preprocessor.
  372. preprocessor_options = '-E -nologo -Wno-nonportable-include-path'
  373. preprocessor_options += ''.join(
  374. [' ' + flag for flag in flags if flag.startswith('/D')])
  375. args = ['midl', '/nologo'] + list(flags) + (['/tlb', tlb] if tlb else []) + [
  376. '/h', h
  377. ] + (['/dlldata', dlldata] if dlldata else []) + ['/iid', iid] + (
  378. ['/proxy', proxy] if proxy else
  379. []) + ['/cpp_cmd', clang, '/cpp_opt', preprocessor_options, idl]
  380. returncode, midl_output_dir = run_midl(args, env_dict)
  381. if returncode != 0:
  382. return returncode
  383. # Now compare the output in midl_output_dir to the copied-over outputs.
  384. _, mismatch, errors = filecmp.cmpfiles(midl_output_dir, outdir, common_files)
  385. assert not errors
  386. if mismatch:
  387. print('midl.exe output different from files in %s, see %s' %
  388. (outdir, midl_output_dir))
  389. for f in mismatch:
  390. if f.endswith('.tlb'): continue
  391. fromfile = os.path.join(outdir, f)
  392. tofile = os.path.join(midl_output_dir, f)
  393. print(''.join(
  394. difflib.unified_diff(
  395. io.open(fromfile).readlines(),
  396. io.open(tofile).readlines(), fromfile, tofile)))
  397. if dynamic_guids:
  398. # |idl_template| can contain one or more occurrences of guids prefixed
  399. # with 'PLACEHOLDER-GUID-'. We first remove the extraneous
  400. # 'PLACEHOLDER-GUID-' prefix and then run MIDL on the substituted IDL
  401. # file.
  402. # No guid substitutions are done at this point, because we want to compile
  403. # with the placeholder guids and then instruct the user to copy the output
  404. # over to |source| which is typically src\third_party\win_build_output\.
  405. # In future runs, the placeholder guids in |source| are replaced with the
  406. # guids specified in |dynamic_guids|.
  407. generate_idl_from_template(idl_template, None, idl)
  408. returncode, midl_output_dir = run_midl(args, env_dict)
  409. if returncode != 0:
  410. return returncode
  411. print('To rebaseline:')
  412. print(r' copy /y %s\* %s' % (midl_output_dir, source))
  413. return 1
  414. return 0
  415. if __name__ == '__main__':
  416. sys.exit(main(*sys.argv[1:]))