Skip to content

Commit 7ff4766

Browse files
Unify check_repo_path
We had 4 identical copies of the check_repo_path function. Replace them by a single copy in the build_tree module where it naturally belongs. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
1 parent 239765a commit 7ff4766

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

scripts/abi_check.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113

114114
import xml.etree.ElementTree as ET
115115

116+
from mbedtls_dev import build_tree
117+
116118

117119
class AbiChecker:
118120
"""API and ABI checker."""
@@ -150,11 +152,6 @@ def __init__(self, old_version, new_version, configuration):
150152
self.git_command = "git"
151153
self.make_command = "make"
152154

153-
@staticmethod
154-
def check_repo_path():
155-
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
156-
raise Exception("Must be run from Mbed TLS root")
157-
158155
def _setup_logger(self):
159156
self.log = logging.getLogger()
160157
if self.verbose:
@@ -540,7 +537,7 @@ def get_abi_compatibility_report(self):
540537
def check_for_abi_changes(self):
541538
"""Generate a report of ABI differences
542539
between self.old_rev and self.new_rev."""
543-
self.check_repo_path()
540+
build_tree.check_repo_path()
544541
if self.check_api or self.check_abi:
545542
self.check_abi_tools_are_installed()
546543
self._get_abi_dump_for_ref(self.old_version)

scripts/mbedtls_dev/build_tree.py

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ def looks_like_mbedtls_root(path: str) -> bool:
2525
return all(os.path.isdir(os.path.join(path, subdir))
2626
for subdir in ['include', 'library', 'programs', 'tests'])
2727

28+
def check_repo_path():
29+
"""
30+
Check that the current working directory is the project root, and throw
31+
an exception if not.
32+
"""
33+
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
34+
raise Exception("This script must be run from Mbed TLS root")
2835

2936
def chdir_to_root() -> None:
3037
"""Detect the root of the Mbed TLS source tree and change to it.

tests/scripts/check_files.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
except ImportError:
3535
pass
3636

37+
import scripts_path # pylint: disable=unused-import
38+
from mbedtls_dev import build_tree
39+
3740

3841
class FileIssueTracker:
3942
"""Base class for file-wide issue tracking.
@@ -338,7 +341,7 @@ def __init__(self, log_file):
338341
"""Instantiate the sanity checker.
339342
Check files under the current directory.
340343
Write a report of issues to log_file."""
341-
self.check_repo_path()
344+
build_tree.check_repo_path()
342345
self.logger = None
343346
self.setup_logger(log_file)
344347
self.issues_to_check = [
@@ -353,11 +356,6 @@ def __init__(self, log_file):
353356
MergeArtifactIssueTracker(),
354357
]
355358

356-
@staticmethod
357-
def check_repo_path():
358-
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
359-
raise Exception("Must be run from Mbed TLS root")
360-
361359
def setup_logger(self, log_file, level=logging.INFO):
362360
self.logger = logging.getLogger()
363361
self.logger.setLevel(level)

tests/scripts/check_names.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
import subprocess
5757
import logging
5858

59+
import scripts_path # pylint: disable=unused-import
60+
from mbedtls_dev import build_tree
61+
62+
5963
# Naming patterns to check against. These are defined outside the NameCheck
6064
# class for ease of modification.
6165
MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
@@ -218,7 +222,7 @@ class CodeParser():
218222
"""
219223
def __init__(self, log):
220224
self.log = log
221-
self.check_repo_path()
225+
build_tree.check_repo_path()
222226

223227
# Memo for storing "glob expression": set(filepaths)
224228
self.files = {}
@@ -227,15 +231,6 @@ def __init__(self, log):
227231
# Note that "*" can match directory separators in exclude lists.
228232
self.excluded_files = ["*/bn_mul", "*/compat-1.3.h"]
229233

230-
@staticmethod
231-
def check_repo_path():
232-
"""
233-
Check that the current working directory is the project root, and throw
234-
an exception if not.
235-
"""
236-
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
237-
raise Exception("This script must be run from Mbed TLS root")
238-
239234
def comprehensive_parse(self):
240235
"""
241236
Comprehensive ("default") function to call each parsing function and

0 commit comments

Comments
 (0)