blob: 9dec722325e3516983c0d14c4774413520a5ff18 [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
23
24# Following function code snippet was found on StackOverflow (with a change to lower
25# camel-case on the variable names):
26# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
27def find_executable(program):
28 def is_exe(fPath):
29 return os.path.isfile(fPath) and os.access(fPath, os.X_OK)
30
31 fPath, fName = os.path.split(program)
32 if fPath:
33 if is_exe(program):
34 return program
35 else:
36 for path in os.environ["PATH"].split(os.pathsep):
37 path = path.strip('"')
38 exe_file = os.path.join(path, program)
39 if is_exe(exe_file):
40 return exe_file
41
42 return None
Mark Lobodzinski0e393752016-05-04 09:19:54 -060043
Mark Youngc65d3252016-01-06 15:58:55 -070044def determine_year(version):
Mark Lobodzinski0e393752016-05-04 09:19:54 -060045 if version == 8:
46 return 2005
47 elif version == 9:
48 return 2008
49 elif version == 10:
50 return 2010
51 elif version == 11:
52 return 2012
53 elif version == 12:
54 return 2013
55 elif version == 14:
56 return 2015
57 else:
58 return 0000
59
Mark Youngc65d3252016-01-06 15:58:55 -070060# Determine if msbuild is in the path, then call it to determine the version and parse
61# it into a format we can use, which is "<version_num> <version_year>".
62if __name__ == '__main__':
Mark Lobodzinski0e393752016-05-04 09:19:54 -060063 exeName = 'msbuild.exe'
64 versionCall = exeName + ' /ver'
Mark Youngc65d3252016-01-06 15:58:55 -070065
Mark Lobodzinski0e393752016-05-04 09:19:54 -060066 # Determine if the executable exists in the path, this is critical.
67 #
68 foundExeName = find_executable(exeName)
Mark Youngc65d3252016-01-06 15:58:55 -070069
Mark Lobodzinski0e393752016-05-04 09:19:54 -060070 # If not found, return an invalid number but in the appropriate format so it will
71 # fail if the program above tries to use it.
72 if foundExeName == None:
73 print('00 0000')
74 print('Executable ' + exeName + ' not found in PATH!')
75 else:
76 sysCallOut = os.popen(versionCall).read()
Mark Younge7da8372016-01-07 12:43:07 -070077
Mark Lobodzinski0e393752016-05-04 09:19:54 -060078 version = None
79
80 # Split around any spaces first
81 spaceList = sysCallOut.split(' ')
82 for spaceString in spaceList:
83
84 # If we've already found it, bail.
85 if version != None:
86 break
87
88 # Now split around line feeds
89 lineList = spaceString.split('\n')
90 for curLine in lineList:
91
92 # If we've already found it, bail.
93 if version != None:
94 break
95
96 # We only want to continue if there's a period in the list
97 if '.' not in curLine:
98 continue
99
100 # Get the first element and determine if it is a number, if so, we've
101 # got our number.
102 splitAroundPeriod = curLine.split('.')
103 if splitAroundPeriod[0].isdigit():
104 version = int (splitAroundPeriod[0])
105 break
106
107 # Failsafe to return a number in the proper format, but one that will fail.
108 if version == None:
109 version = 00
110
111 # Determine the year associated with that version
112 year = determine_year(version)
113
114 # Output the string we need for Cmake to properly build for this version
115 print(str(version) + ' ' + str(year))