blob: e19f2c0c660ab16cf0f829c64b4ccff98d059535 [file] [log] [blame]
Darryl Green7c2dd582018-03-01 14:53:49 +00001#!/usr/bin/env python3
Darryl Green78696802018-04-06 11:23:22 +01002"""
3This file is part of Mbed TLS (https://tls.mbed.org)
4
5Copyright (c) 2018, Arm Limited, All Rights Reserved
6
7Purpose
8
9This script is a small wrapper around the abi-compliance-checker and
10abi-dumper tools, applying them to compare the ABI and API of the library
11files from two different Git revisions within an Mbed TLS repository.
Darryl Greene62f9bb2019-02-21 13:09:26 +000012The results of the comparison are either formatted as HTML and stored at
Darryl Green4cde8a02019-03-05 15:21:32 +000013a configurable location, or are given as a brief list of problems.
Darryl Greene62f9bb2019-02-21 13:09:26 +000014Returns 0 on success, 1 on ABI/API non-compliance, and 2 if there is an error
15while running the script. Note: must be run from Mbed TLS root.
Darryl Green78696802018-04-06 11:23:22 +010016"""
Darryl Green7c2dd582018-03-01 14:53:49 +000017
18import os
19import sys
20import traceback
21import shutil
22import subprocess
23import argparse
24import logging
25import tempfile
Darryl Green9f357d62019-02-25 11:35:05 +000026import fnmatch
Darryl Green0d1ca512019-04-09 09:14:17 +010027from types import SimpleNamespace
Darryl Green7c2dd582018-03-01 14:53:49 +000028
Darryl Greene62f9bb2019-02-21 13:09:26 +000029import xml.etree.ElementTree as ET
30
Darryl Green7c2dd582018-03-01 14:53:49 +000031
32class AbiChecker(object):
Gilles Peskine712afa72019-02-25 20:36:52 +010033 """API and ABI checker."""
Darryl Green7c2dd582018-03-01 14:53:49 +000034
Darryl Green0d1ca512019-04-09 09:14:17 +010035 def __init__(self, old_version, new_version, configuration):
Gilles Peskine712afa72019-02-25 20:36:52 +010036 """Instantiate the API/ABI checker.
37
Darryl Green7c1a7332019-03-05 16:25:38 +000038 old_version: RepoVersion containing details to compare against
39 new_version: RepoVersion containing details to check
Darryl Greenf67e3492019-04-12 15:17:02 +010040 configuration.report_dir: directory for output files
41 configuration.keep_all_reports: if false, delete old reports
42 configuration.brief: if true, output shorter report to stdout
43 configuration.skip_file: path to file containing symbols and types to skip
Gilles Peskine712afa72019-02-25 20:36:52 +010044 """
Darryl Green7c2dd582018-03-01 14:53:49 +000045 self.repo_path = "."
46 self.log = None
Darryl Green0d1ca512019-04-09 09:14:17 +010047 self.verbose = configuration.verbose
Darryl Green3a5f6c82019-03-05 16:30:39 +000048 self._setup_logger()
Darryl Green0d1ca512019-04-09 09:14:17 +010049 self.report_dir = os.path.abspath(configuration.report_dir)
50 self.keep_all_reports = configuration.keep_all_reports
Darryl Green492bc402019-04-11 15:50:41 +010051 self.can_remove_report_dir = not (os.path.exists(self.report_dir) or
Darryl Green0d1ca512019-04-09 09:14:17 +010052 self.keep_all_reports)
Darryl Green7c1a7332019-03-05 16:25:38 +000053 self.old_version = old_version
54 self.new_version = new_version
Darryl Green0d1ca512019-04-09 09:14:17 +010055 self.skip_file = configuration.skip_file
56 self.brief = configuration.brief
Darryl Green7c2dd582018-03-01 14:53:49 +000057 self.git_command = "git"
58 self.make_command = "make"
59
Gilles Peskine712afa72019-02-25 20:36:52 +010060 @staticmethod
61 def check_repo_path():
Gilles Peskine6aa32cc2019-07-04 18:59:36 +020062 if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
Darryl Green7c2dd582018-03-01 14:53:49 +000063 raise Exception("Must be run from Mbed TLS root")
64
Darryl Green3a5f6c82019-03-05 16:30:39 +000065 def _setup_logger(self):
Darryl Green7c2dd582018-03-01 14:53:49 +000066 self.log = logging.getLogger()
Darryl Green3c3da792019-03-08 11:30:04 +000067 if self.verbose:
68 self.log.setLevel(logging.DEBUG)
69 else:
70 self.log.setLevel(logging.INFO)
Darryl Green7c2dd582018-03-01 14:53:49 +000071 self.log.addHandler(logging.StreamHandler())
72
Gilles Peskine712afa72019-02-25 20:36:52 +010073 @staticmethod
74 def check_abi_tools_are_installed():
Darryl Green7c2dd582018-03-01 14:53:49 +000075 for command in ["abi-dumper", "abi-compliance-checker"]:
76 if not shutil.which(command):
77 raise Exception("{} not installed, aborting".format(command))
78
Darryl Green3a5f6c82019-03-05 16:30:39 +000079 def _get_clean_worktree_for_git_revision(self, version):
Darryl Green7c1a7332019-03-05 16:25:38 +000080 """Make a separate worktree with version.revision checked out.
Gilles Peskine712afa72019-02-25 20:36:52 +010081 Do not modify the current worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +000082 git_worktree_path = tempfile.mkdtemp()
Darryl Green7c1a7332019-03-05 16:25:38 +000083 if version.repository:
Darryl Green3c3da792019-03-08 11:30:04 +000084 self.log.debug(
Darryl Greenda84e322019-02-19 16:59:33 +000085 "Checking out git worktree for revision {} from {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +000086 version.revision, version.repository
Darryl Greenda84e322019-02-19 16:59:33 +000087 )
88 )
Darryl Greenb2ee0b82019-04-12 16:24:25 +010089 fetch_output = subprocess.check_output(
Darryl Green7c1a7332019-03-05 16:25:38 +000090 [self.git_command, "fetch",
91 version.repository, version.revision],
Darryl Greenda84e322019-02-19 16:59:33 +000092 cwd=self.repo_path,
Darryl Greenda84e322019-02-19 16:59:33 +000093 stderr=subprocess.STDOUT
94 )
Darryl Green3c3da792019-03-08 11:30:04 +000095 self.log.debug(fetch_output.decode("utf-8"))
Darryl Greenda84e322019-02-19 16:59:33 +000096 worktree_rev = "FETCH_HEAD"
97 else:
Darryl Green3c3da792019-03-08 11:30:04 +000098 self.log.debug("Checking out git worktree for revision {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +000099 version.revision
100 ))
101 worktree_rev = version.revision
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100102 worktree_output = subprocess.check_output(
Darryl Greenda84e322019-02-19 16:59:33 +0000103 [self.git_command, "worktree", "add", "--detach",
104 git_worktree_path, worktree_rev],
Darryl Green7c2dd582018-03-01 14:53:49 +0000105 cwd=self.repo_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000106 stderr=subprocess.STDOUT
107 )
Darryl Green3c3da792019-03-08 11:30:04 +0000108 self.log.debug(worktree_output.decode("utf-8"))
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200109 version.commit = subprocess.check_output(
Darryl Green762351b2019-07-25 14:33:33 +0100110 [self.git_command, "rev-parse", "HEAD"],
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200111 cwd=git_worktree_path,
112 stderr=subprocess.STDOUT
113 ).decode("ascii").rstrip()
114 self.log.debug("Commit is {}".format(version.commit))
Darryl Green7c2dd582018-03-01 14:53:49 +0000115 return git_worktree_path
116
Darryl Green3a5f6c82019-03-05 16:30:39 +0000117 def _update_git_submodules(self, git_worktree_path, version):
Darryl Green8184df52019-04-05 17:06:17 +0100118 """If the crypto submodule is present, initialize it.
119 if version.crypto_revision exists, update it to that revision,
120 otherwise update it to the default revision"""
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100121 update_output = subprocess.check_output(
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000122 [self.git_command, "submodule", "update", "--init", '--recursive'],
123 cwd=git_worktree_path,
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000124 stderr=subprocess.STDOUT
125 )
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100126 self.log.debug(update_output.decode("utf-8"))
Darryl Greene29ce702019-03-05 15:23:25 +0000127 if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
Darryl Green7c1a7332019-03-05 16:25:38 +0000128 and version.crypto_revision):
Darryl Greene29ce702019-03-05 15:23:25 +0000129 return
130
Darryl Green7c1a7332019-03-05 16:25:38 +0000131 if version.crypto_repository:
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100132 fetch_output = subprocess.check_output(
Darryl Green1d95c532019-03-08 11:12:19 +0000133 [self.git_command, "fetch", version.crypto_repository,
134 version.crypto_revision],
Darryl Greene29ce702019-03-05 15:23:25 +0000135 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Greene29ce702019-03-05 15:23:25 +0000136 stderr=subprocess.STDOUT
137 )
Darryl Green3c3da792019-03-08 11:30:04 +0000138 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green1d95c532019-03-08 11:12:19 +0000139 crypto_rev = "FETCH_HEAD"
140 else:
141 crypto_rev = version.crypto_revision
142
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100143 checkout_output = subprocess.check_output(
Darryl Green1d95c532019-03-08 11:12:19 +0000144 [self.git_command, "checkout", crypto_rev],
145 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Green1d95c532019-03-08 11:12:19 +0000146 stderr=subprocess.STDOUT
147 )
Darryl Green3c3da792019-03-08 11:30:04 +0000148 self.log.debug(checkout_output.decode("utf-8"))
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000149
Darryl Green3a5f6c82019-03-05 16:30:39 +0000150 def _build_shared_libraries(self, git_worktree_path, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100151 """Build the shared libraries in the specified worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000152 my_environment = os.environ.copy()
153 my_environment["CFLAGS"] = "-g -Og"
154 my_environment["SHARED"] = "1"
Darryl Greend2dba362019-05-09 13:03:05 +0100155 if os.path.exists(os.path.join(git_worktree_path, "crypto")):
156 my_environment["USE_CRYPTO_SUBMODULE"] = "1"
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100157 make_output = subprocess.check_output(
Darryl Greenddf25a62019-02-28 11:52:39 +0000158 [self.make_command, "lib"],
Darryl Green7c2dd582018-03-01 14:53:49 +0000159 env=my_environment,
160 cwd=git_worktree_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000161 stderr=subprocess.STDOUT
162 )
Darryl Green3c3da792019-03-08 11:30:04 +0000163 self.log.debug(make_output.decode("utf-8"))
Darryl Greenf025d532019-04-12 15:18:02 +0100164 for root, _dirs, files in os.walk(git_worktree_path):
Darryl Green9f357d62019-02-25 11:35:05 +0000165 for file in fnmatch.filter(files, "*.so"):
Darryl Green7c1a7332019-03-05 16:25:38 +0000166 version.modules[os.path.splitext(file)[0]] = (
Darryl Green3e7a9802019-02-27 16:53:40 +0000167 os.path.join(root, file)
Darryl Green9f357d62019-02-25 11:35:05 +0000168 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000169
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200170 @staticmethod
171 def _pretty_revision(version):
172 if version.revision == version.commit:
173 return version.revision
174 else:
175 return "{} ({})".format(version.revision, version.commit)
176
Darryl Green8184df52019-04-05 17:06:17 +0100177 def _get_abi_dumps_from_shared_libraries(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100178 """Generate the ABI dumps for the specified git revision.
Darryl Green8184df52019-04-05 17:06:17 +0100179 The shared libraries must have been built and the module paths
180 present in version.modules."""
Darryl Green7c1a7332019-03-05 16:25:38 +0000181 for mbed_module, module_path in version.modules.items():
Darryl Green7c2dd582018-03-01 14:53:49 +0000182 output_path = os.path.join(
Darryl Greenfe9a6752019-04-04 14:39:33 +0100183 self.report_dir, "{}-{}-{}.dump".format(
184 mbed_module, version.revision, version.version
Darryl Green3e7a9802019-02-27 16:53:40 +0000185 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000186 )
187 abi_dump_command = [
188 "abi-dumper",
Darryl Green9f357d62019-02-25 11:35:05 +0000189 module_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000190 "-o", output_path,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200191 "-lver", self._pretty_revision(version),
Darryl Green7c2dd582018-03-01 14:53:49 +0000192 ]
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100193 abi_dump_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000194 abi_dump_command,
Darryl Green7c2dd582018-03-01 14:53:49 +0000195 stderr=subprocess.STDOUT
196 )
Darryl Green3c3da792019-03-08 11:30:04 +0000197 self.log.debug(abi_dump_output.decode("utf-8"))
Darryl Green7c1a7332019-03-05 16:25:38 +0000198 version.abi_dumps[mbed_module] = output_path
Darryl Green7c2dd582018-03-01 14:53:49 +0000199
Darryl Green3a5f6c82019-03-05 16:30:39 +0000200 def _cleanup_worktree(self, git_worktree_path):
Gilles Peskine712afa72019-02-25 20:36:52 +0100201 """Remove the specified git worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000202 shutil.rmtree(git_worktree_path)
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100203 worktree_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000204 [self.git_command, "worktree", "prune"],
205 cwd=self.repo_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000206 stderr=subprocess.STDOUT
207 )
Darryl Green3c3da792019-03-08 11:30:04 +0000208 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000209
Darryl Green3a5f6c82019-03-05 16:30:39 +0000210 def _get_abi_dump_for_ref(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100211 """Generate the ABI dumps for the specified git revision."""
Darryl Green3a5f6c82019-03-05 16:30:39 +0000212 git_worktree_path = self._get_clean_worktree_for_git_revision(version)
213 self._update_git_submodules(git_worktree_path, version)
214 self._build_shared_libraries(git_worktree_path, version)
Darryl Green8184df52019-04-05 17:06:17 +0100215 self._get_abi_dumps_from_shared_libraries(version)
Darryl Green3a5f6c82019-03-05 16:30:39 +0000216 self._cleanup_worktree(git_worktree_path)
Darryl Green7c2dd582018-03-01 14:53:49 +0000217
Darryl Green3a5f6c82019-03-05 16:30:39 +0000218 def _remove_children_with_tag(self, parent, tag):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000219 children = parent.getchildren()
220 for child in children:
221 if child.tag == tag:
222 parent.remove(child)
223 else:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000224 self._remove_children_with_tag(child, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000225
Darryl Green3a5f6c82019-03-05 16:30:39 +0000226 def _remove_extra_detail_from_report(self, report_root):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000227 for tag in ['test_info', 'test_results', 'problem_summary',
Darryl Greenc6f874b2019-06-05 12:57:50 +0100228 'added_symbols', 'affected']:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000229 self._remove_children_with_tag(report_root, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000230
231 for report in report_root:
232 for problems in report.getchildren()[:]:
233 if not problems.getchildren():
234 report.remove(problems)
235
Gilles Peskineada828f2019-07-04 19:17:40 +0200236 def _abi_compliance_command(self, mbed_module, output_path):
237 """Build the command to run to analyze the library mbed_module.
238 The report will be placed in output_path."""
239 abi_compliance_command = [
240 "abi-compliance-checker",
241 "-l", mbed_module,
242 "-old", self.old_version.abi_dumps[mbed_module],
243 "-new", self.new_version.abi_dumps[mbed_module],
244 "-strict",
245 "-report-path", output_path,
246 ]
247 if self.skip_file:
248 abi_compliance_command += ["-skip-symbols", self.skip_file,
249 "-skip-types", self.skip_file]
250 if self.brief:
251 abi_compliance_command += ["-report-format", "xml",
252 "-stdout"]
253 return abi_compliance_command
254
255 def _is_library_compatible(self, mbed_module, compatibility_report):
256 """Test if the library mbed_module has remained compatible.
257 Append a message regarding compatibility to compatibility_report."""
258 output_path = os.path.join(
259 self.report_dir, "{}-{}-{}.html".format(
260 mbed_module, self.old_version.revision,
261 self.new_version.revision
262 )
263 )
264 try:
265 subprocess.check_output(
266 self._abi_compliance_command(mbed_module, output_path),
267 stderr=subprocess.STDOUT
268 )
269 except subprocess.CalledProcessError as err:
270 if err.returncode != 1:
271 raise err
272 if self.brief:
273 self.log.info(
274 "Compatibility issues found for {}".format(mbed_module)
275 )
276 report_root = ET.fromstring(err.output.decode("utf-8"))
277 self._remove_extra_detail_from_report(report_root)
278 self.log.info(ET.tostring(report_root).decode("utf-8"))
279 else:
280 self.can_remove_report_dir = False
281 compatibility_report.append(
282 "Compatibility issues found for {}, "
283 "for details see {}".format(mbed_module, output_path)
284 )
285 return False
286 compatibility_report.append(
287 "No compatibility issues for {}".format(mbed_module)
288 )
289 if not (self.keep_all_reports or self.brief):
290 os.remove(output_path)
291 return True
292
Darryl Green7c2dd582018-03-01 14:53:49 +0000293 def get_abi_compatibility_report(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100294 """Generate a report of the differences between the reference ABI
Darryl Green8184df52019-04-05 17:06:17 +0100295 and the new ABI. ABI dumps from self.old_version and self.new_version
296 must be available."""
Gilles Peskineada828f2019-07-04 19:17:40 +0200297 compatibility_report = ["Checking evolution from {} to {}".format(
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200298 self._pretty_revision(self.old_version),
299 self._pretty_revision(self.new_version)
Gilles Peskineada828f2019-07-04 19:17:40 +0200300 )]
Darryl Green7c2dd582018-03-01 14:53:49 +0000301 compliance_return_code = 0
Darryl Green7c1a7332019-03-05 16:25:38 +0000302 shared_modules = list(set(self.old_version.modules.keys()) &
303 set(self.new_version.modules.keys()))
Darryl Green3e7a9802019-02-27 16:53:40 +0000304 for mbed_module in shared_modules:
Gilles Peskineada828f2019-07-04 19:17:40 +0200305 if not self._is_library_compatible(mbed_module,
306 compatibility_report):
307 compliance_return_code = 1
Darryl Greenf2688e22019-05-29 11:29:08 +0100308 for version in [self.old_version, self.new_version]:
309 for mbed_module, mbed_module_dump in version.abi_dumps.items():
310 os.remove(mbed_module_dump)
Darryl Green3d3d5522019-02-25 17:01:55 +0000311 if self.can_remove_report_dir:
Darryl Green7c2dd582018-03-01 14:53:49 +0000312 os.rmdir(self.report_dir)
Gilles Peskineada828f2019-07-04 19:17:40 +0200313 self.log.info("\n".join(compatibility_report))
Darryl Green7c2dd582018-03-01 14:53:49 +0000314 return compliance_return_code
315
316 def check_for_abi_changes(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100317 """Generate a report of ABI differences
318 between self.old_rev and self.new_rev."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000319 self.check_repo_path()
320 self.check_abi_tools_are_installed()
Darryl Green3a5f6c82019-03-05 16:30:39 +0000321 self._get_abi_dump_for_ref(self.old_version)
322 self._get_abi_dump_for_ref(self.new_version)
Darryl Green7c2dd582018-03-01 14:53:49 +0000323 return self.get_abi_compatibility_report()
324
325
326def run_main():
327 try:
328 parser = argparse.ArgumentParser(
329 description=(
Darryl Green418527b2018-04-16 12:02:29 +0100330 """This script is a small wrapper around the
331 abi-compliance-checker and abi-dumper tools, applying them
332 to compare the ABI and API of the library files from two
333 different Git revisions within an Mbed TLS repository.
Darryl Greene62f9bb2019-02-21 13:09:26 +0000334 The results of the comparison are either formatted as HTML and
Darryl Green4cde8a02019-03-05 15:21:32 +0000335 stored at a configurable location, or are given as a brief list
336 of problems. Returns 0 on success, 1 on ABI/API non-compliance,
337 and 2 if there is an error while running the script.
338 Note: must be run from Mbed TLS root."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000339 )
340 )
341 parser.add_argument(
Darryl Green3c3da792019-03-08 11:30:04 +0000342 "-v", "--verbose", action="store_true",
343 help="set verbosity level",
344 )
345 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100346 "-r", "--report-dir", type=str, default="reports",
Darryl Green7c2dd582018-03-01 14:53:49 +0000347 help="directory where reports are stored, default is reports",
348 )
349 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100350 "-k", "--keep-all-reports", action="store_true",
Darryl Green7c2dd582018-03-01 14:53:49 +0000351 help="keep all reports, even if there are no compatibility issues",
352 )
353 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000354 "-o", "--old-rev", type=str, help="revision for old version.",
355 required=True,
Darryl Green7c2dd582018-03-01 14:53:49 +0000356 )
357 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000358 "-or", "--old-repo", type=str, help="repository for old version."
Darryl Green9f357d62019-02-25 11:35:05 +0000359 )
360 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000361 "-oc", "--old-crypto-rev", type=str,
362 help="revision for old crypto submodule."
Darryl Green7c2dd582018-03-01 14:53:49 +0000363 )
Darryl Greenc2883a22019-02-20 15:01:56 +0000364 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000365 "-ocr", "--old-crypto-repo", type=str,
366 help="repository for old crypto submodule."
367 )
368 parser.add_argument(
369 "-n", "--new-rev", type=str, help="revision for new version",
370 required=True,
371 )
372 parser.add_argument(
373 "-nr", "--new-repo", type=str, help="repository for new version."
374 )
375 parser.add_argument(
376 "-nc", "--new-crypto-rev", type=str,
377 help="revision for new crypto version"
378 )
379 parser.add_argument(
380 "-ncr", "--new-crypto-repo", type=str,
381 help="repository for new crypto submodule."
Darryl Green9f357d62019-02-25 11:35:05 +0000382 )
383 parser.add_argument(
Darryl Greenc2883a22019-02-20 15:01:56 +0000384 "-s", "--skip-file", type=str,
Gilles Peskineb6ce2342019-07-04 19:00:31 +0200385 help=("path to file containing symbols and types to skip "
386 "(typically \"-s identifiers\" after running "
387 "\"tests/scripts/list-identifiers.sh --internal\")")
Darryl Greenc2883a22019-02-20 15:01:56 +0000388 )
Darryl Greene62f9bb2019-02-21 13:09:26 +0000389 parser.add_argument(
390 "-b", "--brief", action="store_true",
391 help="output only the list of issues to stdout, instead of a full report",
392 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000393 abi_args = parser.parse_args()
Darryl Green492bc402019-04-11 15:50:41 +0100394 if os.path.isfile(abi_args.report_dir):
395 print("Error: {} is not a directory".format(abi_args.report_dir))
396 parser.exit()
Darryl Green0d1ca512019-04-09 09:14:17 +0100397 old_version = SimpleNamespace(
398 version="old",
399 repository=abi_args.old_repo,
400 revision=abi_args.old_rev,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200401 commit=None,
Darryl Green0d1ca512019-04-09 09:14:17 +0100402 crypto_repository=abi_args.old_crypto_repo,
403 crypto_revision=abi_args.old_crypto_rev,
404 abi_dumps={},
405 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100406 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100407 new_version = SimpleNamespace(
408 version="new",
409 repository=abi_args.new_repo,
410 revision=abi_args.new_rev,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200411 commit=None,
Darryl Green0d1ca512019-04-09 09:14:17 +0100412 crypto_repository=abi_args.new_crypto_repo,
413 crypto_revision=abi_args.new_crypto_rev,
414 abi_dumps={},
415 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100416 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100417 configuration = SimpleNamespace(
418 verbose=abi_args.verbose,
419 report_dir=abi_args.report_dir,
420 keep_all_reports=abi_args.keep_all_reports,
421 brief=abi_args.brief,
422 skip_file=abi_args.skip_file
Darryl Green7c2dd582018-03-01 14:53:49 +0000423 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100424 abi_check = AbiChecker(old_version, new_version, configuration)
Darryl Green7c2dd582018-03-01 14:53:49 +0000425 return_code = abi_check.check_for_abi_changes()
426 sys.exit(return_code)
Gilles Peskinee915d532019-02-25 21:39:42 +0100427 except Exception: # pylint: disable=broad-except
428 # Print the backtrace and exit explicitly so as to exit with
429 # status 2, not 1.
Darryl Greena6f430f2018-03-15 10:12:06 +0000430 traceback.print_exc()
Darryl Green7c2dd582018-03-01 14:53:49 +0000431 sys.exit(2)
432
433
434if __name__ == "__main__":
435 run_main()