blob: 7982bf7173e22dd237a1752eec1a4f75445dc6af [file] [log] [blame]
Mark Youngc65d3252016-01-06 15:58:55 -07001#!/usr/bin/env python3
2#
Karl Schultz8e42f402016-02-02 19:32:33 -07003# Copyright (c) 2016 The Khronos Group Inc.
4# Copyright (c) 2016 Valve Corporation
5# Copyright (c) 2016 LunarG, Inc.
Mark Youngc65d3252016-01-06 15:58:55 -07006#
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
Mark Youngc65d3252016-01-06 15:58:55 -070010#
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011# http://www.apache.org/licenses/LICENSE-2.0
Mark Youngc65d3252016-01-06 15:58:55 -070012#
Jon Ashburn3ebf1252016-04-19 11:30:31 -060013# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
Mark Youngc65d3252016-01-06 15:58:55 -070018#
19# Author: Mark Young <marky@lunarg.com>
20
21import sys
22import os
saschawillems7eed14f2017-12-29 19:31:21 +010023import subprocess
Mark Youngc65d3252016-01-06 15:58:55 -070024
25# Following function code snippet was found on StackOverflow (with a change to lower
26# camel-case on the variable names):
27# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
28def find_executable(program):
29 def is_exe(fPath):
30 return os.path.isfile(fPath) and os.access(fPath, os.X_OK)
31
32 fPath, fName = os.path.split(program)
33 if fPath:
34 if is_exe(program):
35 return program
36 else:
37 for path in os.environ["PATH"].split(os.pathsep):
38 path = path.strip('"')
39 exe_file = os.path.join(path, program)
40 if is_exe(exe_file):
41 return exe_file
42
43 return None
Mark Lobodzinski0e393752016-05-04 09:19:54 -060044
Mark Youngc65d3252016-01-06 15:58:55 -070045def determine_year(version):
Mark Lobodzinski0e393752016-05-04 09:19:54 -060046 if version == 8:
47 return 2005
48 elif version == 9:
49 return 2008
50 elif version == 10:
51 return 2010
52 elif version == 11:
53 return 2012
54 elif version == 12:
55 return 2013
56 elif version == 14:
57 return 2015
Karl Schultzcf0d5182017-02-08 17:27:02 -070058 elif version == 15:
59 return 2017
Mark Lobodzinski0e393752016-05-04 09:19:54 -060060 else:
61 return 0000
62
Mark Youngc65d3252016-01-06 15:58:55 -070063# Determine if msbuild is in the path, then call it to determine the version and parse
64# it into a format we can use, which is "<version_num> <version_year>".
65if __name__ == '__main__':
Mark Lobodzinski0e393752016-05-04 09:19:54 -060066 exeName = 'msbuild.exe'
saschawillems7eed14f2017-12-29 19:31:21 +010067 arguments = '/ver'
Mark Youngc65d3252016-01-06 15:58:55 -070068
Mark Lobodzinski0e393752016-05-04 09:19:54 -060069 # Determine if the executable exists in the path, this is critical.
70 #
71 foundExeName = find_executable(exeName)
Mark Youngc65d3252016-01-06 15:58:55 -070072
Mark Lobodzinski0e393752016-05-04 09:19:54 -060073 # If not found, return an invalid number but in the appropriate format so it will
74 # fail if the program above tries to use it.
75 if foundExeName == None:
76 print('00 0000')
77 print('Executable ' + exeName + ' not found in PATH!')
78 else:
saschawillems7eed14f2017-12-29 19:31:21 +010079 proc = subprocess.Popen([exeName, arguments], stdout=subprocess.PIPE)
80 sysCallOut = proc.stdout.readline().decode('iso-8859-1').rstrip()
Mark Younge7da8372016-01-07 12:43:07 -070081
Mark Lobodzinski0e393752016-05-04 09:19:54 -060082 version = None
83
84 # Split around any spaces first
85 spaceList = sysCallOut.split(' ')
86 for spaceString in spaceList:
87
88 # If we've already found it, bail.
89 if version != None:
90 break
91
92 # Now split around line feeds
93 lineList = spaceString.split('\n')
94 for curLine in lineList:
95
96 # If we've already found it, bail.
97 if version != None:
98 break
99
100 # We only want to continue if there's a period in the list
101 if '.' not in curLine:
102 continue
103
104 # Get the first element and determine if it is a number, if so, we've
105 # got our number.
106 splitAroundPeriod = curLine.split('.')
107 if splitAroundPeriod[0].isdigit():
108 version = int (splitAroundPeriod[0])
109 break
110
111 # Failsafe to return a number in the proper format, but one that will fail.
112 if version == None:
113 version = 00
114
115 # Determine the year associated with that version
116 year = determine_year(version)
117
118 # Output the string we need for Cmake to properly build for this version
119 print(str(version) + ' ' + str(year))