Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Karl Schultz | 8e42f40 | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 3 | # Copyright (c) 2016 The Khronos Group Inc. |
| 4 | # Copyright (c) 2016 Valve Corporation |
| 5 | # Copyright (c) 2016 LunarG, Inc. |
Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 6 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 7 | # 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 Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 10 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 12 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 13 | # 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 Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 18 | # |
| 19 | # Author: Mark Young <marky@lunarg.com> |
| 20 | |
| 21 | import sys |
| 22 | import os |
saschawillems | 7eed14f | 2017-12-29 19:31:21 +0100 | [diff] [blame] | 23 | import subprocess |
Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 24 | |
| 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 |
| 28 | def 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 Lobodzinski | 0e39375 | 2016-05-04 09:19:54 -0600 | [diff] [blame] | 44 | |
Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 45 | def determine_year(version): |
Mark Lobodzinski | 0e39375 | 2016-05-04 09:19:54 -0600 | [diff] [blame] | 46 | 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 Schultz | cf0d518 | 2017-02-08 17:27:02 -0700 | [diff] [blame] | 58 | elif version == 15: |
| 59 | return 2017 |
Mark Lobodzinski | 0e39375 | 2016-05-04 09:19:54 -0600 | [diff] [blame] | 60 | else: |
| 61 | return 0000 |
| 62 | |
Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 63 | # 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>". |
| 65 | if __name__ == '__main__': |
Mark Lobodzinski | 0e39375 | 2016-05-04 09:19:54 -0600 | [diff] [blame] | 66 | exeName = 'msbuild.exe' |
saschawillems | 7eed14f | 2017-12-29 19:31:21 +0100 | [diff] [blame] | 67 | arguments = '/ver' |
Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 68 | |
Mark Lobodzinski | 0e39375 | 2016-05-04 09:19:54 -0600 | [diff] [blame] | 69 | # Determine if the executable exists in the path, this is critical. |
| 70 | # |
| 71 | foundExeName = find_executable(exeName) |
Mark Young | c65d325 | 2016-01-06 15:58:55 -0700 | [diff] [blame] | 72 | |
Mark Lobodzinski | 0e39375 | 2016-05-04 09:19:54 -0600 | [diff] [blame] | 73 | # 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: |
saschawillems | 7eed14f | 2017-12-29 19:31:21 +0100 | [diff] [blame] | 79 | proc = subprocess.Popen([exeName, arguments], stdout=subprocess.PIPE) |
| 80 | sysCallOut = proc.stdout.readline().decode('iso-8859-1').rstrip() |
Mark Young | e7da837 | 2016-01-07 12:43:07 -0700 | [diff] [blame] | 81 | |
Mark Lobodzinski | 0e39375 | 2016-05-04 09:19:54 -0600 | [diff] [blame] | 82 | 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)) |