blob: 3cfd95a0681598e077c638781b7d059303e34023 [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úti1e148272020-08-07 13:07:28 +020014# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +020015# 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.
Bence Szépkútic7da1fe2020-05-26 01:54:15 +020028
Darryl Green7c2dd582018-03-01 14:53:49 +000029import os
30import sys
31import traceback
32import shutil
33import subprocess
34import argparse
35import logging
36import tempfile
Darryl Green9f357d62019-02-25 11:35:05 +000037import fnmatch
Darryl Green0d1ca512019-04-09 09:14:17 +010038from types import SimpleNamespace
Darryl Green7c2dd582018-03-01 14:53:49 +000039
Darryl Greene62f9bb2019-02-21 13:09:26 +000040import xml.etree.ElementTree as ET
41
Darryl Green7c2dd582018-03-01 14:53:49 +000042
Gilles Peskine184c0962020-03-24 18:25:17 +010043class AbiChecker:
Gilles Peskine712afa72019-02-25 20:36:52 +010044 """API and ABI checker."""
Darryl Green7c2dd582018-03-01 14:53:49 +000045
Darryl Green0d1ca512019-04-09 09:14:17 +010046 def __init__(self, old_version, new_version, configuration):
Gilles Peskine712afa72019-02-25 20:36:52 +010047 """Instantiate the API/ABI checker.
48
Darryl Green7c1a7332019-03-05 16:25:38 +000049 old_version: RepoVersion containing details to compare against
50 new_version: RepoVersion containing details to check
Darryl Greenf67e3492019-04-12 15:17:02 +010051 configuration.report_dir: directory for output files
52 configuration.keep_all_reports: if false, delete old reports
53 configuration.brief: if true, output shorter report to stdout
54 configuration.skip_file: path to file containing symbols and types to skip
Gilles Peskine712afa72019-02-25 20:36:52 +010055 """
Darryl Green7c2dd582018-03-01 14:53:49 +000056 self.repo_path = "."
57 self.log = None
Darryl Green0d1ca512019-04-09 09:14:17 +010058 self.verbose = configuration.verbose
Darryl Green3a5f6c82019-03-05 16:30:39 +000059 self._setup_logger()
Darryl Green0d1ca512019-04-09 09:14:17 +010060 self.report_dir = os.path.abspath(configuration.report_dir)
61 self.keep_all_reports = configuration.keep_all_reports
Darryl Green492bc402019-04-11 15:50:41 +010062 self.can_remove_report_dir = not (os.path.exists(self.report_dir) or
Darryl Green0d1ca512019-04-09 09:14:17 +010063 self.keep_all_reports)
Darryl Green7c1a7332019-03-05 16:25:38 +000064 self.old_version = old_version
65 self.new_version = new_version
Darryl Green0d1ca512019-04-09 09:14:17 +010066 self.skip_file = configuration.skip_file
67 self.brief = configuration.brief
Darryl Green7c2dd582018-03-01 14:53:49 +000068 self.git_command = "git"
69 self.make_command = "make"
70
Gilles Peskine712afa72019-02-25 20:36:52 +010071 @staticmethod
72 def check_repo_path():
Gilles Peskine6aa32cc2019-07-04 18:59:36 +020073 if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
Darryl Green7c2dd582018-03-01 14:53:49 +000074 raise Exception("Must be run from Mbed TLS root")
75
Darryl Green3a5f6c82019-03-05 16:30:39 +000076 def _setup_logger(self):
Darryl Green7c2dd582018-03-01 14:53:49 +000077 self.log = logging.getLogger()
Darryl Green3c3da792019-03-08 11:30:04 +000078 if self.verbose:
79 self.log.setLevel(logging.DEBUG)
80 else:
81 self.log.setLevel(logging.INFO)
Darryl Green7c2dd582018-03-01 14:53:49 +000082 self.log.addHandler(logging.StreamHandler())
83
Gilles Peskine712afa72019-02-25 20:36:52 +010084 @staticmethod
85 def check_abi_tools_are_installed():
Darryl Green7c2dd582018-03-01 14:53:49 +000086 for command in ["abi-dumper", "abi-compliance-checker"]:
87 if not shutil.which(command):
88 raise Exception("{} not installed, aborting".format(command))
89
Darryl Green3a5f6c82019-03-05 16:30:39 +000090 def _get_clean_worktree_for_git_revision(self, version):
Darryl Green7c1a7332019-03-05 16:25:38 +000091 """Make a separate worktree with version.revision checked out.
Gilles Peskine712afa72019-02-25 20:36:52 +010092 Do not modify the current worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +000093 git_worktree_path = tempfile.mkdtemp()
Darryl Green7c1a7332019-03-05 16:25:38 +000094 if version.repository:
Darryl Green3c3da792019-03-08 11:30:04 +000095 self.log.debug(
Darryl Greenda84e322019-02-19 16:59:33 +000096 "Checking out git worktree for revision {} from {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +000097 version.revision, version.repository
Darryl Greenda84e322019-02-19 16:59:33 +000098 )
99 )
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100100 fetch_output = subprocess.check_output(
Darryl Green7c1a7332019-03-05 16:25:38 +0000101 [self.git_command, "fetch",
102 version.repository, version.revision],
Darryl Greenda84e322019-02-19 16:59:33 +0000103 cwd=self.repo_path,
Darryl Greenda84e322019-02-19 16:59:33 +0000104 stderr=subprocess.STDOUT
105 )
Darryl Green3c3da792019-03-08 11:30:04 +0000106 self.log.debug(fetch_output.decode("utf-8"))
Darryl Greenda84e322019-02-19 16:59:33 +0000107 worktree_rev = "FETCH_HEAD"
108 else:
Darryl Green3c3da792019-03-08 11:30:04 +0000109 self.log.debug("Checking out git worktree for revision {}".format(
Darryl Green7c1a7332019-03-05 16:25:38 +0000110 version.revision
111 ))
112 worktree_rev = version.revision
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100113 worktree_output = subprocess.check_output(
Darryl Greenda84e322019-02-19 16:59:33 +0000114 [self.git_command, "worktree", "add", "--detach",
115 git_worktree_path, worktree_rev],
Darryl Green7c2dd582018-03-01 14:53:49 +0000116 cwd=self.repo_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000117 stderr=subprocess.STDOUT
118 )
Darryl Green3c3da792019-03-08 11:30:04 +0000119 self.log.debug(worktree_output.decode("utf-8"))
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200120 version.commit = subprocess.check_output(
Darryl Green762351b2019-07-25 14:33:33 +0100121 [self.git_command, "rev-parse", "HEAD"],
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200122 cwd=git_worktree_path,
123 stderr=subprocess.STDOUT
124 ).decode("ascii").rstrip()
125 self.log.debug("Commit is {}".format(version.commit))
Darryl Green7c2dd582018-03-01 14:53:49 +0000126 return git_worktree_path
127
Darryl Green3a5f6c82019-03-05 16:30:39 +0000128 def _update_git_submodules(self, git_worktree_path, version):
Darryl Green8184df52019-04-05 17:06:17 +0100129 """If the crypto submodule is present, initialize it.
130 if version.crypto_revision exists, update it to that revision,
131 otherwise update it to the default revision"""
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100132 update_output = subprocess.check_output(
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000133 [self.git_command, "submodule", "update", "--init", '--recursive'],
134 cwd=git_worktree_path,
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000135 stderr=subprocess.STDOUT
136 )
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100137 self.log.debug(update_output.decode("utf-8"))
Darryl Greene29ce702019-03-05 15:23:25 +0000138 if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
Darryl Green7c1a7332019-03-05 16:25:38 +0000139 and version.crypto_revision):
Darryl Greene29ce702019-03-05 15:23:25 +0000140 return
141
Darryl Green7c1a7332019-03-05 16:25:38 +0000142 if version.crypto_repository:
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100143 fetch_output = subprocess.check_output(
Darryl Green1d95c532019-03-08 11:12:19 +0000144 [self.git_command, "fetch", version.crypto_repository,
145 version.crypto_revision],
Darryl Greene29ce702019-03-05 15:23:25 +0000146 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Greene29ce702019-03-05 15:23:25 +0000147 stderr=subprocess.STDOUT
148 )
Darryl Green3c3da792019-03-08 11:30:04 +0000149 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green1d95c532019-03-08 11:12:19 +0000150 crypto_rev = "FETCH_HEAD"
151 else:
152 crypto_rev = version.crypto_revision
153
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100154 checkout_output = subprocess.check_output(
Darryl Green1d95c532019-03-08 11:12:19 +0000155 [self.git_command, "checkout", crypto_rev],
156 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Green1d95c532019-03-08 11:12:19 +0000157 stderr=subprocess.STDOUT
158 )
Darryl Green3c3da792019-03-08 11:30:04 +0000159 self.log.debug(checkout_output.decode("utf-8"))
Jaeden Ameroffeb1b82018-11-02 16:35:09 +0000160
Darryl Green3a5f6c82019-03-05 16:30:39 +0000161 def _build_shared_libraries(self, git_worktree_path, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100162 """Build the shared libraries in the specified worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000163 my_environment = os.environ.copy()
164 my_environment["CFLAGS"] = "-g -Og"
165 my_environment["SHARED"] = "1"
Darryl Greend2dba362019-05-09 13:03:05 +0100166 if os.path.exists(os.path.join(git_worktree_path, "crypto")):
167 my_environment["USE_CRYPTO_SUBMODULE"] = "1"
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100168 make_output = subprocess.check_output(
Darryl Greenddf25a62019-02-28 11:52:39 +0000169 [self.make_command, "lib"],
Darryl Green7c2dd582018-03-01 14:53:49 +0000170 env=my_environment,
171 cwd=git_worktree_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000172 stderr=subprocess.STDOUT
173 )
Darryl Green3c3da792019-03-08 11:30:04 +0000174 self.log.debug(make_output.decode("utf-8"))
Darryl Greenf025d532019-04-12 15:18:02 +0100175 for root, _dirs, files in os.walk(git_worktree_path):
Darryl Green9f357d62019-02-25 11:35:05 +0000176 for file in fnmatch.filter(files, "*.so"):
Darryl Green7c1a7332019-03-05 16:25:38 +0000177 version.modules[os.path.splitext(file)[0]] = (
Darryl Green3e7a9802019-02-27 16:53:40 +0000178 os.path.join(root, file)
Darryl Green9f357d62019-02-25 11:35:05 +0000179 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000180
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200181 @staticmethod
182 def _pretty_revision(version):
183 if version.revision == version.commit:
184 return version.revision
185 else:
186 return "{} ({})".format(version.revision, version.commit)
187
Darryl Green8184df52019-04-05 17:06:17 +0100188 def _get_abi_dumps_from_shared_libraries(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100189 """Generate the ABI dumps for the specified git revision.
Darryl Green8184df52019-04-05 17:06:17 +0100190 The shared libraries must have been built and the module paths
191 present in version.modules."""
Darryl Green7c1a7332019-03-05 16:25:38 +0000192 for mbed_module, module_path in version.modules.items():
Darryl Green7c2dd582018-03-01 14:53:49 +0000193 output_path = os.path.join(
Darryl Greenfe9a6752019-04-04 14:39:33 +0100194 self.report_dir, "{}-{}-{}.dump".format(
195 mbed_module, version.revision, version.version
Darryl Green3e7a9802019-02-27 16:53:40 +0000196 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000197 )
198 abi_dump_command = [
199 "abi-dumper",
Darryl Green9f357d62019-02-25 11:35:05 +0000200 module_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000201 "-o", output_path,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200202 "-lver", self._pretty_revision(version),
Darryl Green7c2dd582018-03-01 14:53:49 +0000203 ]
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100204 abi_dump_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000205 abi_dump_command,
Darryl Green7c2dd582018-03-01 14:53:49 +0000206 stderr=subprocess.STDOUT
207 )
Darryl Green3c3da792019-03-08 11:30:04 +0000208 self.log.debug(abi_dump_output.decode("utf-8"))
Darryl Green7c1a7332019-03-05 16:25:38 +0000209 version.abi_dumps[mbed_module] = output_path
Darryl Green7c2dd582018-03-01 14:53:49 +0000210
Darryl Green3a5f6c82019-03-05 16:30:39 +0000211 def _cleanup_worktree(self, git_worktree_path):
Gilles Peskine712afa72019-02-25 20:36:52 +0100212 """Remove the specified git worktree."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000213 shutil.rmtree(git_worktree_path)
Darryl Greenb2ee0b82019-04-12 16:24:25 +0100214 worktree_output = subprocess.check_output(
Darryl Green7c2dd582018-03-01 14:53:49 +0000215 [self.git_command, "worktree", "prune"],
216 cwd=self.repo_path,
Darryl Green7c2dd582018-03-01 14:53:49 +0000217 stderr=subprocess.STDOUT
218 )
Darryl Green3c3da792019-03-08 11:30:04 +0000219 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green7c2dd582018-03-01 14:53:49 +0000220
Darryl Green3a5f6c82019-03-05 16:30:39 +0000221 def _get_abi_dump_for_ref(self, version):
Gilles Peskine712afa72019-02-25 20:36:52 +0100222 """Generate the ABI dumps for the specified git revision."""
Darryl Green3a5f6c82019-03-05 16:30:39 +0000223 git_worktree_path = self._get_clean_worktree_for_git_revision(version)
224 self._update_git_submodules(git_worktree_path, version)
225 self._build_shared_libraries(git_worktree_path, version)
Darryl Green8184df52019-04-05 17:06:17 +0100226 self._get_abi_dumps_from_shared_libraries(version)
Darryl Green3a5f6c82019-03-05 16:30:39 +0000227 self._cleanup_worktree(git_worktree_path)
Darryl Green7c2dd582018-03-01 14:53:49 +0000228
Darryl Green3a5f6c82019-03-05 16:30:39 +0000229 def _remove_children_with_tag(self, parent, tag):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000230 children = parent.getchildren()
231 for child in children:
232 if child.tag == tag:
233 parent.remove(child)
234 else:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000235 self._remove_children_with_tag(child, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000236
Darryl Green3a5f6c82019-03-05 16:30:39 +0000237 def _remove_extra_detail_from_report(self, report_root):
Darryl Greene62f9bb2019-02-21 13:09:26 +0000238 for tag in ['test_info', 'test_results', 'problem_summary',
Darryl Greenc6f874b2019-06-05 12:57:50 +0100239 'added_symbols', 'affected']:
Darryl Green3a5f6c82019-03-05 16:30:39 +0000240 self._remove_children_with_tag(report_root, tag)
Darryl Greene62f9bb2019-02-21 13:09:26 +0000241
242 for report in report_root:
243 for problems in report.getchildren()[:]:
244 if not problems.getchildren():
245 report.remove(problems)
246
Gilles Peskineada828f2019-07-04 19:17:40 +0200247 def _abi_compliance_command(self, mbed_module, output_path):
248 """Build the command to run to analyze the library mbed_module.
249 The report will be placed in output_path."""
250 abi_compliance_command = [
251 "abi-compliance-checker",
252 "-l", mbed_module,
253 "-old", self.old_version.abi_dumps[mbed_module],
254 "-new", self.new_version.abi_dumps[mbed_module],
255 "-strict",
256 "-report-path", output_path,
257 ]
258 if self.skip_file:
259 abi_compliance_command += ["-skip-symbols", self.skip_file,
260 "-skip-types", self.skip_file]
261 if self.brief:
262 abi_compliance_command += ["-report-format", "xml",
263 "-stdout"]
264 return abi_compliance_command
265
266 def _is_library_compatible(self, mbed_module, compatibility_report):
267 """Test if the library mbed_module has remained compatible.
268 Append a message regarding compatibility to compatibility_report."""
269 output_path = os.path.join(
270 self.report_dir, "{}-{}-{}.html".format(
271 mbed_module, self.old_version.revision,
272 self.new_version.revision
273 )
274 )
275 try:
276 subprocess.check_output(
277 self._abi_compliance_command(mbed_module, output_path),
278 stderr=subprocess.STDOUT
279 )
280 except subprocess.CalledProcessError as err:
281 if err.returncode != 1:
282 raise err
283 if self.brief:
284 self.log.info(
285 "Compatibility issues found for {}".format(mbed_module)
286 )
287 report_root = ET.fromstring(err.output.decode("utf-8"))
288 self._remove_extra_detail_from_report(report_root)
289 self.log.info(ET.tostring(report_root).decode("utf-8"))
290 else:
291 self.can_remove_report_dir = False
292 compatibility_report.append(
293 "Compatibility issues found for {}, "
294 "for details see {}".format(mbed_module, output_path)
295 )
296 return False
297 compatibility_report.append(
298 "No compatibility issues for {}".format(mbed_module)
299 )
300 if not (self.keep_all_reports or self.brief):
301 os.remove(output_path)
302 return True
303
Darryl Green7c2dd582018-03-01 14:53:49 +0000304 def get_abi_compatibility_report(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100305 """Generate a report of the differences between the reference ABI
Darryl Green8184df52019-04-05 17:06:17 +0100306 and the new ABI. ABI dumps from self.old_version and self.new_version
307 must be available."""
Gilles Peskineada828f2019-07-04 19:17:40 +0200308 compatibility_report = ["Checking evolution from {} to {}".format(
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200309 self._pretty_revision(self.old_version),
310 self._pretty_revision(self.new_version)
Gilles Peskineada828f2019-07-04 19:17:40 +0200311 )]
Darryl Green7c2dd582018-03-01 14:53:49 +0000312 compliance_return_code = 0
Darryl Green7c1a7332019-03-05 16:25:38 +0000313 shared_modules = list(set(self.old_version.modules.keys()) &
314 set(self.new_version.modules.keys()))
Darryl Green3e7a9802019-02-27 16:53:40 +0000315 for mbed_module in shared_modules:
Gilles Peskineada828f2019-07-04 19:17:40 +0200316 if not self._is_library_compatible(mbed_module,
317 compatibility_report):
318 compliance_return_code = 1
Darryl Greenf2688e22019-05-29 11:29:08 +0100319 for version in [self.old_version, self.new_version]:
320 for mbed_module, mbed_module_dump in version.abi_dumps.items():
321 os.remove(mbed_module_dump)
Darryl Green3d3d5522019-02-25 17:01:55 +0000322 if self.can_remove_report_dir:
Darryl Green7c2dd582018-03-01 14:53:49 +0000323 os.rmdir(self.report_dir)
Gilles Peskineada828f2019-07-04 19:17:40 +0200324 self.log.info("\n".join(compatibility_report))
Darryl Green7c2dd582018-03-01 14:53:49 +0000325 return compliance_return_code
326
327 def check_for_abi_changes(self):
Gilles Peskine712afa72019-02-25 20:36:52 +0100328 """Generate a report of ABI differences
329 between self.old_rev and self.new_rev."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000330 self.check_repo_path()
331 self.check_abi_tools_are_installed()
Darryl Green3a5f6c82019-03-05 16:30:39 +0000332 self._get_abi_dump_for_ref(self.old_version)
333 self._get_abi_dump_for_ref(self.new_version)
Darryl Green7c2dd582018-03-01 14:53:49 +0000334 return self.get_abi_compatibility_report()
335
336
337def run_main():
338 try:
339 parser = argparse.ArgumentParser(
340 description=(
Darryl Green418527b2018-04-16 12:02:29 +0100341 """This script is a small wrapper around the
342 abi-compliance-checker and abi-dumper tools, applying them
343 to compare the ABI and API of the library files from two
344 different Git revisions within an Mbed TLS repository.
Darryl Greene62f9bb2019-02-21 13:09:26 +0000345 The results of the comparison are either formatted as HTML and
Darryl Green4cde8a02019-03-05 15:21:32 +0000346 stored at a configurable location, or are given as a brief list
347 of problems. Returns 0 on success, 1 on ABI/API non-compliance,
348 and 2 if there is an error while running the script.
349 Note: must be run from Mbed TLS root."""
Darryl Green7c2dd582018-03-01 14:53:49 +0000350 )
351 )
352 parser.add_argument(
Darryl Green3c3da792019-03-08 11:30:04 +0000353 "-v", "--verbose", action="store_true",
354 help="set verbosity level",
355 )
356 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100357 "-r", "--report-dir", type=str, default="reports",
Darryl Green7c2dd582018-03-01 14:53:49 +0000358 help="directory where reports are stored, default is reports",
359 )
360 parser.add_argument(
Darryl Green418527b2018-04-16 12:02:29 +0100361 "-k", "--keep-all-reports", action="store_true",
Darryl Green7c2dd582018-03-01 14:53:49 +0000362 help="keep all reports, even if there are no compatibility issues",
363 )
364 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000365 "-o", "--old-rev", type=str, help="revision for old version.",
366 required=True,
Darryl Green7c2dd582018-03-01 14:53:49 +0000367 )
368 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000369 "-or", "--old-repo", type=str, help="repository for old version."
Darryl Green9f357d62019-02-25 11:35:05 +0000370 )
371 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000372 "-oc", "--old-crypto-rev", type=str,
373 help="revision for old crypto submodule."
Darryl Green7c2dd582018-03-01 14:53:49 +0000374 )
Darryl Greenc2883a22019-02-20 15:01:56 +0000375 parser.add_argument(
Darryl Greenc5132ff2019-03-01 09:54:44 +0000376 "-ocr", "--old-crypto-repo", type=str,
377 help="repository for old crypto submodule."
378 )
379 parser.add_argument(
380 "-n", "--new-rev", type=str, help="revision for new version",
381 required=True,
382 )
383 parser.add_argument(
384 "-nr", "--new-repo", type=str, help="repository for new version."
385 )
386 parser.add_argument(
387 "-nc", "--new-crypto-rev", type=str,
388 help="revision for new crypto version"
389 )
390 parser.add_argument(
391 "-ncr", "--new-crypto-repo", type=str,
392 help="repository for new crypto submodule."
Darryl Green9f357d62019-02-25 11:35:05 +0000393 )
394 parser.add_argument(
Darryl Greenc2883a22019-02-20 15:01:56 +0000395 "-s", "--skip-file", type=str,
Gilles Peskineb6ce2342019-07-04 19:00:31 +0200396 help=("path to file containing symbols and types to skip "
397 "(typically \"-s identifiers\" after running "
398 "\"tests/scripts/list-identifiers.sh --internal\")")
Darryl Greenc2883a22019-02-20 15:01:56 +0000399 )
Darryl Greene62f9bb2019-02-21 13:09:26 +0000400 parser.add_argument(
401 "-b", "--brief", action="store_true",
402 help="output only the list of issues to stdout, instead of a full report",
403 )
Darryl Green7c2dd582018-03-01 14:53:49 +0000404 abi_args = parser.parse_args()
Darryl Green492bc402019-04-11 15:50:41 +0100405 if os.path.isfile(abi_args.report_dir):
406 print("Error: {} is not a directory".format(abi_args.report_dir))
407 parser.exit()
Darryl Green0d1ca512019-04-09 09:14:17 +0100408 old_version = SimpleNamespace(
409 version="old",
410 repository=abi_args.old_repo,
411 revision=abi_args.old_rev,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200412 commit=None,
Darryl Green0d1ca512019-04-09 09:14:17 +0100413 crypto_repository=abi_args.old_crypto_repo,
414 crypto_revision=abi_args.old_crypto_rev,
415 abi_dumps={},
416 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100417 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100418 new_version = SimpleNamespace(
419 version="new",
420 repository=abi_args.new_repo,
421 revision=abi_args.new_rev,
Gilles Peskine3e2da4a2019-07-04 19:01:22 +0200422 commit=None,
Darryl Green0d1ca512019-04-09 09:14:17 +0100423 crypto_repository=abi_args.new_crypto_repo,
424 crypto_revision=abi_args.new_crypto_rev,
425 abi_dumps={},
426 modules={}
Darryl Green8184df52019-04-05 17:06:17 +0100427 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100428 configuration = SimpleNamespace(
429 verbose=abi_args.verbose,
430 report_dir=abi_args.report_dir,
431 keep_all_reports=abi_args.keep_all_reports,
432 brief=abi_args.brief,
433 skip_file=abi_args.skip_file
Darryl Green7c2dd582018-03-01 14:53:49 +0000434 )
Darryl Green0d1ca512019-04-09 09:14:17 +0100435 abi_check = AbiChecker(old_version, new_version, configuration)
Darryl Green7c2dd582018-03-01 14:53:49 +0000436 return_code = abi_check.check_for_abi_changes()
437 sys.exit(return_code)
Gilles Peskinee915d532019-02-25 21:39:42 +0100438 except Exception: # pylint: disable=broad-except
439 # Print the backtrace and exit explicitly so as to exit with
440 # status 2, not 1.
Darryl Greena6f430f2018-03-15 10:12:06 +0000441 traceback.print_exc()
Darryl Green7c2dd582018-03-01 14:53:49 +0000442 sys.exit(2)
443
444
445if __name__ == "__main__":
446 run_main()