blob: 7dc134f013b628feb65d5d7f11a86879151b29eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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()
|