blob: af293cd2aa4b2d824c614df2417612f43ccd7457 [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():
Darryl Greena6f430f2018-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 Green7c2dd582018-03-01 14:53:49 +000065 raise Exception("Must be run from Mbed TLS root")
66
Darryl Green3a5f6c82019-03-05 16:30:39 +000067 def _setup_logger(self):
Darryl Green7c2dd582018-03-01 14:53:49 +000068 self.log = logging.getLogger()
Darryl Green3c3da792019-03-08 11:30:04 +000069 if self.verbose:
70 self.log.setLevel(logging.DEBUG)
71 else:
72 self.log.setLevel(logging.INFO)
Darryl Green7c2dd582018-03-01 14:53:49 +000073 self.log.addHandler(logging.StreamHandler())
74
Gilles Peskine712afa72019-02-25 20:36:52 +010075 @staticmethod
76 def check_abi_tools_are_installed():
Darryl Green7c2dd582018-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 Green3a5f6c82019-03-05 16:30:39 +000081 def _get_clean_worktree_for_git_revision(self, version):
Darryl Green7c1a7332019-03-05 16:25:38 +000082 """Make a separate worktree with version.revision checked out.
Gilles Peskine712afa72019-02-25 20:36:52 +010083 Do not modify the current worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +000084 git_worktree_path = tempfile.mkdtemp()
Darryl Green7c1a7332019-03-05 16:25:38 +000085 if version.repository:
Darryl Green3c3da792019-03-08 11:30:04 +000086 self.log.debug(
Darryl Greenda84e322019-02-19 16:59:33 +000087 "Checking out git worktree for revision {} from {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +000088 version.revision, version.repository
Darryl Greenda84e322019-02-19 16:59:33 +000089 )
90 )
91 fetch_process = subprocess.Popen(
Darryl Green7c1a7332019-03-05 16:25:38 +000092 [self.git_command, "fetch",
93 version.repository, version.revision],
Darryl Greenda84e322019-02-19 16:59:33 +000094 cwd=self.repo_path,
95 stdout=subprocess.PIPE,
96 stderr=subprocess.STDOUT
97 )
98 fetch_output, _ = fetch_process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +000099 self.log.debug(fetch_output.decode("utf-8"))
Darryl Greenda84e322019-02-19 16:59:33 +0000100 if fetch_process.returncode != 0:
101 raise Exception("Fetching revision failed, aborting")
102 worktree_rev = "FETCH_HEAD"
103 else:
Darryl Green3c3da792019-03-08 11:30:04 +0000104 self.log.debug("Checking out git worktree for revision {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +0000105 version.revision
106 ))
107 worktree_rev = version.revision
Darryl Green7c2dd582018-03-01 14:53:49 +0000108 worktree_process = subprocess.Popen(
Darryl Greenda84e322019-02-19 16:59:33 +0000109 [self.git_command, "worktree", "add", "--detach",
110 git_worktree_path, worktree_rev],
Darryl Green7c2dd582018-03-01 14:53:49 +0000111 cwd=self.repo_path,
112 stdout=subprocess.PIPE,
113 stderr=subprocess.STDOUT
114 )
115 worktree_output, _ = worktree_process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +0000116 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000117 if worktree_process.returncode != 0:
118 raise Exception("Checking out worktree failed, aborting")
119 return git_worktree_path
120
Darryl Green3a5f6c82019-03-05 16:30:39 +0000121 def _update_git_submodules(self, git_worktree_path, version):
Darryl Green8184df52019-04-05 17:06:17 +0100122 """If the crypto submodule is present, initialize it.
123 if version.crypto_revision exists, update it to that revision,
124 otherwise update it to the default revision"""
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000125 process = subprocess.Popen(
126 [self.git_command, "submodule", "update", "--init", '--recursive'],
127 cwd=git_worktree_path,
128 stdout=subprocess.PIPE,
129 stderr=subprocess.STDOUT
130 )
131 output, _ = process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +0000132 self.log.debug(output.decode("utf-8"))
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000133 if process.returncode != 0:
134 raise Exception("git submodule update failed, aborting")
Darryl Greene29ce702019-03-05 15:23:25 +0000135 if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
Darryl Green7c1a7332019-03-05 16:25:38 +0000136 and version.crypto_revision):
Darryl Greene29ce702019-03-05 15:23:25 +0000137 return
138
Darryl Green7c1a7332019-03-05 16:25:38 +0000139 if version.crypto_repository:
Darryl Green1d95c532019-03-08 11:12:19 +0000140 fetch_process = subprocess.Popen(
141 [self.git_command, "fetch", version.crypto_repository,
142 version.crypto_revision],
Darryl Greene29ce702019-03-05 15:23:25 +0000143 cwd=os.path.join(git_worktree_path, "crypto"),
144 stdout=subprocess.PIPE,
145 stderr=subprocess.STDOUT
146 )
Darryl Green1d95c532019-03-08 11:12:19 +0000147 fetch_output, _ = fetch_process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +0000148 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green1d95c532019-03-08 11:12:19 +0000149 if fetch_process.returncode != 0:
150 raise Exception("git fetch failed, aborting")
151 crypto_rev = "FETCH_HEAD"
152 else:
153 crypto_rev = version.crypto_revision
154
155 checkout_process = subprocess.Popen(
156 [self.git_command, "checkout", crypto_rev],
157 cwd=os.path.join(git_worktree_path, "crypto"),
158 stdout=subprocess.PIPE,
159 stderr=subprocess.STDOUT
160 )
161 checkout_output, _ = checkout_process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +0000162 self.log.debug(checkout_output.decode("utf-8"))
Darryl Green1d95c532019-03-08 11:12:19 +0000163 if checkout_process.returncode != 0:
164 raise Exception("git checkout failed, aborting")
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000165
Darryl Green3a5f6c82019-03-05 16:30:39 +0000166 def _build_shared_libraries(self, git_worktree_path, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100167 """Build the shared libraries in the specified worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000168 my_environment = os.environ.copy()
169 my_environment["CFLAGS"] = "-g -Og"
170 my_environment["SHARED"] = "1"
Darryl Green9f357d62019-02-25 11:35:05 +0000171 my_environment["USE_CRYPTO_SUBMODULE"] = "1"
Darryl Green7c2dd582018-03-01 14:53:49 +0000172 make_process = subprocess.Popen(
Darryl Greenddf25a62019-02-28 11:52:39 +0000173 [self.make_command, "lib"],
Darryl Green7c2dd582018-03-01 14:53:49 +0000174 env=my_environment,
175 cwd=git_worktree_path,
176 stdout=subprocess.PIPE,
177 stderr=subprocess.STDOUT
178 )
179 make_output, _ = make_process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +0000180 self.log.debug(make_output.decode("utf-8"))
Darryl Greenf025d532019-04-12 15:18:02 +0100181 for root, _dirs, files in os.walk(git_worktree_path):
Darryl Green9f357d62019-02-25 11:35:05 +0000182 for file in fnmatch.filter(files, "*.so"):
Darryl Green7c1a7332019-03-05 16:25:38 +0000183 version.modules[os.path.splitext(file)[0]] = (
Darryl Green3e7a9802019-02-27 16:53:40 +0000184 os.path.join(root, file)
Darryl Green9f357d62019-02-25 11:35:05 +0000185 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000186 if make_process.returncode != 0:
187 raise Exception("make failed, aborting")
188
Darryl Green8184df52019-04-05 17:06:17 +0100189 def _get_abi_dumps_from_shared_libraries(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100190 """Generate the ABI dumps for the specified git revision.
Darryl Green8184df52019-04-05 17:06:17 +0100191 The shared libraries must have been built and the module paths
192 present in version.modules."""
Darryl Green7c1a7332019-03-05 16:25:38 +0000193 for mbed_module, module_path in version.modules.items():
Darryl Green7c2dd582018-03-01 14:53:49 +0000194 output_path = os.path.join(
Darryl Greenfe9a6752019-04-04 14:39:33 +0100195 self.report_dir, "{}-{}-{}.dump".format(
196 mbed_module, version.revision, version.version
Darryl Green3e7a9802019-02-27 16:53:40 +0000197 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000198 )
199 abi_dump_command = [
200 "abi-dumper",
Darryl Green9f357d62019-02-25 11:35:05 +0000201 module_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000202 "-o", output_path,
Darryl Green7c1a7332019-03-05 16:25:38 +0000203 "-lver", version.revision
Darryl Green7c2dd582018-03-01 14:53:49 +0000204 ]
205 abi_dump_process = subprocess.Popen(
206 abi_dump_command,
207 stdout=subprocess.PIPE,
208 stderr=subprocess.STDOUT
209 )
210 abi_dump_output, _ = abi_dump_process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +0000211 self.log.debug(abi_dump_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000212 if abi_dump_process.returncode != 0:
213 raise Exception("abi-dumper failed, aborting")
Darryl Green7c1a7332019-03-05 16:25:38 +0000214 version.abi_dumps[mbed_module] = output_path
Darryl Green7c2dd582018-03-01 14:53:49 +0000215
Darryl Green3a5f6c82019-03-05 16:30:39 +0000216 def _cleanup_worktree(self, git_worktree_path):
Gilles Peskine712afa72019-02-25 20:36:52 +0100217 """Remove the specified git worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000218 shutil.rmtree(git_worktree_path)
219 worktree_process = subprocess.Popen(
220 [self.git_command, "worktree", "prune"],
221 cwd=self.repo_path,
222 stdout=subprocess.PIPE,
223 stderr=subprocess.STDOUT
224 )
225 worktree_output, _ = worktree_process.communicate()
Darryl Green3c3da792019-03-08 11:30:04 +0000226 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000227 if worktree_process.returncode != 0:
228 raise Exception("Worktree cleanup failed, aborting")
229
Darryl Green3a5f6c82019-03-05 16:30:39 +0000230 def _get_abi_dump_for_ref(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100231 """Generate the ABI dumps for the specified git revision."""
Darryl Green3a5f6c82019-03-05 16:30:39 +0000232 git_worktree_path = self._get_clean_worktree_for_git_revision(version)
233 self._update_git_submodules(git_worktree_path, version)
234 self._build_shared_libraries(git_worktree_path, version)
Darryl Green8184df52019-04-05 17:06:17 +0100235 self._get_abi_dumps_from_shared_libraries(version)
Darryl Green3a5f6c82019-03-05 16:30:39 +0000236 self._cleanup_worktree(git_worktree_path)
Darryl Green7c2dd582018-03-01 14:53:49 +0000237
Darryl Green3a5f6c82019-03-05 16:30:39 +0000238 def _remove_children_with_tag(self, parent, tag):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000239 children = parent.getchildren()
240 for child in children:
241 if child.tag == tag:
242 parent.remove(child)
243 else:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000244 self._remove_children_with_tag(child, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000245
Darryl Green3a5f6c82019-03-05 16:30:39 +0000246 def _remove_extra_detail_from_report(self, report_root):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000247 for tag in ['test_info', 'test_results', 'problem_summary',
Darryl Green8184df52019-04-05 17:06:17 +0100248 'added_symbols', 'removed_symbols', 'affected']:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000249 self._remove_children_with_tag(report_root, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000250
251 for report in report_root:
252 for problems in report.getchildren()[:]:
253 if not problems.getchildren():
254 report.remove(problems)
255
Darryl Green7c2dd582018-03-01 14:53:49 +0000256 def get_abi_compatibility_report(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100257 """Generate a report of the differences between the reference ABI
Darryl Green8184df52019-04-05 17:06:17 +0100258 and the new ABI. ABI dumps from self.old_version and self.new_version
259 must be available."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000260 compatibility_report = ""
261 compliance_return_code = 0
Darryl Green7c1a7332019-03-05 16:25:38 +0000262 shared_modules = list(set(self.old_version.modules.keys()) &
263 set(self.new_version.modules.keys()))
Darryl Green3e7a9802019-02-27 16:53:40 +0000264 for mbed_module in shared_modules:
Darryl Green7c2dd582018-03-01 14:53:49 +0000265 output_path = os.path.join(
266 self.report_dir, "{}-{}-{}.html".format(
Darryl Green7c1a7332019-03-05 16:25:38 +0000267 mbed_module, self.old_version.revision,
268 self.new_version.revision
Darryl Green7c2dd582018-03-01 14:53:49 +0000269 )
270 )
271 abi_compliance_command = [
272 "abi-compliance-checker",
273 "-l", mbed_module,
Darryl Green7c1a7332019-03-05 16:25:38 +0000274 "-old", self.old_version.abi_dumps[mbed_module],
275 "-new", self.new_version.abi_dumps[mbed_module],
Darryl Green7c2dd582018-03-01 14:53:49 +0000276 "-strict",
Darryl Greene62f9bb2019-02-21 13:09:26 +0000277 "-report-path", output_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000278 ]
Darryl Greenc2883a22019-02-20 15:01:56 +0000279 if self.skip_file:
280 abi_compliance_command += ["-skip-symbols", self.skip_file,
281 "-skip-types", self.skip_file]
Darryl Greene62f9bb2019-02-21 13:09:26 +0000282 if self.brief:
283 abi_compliance_command += ["-report-format", "xml",
284 "-stdout"]
Darryl Green7c2dd582018-03-01 14:53:49 +0000285 abi_compliance_process = subprocess.Popen(
286 abi_compliance_command,
287 stdout=subprocess.PIPE,
288 stderr=subprocess.STDOUT
289 )
290 abi_compliance_output, _ = abi_compliance_process.communicate()
Darryl Green7c2dd582018-03-01 14:53:49 +0000291 if abi_compliance_process.returncode == 0:
292 compatibility_report += (
293 "No compatibility issues for {}\n".format(mbed_module)
294 )
Darryl Greene62f9bb2019-02-21 13:09:26 +0000295 if not (self.keep_all_reports or self.brief):
Darryl Green7c2dd582018-03-01 14:53:49 +0000296 os.remove(output_path)
297 elif abi_compliance_process.returncode == 1:
Darryl Greene62f9bb2019-02-21 13:09:26 +0000298 if self.brief:
299 self.log.info(
300 "Compatibility issues found for {}".format(mbed_module)
301 )
302 report_root = ET.fromstring(abi_compliance_output.decode("utf-8"))
Darryl Green3a5f6c82019-03-05 16:30:39 +0000303 self._remove_extra_detail_from_report(report_root)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000304 self.log.info(ET.tostring(report_root).decode("utf-8"))
305 else:
306 compliance_return_code = 1
307 self.can_remove_report_dir = False
308 compatibility_report += (
309 "Compatibility issues found for {}, "
310 "for details see {}\n".format(mbed_module, output_path)
311 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000312 else:
313 raise Exception(
314 "abi-compliance-checker failed with a return code of {},"
315 " aborting".format(abi_compliance_process.returncode)
316 )
Darryl Green7c1a7332019-03-05 16:25:38 +0000317 os.remove(self.old_version.abi_dumps[mbed_module])
318 os.remove(self.new_version.abi_dumps[mbed_module])
Darryl Green3d3d5522019-02-25 17:01:55 +0000319 if self.can_remove_report_dir:
Darryl Green7c2dd582018-03-01 14:53:49 +0000320 os.rmdir(self.report_dir)
321 self.log.info(compatibility_report)
322 return compliance_return_code
323
324 def check_for_abi_changes(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100325 """Generate a report of ABI differences
326 between self.old_rev and self.new_rev."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000327 self.check_repo_path()
328 self.check_abi_tools_are_installed()
Darryl Green3a5f6c82019-03-05 16:30:39 +0000329 self._get_abi_dump_for_ref(self.old_version)
330 self._get_abi_dump_for_ref(self.new_version)
Darryl Green7c2dd582018-03-01 14:53:49 +0000331 return self.get_abi_compatibility_report()
332
333
334def run_main():
335 try:
336 parser = argparse.ArgumentParser(
337 description=(
Darryl Green418527b2018-04-16 12:02:29 +0100338 """This script is a small wrapper around the
339 abi-compliance-checker and abi-dumper tools, applying them
340 to compare the ABI and API of the library files from two
341 different Git revisions within an Mbed TLS repository.
Darryl Greene62f9bb2019-02-21 13:09:26 +0000342 The results of the comparison are either formatted as HTML and
Darryl Green4cde8a02019-03-05 15:21:32 +0000343 stored at a configurable location, or are given as a brief list
344 of problems. Returns 0 on success, 1 on ABI/API non-compliance,
345 and 2 if there is an error while running the script.
346 Note: must be run from Mbed TLS root."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000347 )
348 )
349 parser.add_argument(
Darryl Green3c3da792019-03-08 11:30:04 +0000350 "-v", "--verbose", action="store_true",
351 help="set verbosity level",
352 )
353 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100354 "-r", "--report-dir", type=str, default="reports",
Darryl Green7c2dd582018-03-01 14:53:49 +0000355 help="directory where reports are stored, default is reports",
356 )
357 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100358 "-k", "--keep-all-reports", action="store_true",
Darryl Green7c2dd582018-03-01 14:53:49 +0000359 help="keep all reports, even if there are no compatibility issues",
360 )
361 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000362 "-o", "--old-rev", type=str, help="revision for old version.",
363 required=True,
Darryl Green7c2dd582018-03-01 14:53:49 +0000364 )
365 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000366 "-or", "--old-repo", type=str, help="repository for old version."
Darryl Green9f357d62019-02-25 11:35:05 +0000367 )
368 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000369 "-oc", "--old-crypto-rev", type=str,
370 help="revision for old crypto submodule."
Darryl Green7c2dd582018-03-01 14:53:49 +0000371 )
Darryl Greenc2883a22019-02-20 15:01:56 +0000372 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000373 "-ocr", "--old-crypto-repo", type=str,
374 help="repository for old crypto submodule."
375 )
376 parser.add_argument(
377 "-n", "--new-rev", type=str, help="revision for new version",
378 required=True,
379 )
380 parser.add_argument(
381 "-nr", "--new-repo", type=str, help="repository for new version."
382 )
383 parser.add_argument(
384 "-nc", "--new-crypto-rev", type=str,
385 help="revision for new crypto version"
386 )
387 parser.add_argument(
388 "-ncr", "--new-crypto-repo", type=str,
389 help="repository for new crypto submodule."
Darryl Green9f357d62019-02-25 11:35:05 +0000390 )
391 parser.add_argument(
Darryl Greenc2883a22019-02-20 15:01:56 +0000392 "-s", "--skip-file", type=str,
393 help="path to file containing symbols and types to skip"
394 )
Darryl Greene62f9bb2019-02-21 13:09:26 +0000395 parser.add_argument(
396 "-b", "--brief", action="store_true",
397 help="output only the list of issues to stdout, instead of a full report",
398 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000399 abi_args = parser.parse_args()
Darryl Green492bc402019-04-11 15:50:41 +0100400 if os.path.isfile(abi_args.report_dir):
401 print("Error: {} is not a directory".format(abi_args.report_dir))
402 parser.exit()
Darryl Green0d1ca512019-04-09 09:14:17 +0100403 old_version = SimpleNamespace(
404 version="old",
405 repository=abi_args.old_repo,
406 revision=abi_args.old_rev,
407 crypto_repository=abi_args.old_crypto_repo,
408 crypto_revision=abi_args.old_crypto_rev,
409 abi_dumps={},
410 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100411 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100412 new_version = SimpleNamespace(
413 version="new",
414 repository=abi_args.new_repo,
415 revision=abi_args.new_rev,
416 crypto_repository=abi_args.new_crypto_repo,
417 crypto_revision=abi_args.new_crypto_rev,
418 abi_dumps={},
419 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100420 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100421 configuration = SimpleNamespace(
422 verbose=abi_args.verbose,
423 report_dir=abi_args.report_dir,
424 keep_all_reports=abi_args.keep_all_reports,
425 brief=abi_args.brief,
426 skip_file=abi_args.skip_file
Darryl Green7c2dd582018-03-01 14:53:49 +0000427 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100428 abi_check = AbiChecker(old_version, new_version, configuration)
Darryl Green7c2dd582018-03-01 14:53:49 +0000429 return_code = abi_check.check_for_abi_changes()
430 sys.exit(return_code)
Gilles Peskinee915d532019-02-25 21:39:42 +0100431 except Exception: # pylint: disable=broad-except
432 # Print the backtrace and exit explicitly so as to exit with
433 # status 2, not 1.
Darryl Greena6f430f2018-03-15 10:12:06 +0000434 traceback.print_exc()
Darryl Green7c2dd582018-03-01 14:53:49 +0000435 sys.exit(2)
436
437
438if __name__ == "__main__":
439 run_main()