blob: e5d5c99c309cc8d89b25960a46254534fdf116f5 [file] [log] [blame]
Darryl Green3da15042018-03-01 14:53:49 +00001#!/usr/bin/env python3
Darryl Green4cd7a9b2018-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 Green32e7a502019-02-21 13:09:26 +000012The results of the comparison are either formatted as HTML and stored at
Darryl Green765d20d2019-03-05 15:21:32 +000013a configurable location, or are given as a brief list of problems.
Darryl Green32e7a502019-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 Green4cd7a9b2018-04-06 11:23:22 +010016"""
Darryl Green3da15042018-03-01 14:53:49 +000017
18import os
19import sys
20import traceback
21import shutil
22import subprocess
23import argparse
24import logging
25import tempfile
Darryl Greend9ad9ec2019-02-25 11:35:05 +000026import fnmatch
Darryl Greenf1d272d2019-04-09 09:14:17 +010027from types import SimpleNamespace
Darryl Green3da15042018-03-01 14:53:49 +000028
Darryl Green32e7a502019-02-21 13:09:26 +000029import xml.etree.ElementTree as ET
30
Darryl Green3da15042018-03-01 14:53:49 +000031
32class AbiChecker(object):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010033 """API and ABI checker."""
Darryl Green3da15042018-03-01 14:53:49 +000034
Darryl Greenf1d272d2019-04-09 09:14:17 +010035 def __init__(self, old_version, new_version, configuration):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010036 """Instantiate the API/ABI checker.
37
Darryl Green02b68652019-03-05 16:25:38 +000038 old_version: RepoVersion containing details to compare against
39 new_version: RepoVersion containing details to check
Darryl Greenbbc6ccf2019-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 Peskinefceb4ce2019-02-25 20:36:52 +010044 """
Darryl Green3da15042018-03-01 14:53:49 +000045 self.repo_path = "."
46 self.log = None
Darryl Greenf1d272d2019-04-09 09:14:17 +010047 self.verbose = configuration.verbose
Darryl Green7bb9cb52019-03-05 16:30:39 +000048 self._setup_logger()
Darryl Greenf1d272d2019-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 Green03625fe2019-04-11 15:50:41 +010051 self.can_remove_report_dir = not (os.path.exists(self.report_dir) or
Darryl Greenf1d272d2019-04-09 09:14:17 +010052 self.keep_all_reports)
Darryl Green02b68652019-03-05 16:25:38 +000053 self.old_version = old_version
54 self.new_version = new_version
Darryl Greenf1d272d2019-04-09 09:14:17 +010055 self.skip_file = configuration.skip_file
56 self.brief = configuration.brief
Darryl Green3da15042018-03-01 14:53:49 +000057 self.git_command = "git"
58 self.make_command = "make"
59
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010060 @staticmethod
61 def check_repo_path():
Darryl Greenc47ac262018-03-15 10:12:06 +000062 current_dir = os.path.realpath('.')
63 root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
64 if current_dir != root_dir:
Darryl Green3da15042018-03-01 14:53:49 +000065 raise Exception("Must be run from Mbed TLS root")
66
Darryl Green7bb9cb52019-03-05 16:30:39 +000067 def _setup_logger(self):
Darryl Green3da15042018-03-01 14:53:49 +000068 self.log = logging.getLogger()
Darryl Greenf0f9f7f2019-03-08 11:30:04 +000069 if self.verbose:
70 self.log.setLevel(logging.DEBUG)
71 else:
72 self.log.setLevel(logging.INFO)
Darryl Green3da15042018-03-01 14:53:49 +000073 self.log.addHandler(logging.StreamHandler())
74
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010075 @staticmethod
76 def check_abi_tools_are_installed():
Darryl Green3da15042018-03-01 14:53:49 +000077 for command in ["abi-dumper", "abi-compliance-checker"]:
78 if not shutil.which(command):
79 raise Exception("{} not installed, aborting".format(command))
80
Darryl Green7bb9cb52019-03-05 16:30:39 +000081 def _get_clean_worktree_for_git_revision(self, version):
Darryl Green02b68652019-03-05 16:25:38 +000082 """Make a separate worktree with version.revision checked out.
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010083 Do not modify the current worktree."""
Darryl Green3da15042018-03-01 14:53:49 +000084 git_worktree_path = tempfile.mkdtemp()
Darryl Green02b68652019-03-05 16:25:38 +000085 if version.repository:
Darryl Greenf0f9f7f2019-03-08 11:30:04 +000086 self.log.debug(
Darryl Green834ebc42019-02-19 16:59:33 +000087 "Checking out git worktree for revision {} from {}".format(
Darryl Green02b68652019-03-05 16:25:38 +000088 version.revision, version.repository
Darryl Green834ebc42019-02-19 16:59:33 +000089 )
90 )
Darryl Green4a483e42019-04-12 16:24:25 +010091 fetch_output = subprocess.check_output(
Darryl Green02b68652019-03-05 16:25:38 +000092 [self.git_command, "fetch",
93 version.repository, version.revision],
Darryl Green834ebc42019-02-19 16:59:33 +000094 cwd=self.repo_path,
Darryl Green834ebc42019-02-19 16:59:33 +000095 stderr=subprocess.STDOUT
96 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +000097 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green834ebc42019-02-19 16:59:33 +000098 worktree_rev = "FETCH_HEAD"
99 else:
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000100 self.log.debug("Checking out git worktree for revision {}".format(
Darryl Green02b68652019-03-05 16:25:38 +0000101 version.revision
102 ))
103 worktree_rev = version.revision
Darryl Green4a483e42019-04-12 16:24:25 +0100104 worktree_output = subprocess.check_output(
Darryl Green834ebc42019-02-19 16:59:33 +0000105 [self.git_command, "worktree", "add", "--detach",
106 git_worktree_path, worktree_rev],
Darryl Green3da15042018-03-01 14:53:49 +0000107 cwd=self.repo_path,
Darryl Green3da15042018-03-01 14:53:49 +0000108 stderr=subprocess.STDOUT
109 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000110 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green3da15042018-03-01 14:53:49 +0000111 return git_worktree_path
112
Darryl Green7bb9cb52019-03-05 16:30:39 +0000113 def _update_git_submodules(self, git_worktree_path, version):
Darryl Greenb7447e72019-04-05 17:06:17 +0100114 """If the crypto submodule is present, initialize it.
115 if version.crypto_revision exists, update it to that revision,
116 otherwise update it to the default revision"""
Darryl Green4a483e42019-04-12 16:24:25 +0100117 update_output = subprocess.check_output(
Jaeden Amero346f9592018-11-02 16:35:09 +0000118 [self.git_command, "submodule", "update", "--init", '--recursive'],
119 cwd=git_worktree_path,
Jaeden Amero346f9592018-11-02 16:35:09 +0000120 stderr=subprocess.STDOUT
121 )
Darryl Green4a483e42019-04-12 16:24:25 +0100122 self.log.debug(update_output.decode("utf-8"))
Darryl Green7be79c92019-03-05 15:23:25 +0000123 if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
Darryl Green02b68652019-03-05 16:25:38 +0000124 and version.crypto_revision):
Darryl Green7be79c92019-03-05 15:23:25 +0000125 return
126
Darryl Green02b68652019-03-05 16:25:38 +0000127 if version.crypto_repository:
Darryl Green4a483e42019-04-12 16:24:25 +0100128 fetch_output = subprocess.check_output(
Darryl Greenb7433092019-03-08 11:12:19 +0000129 [self.git_command, "fetch", version.crypto_repository,
130 version.crypto_revision],
Darryl Green7be79c92019-03-05 15:23:25 +0000131 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Green7be79c92019-03-05 15:23:25 +0000132 stderr=subprocess.STDOUT
133 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000134 self.log.debug(fetch_output.decode("utf-8"))
Darryl Greenb7433092019-03-08 11:12:19 +0000135 crypto_rev = "FETCH_HEAD"
136 else:
137 crypto_rev = version.crypto_revision
138
Darryl Green4a483e42019-04-12 16:24:25 +0100139 checkout_output = subprocess.check_output(
Darryl Greenb7433092019-03-08 11:12:19 +0000140 [self.git_command, "checkout", crypto_rev],
141 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Greenb7433092019-03-08 11:12:19 +0000142 stderr=subprocess.STDOUT
143 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000144 self.log.debug(checkout_output.decode("utf-8"))
Jaeden Amero346f9592018-11-02 16:35:09 +0000145
Darryl Green7bb9cb52019-03-05 16:30:39 +0000146 def _build_shared_libraries(self, git_worktree_path, version):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100147 """Build the shared libraries in the specified worktree."""
Darryl Green3da15042018-03-01 14:53:49 +0000148 my_environment = os.environ.copy()
149 my_environment["CFLAGS"] = "-g -Og"
150 my_environment["SHARED"] = "1"
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000151 my_environment["USE_CRYPTO_SUBMODULE"] = "1"
Darryl Green4a483e42019-04-12 16:24:25 +0100152 make_output = subprocess.check_output(
Darryl Green997c2872019-02-28 11:52:39 +0000153 [self.make_command, "lib"],
Darryl Green3da15042018-03-01 14:53:49 +0000154 env=my_environment,
155 cwd=git_worktree_path,
Darryl Green3da15042018-03-01 14:53:49 +0000156 stderr=subprocess.STDOUT
157 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000158 self.log.debug(make_output.decode("utf-8"))
Darryl Green31a1e992019-04-12 15:18:02 +0100159 for root, _dirs, files in os.walk(git_worktree_path):
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000160 for file in fnmatch.filter(files, "*.so"):
Darryl Green02b68652019-03-05 16:25:38 +0000161 version.modules[os.path.splitext(file)[0]] = (
Darryl Greend98d8b52019-02-27 16:53:40 +0000162 os.path.join(root, file)
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000163 )
Darryl Green3da15042018-03-01 14:53:49 +0000164
Darryl Greenb7447e72019-04-05 17:06:17 +0100165 def _get_abi_dumps_from_shared_libraries(self, version):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100166 """Generate the ABI dumps for the specified git revision.
Darryl Greenb7447e72019-04-05 17:06:17 +0100167 The shared libraries must have been built and the module paths
168 present in version.modules."""
Darryl Green02b68652019-03-05 16:25:38 +0000169 for mbed_module, module_path in version.modules.items():
Darryl Green3da15042018-03-01 14:53:49 +0000170 output_path = os.path.join(
Darryl Greencf434252019-04-04 14:39:33 +0100171 self.report_dir, "{}-{}-{}.dump".format(
172 mbed_module, version.revision, version.version
Darryl Greend98d8b52019-02-27 16:53:40 +0000173 )
Darryl Green3da15042018-03-01 14:53:49 +0000174 )
175 abi_dump_command = [
176 "abi-dumper",
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000177 module_path,
Darryl Green3da15042018-03-01 14:53:49 +0000178 "-o", output_path,
Darryl Green02b68652019-03-05 16:25:38 +0000179 "-lver", version.revision
Darryl Green3da15042018-03-01 14:53:49 +0000180 ]
Darryl Green4a483e42019-04-12 16:24:25 +0100181 abi_dump_output = subprocess.check_output(
Darryl Green3da15042018-03-01 14:53:49 +0000182 abi_dump_command,
Darryl Green3da15042018-03-01 14:53:49 +0000183 stderr=subprocess.STDOUT
184 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000185 self.log.debug(abi_dump_output.decode("utf-8"))
Darryl Green02b68652019-03-05 16:25:38 +0000186 version.abi_dumps[mbed_module] = output_path
Darryl Green3da15042018-03-01 14:53:49 +0000187
Darryl Green7bb9cb52019-03-05 16:30:39 +0000188 def _cleanup_worktree(self, git_worktree_path):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100189 """Remove the specified git worktree."""
Darryl Green3da15042018-03-01 14:53:49 +0000190 shutil.rmtree(git_worktree_path)
Darryl Green4a483e42019-04-12 16:24:25 +0100191 worktree_output = subprocess.check_output(
Darryl Green3da15042018-03-01 14:53:49 +0000192 [self.git_command, "worktree", "prune"],
193 cwd=self.repo_path,
Darryl Green3da15042018-03-01 14:53:49 +0000194 stderr=subprocess.STDOUT
195 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000196 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green3da15042018-03-01 14:53:49 +0000197
Darryl Green7bb9cb52019-03-05 16:30:39 +0000198 def _get_abi_dump_for_ref(self, version):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100199 """Generate the ABI dumps for the specified git revision."""
Darryl Green7bb9cb52019-03-05 16:30:39 +0000200 git_worktree_path = self._get_clean_worktree_for_git_revision(version)
201 self._update_git_submodules(git_worktree_path, version)
202 self._build_shared_libraries(git_worktree_path, version)
Darryl Greenb7447e72019-04-05 17:06:17 +0100203 self._get_abi_dumps_from_shared_libraries(version)
Darryl Green7bb9cb52019-03-05 16:30:39 +0000204 self._cleanup_worktree(git_worktree_path)
Darryl Green3da15042018-03-01 14:53:49 +0000205
Darryl Green7bb9cb52019-03-05 16:30:39 +0000206 def _remove_children_with_tag(self, parent, tag):
Darryl Green32e7a502019-02-21 13:09:26 +0000207 children = parent.getchildren()
208 for child in children:
209 if child.tag == tag:
210 parent.remove(child)
211 else:
Darryl Green7bb9cb52019-03-05 16:30:39 +0000212 self._remove_children_with_tag(child, tag)
Darryl Green32e7a502019-02-21 13:09:26 +0000213
Darryl Green7bb9cb52019-03-05 16:30:39 +0000214 def _remove_extra_detail_from_report(self, report_root):
Darryl Green32e7a502019-02-21 13:09:26 +0000215 for tag in ['test_info', 'test_results', 'problem_summary',
Darryl Greenb7447e72019-04-05 17:06:17 +0100216 'added_symbols', 'removed_symbols', 'affected']:
Darryl Green7bb9cb52019-03-05 16:30:39 +0000217 self._remove_children_with_tag(report_root, tag)
Darryl Green32e7a502019-02-21 13:09:26 +0000218
219 for report in report_root:
220 for problems in report.getchildren()[:]:
221 if not problems.getchildren():
222 report.remove(problems)
223
Darryl Green3da15042018-03-01 14:53:49 +0000224 def get_abi_compatibility_report(self):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100225 """Generate a report of the differences between the reference ABI
Darryl Greenb7447e72019-04-05 17:06:17 +0100226 and the new ABI. ABI dumps from self.old_version and self.new_version
227 must be available."""
Darryl Green3da15042018-03-01 14:53:49 +0000228 compatibility_report = ""
229 compliance_return_code = 0
Darryl Green02b68652019-03-05 16:25:38 +0000230 shared_modules = list(set(self.old_version.modules.keys()) &
231 set(self.new_version.modules.keys()))
Darryl Greend98d8b52019-02-27 16:53:40 +0000232 for mbed_module in shared_modules:
Darryl Green3da15042018-03-01 14:53:49 +0000233 output_path = os.path.join(
234 self.report_dir, "{}-{}-{}.html".format(
Darryl Green02b68652019-03-05 16:25:38 +0000235 mbed_module, self.old_version.revision,
236 self.new_version.revision
Darryl Green3da15042018-03-01 14:53:49 +0000237 )
238 )
239 abi_compliance_command = [
240 "abi-compliance-checker",
241 "-l", mbed_module,
Darryl Green02b68652019-03-05 16:25:38 +0000242 "-old", self.old_version.abi_dumps[mbed_module],
243 "-new", self.new_version.abi_dumps[mbed_module],
Darryl Green3da15042018-03-01 14:53:49 +0000244 "-strict",
Darryl Green32e7a502019-02-21 13:09:26 +0000245 "-report-path", output_path,
Darryl Green3da15042018-03-01 14:53:49 +0000246 ]
Darryl Greend3cde6f2019-02-20 15:01:56 +0000247 if self.skip_file:
248 abi_compliance_command += ["-skip-symbols", self.skip_file,
249 "-skip-types", self.skip_file]
Darryl Green32e7a502019-02-21 13:09:26 +0000250 if self.brief:
251 abi_compliance_command += ["-report-format", "xml",
252 "-stdout"]
Darryl Green4a483e42019-04-12 16:24:25 +0100253 try:
254 subprocess.check_output(
255 abi_compliance_command,
256 stderr=subprocess.STDOUT
257 )
258 except subprocess.CalledProcessError as err:
259 if err.returncode == 1:
260 compliance_return_code = 1
261 if self.brief:
262 self.log.info(
263 "Compatibility issues found for {}".format(mbed_module)
264 )
265 report_root = ET.fromstring(err.output.decode("utf-8"))
266 self._remove_extra_detail_from_report(report_root)
267 self.log.info(ET.tostring(report_root).decode("utf-8"))
268 else:
269 self.can_remove_report_dir = False
270 compatibility_report += (
271 "Compatibility issues found for {}, "
272 "for details see {}\n".format(mbed_module, output_path)
273 )
274 else:
275 raise err
276 else:
Darryl Green3da15042018-03-01 14:53:49 +0000277 compatibility_report += (
278 "No compatibility issues for {}\n".format(mbed_module)
279 )
Darryl Green32e7a502019-02-21 13:09:26 +0000280 if not (self.keep_all_reports or self.brief):
Darryl Green3da15042018-03-01 14:53:49 +0000281 os.remove(output_path)
Darryl Green02b68652019-03-05 16:25:38 +0000282 os.remove(self.old_version.abi_dumps[mbed_module])
283 os.remove(self.new_version.abi_dumps[mbed_module])
Darryl Greenab3893b2019-02-25 17:01:55 +0000284 if self.can_remove_report_dir:
Darryl Green3da15042018-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 Peskinefceb4ce2019-02-25 20:36:52 +0100290 """Generate a report of ABI differences
291 between self.old_rev and self.new_rev."""
Darryl Green3da15042018-03-01 14:53:49 +0000292 self.check_repo_path()
293 self.check_abi_tools_are_installed()
Darryl Green7bb9cb52019-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 Green3da15042018-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 Green31321ca2018-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 Green32e7a502019-02-21 13:09:26 +0000307 The results of the comparison are either formatted as HTML and
Darryl Green765d20d2019-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 Green3da15042018-03-01 14:53:49 +0000312 )
313 )
314 parser.add_argument(
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000315 "-v", "--verbose", action="store_true",
316 help="set verbosity level",
317 )
318 parser.add_argument(
Darryl Green31321ca2018-04-16 12:02:29 +0100319 "-r", "--report-dir", type=str, default="reports",
Darryl Green3da15042018-03-01 14:53:49 +0000320 help="directory where reports are stored, default is reports",
321 )
322 parser.add_argument(
Darryl Green31321ca2018-04-16 12:02:29 +0100323 "-k", "--keep-all-reports", action="store_true",
Darryl Green3da15042018-03-01 14:53:49 +0000324 help="keep all reports, even if there are no compatibility issues",
325 )
326 parser.add_argument(
Darryl Green826e5af2019-03-01 09:54:44 +0000327 "-o", "--old-rev", type=str, help="revision for old version.",
328 required=True,
Darryl Green3da15042018-03-01 14:53:49 +0000329 )
330 parser.add_argument(
Darryl Green826e5af2019-03-01 09:54:44 +0000331 "-or", "--old-repo", type=str, help="repository for old version."
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000332 )
333 parser.add_argument(
Darryl Green826e5af2019-03-01 09:54:44 +0000334 "-oc", "--old-crypto-rev", type=str,
335 help="revision for old crypto submodule."
Darryl Green3da15042018-03-01 14:53:49 +0000336 )
Darryl Greend3cde6f2019-02-20 15:01:56 +0000337 parser.add_argument(
Darryl Green826e5af2019-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 Greend9ad9ec2019-02-25 11:35:05 +0000355 )
356 parser.add_argument(
Darryl Greend3cde6f2019-02-20 15:01:56 +0000357 "-s", "--skip-file", type=str,
358 help="path to file containing symbols and types to skip"
359 )
Darryl Green32e7a502019-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 Green3da15042018-03-01 14:53:49 +0000364 abi_args = parser.parse_args()
Darryl Green03625fe2019-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 Greenf1d272d2019-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 Greenb7447e72019-04-05 17:06:17 +0100376 )
Darryl Greenf1d272d2019-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 Greenb7447e72019-04-05 17:06:17 +0100385 )
Darryl Greenf1d272d2019-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 Green3da15042018-03-01 14:53:49 +0000392 )
Darryl Greenf1d272d2019-04-09 09:14:17 +0100393 abi_check = AbiChecker(old_version, new_version, configuration)
Darryl Green3da15042018-03-01 14:53:49 +0000394 return_code = abi_check.check_for_abi_changes()
395 sys.exit(return_code)
Darryl Greenc47ac262018-03-15 10:12:06 +0000396 except Exception:
397 traceback.print_exc()
Darryl Green3da15042018-03-01 14:53:49 +0000398 sys.exit(2)
399
400
401if __name__ == "__main__":
402 run_main()