blob: 76e6815449fe7455011b650f678f69b7727cadf1 [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.
6# Copyright (c) 2016 Google Inc.
Mark Youngc65d3252016-01-06 15:58:55 -07007#
Karl Schultz8e42f402016-02-02 19:32:33 -07008# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and/or associated documentation files (the "Materials"), to
10# deal in the Materials without restriction, including without limitation the
11# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12# sell copies of the Materials, and to permit persons to whom the Materials
13# are furnished to do so, subject to the following conditions:
Mark Youngc65d3252016-01-06 15:58:55 -070014#
Karl Schultz8e42f402016-02-02 19:32:33 -070015# The above copyright notice(s) and this permission notice shall be included
16# in all copies or substantial portions of the Materials.
Mark Youngc65d3252016-01-06 15:58:55 -070017#
Karl Schultz8e42f402016-02-02 19:32:33 -070018# The Materials are Confidential Information as defined by the Khronos
19# Membership Agreement until designated non-confidential by Khronos, at which
20# point this condition clause shall be removed.
21#
22# THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Mark Youngc65d3252016-01-06 15:58:55 -070023# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Karl Schultz8e42f402016-02-02 19:32:33 -070024# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25#
26# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
29# USE OR OTHER DEALINGS IN THE MATERIALS
Mark Youngc65d3252016-01-06 15:58:55 -070030#
31# Author: Mark Young <marky@lunarg.com>
32
33import sys
34import os
35
36# Following function code snippet was found on StackOverflow (with a change to lower
37# camel-case on the variable names):
38# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
39def find_executable(program):
40 def is_exe(fPath):
41 return os.path.isfile(fPath) and os.access(fPath, os.X_OK)
42
43 fPath, fName = os.path.split(program)
44 if fPath:
45 if is_exe(program):
46 return program
47 else:
48 for path in os.environ["PATH"].split(os.pathsep):
49 path = path.strip('"')
50 exe_file = os.path.join(path, program)
51 if is_exe(exe_file):
52 return exe_file
53
54 return None
55
56def determine_year(version):
57 if version == 8:
58 return 2005
59 elif version == 9:
60 return 2008
61 elif version == 10:
62 return 2010
63 elif version == 11:
64 return 2012
65 elif version == 12:
66 return 2013
67 elif version == 14:
68 return 2015
69 else:
70 return 0000
71
72# Determine if msbuild is in the path, then call it to determine the version and parse
73# it into a format we can use, which is "<version_num> <version_year>".
74if __name__ == '__main__':
75 exeName = 'msbuild.exe'
76 versionCall = exeName + ' /ver'
77
78 # Determine if the executable exists in the path, this is critical.
79 #
80 foundExeName = find_executable(exeName)
81
82 # If not found, return an invalid number but in the appropriate format so it will
83 # fail if the program above tries to use it.
84 if foundExeName == None:
Mark Young93ecb1d2016-01-13 13:47:16 -070085 print('00 0000')
Mark Youngc65d3252016-01-06 15:58:55 -070086 print('Executable ' + exeName + ' not found in PATH!')
87 else:
88 sysCallOut = os.popen(versionCall).read()
89
90 version = None
91
92 # Split around any spaces first
93 spaceList = sysCallOut.split(' ')
94 for spaceString in spaceList:
95
96 # If we've already found it, bail.
97 if version != None:
98 break
99
100 # Now split around line feeds
101 lineList = spaceString.split('\n')
102 for curLine in lineList:
103
104 # If we've already found it, bail.
105 if version != None:
106 break
107
108 # We only want to continue if there's a period in the list
109 if '.' not in curLine:
110 continue
111
112 # Get the first element and determine if it is a number, if so, we've
113 # got our number.
114 splitAroundPeriod = curLine.split('.')
115 if splitAroundPeriod[0].isdigit():
116 version = int (splitAroundPeriod[0])
117 break
118
119 # Failsafe to return a number in the proper format, but one that will fail.
120 if version == None:
121 version = 00
122
123 # Determine the year associated with that version
124 year = determine_year(version)
Mark Younge7da8372016-01-07 12:43:07 -0700125
Mark Youngc65d3252016-01-06 15:58:55 -0700126 # Output the string we need for Cmake to properly build for this version
Mark Young93ecb1d2016-01-13 13:47:16 -0700127 print(str(version) + ' ' + str(year))