blob: b8fc9b800e88f2d4347272186fd0a5ac447e1151 [file] [log] [blame]
Darryl Green7c2dd582018-03-01 14:53:49 +00001#!/usr/bin/env python3
Darryl Green78696802018-04-06 11:23:22 +01002"""
Darryl Green78696802018-04-06 11:23:22 +01003Purpose
4
5This script is a small wrapper around the abi-compliance-checker and
6abi-dumper tools, applying them to compare the ABI and API of the library
7files from two different Git revisions within an Mbed TLS repository.
Darryl Greene62f9bb2019-02-21 13:09:26 +00008The results of the comparison are either formatted as HTML and stored at
Darryl Green4cde8a02019-03-05 15:21:32 +00009a configurable location, or are given as a brief list of problems.
Darryl Greene62f9bb2019-02-21 13:09:26 +000010Returns 0 on success, 1 on ABI/API non-compliance, and 2 if there is an error
11while running the script. Note: must be run from Mbed TLS root.
Darryl Green78696802018-04-06 11:23:22 +010012"""
Darryl Green7c2dd582018-03-01 14:53:49 +000013
Bence Szépkútic7da1fe2020-05-26 01:54:15 +020014# Copyright (c) 2018, Arm Limited, All Rights Reserved
15# SPDX-License-Identifier: Apache-2.0
16#
17# Licensed under the Apache License, Version 2.0 (the "License"); you may
18# not use this file except in compliance with the License.
19# You may obtain a copy of the License at
20#
21# http://www.apache.org/licenses/LICENSE-2.0
22#
23# Unless required by applicable law or agreed to in writing, software
24# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26# See the License for the specific language governing permissions and
27# limitations under the License.
28#
29# This file is part of Mbed TLS (https://tls.mbed.org)
30
Darryl Green7c2dd582018-03-01 14:53:49 +000031import os
32import sys
33import traceback
34import shutil
35import subprocess
36import argparse
37import logging
38import tempfile
Darryl Green9f357d62019-02-25 11:35:05 +000039import fnmatch
Darryl Green0d1ca512019-04-09 09:14:17 +010040from types import SimpleNamespace
Darryl Green7c2dd582018-03-01 14:53:49 +000041
Darryl Greene62f9bb2019-02-21 13:09:26 +000042import xml.etree.ElementTree as ET
43
Darryl Green7c2dd582018-03-01 14:53:49 +000044
Gilles Peskine184c0962020-03-24 18:25:17 +010045class AbiChecker:
Gilles Peskine712afa72019-02-25 20:36:52 +010046 """API and ABI checker."""
Darryl Green7c2dd582018-03-01 14:53:49 +000047
Darryl Green0d1ca512019-04-09 09:14:17 +010048 def __init__(self, old_version, new_version, configuration):
Gilles Peskine712afa72019-02-25 20:36:52 +010049 """Instantiate the API/ABI checker.
50
Darryl Green7c1a7332019-03-05 16:25:38 +000051 old_version: RepoVersion containing details to compare against
52 new_version: RepoVersion containing details to check
Darryl Greenf67e3492019-04-12 15:17:02 +010053 configuration.report_dir: directory for output files
54 configuration.keep_all_reports: if false, delete old reports
55 configuration.brief: if true, output shorter report to stdout
56 configuration.skip_file: path to file containing symbols and types to skip
Gilles Peskine712afa72019-02-25 20:36:52 +010057 """
Darryl Green7c2dd582018-03-01 14:53:49 +000058 self.repo_path = "."
59 self.log = None
Darryl Green0d1ca512019-04-09 09:14:17 +010060 self.verbose = configuration.verbose
Darryl Green3a5f6c82019-03-05 16:30:39 +000061 self._setup_logger()
Darryl Green0d1ca512019-04-09 09:14:17 +010062 self.report_dir = os.path.abspath(configuration.report_dir)
63 self.keep_all_reports = configuration.keep_all_reports
Darryl Green492bc402019-04-11 15:50:41 +010064 self.can_remove_report_dir = not (os.path.exists(self.report_dir) or
Darryl Green0d1ca512019-04-09 09:14:17 +010065 self.keep_all_reports)
Darryl Green7c1a7332019-03-05 16:25:38 +000066 self.old_version = old_version
67 self.new_version = new_version
Darryl Green0d1ca512019-04-09 09:14:17 +010068 self.skip_file = configuration.skip_file
69 self.brief = configuration.brief
Darryl Green7c2dd582018-03-01 14:53:49 +000070 self.git_command = "git"
71 self.make_command = "make"
72
Gilles Peskine712afa72019-02-25 20:36:52 +010073 @staticmethod
74 def check_repo_path():
Gilles Peskine6aa32cc2019-07-04 18:59:36 +020075 if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
Darryl Green7c2dd582018-03-01 14:53:49 +000076 raise Exception("Must be run from Mbed TLS root")
77
Darryl Green3a5f6c82019-03-05 16:30:39 +000078 def _setup_logger(self):
Darryl Green7c2dd582018-03-01 14:53:49 +000079 self.log = logging.getLogger()
Darryl Green3c3da792019-03-08 11:30:04 +000080 if self.verbose:
81 self.log.setLevel(logging.DEBUG)
82 else:
83 self.log.setLevel(logging.INFO)
Darryl Green7c2dd582018-03-01 14:53:49 +000084 self.log.addHandler(logging.StreamHandler())
85
Gilles Peskine712afa72019-02-25 20:36:52 +010086 @staticmethod
87 def check_abi_tools_are_installed():
Darryl Green7c2dd582018-03-01 14:53:49 +000088 for command in ["abi-dumper", "abi-compliance-checker"]:
89 if not shutil.which(command):
90 raise Exception("{} not installed, aborting".format(command))
91
Darryl Green3a5f6c82019-03-05 16:30:39 +000092 def _get_clean_worktree_for_git_revision(self, version):
Darryl Green7c1a7332019-03-05 16:25:38 +000093 """Make a separate worktree with version.revision checked out.
Gilles Peskine712afa72019-02-25 20:36:52 +010094 Do not modify the current worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +000095 git_worktree_path = tempfile.mkdtemp()
Darryl Green7c1a7332019-03-05 16:25:38 +000096 if version.repository:
Darryl Green3c3da792019-03-08 11:30:04 +000097 self.log.debug(
Darryl Greenda84e322019-02-19 16:59:33 +000098 "Checking out git worktree for revision {} from {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +000099 version.revision, version.repository
Darryl Greenda84e322019-02-19 16:59:33 +0000100 )
101 )
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100102 fetch_output = subprocess.check_output(
Darryl Green7c1a7332019-03-05 16:25:38 +0000103 [self.git_command, "fetch",
104 version.repository, version.revision],
Darryl Greenda84e322019-02-19 16:59:33 +0000105 cwd=self.repo_path,
Darryl Greenda84e322019-02-19 16:59:33 +0000106 stderr=subprocess.STDOUT
107 )
Darryl Green3c3da792019-03-08 11:30:04 +0000108 self.log.debug(fetch_output.decode("utf-8"))
Darryl Greenda84e322019-02-19 16:59:33 +0000109 worktree_rev = "FETCH_HEAD"
110 else:
Darryl Green3c3da792019-03-08 11:30:04 +0000111 self.log.debug("Checking out git worktree for revision {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +0000112 version.revision
113 ))
114 worktree_rev = version.revision
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100115 worktree_output = subprocess.check_output(
Darryl Greenda84e322019-02-19 16:59:33 +0000116 [self.git_command, "worktree", "add", "--detach",
117 git_worktree_path, worktree_rev],
Darryl Green7c2dd582018-03-01 14:53:49 +0000118 cwd=self.repo_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000119 stderr=subprocess.STDOUT
120 )
Darryl Green3c3da792019-03-08 11:30:04 +0000121 self.log.debug(worktree_output.decode("utf-8"))
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200122 version.commit = subprocess.check_output(
Darryl Green762351b2019-07-25 14:33:33 +0100123 [self.git_command, "rev-parse", "HEAD"],
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200124 cwd=git_worktree_path,
125 stderr=subprocess.STDOUT
126 ).decode("ascii").rstrip()
127 self.log.debug("Commit is {}".format(version.commit))
Darryl Green7c2dd582018-03-01 14:53:49 +0000128 return git_worktree_path
129
Darryl Green3a5f6c82019-03-05 16:30:39 +0000130 def _update_git_submodules(self, git_worktree_path, version):
Darryl Green8184df52019-04-05 17:06:17 +0100131 """If the crypto submodule is present, initialize it.
132 if version.crypto_revision exists, update it to that revision,
133 otherwise update it to the default revision"""
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100134 update_output = subprocess.check_output(
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000135 [self.git_command, "submodule", "update", "--init", '--recursive'],
136 cwd=git_worktree_path,
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000137 stderr=subprocess.STDOUT
138 )
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100139 self.log.debug(update_output.decode("utf-8"))
Darryl Greene29ce702019-03-05 15:23:25 +0000140 if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
Darryl Green7c1a7332019-03-05 16:25:38 +0000141 and version.crypto_revision):
Darryl Greene29ce702019-03-05 15:23:25 +0000142 return
143
Darryl Green7c1a7332019-03-05 16:25:38 +0000144 if version.crypto_repository:
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100145 fetch_output = subprocess.check_output(
Darryl Green1d95c532019-03-08 11:12:19 +0000146 [self.git_command, "fetch", version.crypto_repository,
147 version.crypto_revision],
Darryl Greene29ce702019-03-05 15:23:25 +0000148 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Greene29ce702019-03-05 15:23:25 +0000149 stderr=subprocess.STDOUT
150 )
Darryl Green3c3da792019-03-08 11:30:04 +0000151 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green1d95c532019-03-08 11:12:19 +0000152 crypto_rev = "FETCH_HEAD"
153 else:
154 crypto_rev = version.crypto_revision
155
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100156 checkout_output = subprocess.check_output(
Darryl Green1d95c532019-03-08 11:12:19 +0000157 [self.git_command, "checkout", crypto_rev],
158 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Green1d95c532019-03-08 11:12:19 +0000159 stderr=subprocess.STDOUT
160 )
Darryl Green3c3da792019-03-08 11:30:04 +0000161 self.log.debug(checkout_output.decode("utf-8"))
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000162
Darryl Green3a5f6c82019-03-05 16:30:39 +0000163 def _build_shared_libraries(self, git_worktree_path, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100164 """Build the shared libraries in the specified worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000165 my_environment = os.environ.copy()
166 my_environment["CFLAGS"] = "-g -Og"
167 my_environment["SHARED"] = "1"
Darryl Greend2dba362019-05-09 13:03:05 +0100168 if os.path.exists(os.path.join(git_worktree_path, "crypto")):
169 my_environment["USE_CRYPTO_SUBMODULE"] = "1"
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100170 make_output = subprocess.check_output(
Darryl Greenddf25a62019-02-28 11:52:39 +0000171 [self.make_command, "lib"],
Darryl Green7c2dd582018-03-01 14:53:49 +0000172 env=my_environment,
173 cwd=git_worktree_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000174 stderr=subprocess.STDOUT
175 )
Darryl Green3c3da792019-03-08 11:30:04 +0000176 self.log.debug(make_output.decode("utf-8"))
Darryl Greenf025d532019-04-12 15:18:02 +0100177 for root, _dirs, files in os.walk(git_worktree_path):
Darryl Green9f357d62019-02-25 11:35:05 +0000178 for file in fnmatch.filter(files, "*.so"):
Darryl Green7c1a7332019-03-05 16:25:38 +0000179 version.modules[os.path.splitext(file)[0]] = (
Darryl Green3e7a9802019-02-27 16:53:40 +0000180 os.path.join(root, file)
Darryl Green9f357d62019-02-25 11:35:05 +0000181 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000182
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200183 @staticmethod
184 def _pretty_revision(version):
185 if version.revision == version.commit:
186 return version.revision
187 else:
188 return "{} ({})".format(version.revision, version.commit)
189
Darryl Green8184df52019-04-05 17:06:17 +0100190 def _get_abi_dumps_from_shared_libraries(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100191 """Generate the ABI dumps for the specified git revision.
Darryl Green8184df52019-04-05 17:06:17 +0100192 The shared libraries must have been built and the module paths
193 present in version.modules."""
Darryl Green7c1a7332019-03-05 16:25:38 +0000194 for mbed_module, module_path in version.modules.items():
Darryl Green7c2dd582018-03-01 14:53:49 +0000195 output_path = os.path.join(
Darryl Greenfe9a6752019-04-04 14:39:33 +0100196 self.report_dir, "{}-{}-{}.dump".format(
197 mbed_module, version.revision, version.version
Darryl Green3e7a9802019-02-27 16:53:40 +0000198 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000199 )
200 abi_dump_command = [
201 "abi-dumper",
Darryl Green9f357d62019-02-25 11:35:05 +0000202 module_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000203 "-o", output_path,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200204 "-lver", self._pretty_revision(version),
Darryl Green7c2dd582018-03-01 14:53:49 +0000205 ]
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100206 abi_dump_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000207 abi_dump_command,
Darryl Green7c2dd582018-03-01 14:53:49 +0000208 stderr=subprocess.STDOUT
209 )
Darryl Green3c3da792019-03-08 11:30:04 +0000210 self.log.debug(abi_dump_output.decode("utf-8"))
Darryl Green7c1a7332019-03-05 16:25:38 +0000211 version.abi_dumps[mbed_module] = output_path
Darryl Green7c2dd582018-03-01 14:53:49 +0000212
Darryl Green3a5f6c82019-03-05 16:30:39 +0000213 def _cleanup_worktree(self, git_worktree_path):
Gilles Peskine712afa72019-02-25 20:36:52 +0100214 """Remove the specified git worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000215 shutil.rmtree(git_worktree_path)
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100216 worktree_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000217 [self.git_command, "worktree", "prune"],
218 cwd=self.repo_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000219 stderr=subprocess.STDOUT
220 )
Darryl Green3c3da792019-03-08 11:30:04 +0000221 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000222
Darryl Green3a5f6c82019-03-05 16:30:39 +0000223 def _get_abi_dump_for_ref(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100224 """Generate the ABI dumps for the specified git revision."""
Darryl Green3a5f6c82019-03-05 16:30:39 +0000225 git_worktree_path = self._get_clean_worktree_for_git_revision(version)
226 self._update_git_submodules(git_worktree_path, version)
227 self._build_shared_libraries(git_worktree_path, version)
Darryl Green8184df52019-04-05 17:06:17 +0100228 self._get_abi_dumps_from_shared_libraries(version)
Darryl Green3a5f6c82019-03-05 16:30:39 +0000229 self._cleanup_worktree(git_worktree_path)
Darryl Green7c2dd582018-03-01 14:53:49 +0000230
Darryl Green3a5f6c82019-03-05 16:30:39 +0000231 def _remove_children_with_tag(self, parent, tag):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000232 children = parent.getchildren()
233 for child in children:
234 if child.tag == tag:
235 parent.remove(child)
236 else:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000237 self._remove_children_with_tag(child, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000238
Darryl Green3a5f6c82019-03-05 16:30:39 +0000239 def _remove_extra_detail_from_report(self, report_root):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000240 for tag in ['test_info', 'test_results', 'problem_summary',
Darryl Greenc6f874b2019-06-05 12:57:50 +0100241 'added_symbols', 'affected']:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000242 self._remove_children_with_tag(report_root, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000243
244 for report in report_root:
245 for problems in report.getchildren()[:]:
246 if not problems.getchildren():
247 report.remove(problems)
248
Gilles Peskineada828f2019-07-04 19:17:40 +0200249 def _abi_compliance_command(self, mbed_module, output_path):
250 """Build the command to run to analyze the library mbed_module.
251 The report will be placed in output_path."""
252 abi_compliance_command = [
253 "abi-compliance-checker",
254 "-l", mbed_module,
255 "-old", self.old_version.abi_dumps[mbed_module],
256 "-new", self.new_version.abi_dumps[mbed_module],
257 "-strict",
258 "-report-path", output_path,
259 ]
260 if self.skip_file:
261 abi_compliance_command += ["-skip-symbols", self.skip_file,
262 "-skip-types", self.skip_file]
263 if self.brief:
264 abi_compliance_command += ["-report-format", "xml",
265 "-stdout"]
266 return abi_compliance_command
267
268 def _is_library_compatible(self, mbed_module, compatibility_report):
269 """Test if the library mbed_module has remained compatible.
270 Append a message regarding compatibility to compatibility_report."""
271 output_path = os.path.join(
272 self.report_dir, "{}-{}-{}.html".format(
273 mbed_module, self.old_version.revision,
274 self.new_version.revision
275 )
276 )
277 try:
278 subprocess.check_output(
279 self._abi_compliance_command(mbed_module, output_path),
280 stderr=subprocess.STDOUT
281 )
282 except subprocess.CalledProcessError as err:
283 if err.returncode != 1:
284 raise err
285 if self.brief:
286 self.log.info(
287 "Compatibility issues found for {}".format(mbed_module)
288 )
289 report_root = ET.fromstring(err.output.decode("utf-8"))
290 self._remove_extra_detail_from_report(report_root)
291 self.log.info(ET.tostring(report_root).decode("utf-8"))
292 else:
293 self.can_remove_report_dir = False
294 compatibility_report.append(
295 "Compatibility issues found for {}, "
296 "for details see {}".format(mbed_module, output_path)
297 )
298 return False
299 compatibility_report.append(
300 "No compatibility issues for {}".format(mbed_module)
301 )
302 if not (self.keep_all_reports or self.brief):
303 os.remove(output_path)
304 return True
305
Darryl Green7c2dd582018-03-01 14:53:49 +0000306 def get_abi_compatibility_report(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100307 """Generate a report of the differences between the reference ABI
Darryl Green8184df52019-04-05 17:06:17 +0100308 and the new ABI. ABI dumps from self.old_version and self.new_version
309 must be available."""
Gilles Peskineada828f2019-07-04 19:17:40 +0200310 compatibility_report = ["Checking evolution from {} to {}".format(
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200311 self._pretty_revision(self.old_version),
312 self._pretty_revision(self.new_version)
Gilles Peskineada828f2019-07-04 19:17:40 +0200313 )]
Darryl Green7c2dd582018-03-01 14:53:49 +0000314 compliance_return_code = 0
Darryl Green7c1a7332019-03-05 16:25:38 +0000315 shared_modules = list(set(self.old_version.modules.keys()) &
316 set(self.new_version.modules.keys()))
Darryl Green3e7a9802019-02-27 16:53:40 +0000317 for mbed_module in shared_modules:
Gilles Peskineada828f2019-07-04 19:17:40 +0200318 if not self._is_library_compatible(mbed_module,
319 compatibility_report):
320 compliance_return_code = 1
Darryl Greenf2688e22019-05-29 11:29:08 +0100321 for version in [self.old_version, self.new_version]:
322 for mbed_module, mbed_module_dump in version.abi_dumps.items():
323 os.remove(mbed_module_dump)
Darryl Green3d3d5522019-02-25 17:01:55 +0000324 if self.can_remove_report_dir:
Darryl Green7c2dd582018-03-01 14:53:49 +0000325 os.rmdir(self.report_dir)
Gilles Peskineada828f2019-07-04 19:17:40 +0200326 self.log.info("\n".join(compatibility_report))
Darryl Green7c2dd582018-03-01 14:53:49 +0000327 return compliance_return_code
328
329 def check_for_abi_changes(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100330 """Generate a report of ABI differences
331 between self.old_rev and self.new_rev."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000332 self.check_repo_path()
333 self.check_abi_tools_are_installed()
Darryl Green3a5f6c82019-03-05 16:30:39 +0000334 self._get_abi_dump_for_ref(self.old_version)
335 self._get_abi_dump_for_ref(self.new_version)
Darryl Green7c2dd582018-03-01 14:53:49 +0000336 return self.get_abi_compatibility_report()
337
338
339def run_main():
340 try:
341 parser = argparse.ArgumentParser(
342 description=(
Darryl Green418527b2018-04-16 12:02:29 +0100343 """This script is a small wrapper around the
344 abi-compliance-checker and abi-dumper tools, applying them
345 to compare the ABI and API of the library files from two
346 different Git revisions within an Mbed TLS repository.
Darryl Greene62f9bb2019-02-21 13:09:26 +0000347 The results of the comparison are either formatted as HTML and
Darryl Green4cde8a02019-03-05 15:21:32 +0000348 stored at a configurable location, or are given as a brief list
349 of problems. Returns 0 on success, 1 on ABI/API non-compliance,
350 and 2 if there is an error while running the script.
351 Note: must be run from Mbed TLS root."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000352 )
353 )
354 parser.add_argument(
Darryl Green3c3da792019-03-08 11:30:04 +0000355 "-v", "--verbose", action="store_true",
356 help="set verbosity level",
357 )
358 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100359 "-r", "--report-dir", type=str, default="reports",
Darryl Green7c2dd582018-03-01 14:53:49 +0000360 help="directory where reports are stored, default is reports",
361 )
362 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100363 "-k", "--keep-all-reports", action="store_true",
Darryl Green7c2dd582018-03-01 14:53:49 +0000364 help="keep all reports, even if there are no compatibility issues",
365 )
366 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000367 "-o", "--old-rev", type=str, help="revision for old version.",
368 required=True,
Darryl Green7c2dd582018-03-01 14:53:49 +0000369 )
370 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000371 "-or", "--old-repo", type=str, help="repository for old version."
Darryl Green9f357d62019-02-25 11:35:05 +0000372 )
373 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000374 "-oc", "--old-crypto-rev", type=str,
375 help="revision for old crypto submodule."
Darryl Green7c2dd582018-03-01 14:53:49 +0000376 )
Darryl Greenc2883a22019-02-20 15:01:56 +0000377 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000378 "-ocr", "--old-crypto-repo", type=str,
379 help="repository for old crypto submodule."
380 )
381 parser.add_argument(
382 "-n", "--new-rev", type=str, help="revision for new version",
383 required=True,
384 )
385 parser.add_argument(
386 "-nr", "--new-repo", type=str, help="repository for new version."
387 )
388 parser.add_argument(
389 "-nc", "--new-crypto-rev", type=str,
390 help="revision for new crypto version"
391 )
392 parser.add_argument(
393 "-ncr", "--new-crypto-repo", type=str,
394 help="repository for new crypto submodule."
Darryl Green9f357d62019-02-25 11:35:05 +0000395 )
396 parser.add_argument(
Darryl Greenc2883a22019-02-20 15:01:56 +0000397 "-s", "--skip-file", type=str,
Gilles Peskineb6ce2342019-07-04 19:00:31 +0200398 help=("path to file containing symbols and types to skip "
399 "(typically \"-s identifiers\" after running "
400 "\"tests/scripts/list-identifiers.sh --internal\")")
Darryl Greenc2883a22019-02-20 15:01:56 +0000401 )
Darryl Greene62f9bb2019-02-21 13:09:26 +0000402 parser.add_argument(
403 "-b", "--brief", action="store_true",
404 help="output only the list of issues to stdout, instead of a full report",
405 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000406 abi_args = parser.parse_args()
Darryl Green492bc402019-04-11 15:50:41 +0100407 if os.path.isfile(abi_args.report_dir):
408 print("Error: {} is not a directory".format(abi_args.report_dir))
409 parser.exit()
Darryl Green0d1ca512019-04-09 09:14:17 +0100410 old_version = SimpleNamespace(
411 version="old",
412 repository=abi_args.old_repo,
413 revision=abi_args.old_rev,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200414 commit=None,
Darryl Green0d1ca512019-04-09 09:14:17 +0100415 crypto_repository=abi_args.old_crypto_repo,
416 crypto_revision=abi_args.old_crypto_rev,
417 abi_dumps={},
418 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100419 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100420 new_version = SimpleNamespace(
421 version="new",
422 repository=abi_args.new_repo,
423 revision=abi_args.new_rev,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200424 commit=None,
Darryl Green0d1ca512019-04-09 09:14:17 +0100425 crypto_repository=abi_args.new_crypto_repo,
426 crypto_revision=abi_args.new_crypto_rev,
427 abi_dumps={},
428 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100429 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100430 configuration = SimpleNamespace(
431 verbose=abi_args.verbose,
432 report_dir=abi_args.report_dir,
433 keep_all_reports=abi_args.keep_all_reports,
434 brief=abi_args.brief,
435 skip_file=abi_args.skip_file
Darryl Green7c2dd582018-03-01 14:53:49 +0000436 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100437 abi_check = AbiChecker(old_version, new_version, configuration)
Darryl Green7c2dd582018-03-01 14:53:49 +0000438 return_code = abi_check.check_for_abi_changes()
439 sys.exit(return_code)
Gilles Peskinee915d532019-02-25 21:39:42 +0100440 except Exception: # pylint: disable=broad-except
441 # Print the backtrace and exit explicitly so as to exit with
442 # status 2, not 1.
Darryl Greena6f430f2018-03-15 10:12:06 +0000443 traceback.print_exc()
Darryl Green7c2dd582018-03-01 14:53:49 +0000444 sys.exit(2)
445
446
447if __name__ == "__main__":
448 run_main()