mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-06 12:40:02 +00:00
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>
This commit is contained in:
parent
15997bd389
commit
d9071e7d96
@ -113,6 +113,8 @@ from types import SimpleNamespace
|
|||||||
|
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
from mbedtls_dev import build_tree
|
||||||
|
|
||||||
|
|
||||||
class AbiChecker:
|
class AbiChecker:
|
||||||
"""API and ABI checker."""
|
"""API and ABI checker."""
|
||||||
@ -150,11 +152,6 @@ class AbiChecker:
|
|||||||
self.git_command = "git"
|
self.git_command = "git"
|
||||||
self.make_command = "make"
|
self.make_command = "make"
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def check_repo_path():
|
|
||||||
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
|
||||||
raise Exception("Must be run from Mbed TLS root")
|
|
||||||
|
|
||||||
def _setup_logger(self):
|
def _setup_logger(self):
|
||||||
self.log = logging.getLogger()
|
self.log = logging.getLogger()
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
@ -540,7 +537,7 @@ class AbiChecker:
|
|||||||
def check_for_abi_changes(self):
|
def check_for_abi_changes(self):
|
||||||
"""Generate a report of ABI differences
|
"""Generate a report of ABI differences
|
||||||
between self.old_rev and self.new_rev."""
|
between self.old_rev and self.new_rev."""
|
||||||
self.check_repo_path()
|
build_tree.check_repo_path()
|
||||||
if self.check_api or self.check_abi:
|
if self.check_api or self.check_abi:
|
||||||
self.check_abi_tools_are_installed()
|
self.check_abi_tools_are_installed()
|
||||||
self._get_abi_dump_for_ref(self.old_version)
|
self._get_abi_dump_for_ref(self.old_version)
|
||||||
|
@ -30,6 +30,9 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from mbedtls_dev import build_tree
|
||||||
|
|
||||||
|
|
||||||
class CodeSizeComparison:
|
class CodeSizeComparison:
|
||||||
"""Compare code size between two Git revisions."""
|
"""Compare code size between two Git revisions."""
|
||||||
|
|
||||||
@ -51,11 +54,6 @@ class CodeSizeComparison:
|
|||||||
self.git_command = "git"
|
self.git_command = "git"
|
||||||
self.make_command = "make"
|
self.make_command = "make"
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def check_repo_path():
|
|
||||||
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
|
||||||
raise Exception("Must be run from Mbed TLS root")
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_revision(revision):
|
def validate_revision(revision):
|
||||||
result = subprocess.check_output(["git", "rev-parse", "--verify",
|
result = subprocess.check_output(["git", "rev-parse", "--verify",
|
||||||
@ -172,7 +170,7 @@ class CodeSizeComparison:
|
|||||||
def get_comparision_results(self):
|
def get_comparision_results(self):
|
||||||
"""Compare size of library/*.o between self.old_rev and self.new_rev,
|
"""Compare size of library/*.o between self.old_rev and self.new_rev,
|
||||||
and generate the result file."""
|
and generate the result file."""
|
||||||
self.check_repo_path()
|
build_tree.check_repo_path()
|
||||||
self._get_code_size_for_rev(self.old_rev)
|
self._get_code_size_for_rev(self.old_rev)
|
||||||
self._get_code_size_for_rev(self.new_rev)
|
self._get_code_size_for_rev(self.new_rev)
|
||||||
return self.compare_code_size()
|
return self.compare_code_size()
|
||||||
|
@ -25,6 +25,13 @@ def looks_like_mbedtls_root(path: str) -> bool:
|
|||||||
return all(os.path.isdir(os.path.join(path, subdir))
|
return all(os.path.isdir(os.path.join(path, subdir))
|
||||||
for subdir in ['include', 'library', 'programs', 'tests'])
|
for subdir in ['include', 'library', 'programs', 'tests'])
|
||||||
|
|
||||||
|
def check_repo_path():
|
||||||
|
"""
|
||||||
|
Check that the current working directory is the project root, and throw
|
||||||
|
an exception if not.
|
||||||
|
"""
|
||||||
|
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
||||||
|
raise Exception("This script must be run from Mbed TLS root")
|
||||||
|
|
||||||
def chdir_to_root() -> None:
|
def chdir_to_root() -> None:
|
||||||
"""Detect the root of the Mbed TLS source tree and change to it.
|
"""Detect the root of the Mbed TLS source tree and change to it.
|
||||||
|
@ -34,6 +34,9 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
import scripts_path # pylint: disable=unused-import
|
||||||
|
from mbedtls_dev import build_tree
|
||||||
|
|
||||||
|
|
||||||
class FileIssueTracker:
|
class FileIssueTracker:
|
||||||
"""Base class for file-wide issue tracking.
|
"""Base class for file-wide issue tracking.
|
||||||
@ -338,7 +341,7 @@ class IntegrityChecker:
|
|||||||
"""Instantiate the sanity checker.
|
"""Instantiate the sanity checker.
|
||||||
Check files under the current directory.
|
Check files under the current directory.
|
||||||
Write a report of issues to log_file."""
|
Write a report of issues to log_file."""
|
||||||
self.check_repo_path()
|
build_tree.check_repo_path()
|
||||||
self.logger = None
|
self.logger = None
|
||||||
self.setup_logger(log_file)
|
self.setup_logger(log_file)
|
||||||
self.issues_to_check = [
|
self.issues_to_check = [
|
||||||
@ -353,11 +356,6 @@ class IntegrityChecker:
|
|||||||
MergeArtifactIssueTracker(),
|
MergeArtifactIssueTracker(),
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def check_repo_path():
|
|
||||||
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
|
||||||
raise Exception("Must be run from Mbed TLS root")
|
|
||||||
|
|
||||||
def setup_logger(self, log_file, level=logging.INFO):
|
def setup_logger(self, log_file, level=logging.INFO):
|
||||||
self.logger = logging.getLogger()
|
self.logger = logging.getLogger()
|
||||||
self.logger.setLevel(level)
|
self.logger.setLevel(level)
|
||||||
|
@ -56,6 +56,10 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import scripts_path # pylint: disable=unused-import
|
||||||
|
from mbedtls_dev import build_tree
|
||||||
|
|
||||||
|
|
||||||
# Naming patterns to check against. These are defined outside the NameCheck
|
# Naming patterns to check against. These are defined outside the NameCheck
|
||||||
# class for ease of modification.
|
# class for ease of modification.
|
||||||
PUBLIC_MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
|
PUBLIC_MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
|
||||||
@ -219,7 +223,7 @@ class CodeParser():
|
|||||||
"""
|
"""
|
||||||
def __init__(self, log):
|
def __init__(self, log):
|
||||||
self.log = log
|
self.log = log
|
||||||
self.check_repo_path()
|
build_tree.check_repo_path()
|
||||||
|
|
||||||
# Memo for storing "glob expression": set(filepaths)
|
# Memo for storing "glob expression": set(filepaths)
|
||||||
self.files = {}
|
self.files = {}
|
||||||
@ -228,15 +232,6 @@ class CodeParser():
|
|||||||
# Note that "*" can match directory separators in exclude lists.
|
# Note that "*" can match directory separators in exclude lists.
|
||||||
self.excluded_files = ["*/bn_mul", "*/compat-2.x.h"]
|
self.excluded_files = ["*/bn_mul", "*/compat-2.x.h"]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def check_repo_path():
|
|
||||||
"""
|
|
||||||
Check that the current working directory is the project root, and throw
|
|
||||||
an exception if not.
|
|
||||||
"""
|
|
||||||
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
|
||||||
raise Exception("This script must be run from Mbed TLS root")
|
|
||||||
|
|
||||||
def comprehensive_parse(self):
|
def comprehensive_parse(self):
|
||||||
"""
|
"""
|
||||||
Comprehensive ("default") function to call each parsing function and
|
Comprehensive ("default") function to call each parsing function and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user