summaryrefslogtreecommitdiffstats
path: root/src/pmdk/utils/check_sdk_version.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/pmdk/utils/check_sdk_version.py
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pmdk/utils/check_sdk_version.py')
-rwxr-xr-xsrc/pmdk/utils/check_sdk_version.py76
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()