abi_check.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. #!/usr/bin/env python3
  2. """This script compares the interfaces of two versions of Mbed TLS, looking
  3. for backward incompatibilities between two different Git revisions within
  4. an Mbed TLS repository. It must be run from the root of a Git working tree.
  5. ### How the script works ###
  6. For the source (API) and runtime (ABI) interface compatibility, this script
  7. is a small wrapper around the abi-compliance-checker and abi-dumper tools,
  8. applying them to compare the header and library files.
  9. For the storage format, this script compares the automatically generated
  10. storage tests and the manual read tests, and complains if there is a
  11. reduction in coverage. A change in test data will be signaled as a
  12. coverage reduction since the old test data is no longer present. A change in
  13. how test data is presented will be signaled as well; this would be a false
  14. positive.
  15. The results of the API/ABI comparison are either formatted as HTML and stored
  16. at a configurable location, or are given as a brief list of problems.
  17. Returns 0 on success, 1 on non-compliance, and 2 if there is an error
  18. while running the script.
  19. ### How to interpret non-compliance ###
  20. This script has relatively common false positives. In many scenarios, it only
  21. reports a pass if there is a strict textual match between the old version and
  22. the new version, and it reports problems where there is a sufficient semantic
  23. match but not a textual match. This section lists some common false positives.
  24. This is not an exhaustive list: in the end what matters is whether we are
  25. breaking a backward compatibility goal.
  26. **API**: the goal is that if an application works with the old version of the
  27. library, it can be recompiled against the new version and will still work.
  28. This is normally validated by comparing the declarations in `include/*/*.h`.
  29. A failure is a declaration that has disappeared or that now has a different
  30. type.
  31. * It's ok to change or remove macros and functions that are documented as
  32. for internal use only or as experimental.
  33. * It's ok to rename function or macro parameters as long as the semantics
  34. has not changed.
  35. * It's ok to change or remove structure fields that are documented as
  36. private.
  37. * It's ok to add fields to a structure that already had private fields
  38. or was documented as extensible.
  39. **ABI**: the goal is that if an application was built against the old version
  40. of the library, the same binary will work when linked against the new version.
  41. This is normally validated by comparing the symbols exported by `libmbed*.so`.
  42. A failure is a symbol that is no longer exported by the same library or that
  43. now has a different type.
  44. * All ABI changes are acceptable if the library version is bumped
  45. (see `scripts/bump_version.sh`).
  46. * ABI changes that concern functions which are declared only inside the
  47. library directory, and not in `include/*/*.h`, are acceptable only if
  48. the function was only ever used inside the same library (libmbedcrypto,
  49. libmbedx509, libmbedtls). As a counter example, if the old version
  50. of libmbedtls calls mbedtls_foo() from libmbedcrypto, and the new version
  51. of libmbedcrypto no longer has a compatible mbedtls_foo(), this does
  52. require a version bump for libmbedcrypto.
  53. **Storage format**: the goal is to check that persistent keys stored by the
  54. old version can be read by the new version. This is normally validated by
  55. comparing the `*read*` test cases in `test_suite*storage_format*.data`.
  56. A failure is a storage read test case that is no longer present with the same
  57. function name and parameter list.
  58. * It's ok if the same test data is present, but its presentation has changed,
  59. for example if a test function is renamed or has different parameters.
  60. * It's ok if redundant tests are removed.
  61. **Generated test coverage**: the goal is to check that automatically
  62. generated tests have as much coverage as before. This is normally validated
  63. by comparing the test cases that are automatically generated by a script.
  64. A failure is a generated test case that is no longer present with the same
  65. function name and parameter list.
  66. * It's ok if the same test data is present, but its presentation has changed,
  67. for example if a test function is renamed or has different parameters.
  68. * It's ok if redundant tests are removed.
  69. """
  70. # Copyright The Mbed TLS Contributors
  71. # SPDX-License-Identifier: Apache-2.0
  72. #
  73. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  74. # not use this file except in compliance with the License.
  75. # You may obtain a copy of the License at
  76. #
  77. # http://www.apache.org/licenses/LICENSE-2.0
  78. #
  79. # Unless required by applicable law or agreed to in writing, software
  80. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  81. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  82. # See the License for the specific language governing permissions and
  83. # limitations under the License.
  84. import glob
  85. import os
  86. import re
  87. import sys
  88. import traceback
  89. import shutil
  90. import subprocess
  91. import argparse
  92. import logging
  93. import tempfile
  94. import fnmatch
  95. from types import SimpleNamespace
  96. import xml.etree.ElementTree as ET
  97. from mbedtls_dev import build_tree
  98. class AbiChecker:
  99. """API and ABI checker."""
  100. def __init__(self, old_version, new_version, configuration):
  101. """Instantiate the API/ABI checker.
  102. old_version: RepoVersion containing details to compare against
  103. new_version: RepoVersion containing details to check
  104. configuration.report_dir: directory for output files
  105. configuration.keep_all_reports: if false, delete old reports
  106. configuration.brief: if true, output shorter report to stdout
  107. configuration.check_abi: if true, compare ABIs
  108. configuration.check_api: if true, compare APIs
  109. configuration.check_storage: if true, compare storage format tests
  110. configuration.skip_file: path to file containing symbols and types to skip
  111. """
  112. self.repo_path = "."
  113. self.log = None
  114. self.verbose = configuration.verbose
  115. self._setup_logger()
  116. self.report_dir = os.path.abspath(configuration.report_dir)
  117. self.keep_all_reports = configuration.keep_all_reports
  118. self.can_remove_report_dir = not (os.path.exists(self.report_dir) or
  119. self.keep_all_reports)
  120. self.old_version = old_version
  121. self.new_version = new_version
  122. self.skip_file = configuration.skip_file
  123. self.check_abi = configuration.check_abi
  124. self.check_api = configuration.check_api
  125. if self.check_abi != self.check_api:
  126. raise Exception('Checking API without ABI or vice versa is not supported')
  127. self.check_storage_tests = configuration.check_storage
  128. self.brief = configuration.brief
  129. self.git_command = "git"
  130. self.make_command = "make"
  131. def _setup_logger(self):
  132. self.log = logging.getLogger()
  133. if self.verbose:
  134. self.log.setLevel(logging.DEBUG)
  135. else:
  136. self.log.setLevel(logging.INFO)
  137. self.log.addHandler(logging.StreamHandler())
  138. @staticmethod
  139. def check_abi_tools_are_installed():
  140. for command in ["abi-dumper", "abi-compliance-checker"]:
  141. if not shutil.which(command):
  142. raise Exception("{} not installed, aborting".format(command))
  143. def _get_clean_worktree_for_git_revision(self, version):
  144. """Make a separate worktree with version.revision checked out.
  145. Do not modify the current worktree."""
  146. git_worktree_path = tempfile.mkdtemp()
  147. if version.repository:
  148. self.log.debug(
  149. "Checking out git worktree for revision {} from {}".format(
  150. version.revision, version.repository
  151. )
  152. )
  153. fetch_output = subprocess.check_output(
  154. [self.git_command, "fetch",
  155. version.repository, version.revision],
  156. cwd=self.repo_path,
  157. stderr=subprocess.STDOUT
  158. )
  159. self.log.debug(fetch_output.decode("utf-8"))
  160. worktree_rev = "FETCH_HEAD"
  161. else:
  162. self.log.debug("Checking out git worktree for revision {}".format(
  163. version.revision
  164. ))
  165. worktree_rev = version.revision
  166. worktree_output = subprocess.check_output(
  167. [self.git_command, "worktree", "add", "--detach",
  168. git_worktree_path, worktree_rev],
  169. cwd=self.repo_path,
  170. stderr=subprocess.STDOUT
  171. )
  172. self.log.debug(worktree_output.decode("utf-8"))
  173. version.commit = subprocess.check_output(
  174. [self.git_command, "rev-parse", "HEAD"],
  175. cwd=git_worktree_path,
  176. stderr=subprocess.STDOUT
  177. ).decode("ascii").rstrip()
  178. self.log.debug("Commit is {}".format(version.commit))
  179. return git_worktree_path
  180. def _update_git_submodules(self, git_worktree_path, version):
  181. """If the crypto submodule is present, initialize it.
  182. if version.crypto_revision exists, update it to that revision,
  183. otherwise update it to the default revision"""
  184. update_output = subprocess.check_output(
  185. [self.git_command, "submodule", "update", "--init", '--recursive'],
  186. cwd=git_worktree_path,
  187. stderr=subprocess.STDOUT
  188. )
  189. self.log.debug(update_output.decode("utf-8"))
  190. if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
  191. and version.crypto_revision):
  192. return
  193. if version.crypto_repository:
  194. fetch_output = subprocess.check_output(
  195. [self.git_command, "fetch", version.crypto_repository,
  196. version.crypto_revision],
  197. cwd=os.path.join(git_worktree_path, "crypto"),
  198. stderr=subprocess.STDOUT
  199. )
  200. self.log.debug(fetch_output.decode("utf-8"))
  201. crypto_rev = "FETCH_HEAD"
  202. else:
  203. crypto_rev = version.crypto_revision
  204. checkout_output = subprocess.check_output(
  205. [self.git_command, "checkout", crypto_rev],
  206. cwd=os.path.join(git_worktree_path, "crypto"),
  207. stderr=subprocess.STDOUT
  208. )
  209. self.log.debug(checkout_output.decode("utf-8"))
  210. def _build_shared_libraries(self, git_worktree_path, version):
  211. """Build the shared libraries in the specified worktree."""
  212. my_environment = os.environ.copy()
  213. my_environment["CFLAGS"] = "-g -Og"
  214. my_environment["SHARED"] = "1"
  215. if os.path.exists(os.path.join(git_worktree_path, "crypto")):
  216. my_environment["USE_CRYPTO_SUBMODULE"] = "1"
  217. make_output = subprocess.check_output(
  218. [self.make_command, "lib"],
  219. env=my_environment,
  220. cwd=git_worktree_path,
  221. stderr=subprocess.STDOUT
  222. )
  223. self.log.debug(make_output.decode("utf-8"))
  224. for root, _dirs, files in os.walk(git_worktree_path):
  225. for file in fnmatch.filter(files, "*.so"):
  226. version.modules[os.path.splitext(file)[0]] = (
  227. os.path.join(root, file)
  228. )
  229. @staticmethod
  230. def _pretty_revision(version):
  231. if version.revision == version.commit:
  232. return version.revision
  233. else:
  234. return "{} ({})".format(version.revision, version.commit)
  235. def _get_abi_dumps_from_shared_libraries(self, version):
  236. """Generate the ABI dumps for the specified git revision.
  237. The shared libraries must have been built and the module paths
  238. present in version.modules."""
  239. for mbed_module, module_path in version.modules.items():
  240. output_path = os.path.join(
  241. self.report_dir, "{}-{}-{}.dump".format(
  242. mbed_module, version.revision, version.version
  243. )
  244. )
  245. abi_dump_command = [
  246. "abi-dumper",
  247. module_path,
  248. "-o", output_path,
  249. "-lver", self._pretty_revision(version),
  250. ]
  251. abi_dump_output = subprocess.check_output(
  252. abi_dump_command,
  253. stderr=subprocess.STDOUT
  254. )
  255. self.log.debug(abi_dump_output.decode("utf-8"))
  256. version.abi_dumps[mbed_module] = output_path
  257. @staticmethod
  258. def _normalize_storage_test_case_data(line):
  259. """Eliminate cosmetic or irrelevant details in storage format test cases."""
  260. line = re.sub(r'\s+', r'', line)
  261. return line
  262. def _read_storage_tests(self,
  263. directory,
  264. filename,
  265. is_generated,
  266. storage_tests):
  267. """Record storage tests from the given file.
  268. Populate the storage_tests dictionary with test cases read from
  269. filename under directory.
  270. """
  271. at_paragraph_start = True
  272. description = None
  273. full_path = os.path.join(directory, filename)
  274. with open(full_path) as fd:
  275. for line_number, line in enumerate(fd, 1):
  276. line = line.strip()
  277. if not line:
  278. at_paragraph_start = True
  279. continue
  280. if line.startswith('#'):
  281. continue
  282. if at_paragraph_start:
  283. description = line.strip()
  284. at_paragraph_start = False
  285. continue
  286. if line.startswith('depends_on:'):
  287. continue
  288. # We've reached a test case data line
  289. test_case_data = self._normalize_storage_test_case_data(line)
  290. if not is_generated:
  291. # In manual test data, only look at read tests.
  292. function_name = test_case_data.split(':', 1)[0]
  293. if 'read' not in function_name.split('_'):
  294. continue
  295. metadata = SimpleNamespace(
  296. filename=filename,
  297. line_number=line_number,
  298. description=description
  299. )
  300. storage_tests[test_case_data] = metadata
  301. @staticmethod
  302. def _list_generated_test_data_files(git_worktree_path):
  303. """List the generated test data files."""
  304. output = subprocess.check_output(
  305. ['tests/scripts/generate_psa_tests.py', '--list'],
  306. cwd=git_worktree_path,
  307. ).decode('ascii')
  308. return [line for line in output.split('\n') if line]
  309. def _get_storage_format_tests(self, version, git_worktree_path):
  310. """Record the storage format tests for the specified git version.
  311. The storage format tests are the test suite data files whose name
  312. contains "storage_format".
  313. The version must be checked out at git_worktree_path.
  314. This function creates or updates the generated data files.
  315. """
  316. # Existing test data files. This may be missing some automatically
  317. # generated files if they haven't been generated yet.
  318. storage_data_files = set(glob.glob(
  319. 'tests/suites/test_suite_*storage_format*.data'
  320. ))
  321. # Discover and (re)generate automatically generated data files.
  322. to_be_generated = set()
  323. for filename in self._list_generated_test_data_files(git_worktree_path):
  324. if 'storage_format' in filename:
  325. storage_data_files.add(filename)
  326. to_be_generated.add(filename)
  327. subprocess.check_call(
  328. ['tests/scripts/generate_psa_tests.py'] + sorted(to_be_generated),
  329. cwd=git_worktree_path,
  330. )
  331. for test_file in sorted(storage_data_files):
  332. self._read_storage_tests(git_worktree_path,
  333. test_file,
  334. test_file in to_be_generated,
  335. version.storage_tests)
  336. def _cleanup_worktree(self, git_worktree_path):
  337. """Remove the specified git worktree."""
  338. shutil.rmtree(git_worktree_path)
  339. worktree_output = subprocess.check_output(
  340. [self.git_command, "worktree", "prune"],
  341. cwd=self.repo_path,
  342. stderr=subprocess.STDOUT
  343. )
  344. self.log.debug(worktree_output.decode("utf-8"))
  345. def _get_abi_dump_for_ref(self, version):
  346. """Generate the interface information for the specified git revision."""
  347. git_worktree_path = self._get_clean_worktree_for_git_revision(version)
  348. self._update_git_submodules(git_worktree_path, version)
  349. if self.check_abi:
  350. self._build_shared_libraries(git_worktree_path, version)
  351. self._get_abi_dumps_from_shared_libraries(version)
  352. if self.check_storage_tests:
  353. self._get_storage_format_tests(version, git_worktree_path)
  354. self._cleanup_worktree(git_worktree_path)
  355. def _remove_children_with_tag(self, parent, tag):
  356. children = parent.getchildren()
  357. for child in children:
  358. if child.tag == tag:
  359. parent.remove(child)
  360. else:
  361. self._remove_children_with_tag(child, tag)
  362. def _remove_extra_detail_from_report(self, report_root):
  363. for tag in ['test_info', 'test_results', 'problem_summary',
  364. 'added_symbols', 'affected']:
  365. self._remove_children_with_tag(report_root, tag)
  366. for report in report_root:
  367. for problems in report.getchildren()[:]:
  368. if not problems.getchildren():
  369. report.remove(problems)
  370. def _abi_compliance_command(self, mbed_module, output_path):
  371. """Build the command to run to analyze the library mbed_module.
  372. The report will be placed in output_path."""
  373. abi_compliance_command = [
  374. "abi-compliance-checker",
  375. "-l", mbed_module,
  376. "-old", self.old_version.abi_dumps[mbed_module],
  377. "-new", self.new_version.abi_dumps[mbed_module],
  378. "-strict",
  379. "-report-path", output_path,
  380. ]
  381. if self.skip_file:
  382. abi_compliance_command += ["-skip-symbols", self.skip_file,
  383. "-skip-types", self.skip_file]
  384. if self.brief:
  385. abi_compliance_command += ["-report-format", "xml",
  386. "-stdout"]
  387. return abi_compliance_command
  388. def _is_library_compatible(self, mbed_module, compatibility_report):
  389. """Test if the library mbed_module has remained compatible.
  390. Append a message regarding compatibility to compatibility_report."""
  391. output_path = os.path.join(
  392. self.report_dir, "{}-{}-{}.html".format(
  393. mbed_module, self.old_version.revision,
  394. self.new_version.revision
  395. )
  396. )
  397. try:
  398. subprocess.check_output(
  399. self._abi_compliance_command(mbed_module, output_path),
  400. stderr=subprocess.STDOUT
  401. )
  402. except subprocess.CalledProcessError as err:
  403. if err.returncode != 1:
  404. raise err
  405. if self.brief:
  406. self.log.info(
  407. "Compatibility issues found for {}".format(mbed_module)
  408. )
  409. report_root = ET.fromstring(err.output.decode("utf-8"))
  410. self._remove_extra_detail_from_report(report_root)
  411. self.log.info(ET.tostring(report_root).decode("utf-8"))
  412. else:
  413. self.can_remove_report_dir = False
  414. compatibility_report.append(
  415. "Compatibility issues found for {}, "
  416. "for details see {}".format(mbed_module, output_path)
  417. )
  418. return False
  419. compatibility_report.append(
  420. "No compatibility issues for {}".format(mbed_module)
  421. )
  422. if not (self.keep_all_reports or self.brief):
  423. os.remove(output_path)
  424. return True
  425. @staticmethod
  426. def _is_storage_format_compatible(old_tests, new_tests,
  427. compatibility_report):
  428. """Check whether all tests present in old_tests are also in new_tests.
  429. Append a message regarding compatibility to compatibility_report.
  430. """
  431. missing = frozenset(old_tests.keys()).difference(new_tests.keys())
  432. for test_data in sorted(missing):
  433. metadata = old_tests[test_data]
  434. compatibility_report.append(
  435. 'Test case from {} line {} "{}" has disappeared: {}'.format(
  436. metadata.filename, metadata.line_number,
  437. metadata.description, test_data
  438. )
  439. )
  440. compatibility_report.append(
  441. 'FAIL: {}/{} storage format test cases have changed or disappeared.'.format(
  442. len(missing), len(old_tests)
  443. ) if missing else
  444. 'PASS: All {} storage format test cases are preserved.'.format(
  445. len(old_tests)
  446. )
  447. )
  448. compatibility_report.append(
  449. 'Info: number of storage format tests cases: {} -> {}.'.format(
  450. len(old_tests), len(new_tests)
  451. )
  452. )
  453. return not missing
  454. def get_abi_compatibility_report(self):
  455. """Generate a report of the differences between the reference ABI
  456. and the new ABI. ABI dumps from self.old_version and self.new_version
  457. must be available."""
  458. compatibility_report = ["Checking evolution from {} to {}".format(
  459. self._pretty_revision(self.old_version),
  460. self._pretty_revision(self.new_version)
  461. )]
  462. compliance_return_code = 0
  463. if self.check_abi:
  464. shared_modules = list(set(self.old_version.modules.keys()) &
  465. set(self.new_version.modules.keys()))
  466. for mbed_module in shared_modules:
  467. if not self._is_library_compatible(mbed_module,
  468. compatibility_report):
  469. compliance_return_code = 1
  470. if self.check_storage_tests:
  471. if not self._is_storage_format_compatible(
  472. self.old_version.storage_tests,
  473. self.new_version.storage_tests,
  474. compatibility_report):
  475. compliance_return_code = 1
  476. for version in [self.old_version, self.new_version]:
  477. for mbed_module, mbed_module_dump in version.abi_dumps.items():
  478. os.remove(mbed_module_dump)
  479. if self.can_remove_report_dir:
  480. os.rmdir(self.report_dir)
  481. self.log.info("\n".join(compatibility_report))
  482. return compliance_return_code
  483. def check_for_abi_changes(self):
  484. """Generate a report of ABI differences
  485. between self.old_rev and self.new_rev."""
  486. build_tree.check_repo_path()
  487. if self.check_api or self.check_abi:
  488. self.check_abi_tools_are_installed()
  489. self._get_abi_dump_for_ref(self.old_version)
  490. self._get_abi_dump_for_ref(self.new_version)
  491. return self.get_abi_compatibility_report()
  492. def run_main():
  493. try:
  494. parser = argparse.ArgumentParser(
  495. description=__doc__
  496. )
  497. parser.add_argument(
  498. "-v", "--verbose", action="store_true",
  499. help="set verbosity level",
  500. )
  501. parser.add_argument(
  502. "-r", "--report-dir", type=str, default="reports",
  503. help="directory where reports are stored, default is reports",
  504. )
  505. parser.add_argument(
  506. "-k", "--keep-all-reports", action="store_true",
  507. help="keep all reports, even if there are no compatibility issues",
  508. )
  509. parser.add_argument(
  510. "-o", "--old-rev", type=str, help="revision for old version.",
  511. required=True,
  512. )
  513. parser.add_argument(
  514. "-or", "--old-repo", type=str, help="repository for old version."
  515. )
  516. parser.add_argument(
  517. "-oc", "--old-crypto-rev", type=str,
  518. help="revision for old crypto submodule."
  519. )
  520. parser.add_argument(
  521. "-ocr", "--old-crypto-repo", type=str,
  522. help="repository for old crypto submodule."
  523. )
  524. parser.add_argument(
  525. "-n", "--new-rev", type=str, help="revision for new version",
  526. required=True,
  527. )
  528. parser.add_argument(
  529. "-nr", "--new-repo", type=str, help="repository for new version."
  530. )
  531. parser.add_argument(
  532. "-nc", "--new-crypto-rev", type=str,
  533. help="revision for new crypto version"
  534. )
  535. parser.add_argument(
  536. "-ncr", "--new-crypto-repo", type=str,
  537. help="repository for new crypto submodule."
  538. )
  539. parser.add_argument(
  540. "-s", "--skip-file", type=str,
  541. help=("path to file containing symbols and types to skip "
  542. "(typically \"-s identifiers\" after running "
  543. "\"tests/scripts/list-identifiers.sh --internal\")")
  544. )
  545. parser.add_argument(
  546. "--check-abi",
  547. action='store_true', default=True,
  548. help="Perform ABI comparison (default: yes)"
  549. )
  550. parser.add_argument("--no-check-abi", action='store_false', dest='check_abi')
  551. parser.add_argument(
  552. "--check-api",
  553. action='store_true', default=True,
  554. help="Perform API comparison (default: yes)"
  555. )
  556. parser.add_argument("--no-check-api", action='store_false', dest='check_api')
  557. parser.add_argument(
  558. "--check-storage",
  559. action='store_true', default=True,
  560. help="Perform storage tests comparison (default: yes)"
  561. )
  562. parser.add_argument("--no-check-storage", action='store_false', dest='check_storage')
  563. parser.add_argument(
  564. "-b", "--brief", action="store_true",
  565. help="output only the list of issues to stdout, instead of a full report",
  566. )
  567. abi_args = parser.parse_args()
  568. if os.path.isfile(abi_args.report_dir):
  569. print("Error: {} is not a directory".format(abi_args.report_dir))
  570. parser.exit()
  571. old_version = SimpleNamespace(
  572. version="old",
  573. repository=abi_args.old_repo,
  574. revision=abi_args.old_rev,
  575. commit=None,
  576. crypto_repository=abi_args.old_crypto_repo,
  577. crypto_revision=abi_args.old_crypto_rev,
  578. abi_dumps={},
  579. storage_tests={},
  580. modules={}
  581. )
  582. new_version = SimpleNamespace(
  583. version="new",
  584. repository=abi_args.new_repo,
  585. revision=abi_args.new_rev,
  586. commit=None,
  587. crypto_repository=abi_args.new_crypto_repo,
  588. crypto_revision=abi_args.new_crypto_rev,
  589. abi_dumps={},
  590. storage_tests={},
  591. modules={}
  592. )
  593. configuration = SimpleNamespace(
  594. verbose=abi_args.verbose,
  595. report_dir=abi_args.report_dir,
  596. keep_all_reports=abi_args.keep_all_reports,
  597. brief=abi_args.brief,
  598. check_abi=abi_args.check_abi,
  599. check_api=abi_args.check_api,
  600. check_storage=abi_args.check_storage,
  601. skip_file=abi_args.skip_file
  602. )
  603. abi_check = AbiChecker(old_version, new_version, configuration)
  604. return_code = abi_check.check_for_abi_changes()
  605. sys.exit(return_code)
  606. except Exception: # pylint: disable=broad-except
  607. # Print the backtrace and exit explicitly so as to exit with
  608. # status 2, not 1.
  609. traceback.print_exc()
  610. sys.exit(2)
  611. if __name__ == "__main__":
  612. run_main()