blob: a6858a19a3de10e082a4cc07e2cbe728ce7a4f72 [file] [log] [blame]
Darryl Green3da15042018-03-01 14:53:49 +00001#!/usr/bin/env python3
Darryl Green4cd7a9b2018-04-06 11:23:22 +01002"""
Darryl Green4cd7a9b2018-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 Green32e7a502019-02-21 13:09:26 +00008The results of the comparison are either formatted as HTML and stored at
Darryl Green765d20d2019-03-05 15:21:32 +00009a configurable location, or are given as a brief list of problems.
Darryl Green32e7a502019-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 Green4cd7a9b2018-04-06 11:23:22 +010012"""
Darryl Green3da15042018-03-01 14:53:49 +000013
Bence Szépkúti09b4f192020-05-26 01:54:15 +020014# Copyright (c) 2018, Arm Limited, All Rights Reserved
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020015# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
16#
17# This file is provided under the Apache License 2.0, or the
18# GNU General Public License v2.0 or later.
19#
20# **********
21# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020022#
23# Licensed under the Apache License, Version 2.0 (the "License"); you may
24# not use this file except in compliance with the License.
25# You may obtain a copy of the License at
26#
27# http://www.apache.org/licenses/LICENSE-2.0
28#
29# Unless required by applicable law or agreed to in writing, software
30# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
31# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32# See the License for the specific language governing permissions and
33# limitations under the License.
34#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020035# **********
36#
37# **********
38# GNU General Public License v2.0 or later:
39#
40# This program is free software; you can redistribute it and/or modify
41# it under the terms of the GNU General Public License as published by
42# the Free Software Foundation; either version 2 of the License, or
43# (at your option) any later version.
44#
45# This program is distributed in the hope that it will be useful,
46# but WITHOUT ANY WARRANTY; without even the implied warranty of
47# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48# GNU General Public License for more details.
49#
50# You should have received a copy of the GNU General Public License along
51# with this program; if not, write to the Free Software Foundation, Inc.,
52# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
53#
54# **********
55#
Bence Szépkúti09b4f192020-05-26 01:54:15 +020056# This file is part of Mbed TLS (https://tls.mbed.org)
57
Darryl Green3da15042018-03-01 14:53:49 +000058import os
59import sys
60import traceback
61import shutil
62import subprocess
63import argparse
64import logging
65import tempfile
Darryl Greend9ad9ec2019-02-25 11:35:05 +000066import fnmatch
Darryl Greenf1d272d2019-04-09 09:14:17 +010067from types import SimpleNamespace
Darryl Green3da15042018-03-01 14:53:49 +000068
Darryl Green32e7a502019-02-21 13:09:26 +000069import xml.etree.ElementTree as ET
70
Darryl Green3da15042018-03-01 14:53:49 +000071
Gilles Peskineb5847d22020-03-24 18:25:17 +010072class AbiChecker:
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010073 """API and ABI checker."""
Darryl Green3da15042018-03-01 14:53:49 +000074
Darryl Greenf1d272d2019-04-09 09:14:17 +010075 def __init__(self, old_version, new_version, configuration):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010076 """Instantiate the API/ABI checker.
77
Darryl Green02b68652019-03-05 16:25:38 +000078 old_version: RepoVersion containing details to compare against
79 new_version: RepoVersion containing details to check
Darryl Greenbbc6ccf2019-04-12 15:17:02 +010080 configuration.report_dir: directory for output files
81 configuration.keep_all_reports: if false, delete old reports
82 configuration.brief: if true, output shorter report to stdout
83 configuration.skip_file: path to file containing symbols and types to skip
Gilles Peskinefceb4ce2019-02-25 20:36:52 +010084 """
Darryl Green3da15042018-03-01 14:53:49 +000085 self.repo_path = "."
86 self.log = None
Darryl Greenf1d272d2019-04-09 09:14:17 +010087 self.verbose = configuration.verbose
Darryl Green7bb9cb52019-03-05 16:30:39 +000088 self._setup_logger()
Darryl Greenf1d272d2019-04-09 09:14:17 +010089 self.report_dir = os.path.abspath(configuration.report_dir)
90 self.keep_all_reports = configuration.keep_all_reports
Darryl Green03625fe2019-04-11 15:50:41 +010091 self.can_remove_report_dir = not (os.path.exists(self.report_dir) or
Darryl Greenf1d272d2019-04-09 09:14:17 +010092 self.keep_all_reports)
Darryl Green02b68652019-03-05 16:25:38 +000093 self.old_version = old_version
94 self.new_version = new_version
Darryl Greenf1d272d2019-04-09 09:14:17 +010095 self.skip_file = configuration.skip_file
96 self.brief = configuration.brief
Darryl Green3da15042018-03-01 14:53:49 +000097 self.git_command = "git"
98 self.make_command = "make"
99
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100100 @staticmethod
101 def check_repo_path():
Gilles Peskine16dfdb32019-07-04 18:59:36 +0200102 if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
Darryl Green3da15042018-03-01 14:53:49 +0000103 raise Exception("Must be run from Mbed TLS root")
104
Darryl Green7bb9cb52019-03-05 16:30:39 +0000105 def _setup_logger(self):
Darryl Green3da15042018-03-01 14:53:49 +0000106 self.log = logging.getLogger()
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000107 if self.verbose:
108 self.log.setLevel(logging.DEBUG)
109 else:
110 self.log.setLevel(logging.INFO)
Darryl Green3da15042018-03-01 14:53:49 +0000111 self.log.addHandler(logging.StreamHandler())
112
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100113 @staticmethod
114 def check_abi_tools_are_installed():
Darryl Green3da15042018-03-01 14:53:49 +0000115 for command in ["abi-dumper", "abi-compliance-checker"]:
116 if not shutil.which(command):
117 raise Exception("{} not installed, aborting".format(command))
118
Darryl Green7bb9cb52019-03-05 16:30:39 +0000119 def _get_clean_worktree_for_git_revision(self, version):
Darryl Green02b68652019-03-05 16:25:38 +0000120 """Make a separate worktree with version.revision checked out.
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100121 Do not modify the current worktree."""
Darryl Green3da15042018-03-01 14:53:49 +0000122 git_worktree_path = tempfile.mkdtemp()
Darryl Green02b68652019-03-05 16:25:38 +0000123 if version.repository:
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000124 self.log.debug(
Darryl Green834ebc42019-02-19 16:59:33 +0000125 "Checking out git worktree for revision {} from {}".format(
Darryl Green02b68652019-03-05 16:25:38 +0000126 version.revision, version.repository
Darryl Green834ebc42019-02-19 16:59:33 +0000127 )
128 )
Darryl Green4a483e42019-04-12 16:24:25 +0100129 fetch_output = subprocess.check_output(
Darryl Green02b68652019-03-05 16:25:38 +0000130 [self.git_command, "fetch",
131 version.repository, version.revision],
Darryl Green834ebc42019-02-19 16:59:33 +0000132 cwd=self.repo_path,
Darryl Green834ebc42019-02-19 16:59:33 +0000133 stderr=subprocess.STDOUT
134 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000135 self.log.debug(fetch_output.decode("utf-8"))
Darryl Green834ebc42019-02-19 16:59:33 +0000136 worktree_rev = "FETCH_HEAD"
137 else:
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000138 self.log.debug("Checking out git worktree for revision {}".format(
Darryl Green02b68652019-03-05 16:25:38 +0000139 version.revision
140 ))
141 worktree_rev = version.revision
Darryl Green4a483e42019-04-12 16:24:25 +0100142 worktree_output = subprocess.check_output(
Darryl Green834ebc42019-02-19 16:59:33 +0000143 [self.git_command, "worktree", "add", "--detach",
144 git_worktree_path, worktree_rev],
Darryl Green3da15042018-03-01 14:53:49 +0000145 cwd=self.repo_path,
Darryl Green3da15042018-03-01 14:53:49 +0000146 stderr=subprocess.STDOUT
147 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000148 self.log.debug(worktree_output.decode("utf-8"))
Gilles Peskine2b3f1342019-07-04 19:01:22 +0200149 version.commit = subprocess.check_output(
Darryl Greene3a7c9c2019-07-25 14:33:33 +0100150 [self.git_command, "rev-parse", "HEAD"],
Gilles Peskine2b3f1342019-07-04 19:01:22 +0200151 cwd=git_worktree_path,
152 stderr=subprocess.STDOUT
153 ).decode("ascii").rstrip()
154 self.log.debug("Commit is {}".format(version.commit))
Darryl Green3da15042018-03-01 14:53:49 +0000155 return git_worktree_path
156
Darryl Green7bb9cb52019-03-05 16:30:39 +0000157 def _update_git_submodules(self, git_worktree_path, version):
Darryl Greenb7447e72019-04-05 17:06:17 +0100158 """If the crypto submodule is present, initialize it.
159 if version.crypto_revision exists, update it to that revision,
160 otherwise update it to the default revision"""
Darryl Green4a483e42019-04-12 16:24:25 +0100161 update_output = subprocess.check_output(
Jaeden Amero346f9592018-11-02 16:35:09 +0000162 [self.git_command, "submodule", "update", "--init", '--recursive'],
163 cwd=git_worktree_path,
Jaeden Amero346f9592018-11-02 16:35:09 +0000164 stderr=subprocess.STDOUT
165 )
Darryl Green4a483e42019-04-12 16:24:25 +0100166 self.log.debug(update_output.decode("utf-8"))
Darryl Green7be79c92019-03-05 15:23:25 +0000167 if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
Darryl Green02b68652019-03-05 16:25:38 +0000168 and version.crypto_revision):
Darryl Green7be79c92019-03-05 15:23:25 +0000169 return
170
Darryl Green02b68652019-03-05 16:25:38 +0000171 if version.crypto_repository:
Darryl Green4a483e42019-04-12 16:24:25 +0100172 fetch_output = subprocess.check_output(
Darryl Greenb7433092019-03-08 11:12:19 +0000173 [self.git_command, "fetch", version.crypto_repository,
174 version.crypto_revision],
Darryl Green7be79c92019-03-05 15:23:25 +0000175 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Green7be79c92019-03-05 15:23:25 +0000176 stderr=subprocess.STDOUT
177 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000178 self.log.debug(fetch_output.decode("utf-8"))
Darryl Greenb7433092019-03-08 11:12:19 +0000179 crypto_rev = "FETCH_HEAD"
180 else:
181 crypto_rev = version.crypto_revision
182
Darryl Green4a483e42019-04-12 16:24:25 +0100183 checkout_output = subprocess.check_output(
Darryl Greenb7433092019-03-08 11:12:19 +0000184 [self.git_command, "checkout", crypto_rev],
185 cwd=os.path.join(git_worktree_path, "crypto"),
Darryl Greenb7433092019-03-08 11:12:19 +0000186 stderr=subprocess.STDOUT
187 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000188 self.log.debug(checkout_output.decode("utf-8"))
Jaeden Amero346f9592018-11-02 16:35:09 +0000189
Darryl Green7bb9cb52019-03-05 16:30:39 +0000190 def _build_shared_libraries(self, git_worktree_path, version):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100191 """Build the shared libraries in the specified worktree."""
Darryl Green3da15042018-03-01 14:53:49 +0000192 my_environment = os.environ.copy()
193 my_environment["CFLAGS"] = "-g -Og"
194 my_environment["SHARED"] = "1"
Darryl Green81948712019-05-09 13:03:05 +0100195 if os.path.exists(os.path.join(git_worktree_path, "crypto")):
196 my_environment["USE_CRYPTO_SUBMODULE"] = "1"
Darryl Green4a483e42019-04-12 16:24:25 +0100197 make_output = subprocess.check_output(
Darryl Green997c2872019-02-28 11:52:39 +0000198 [self.make_command, "lib"],
Darryl Green3da15042018-03-01 14:53:49 +0000199 env=my_environment,
200 cwd=git_worktree_path,
Darryl Green3da15042018-03-01 14:53:49 +0000201 stderr=subprocess.STDOUT
202 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000203 self.log.debug(make_output.decode("utf-8"))
Darryl Green31a1e992019-04-12 15:18:02 +0100204 for root, _dirs, files in os.walk(git_worktree_path):
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000205 for file in fnmatch.filter(files, "*.so"):
Darryl Green02b68652019-03-05 16:25:38 +0000206 version.modules[os.path.splitext(file)[0]] = (
Darryl Greend98d8b52019-02-27 16:53:40 +0000207 os.path.join(root, file)
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000208 )
Darryl Green3da15042018-03-01 14:53:49 +0000209
Gilles Peskine2b3f1342019-07-04 19:01:22 +0200210 @staticmethod
211 def _pretty_revision(version):
212 if version.revision == version.commit:
213 return version.revision
214 else:
215 return "{} ({})".format(version.revision, version.commit)
216
Darryl Greenb7447e72019-04-05 17:06:17 +0100217 def _get_abi_dumps_from_shared_libraries(self, version):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100218 """Generate the ABI dumps for the specified git revision.
Darryl Greenb7447e72019-04-05 17:06:17 +0100219 The shared libraries must have been built and the module paths
220 present in version.modules."""
Darryl Green02b68652019-03-05 16:25:38 +0000221 for mbed_module, module_path in version.modules.items():
Darryl Green3da15042018-03-01 14:53:49 +0000222 output_path = os.path.join(
Darryl Greencf434252019-04-04 14:39:33 +0100223 self.report_dir, "{}-{}-{}.dump".format(
224 mbed_module, version.revision, version.version
Darryl Greend98d8b52019-02-27 16:53:40 +0000225 )
Darryl Green3da15042018-03-01 14:53:49 +0000226 )
227 abi_dump_command = [
228 "abi-dumper",
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000229 module_path,
Darryl Green3da15042018-03-01 14:53:49 +0000230 "-o", output_path,
Gilles Peskine2b3f1342019-07-04 19:01:22 +0200231 "-lver", self._pretty_revision(version),
Darryl Green3da15042018-03-01 14:53:49 +0000232 ]
Darryl Green4a483e42019-04-12 16:24:25 +0100233 abi_dump_output = subprocess.check_output(
Darryl Green3da15042018-03-01 14:53:49 +0000234 abi_dump_command,
Darryl Green3da15042018-03-01 14:53:49 +0000235 stderr=subprocess.STDOUT
236 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000237 self.log.debug(abi_dump_output.decode("utf-8"))
Darryl Green02b68652019-03-05 16:25:38 +0000238 version.abi_dumps[mbed_module] = output_path
Darryl Green3da15042018-03-01 14:53:49 +0000239
Darryl Green7bb9cb52019-03-05 16:30:39 +0000240 def _cleanup_worktree(self, git_worktree_path):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100241 """Remove the specified git worktree."""
Darryl Green3da15042018-03-01 14:53:49 +0000242 shutil.rmtree(git_worktree_path)
Darryl Green4a483e42019-04-12 16:24:25 +0100243 worktree_output = subprocess.check_output(
Darryl Green3da15042018-03-01 14:53:49 +0000244 [self.git_command, "worktree", "prune"],
245 cwd=self.repo_path,
Darryl Green3da15042018-03-01 14:53:49 +0000246 stderr=subprocess.STDOUT
247 )
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000248 self.log.debug(worktree_output.decode("utf-8"))
Darryl Green3da15042018-03-01 14:53:49 +0000249
Darryl Green7bb9cb52019-03-05 16:30:39 +0000250 def _get_abi_dump_for_ref(self, version):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100251 """Generate the ABI dumps for the specified git revision."""
Darryl Green7bb9cb52019-03-05 16:30:39 +0000252 git_worktree_path = self._get_clean_worktree_for_git_revision(version)
253 self._update_git_submodules(git_worktree_path, version)
254 self._build_shared_libraries(git_worktree_path, version)
Darryl Greenb7447e72019-04-05 17:06:17 +0100255 self._get_abi_dumps_from_shared_libraries(version)
Darryl Green7bb9cb52019-03-05 16:30:39 +0000256 self._cleanup_worktree(git_worktree_path)
Darryl Green3da15042018-03-01 14:53:49 +0000257
Darryl Green7bb9cb52019-03-05 16:30:39 +0000258 def _remove_children_with_tag(self, parent, tag):
Darryl Green32e7a502019-02-21 13:09:26 +0000259 children = parent.getchildren()
260 for child in children:
261 if child.tag == tag:
262 parent.remove(child)
263 else:
Darryl Green7bb9cb52019-03-05 16:30:39 +0000264 self._remove_children_with_tag(child, tag)
Darryl Green32e7a502019-02-21 13:09:26 +0000265
Darryl Green7bb9cb52019-03-05 16:30:39 +0000266 def _remove_extra_detail_from_report(self, report_root):
Darryl Green32e7a502019-02-21 13:09:26 +0000267 for tag in ['test_info', 'test_results', 'problem_summary',
Darryl Greendb95d7e2019-06-05 12:57:50 +0100268 'added_symbols', 'affected']:
Darryl Green7bb9cb52019-03-05 16:30:39 +0000269 self._remove_children_with_tag(report_root, tag)
Darryl Green32e7a502019-02-21 13:09:26 +0000270
271 for report in report_root:
272 for problems in report.getchildren()[:]:
273 if not problems.getchildren():
274 report.remove(problems)
275
Gilles Peskineb14b7302019-07-04 19:17:40 +0200276 def _abi_compliance_command(self, mbed_module, output_path):
277 """Build the command to run to analyze the library mbed_module.
278 The report will be placed in output_path."""
279 abi_compliance_command = [
280 "abi-compliance-checker",
281 "-l", mbed_module,
282 "-old", self.old_version.abi_dumps[mbed_module],
283 "-new", self.new_version.abi_dumps[mbed_module],
284 "-strict",
285 "-report-path", output_path,
286 ]
287 if self.skip_file:
288 abi_compliance_command += ["-skip-symbols", self.skip_file,
289 "-skip-types", self.skip_file]
290 if self.brief:
291 abi_compliance_command += ["-report-format", "xml",
292 "-stdout"]
293 return abi_compliance_command
294
295 def _is_library_compatible(self, mbed_module, compatibility_report):
296 """Test if the library mbed_module has remained compatible.
297 Append a message regarding compatibility to compatibility_report."""
298 output_path = os.path.join(
299 self.report_dir, "{}-{}-{}.html".format(
300 mbed_module, self.old_version.revision,
301 self.new_version.revision
302 )
303 )
304 try:
305 subprocess.check_output(
306 self._abi_compliance_command(mbed_module, output_path),
307 stderr=subprocess.STDOUT
308 )
309 except subprocess.CalledProcessError as err:
310 if err.returncode != 1:
311 raise err
312 if self.brief:
313 self.log.info(
314 "Compatibility issues found for {}".format(mbed_module)
315 )
316 report_root = ET.fromstring(err.output.decode("utf-8"))
317 self._remove_extra_detail_from_report(report_root)
318 self.log.info(ET.tostring(report_root).decode("utf-8"))
319 else:
320 self.can_remove_report_dir = False
321 compatibility_report.append(
322 "Compatibility issues found for {}, "
323 "for details see {}".format(mbed_module, output_path)
324 )
325 return False
326 compatibility_report.append(
327 "No compatibility issues for {}".format(mbed_module)
328 )
329 if not (self.keep_all_reports or self.brief):
330 os.remove(output_path)
331 return True
332
Darryl Green3da15042018-03-01 14:53:49 +0000333 def get_abi_compatibility_report(self):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100334 """Generate a report of the differences between the reference ABI
Darryl Greenb7447e72019-04-05 17:06:17 +0100335 and the new ABI. ABI dumps from self.old_version and self.new_version
336 must be available."""
Gilles Peskineb14b7302019-07-04 19:17:40 +0200337 compatibility_report = ["Checking evolution from {} to {}".format(
Gilles Peskine2b3f1342019-07-04 19:01:22 +0200338 self._pretty_revision(self.old_version),
339 self._pretty_revision(self.new_version)
Gilles Peskineb14b7302019-07-04 19:17:40 +0200340 )]
Darryl Green3da15042018-03-01 14:53:49 +0000341 compliance_return_code = 0
Darryl Green02b68652019-03-05 16:25:38 +0000342 shared_modules = list(set(self.old_version.modules.keys()) &
343 set(self.new_version.modules.keys()))
Darryl Greend98d8b52019-02-27 16:53:40 +0000344 for mbed_module in shared_modules:
Gilles Peskineb14b7302019-07-04 19:17:40 +0200345 if not self._is_library_compatible(mbed_module,
346 compatibility_report):
347 compliance_return_code = 1
Darryl Green3e9626e2019-05-29 11:29:08 +0100348 for version in [self.old_version, self.new_version]:
349 for mbed_module, mbed_module_dump in version.abi_dumps.items():
350 os.remove(mbed_module_dump)
Darryl Greenab3893b2019-02-25 17:01:55 +0000351 if self.can_remove_report_dir:
Darryl Green3da15042018-03-01 14:53:49 +0000352 os.rmdir(self.report_dir)
Gilles Peskineb14b7302019-07-04 19:17:40 +0200353 self.log.info("\n".join(compatibility_report))
Darryl Green3da15042018-03-01 14:53:49 +0000354 return compliance_return_code
355
356 def check_for_abi_changes(self):
Gilles Peskinefceb4ce2019-02-25 20:36:52 +0100357 """Generate a report of ABI differences
358 between self.old_rev and self.new_rev."""
Darryl Green3da15042018-03-01 14:53:49 +0000359 self.check_repo_path()
360 self.check_abi_tools_are_installed()
Darryl Green7bb9cb52019-03-05 16:30:39 +0000361 self._get_abi_dump_for_ref(self.old_version)
362 self._get_abi_dump_for_ref(self.new_version)
Darryl Green3da15042018-03-01 14:53:49 +0000363 return self.get_abi_compatibility_report()
364
365
366def run_main():
367 try:
368 parser = argparse.ArgumentParser(
369 description=(
Darryl Green31321ca2018-04-16 12:02:29 +0100370 """This script is a small wrapper around the
371 abi-compliance-checker and abi-dumper tools, applying them
372 to compare the ABI and API of the library files from two
373 different Git revisions within an Mbed TLS repository.
Darryl Green32e7a502019-02-21 13:09:26 +0000374 The results of the comparison are either formatted as HTML and
Darryl Green765d20d2019-03-05 15:21:32 +0000375 stored at a configurable location, or are given as a brief list
376 of problems. Returns 0 on success, 1 on ABI/API non-compliance,
377 and 2 if there is an error while running the script.
378 Note: must be run from Mbed TLS root."""
Darryl Green3da15042018-03-01 14:53:49 +0000379 )
380 )
381 parser.add_argument(
Darryl Greenf0f9f7f2019-03-08 11:30:04 +0000382 "-v", "--verbose", action="store_true",
383 help="set verbosity level",
384 )
385 parser.add_argument(
Darryl Green31321ca2018-04-16 12:02:29 +0100386 "-r", "--report-dir", type=str, default="reports",
Darryl Green3da15042018-03-01 14:53:49 +0000387 help="directory where reports are stored, default is reports",
388 )
389 parser.add_argument(
Darryl Green31321ca2018-04-16 12:02:29 +0100390 "-k", "--keep-all-reports", action="store_true",
Darryl Green3da15042018-03-01 14:53:49 +0000391 help="keep all reports, even if there are no compatibility issues",
392 )
393 parser.add_argument(
Darryl Green826e5af2019-03-01 09:54:44 +0000394 "-o", "--old-rev", type=str, help="revision for old version.",
395 required=True,
Darryl Green3da15042018-03-01 14:53:49 +0000396 )
397 parser.add_argument(
Darryl Green826e5af2019-03-01 09:54:44 +0000398 "-or", "--old-repo", type=str, help="repository for old version."
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000399 )
400 parser.add_argument(
Darryl Green826e5af2019-03-01 09:54:44 +0000401 "-oc", "--old-crypto-rev", type=str,
402 help="revision for old crypto submodule."
Darryl Green3da15042018-03-01 14:53:49 +0000403 )
Darryl Greend3cde6f2019-02-20 15:01:56 +0000404 parser.add_argument(
Darryl Green826e5af2019-03-01 09:54:44 +0000405 "-ocr", "--old-crypto-repo", type=str,
406 help="repository for old crypto submodule."
407 )
408 parser.add_argument(
409 "-n", "--new-rev", type=str, help="revision for new version",
410 required=True,
411 )
412 parser.add_argument(
413 "-nr", "--new-repo", type=str, help="repository for new version."
414 )
415 parser.add_argument(
416 "-nc", "--new-crypto-rev", type=str,
417 help="revision for new crypto version"
418 )
419 parser.add_argument(
420 "-ncr", "--new-crypto-repo", type=str,
421 help="repository for new crypto submodule."
Darryl Greend9ad9ec2019-02-25 11:35:05 +0000422 )
423 parser.add_argument(
Darryl Greend3cde6f2019-02-20 15:01:56 +0000424 "-s", "--skip-file", type=str,
Gilles Peskinecc026582019-07-04 19:00:31 +0200425 help=("path to file containing symbols and types to skip "
426 "(typically \"-s identifiers\" after running "
427 "\"tests/scripts/list-identifiers.sh --internal\")")
Darryl Greend3cde6f2019-02-20 15:01:56 +0000428 )
Darryl Green32e7a502019-02-21 13:09:26 +0000429 parser.add_argument(
430 "-b", "--brief", action="store_true",
431 help="output only the list of issues to stdout, instead of a full report",
432 )
Darryl Green3da15042018-03-01 14:53:49 +0000433 abi_args = parser.parse_args()
Darryl Green03625fe2019-04-11 15:50:41 +0100434 if os.path.isfile(abi_args.report_dir):
435 print("Error: {} is not a directory".format(abi_args.report_dir))
436 parser.exit()
Darryl Greenf1d272d2019-04-09 09:14:17 +0100437 old_version = SimpleNamespace(
438 version="old",
439 repository=abi_args.old_repo,
440 revision=abi_args.old_rev,
Gilles Peskine2b3f1342019-07-04 19:01:22 +0200441 commit=None,
Darryl Greenf1d272d2019-04-09 09:14:17 +0100442 crypto_repository=abi_args.old_crypto_repo,
443 crypto_revision=abi_args.old_crypto_rev,
444 abi_dumps={},
445 modules={}
Darryl Greenb7447e72019-04-05 17:06:17 +0100446 )
Darryl Greenf1d272d2019-04-09 09:14:17 +0100447 new_version = SimpleNamespace(
448 version="new",
449 repository=abi_args.new_repo,
450 revision=abi_args.new_rev,
Gilles Peskine2b3f1342019-07-04 19:01:22 +0200451 commit=None,
Darryl Greenf1d272d2019-04-09 09:14:17 +0100452 crypto_repository=abi_args.new_crypto_repo,
453 crypto_revision=abi_args.new_crypto_rev,
454 abi_dumps={},
455 modules={}
Darryl Greenb7447e72019-04-05 17:06:17 +0100456 )
Darryl Greenf1d272d2019-04-09 09:14:17 +0100457 configuration = SimpleNamespace(
458 verbose=abi_args.verbose,
459 report_dir=abi_args.report_dir,
460 keep_all_reports=abi_args.keep_all_reports,
461 brief=abi_args.brief,
462 skip_file=abi_args.skip_file
Darryl Green3da15042018-03-01 14:53:49 +0000463 )
Darryl Greenf1d272d2019-04-09 09:14:17 +0100464 abi_check = AbiChecker(old_version, new_version, configuration)
Darryl Green3da15042018-03-01 14:53:49 +0000465 return_code = abi_check.check_for_abi_changes()
466 sys.exit(return_code)
Darryl Green62a18e32019-04-18 14:59:51 +0100467 except Exception: # pylint: disable=broad-except
468 # Print the backtrace and exit explicitly so as to exit with
469 # status 2, not 1.
Darryl Greenc47ac262018-03-15 10:12:06 +0000470 traceback.print_exc()
Darryl Green3da15042018-03-01 14:53:49 +0000471 sys.exit(2)
472
473
474if __name__ == "__main__":
475 run_main()