diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/pmdk/utils/check_sdk_version.py | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pmdk/utils/check_sdk_version.py')
-rwxr-xr-x | src/pmdk/utils/check_sdk_version.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/pmdk/utils/check_sdk_version.py b/src/pmdk/utils/check_sdk_version.py new file mode 100755 index 000000000..7dc134f01 --- /dev/null +++ b/src/pmdk/utils/check_sdk_version.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2019-2020, Intel Corporation + +import argparse +import os +from subprocess import check_output, CalledProcessError +import sys +import shlex +from xml.dom import minidom +from xml.parsers.expat import ExpatError + +VALID_SDK_VERSION = '10.0.17134.0' + + +def get_vcxproj_files(root_dir, ignored): + """Get a list ".vcxproj" files under PMDK directory.""" + to_format = [] + command = 'git ls-files *.vcxproj' + try: + output = check_output(shlex.split(command), + cwd=root_dir).decode("UTF-8") + except CalledProcessError as e: + sys.exit('Error: "' + command + '" failed with returncode: ' + + str(e.returncode)) + + for line in output.splitlines(): + if not line: + continue + file_path = os.path.join(root_dir, line) + if os.path.isfile(file_path): + to_format.append(file_path) + + return to_format + + +def get_sdk_version(file): + """ + Get Windows SDK version from modified/new files from the current + pull request. + """ + tag = 'WindowsTargetPlatformVersion' + try: + xml_file = minidom.parse(file) + except ExpatError as e: + sys.exit('Error: "' + file + '" is incorrect.\n' + str(e)) + version_list = xml_file.getElementsByTagName(tag) + if len(version_list) != 1: + sys.exit('Error: the amount of tags "' + tag + '" is other than 1.') + version = version_list[0].firstChild.data + + return version + + +def main(): + parser = argparse.ArgumentParser(prog='check_sdk_version.py', + description='The script checks Windows SDK version in .vcxproj files.') + parser.add_argument('-d', '--directory', + help='Directory of PMDK tree.', required=True) + args = parser.parse_args() + current_directory = args.directory + if not os.path.isdir(current_directory): + sys.exit('"' + current_directory + '" is not a directory.') + + files = get_vcxproj_files(current_directory, '') + if not files: + sys.exit(0) + for file in files: + sdk_version = get_sdk_version(file) + if sdk_version != VALID_SDK_VERSION: + sys.exit('Wrong Windows SDK version: ' + sdk_version + + ' in file: "' + file + '". Please use: ' + VALID_SDK_VERSION) + + +if __name__ == '__main__': + main() |