blob: 6edc54fde8d3f924769a9bbb1673b866054be2cf [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 Green0da45782019-02-21 13:09:26 +000012The results of the comparison are either formatted as HTML and stored at
Darryl Green7c0e0522019-03-05 15:21:32 +000013a configurable location, or are given as a brief list of problems.
Darryl Green0da45782019-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 Greenae5d66c2019-02-25 11:35:05 +000026import fnmatch
Darryl Green30dc6d52019-04-09 09:14:17 +010027from types import SimpleNamespace
Darryl Green7c2dd582018-03-01 14:53:49 +000028
Darryl Green0da45782019-02-21 13:09:26 +000029import xml.etree.ElementTree as ET
30
Darryl Green7c2dd582018-03-01 14:53:49 +000031
32class AbiChecker(object):
Gilles Peskine9df17632019-02-25 20:36:52 +010033 """API and ABI checker."""
Darryl Green7c2dd582018-03-01 14:53:49 +000034
Darryl Green30dc6d52019-04-09 09:14:17 +010035 def __init__(self, old_version, new_version, configuration):
Gilles Peskine9df17632019-02-25 20:36:52 +010036 """Instantiate the API/ABI checker.
37
Darryl Green7381bea2019-03-05 16:25:38 +000038 old_version: RepoVersion containing details to compare against
39 new_version: RepoVersion containing details to check
Darryl Green3c9e7d22019-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 Peskine9df17632019-02-25 20:36:52 +010044 """
Darryl Green7c2dd582018-03-01 14:53:49 +000045 self.repo_path = "."
46 self.log = None
Darryl Green30dc6d52019-04-09 09:14:17 +010047 self.verbose = configuration.verbose
Darryl Green88bfbc22019-03-05 16:30:39 +000048 self._setup_logger()
Darryl Green30dc6d52019-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 Green6b3cbfa2019-04-11 15:50:41 +010051 self.can_remove_report_dir = not (os.path.exists(self.report_dir) or
Darryl Green30dc6d52019-04-09 09:14:17 +010052 self.keep_all_reports)
Darryl Green7381bea2019-03-05 16:25:38 +000053 self.old_version = old_version
54 self.new_version = new_version
Darryl Green30dc6d52019-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 Peskine9df17632019-02-25 20:36:52 +010060 @staticmethod
61 def check_repo_path():
Gilles Peskinec53b93b2019-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 Green88bfbc22019-03-05 16:30:39 +000065 def _setup_logger(self):
Darryl Green7c2dd582018-03-01 14:53:49 +000066 self.log = logging.getLogger()
Darryl Green66025382019-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 Peskine9df17632019-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 Green88bfbc22019-03-05 16:30:39 +000079 def _get_clean_worktree_for_git_revision(self, version):
Darryl Green7381bea2019-03-05 16:25:38 +000080 """Make a separate worktree with version.revision checked out.
Gilles Peskine9df17632019-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 Green7381bea2019-03-05 16:25:38 +000083 if version.repository:
Darryl Green66025382019-03-08 11:30:04 +000084 self.log.debug(
Darryl Green5a301f02019-02-19 16:59:33 +000085 "Checking out git worktree for revision {} from {}".format(
Darryl Green7381bea2019-03-05 16:25:38 +000086 version.revision, version.repository
Darryl Green5a301f02019-02-19 16:59:33 +000087 )
88 )
Darryl Greena0415bc2019-04-12 16:24:25 +010089 fetch_output = subprocess.check_output(
Darryl Green7381bea2019-03-05 16:25:38 +000090 [self.git_command, "fetch",
91 version.repository, version.revision],
Darryl Green5a301f02019-02-19 16:59:33 +000092 cwd=self.repo_path,
Darryl Green5a301f02019-02-19 16:59:33 +000093 stderr=subprocess.STDOUT
94 )
Darryl Green66025382019-03-08 11:30:04 +000095 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green5a301f02019-02-19 16:59:33 +000096 worktree_rev = "FETCH_HEAD"
97 else:
Darryl Green66025382019-03-08 11:30:04 +000098 self.log.debug("Checking out git worktree for revision {}".format(
Darryl Green7381bea2019-03-05 16:25:38 +000099 version.revision
100 ))
101 worktree_rev = version.revision
Darryl Greena0415bc2019-04-12 16:24:25 +0100102 worktree_output = subprocess.check_output(
Darryl Green5a301f02019-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 Green66025382019-03-08 11:30:04 +0000108 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000109 return git_worktree_path
110
Darryl Green88bfbc22019-03-05 16:30:39 +0000111 def _update_git_submodules(self, git_worktree_path, version):
Darryl Green26dff8e2019-04-05 17:06:17 +0100112 """If the crypto submodule is present, initialize it.
113 if version.crypto_revision exists, update it to that revision,
114 otherwise update it to the default revision"""
Darryl Greena0415bc2019-04-12 16:24:25 +0100115 update_output = subprocess.check_output(
Jaeden Amero4cd4b4b2018-11-02 16:35:09 +0000116 [self.git_command, "submodule", "update", "--init", '--recursive'],
117 cwd=git_worktree_path,
Jaeden Amero4cd4b4b2018-11-02 16:35:09 +0000118 stderr=subprocess.STDOUT
119 )
Darryl Greena0415bc2019-04-12 16:24:25 +0100120 self.log.debug(update_output.decode("utf-8"))
Darryl Green0478a322019-03-05 15:23:25 +0000121 if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
Darryl Green7381bea2019-03-05 16:25:38 +0000122 and version.crypto_revision):
Darryl Green0478a322019-03-05 15:23:25 +0000123 return
124
Darryl Green7381bea2019-03-05 16:25:38 +0000125 if version.crypto_repository:
Darryl Greena0415bc2019-04-12 16:24:25 +0100126 fetch_output = subprocess.check_output(
Darryl Green3f742982019-03-08 11:12:19 +0000127 [self.git_command, "fetch", version.crypto_repository,
128 version.crypto_revision],
Darryl Green0478a322019-03-05 15:23:25 +0000129 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Green0478a322019-03-05 15:23:25 +0000130 stderr=subprocess.STDOUT
131 )
Darryl Green66025382019-03-08 11:30:04 +0000132 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green3f742982019-03-08 11:12:19 +0000133 crypto_rev = "FETCH_HEAD"
134 else:
135 crypto_rev = version.crypto_revision
136
Darryl Greena0415bc2019-04-12 16:24:25 +0100137 checkout_output = subprocess.check_output(
Darryl Green3f742982019-03-08 11:12:19 +0000138 [self.git_command, "checkout", crypto_rev],
139 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Green3f742982019-03-08 11:12:19 +0000140 stderr=subprocess.STDOUT
141 )
Darryl Green66025382019-03-08 11:30:04 +0000142 self.log.debug(checkout_output.decode("utf-8"))
Jaeden Amero4cd4b4b2018-11-02 16:35:09 +0000143
Darryl Green88bfbc22019-03-05 16:30:39 +0000144 def _build_shared_libraries(self, git_worktree_path, version):
Gilles Peskine9df17632019-02-25 20:36:52 +0100145 """Build the shared libraries in the specified worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000146 my_environment = os.environ.copy()
147 my_environment["CFLAGS"] = "-g -Og"
148 my_environment["SHARED"] = "1"
Darryl Greenfbf3c8a2019-05-09 13:03:05 +0100149 if os.path.exists(os.path.join(git_worktree_path, "crypto")):
150 my_environment["USE_CRYPTO_SUBMODULE"] = "1"
Darryl Greena0415bc2019-04-12 16:24:25 +0100151 make_output = subprocess.check_output(
Darryl Greenc8e6ad42019-02-28 11:52:39 +0000152 [self.make_command, "lib"],
Darryl Green7c2dd582018-03-01 14:53:49 +0000153 env=my_environment,
154 cwd=git_worktree_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000155 stderr=subprocess.STDOUT
156 )
Darryl Green66025382019-03-08 11:30:04 +0000157 self.log.debug(make_output.decode("utf-8"))
Darryl Green03c5e852019-04-12 15:18:02 +0100158 for root, _dirs, files in os.walk(git_worktree_path):
Darryl Greenae5d66c2019-02-25 11:35:05 +0000159 for file in fnmatch.filter(files, "*.so"):
Darryl Green7381bea2019-03-05 16:25:38 +0000160 version.modules[os.path.splitext(file)[0]] = (
Darryl Greende118092019-02-27 16:53:40 +0000161 os.path.join(root, file)
Darryl Greenae5d66c2019-02-25 11:35:05 +0000162 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000163
Darryl Green26dff8e2019-04-05 17:06:17 +0100164 def _get_abi_dumps_from_shared_libraries(self, version):
Gilles Peskine9df17632019-02-25 20:36:52 +0100165 """Generate the ABI dumps for the specified git revision.
Darryl Green26dff8e2019-04-05 17:06:17 +0100166 The shared libraries must have been built and the module paths
167 present in version.modules."""
Darryl Green7381bea2019-03-05 16:25:38 +0000168 for mbed_module, module_path in version.modules.items():
Darryl Green7c2dd582018-03-01 14:53:49 +0000169 output_path = os.path.join(
Darryl Green57838472019-04-04 14:39:33 +0100170 self.report_dir, "{}-{}-{}.dump".format(
171 mbed_module, version.revision, version.version
Darryl Greende118092019-02-27 16:53:40 +0000172 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000173 )
174 abi_dump_command = [
175 "abi-dumper",
Darryl Greenae5d66c2019-02-25 11:35:05 +0000176 module_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000177 "-o", output_path,
Darryl Green7381bea2019-03-05 16:25:38 +0000178 "-lver", version.revision
Darryl Green7c2dd582018-03-01 14:53:49 +0000179 ]
Darryl Greena0415bc2019-04-12 16:24:25 +0100180 abi_dump_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000181 abi_dump_command,
Darryl Green7c2dd582018-03-01 14:53:49 +0000182 stderr=subprocess.STDOUT
183 )
Darryl Green66025382019-03-08 11:30:04 +0000184 self.log.debug(abi_dump_output.decode("utf-8"))
Darryl Green7381bea2019-03-05 16:25:38 +0000185 version.abi_dumps[mbed_module] = output_path
Darryl Green7c2dd582018-03-01 14:53:49 +0000186
Darryl Green88bfbc22019-03-05 16:30:39 +0000187 def _cleanup_worktree(self, git_worktree_path):
Gilles Peskine9df17632019-02-25 20:36:52 +0100188 """Remove the specified git worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000189 shutil.rmtree(git_worktree_path)
Darryl Greena0415bc2019-04-12 16:24:25 +0100190 worktree_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000191 [self.git_command, "worktree", "prune"],
192 cwd=self.repo_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000193 stderr=subprocess.STDOUT
194 )
Darryl Green66025382019-03-08 11:30:04 +0000195 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000196
Darryl Green88bfbc22019-03-05 16:30:39 +0000197 def _get_abi_dump_for_ref(self, version):
Gilles Peskine9df17632019-02-25 20:36:52 +0100198 """Generate the ABI dumps for the specified git revision."""
Darryl Green88bfbc22019-03-05 16:30:39 +0000199 git_worktree_path = self._get_clean_worktree_for_git_revision(version)
200 self._update_git_submodules(git_worktree_path, version)
201 self._build_shared_libraries(git_worktree_path, version)
Darryl Green26dff8e2019-04-05 17:06:17 +0100202 self._get_abi_dumps_from_shared_libraries(version)
Darryl Green88bfbc22019-03-05 16:30:39 +0000203 self._cleanup_worktree(git_worktree_path)
Darryl Green7c2dd582018-03-01 14:53:49 +0000204
Darryl Green88bfbc22019-03-05 16:30:39 +0000205 def _remove_children_with_tag(self, parent, tag):
Darryl Green0da45782019-02-21 13:09:26 +0000206 children = parent.getchildren()
207 for child in children:
208 if child.tag == tag:
209 parent.remove(child)
210 else:
Darryl Green88bfbc22019-03-05 16:30:39 +0000211 self._remove_children_with_tag(child, tag)
Darryl Green0da45782019-02-21 13:09:26 +0000212
Darryl Green88bfbc22019-03-05 16:30:39 +0000213 def _remove_extra_detail_from_report(self, report_root):
Darryl Green0da45782019-02-21 13:09:26 +0000214 for tag in ['test_info', 'test_results', 'problem_summary',
Darryl Green0ae1a532019-06-05 12:57:50 +0100215 'added_symbols', 'affected']:
Darryl Green88bfbc22019-03-05 16:30:39 +0000216 self._remove_children_with_tag(report_root, tag)
Darryl Green0da45782019-02-21 13:09:26 +0000217
218 for report in report_root:
219 for problems in report.getchildren()[:]:
220 if not problems.getchildren():
221 report.remove(problems)
222
Darryl Green7c2dd582018-03-01 14:53:49 +0000223 def get_abi_compatibility_report(self):
Gilles Peskine9df17632019-02-25 20:36:52 +0100224 """Generate a report of the differences between the reference ABI
Darryl Green26dff8e2019-04-05 17:06:17 +0100225 and the new ABI. ABI dumps from self.old_version and self.new_version
226 must be available."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000227 compatibility_report = ""
228 compliance_return_code = 0
Darryl Green7381bea2019-03-05 16:25:38 +0000229 shared_modules = list(set(self.old_version.modules.keys()) &
230 set(self.new_version.modules.keys()))
Darryl Greende118092019-02-27 16:53:40 +0000231 for mbed_module in shared_modules:
Darryl Green7c2dd582018-03-01 14:53:49 +0000232 output_path = os.path.join(
233 self.report_dir, "{}-{}-{}.html".format(
Darryl Green7381bea2019-03-05 16:25:38 +0000234 mbed_module, self.old_version.revision,
235 self.new_version.revision
Darryl Green7c2dd582018-03-01 14:53:49 +0000236 )
237 )
238 abi_compliance_command = [
239 "abi-compliance-checker",
240 "-l", mbed_module,
Darryl Green7381bea2019-03-05 16:25:38 +0000241 "-old", self.old_version.abi_dumps[mbed_module],
242 "-new", self.new_version.abi_dumps[mbed_module],
Darryl Green7c2dd582018-03-01 14:53:49 +0000243 "-strict",
Darryl Green0da45782019-02-21 13:09:26 +0000244 "-report-path", output_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000245 ]
Darryl Green668063b2019-02-20 15:01:56 +0000246 if self.skip_file:
247 abi_compliance_command += ["-skip-symbols", self.skip_file,
248 "-skip-types", self.skip_file]
Darryl Green0da45782019-02-21 13:09:26 +0000249 if self.brief:
250 abi_compliance_command += ["-report-format", "xml",
251 "-stdout"]
Darryl Greena0415bc2019-04-12 16:24:25 +0100252 try:
253 subprocess.check_output(
254 abi_compliance_command,
255 stderr=subprocess.STDOUT
256 )
257 except subprocess.CalledProcessError as err:
258 if err.returncode == 1:
259 compliance_return_code = 1
260 if self.brief:
261 self.log.info(
262 "Compatibility issues found for {}".format(mbed_module)
263 )
264 report_root = ET.fromstring(err.output.decode("utf-8"))
265 self._remove_extra_detail_from_report(report_root)
266 self.log.info(ET.tostring(report_root).decode("utf-8"))
267 else:
268 self.can_remove_report_dir = False
269 compatibility_report += (
270 "Compatibility issues found for {}, "
271 "for details see {}\n".format(mbed_module, output_path)
272 )
273 else:
274 raise err
275 else:
Darryl Green7c2dd582018-03-01 14:53:49 +0000276 compatibility_report += (
277 "No compatibility issues for {}\n".format(mbed_module)
278 )
Darryl Green0da45782019-02-21 13:09:26 +0000279 if not (self.keep_all_reports or self.brief):
Darryl Green7c2dd582018-03-01 14:53:49 +0000280 os.remove(output_path)
Darryl Greene831f552019-05-29 11:29:08 +0100281 for version in [self.old_version, self.new_version]:
282 for mbed_module, mbed_module_dump in version.abi_dumps.items():
283 os.remove(mbed_module_dump)
Darryl Green131e24b2019-02-25 17:01:55 +0000284 if self.can_remove_report_dir:
Darryl Green7c2dd582018-03-01 14:53:49 +0000285 os.rmdir(self.report_dir)
286 self.log.info(compatibility_report)
287 return compliance_return_code
288
289 def check_for_abi_changes(self):
Gilles Peskine9df17632019-02-25 20:36:52 +0100290 """Generate a report of ABI differences
291 between self.old_rev and self.new_rev."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000292 self.check_repo_path()
293 self.check_abi_tools_are_installed()
Darryl Green88bfbc22019-03-05 16:30:39 +0000294 self._get_abi_dump_for_ref(self.old_version)
295 self._get_abi_dump_for_ref(self.new_version)
Darryl Green7c2dd582018-03-01 14:53:49 +0000296 return self.get_abi_compatibility_report()
297
298
299def run_main():
300 try:
301 parser = argparse.ArgumentParser(
302 description=(
Darryl Green418527b2018-04-16 12:02:29 +0100303 """This script is a small wrapper around the
304 abi-compliance-checker and abi-dumper tools, applying them
305 to compare the ABI and API of the library files from two
306 different Git revisions within an Mbed TLS repository.
Darryl Green0da45782019-02-21 13:09:26 +0000307 The results of the comparison are either formatted as HTML and
Darryl Green7c0e0522019-03-05 15:21:32 +0000308 stored at a configurable location, or are given as a brief list
309 of problems. Returns 0 on success, 1 on ABI/API non-compliance,
310 and 2 if there is an error while running the script.
311 Note: must be run from Mbed TLS root."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000312 )
313 )
314 parser.add_argument(
Darryl Green66025382019-03-08 11:30:04 +0000315 "-v", "--verbose", action="store_true",
316 help="set verbosity level",
317 )
318 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100319 "-r", "--report-dir", type=str, default="reports",
Darryl Green7c2dd582018-03-01 14:53:49 +0000320 help="directory where reports are stored, default is reports",
321 )
322 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100323 "-k", "--keep-all-reports", action="store_true",
Darryl Green7c2dd582018-03-01 14:53:49 +0000324 help="keep all reports, even if there are no compatibility issues",
325 )
326 parser.add_argument(
Darryl Green06c51d02019-03-01 09:54:44 +0000327 "-o", "--old-rev", type=str, help="revision for old version.",
328 required=True,
Darryl Green7c2dd582018-03-01 14:53:49 +0000329 )
330 parser.add_argument(
Darryl Green06c51d02019-03-01 09:54:44 +0000331 "-or", "--old-repo", type=str, help="repository for old version."
Darryl Greenae5d66c2019-02-25 11:35:05 +0000332 )
333 parser.add_argument(
Darryl Green06c51d02019-03-01 09:54:44 +0000334 "-oc", "--old-crypto-rev", type=str,
335 help="revision for old crypto submodule."
Darryl Green7c2dd582018-03-01 14:53:49 +0000336 )
Darryl Green668063b2019-02-20 15:01:56 +0000337 parser.add_argument(
Darryl Green06c51d02019-03-01 09:54:44 +0000338 "-ocr", "--old-crypto-repo", type=str,
339 help="repository for old crypto submodule."
340 )
341 parser.add_argument(
342 "-n", "--new-rev", type=str, help="revision for new version",
343 required=True,
344 )
345 parser.add_argument(
346 "-nr", "--new-repo", type=str, help="repository for new version."
347 )
348 parser.add_argument(
349 "-nc", "--new-crypto-rev", type=str,
350 help="revision for new crypto version"
351 )
352 parser.add_argument(
353 "-ncr", "--new-crypto-repo", type=str,
354 help="repository for new crypto submodule."
Darryl Greenae5d66c2019-02-25 11:35:05 +0000355 )
356 parser.add_argument(
Darryl Green668063b2019-02-20 15:01:56 +0000357 "-s", "--skip-file", type=str,
358 help="path to file containing symbols and types to skip"
359 )
Darryl Green0da45782019-02-21 13:09:26 +0000360 parser.add_argument(
361 "-b", "--brief", action="store_true",
362 help="output only the list of issues to stdout, instead of a full report",
363 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000364 abi_args = parser.parse_args()
Darryl Green6b3cbfa2019-04-11 15:50:41 +0100365 if os.path.isfile(abi_args.report_dir):
366 print("Error: {} is not a directory".format(abi_args.report_dir))
367 parser.exit()
Darryl Green30dc6d52019-04-09 09:14:17 +0100368 old_version = SimpleNamespace(
369 version="old",
370 repository=abi_args.old_repo,
371 revision=abi_args.old_rev,
372 crypto_repository=abi_args.old_crypto_repo,
373 crypto_revision=abi_args.old_crypto_rev,
374 abi_dumps={},
375 modules={}
Darryl Green26dff8e2019-04-05 17:06:17 +0100376 )
Darryl Green30dc6d52019-04-09 09:14:17 +0100377 new_version = SimpleNamespace(
378 version="new",
379 repository=abi_args.new_repo,
380 revision=abi_args.new_rev,
381 crypto_repository=abi_args.new_crypto_repo,
382 crypto_revision=abi_args.new_crypto_rev,
383 abi_dumps={},
384 modules={}
Darryl Green26dff8e2019-04-05 17:06:17 +0100385 )
Darryl Green30dc6d52019-04-09 09:14:17 +0100386 configuration = SimpleNamespace(
387 verbose=abi_args.verbose,
388 report_dir=abi_args.report_dir,
389 keep_all_reports=abi_args.keep_all_reports,
390 brief=abi_args.brief,
391 skip_file=abi_args.skip_file
Darryl Green7c2dd582018-03-01 14:53:49 +0000392 )
Darryl Green30dc6d52019-04-09 09:14:17 +0100393 abi_check = AbiChecker(old_version, new_version, configuration)
Darryl Green7c2dd582018-03-01 14:53:49 +0000394 return_code = abi_check.check_for_abi_changes()
395 sys.exit(return_code)
Gilles Peskineafd19dd2019-02-25 21:39:42 +0100396 except Exception: # pylint: disable=broad-except
397 # Print the backtrace and exit explicitly so as to exit with
398 # status 2, not 1.
Darryl Greena6f430f2018-03-15 10:12:06 +0000399 traceback.print_exc()
Darryl Green7c2dd582018-03-01 14:53:49 +0000400 sys.exit(2)
401
402
403if __name__ == "__main__":
404 run_main()