|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import time |
| 4 | +import logging |
| 5 | +import subprocess |
| 6 | + |
| 7 | +# Prevent compiling imported .py into .pyc |
| 8 | +sys.dont_write_bytecode = True |
| 9 | + |
| 10 | +import utils |
| 11 | +import build_tools_win |
| 12 | +import build_data_win |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +############################################################################# |
| 17 | +# Arguments: # |
| 18 | +#---------------------------------------------------------------------------# |
| 19 | +# 'rebuild' to force rebuilding the solution # |
| 20 | +# 'release' to build on the Release configuration (default) # |
| 21 | +# 'profile' to build on the Profile configuration # |
| 22 | +# 'win32' to build for 32 bit architecture # |
| 23 | +# 'x64' to build for 64 bit architecture (default) # |
| 24 | +# 'vs20XX' to build against Visual Studio 20XX toolset (default: vs2010) # |
| 25 | +############################################################################# |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +def Run(): |
| 30 | + ################# |
| 31 | + # Configuration # |
| 32 | + ################# |
| 33 | + |
| 34 | + # Name of .sln file for the current project |
| 35 | + projectName = "GITechDemo" |
| 36 | + |
| 37 | + defaultForceRebuild = False |
| 38 | + defaultBuildConfiguration = "Release" |
| 39 | + defaultArchitecture = "x64" |
| 40 | + defaultVSBuildTools = "VS100COMNTOOLS" |
| 41 | + defaultPlatformToolset = "v100" |
| 42 | + |
| 43 | + ################# |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + ######## |
| 48 | + # Main # |
| 49 | + ######## |
| 50 | + |
| 51 | + #os.system('reg query "HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7"') |
| 52 | + #os.system('reg delete "HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v "12.0"') |
| 53 | + #os.system("reg add \"HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7\" /v \"12.0\" /t REG_SZ /d \"C:\Program Files (x86)\Microsoft Visual Studio 12.0\\\\\"") |
| 54 | + |
| 55 | + # Start timer |
| 56 | + start = time.clock() |
| 57 | + |
| 58 | + # Process command arguments |
| 59 | + for opt in sys.argv: |
| 60 | + if(opt.lower() == "rebuild"): |
| 61 | + defaultForceRebuild = True |
| 62 | + if(opt.lower() == "release"): |
| 63 | + defaultBuildConfiguration = "Release" |
| 64 | + if(opt.lower() == "profile"): |
| 65 | + defaultBuildConfiguration = "Profile" |
| 66 | + if(opt.lower() == "x64"): |
| 67 | + defaultArchitecture = "x64" |
| 68 | + if(opt.lower() == "win32"): |
| 69 | + defaultArchitecture = "Win32" |
| 70 | + #if(opt.lower() == "vs2005"): |
| 71 | + # defaultVSBuildTools = "VS80COMNTOOLS" |
| 72 | + # defaultPlatformToolset = "vs80" |
| 73 | + #if(opt.lower() == "vs2008"): |
| 74 | + # defaultVSBuildTools = "VS90COMNTOOLS" |
| 75 | + # defaultPlatformToolset = "vs90" |
| 76 | + if(opt.lower() == "vs2010"): |
| 77 | + defaultVSBuildTools = "VS100COMNTOOLS" |
| 78 | + defaultPlatformToolset = "vs100" |
| 79 | + if(opt.lower() == "vs2012"): |
| 80 | + defaultVSBuildTools = "VS110COMNTOOLS" |
| 81 | + defaultPlatformToolset = "vs110" |
| 82 | + if(opt.lower() == "vs2013"): |
| 83 | + defaultVSBuildTools = "VS120COMNTOOLS" |
| 84 | + defaultPlatformToolset = "vs120" |
| 85 | + if(opt.lower() == "vs2015"): |
| 86 | + defaultVSBuildTools = "VS140COMNTOOLS" |
| 87 | + defaultPlatformToolset = "vs140" |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + # Setup build tools |
| 92 | + envSetupBat = "VsDevCmd.bat" |
| 93 | + if(os.getenv(defaultVSBuildTools)): |
| 94 | + pathToTools = os.getenv(defaultVSBuildTools) |
| 95 | + if( |
| 96 | + defaultVSBuildTools == "VS100COMNTOOLS" or |
| 97 | + defaultVSBuildTools == "VS90COMNTOOLS" or |
| 98 | + defaultVSBuildTools == "VS80COMNTOOLS" |
| 99 | + ): |
| 100 | + envSetupBat = "vsvars32.bat" |
| 101 | + elif(os.getenv("VS140COMNTOOLS")): # Visual Studio 2015 |
| 102 | + pathToTools = os.getenv("VS140COMNTOOLS") |
| 103 | + defaultPlatformToolset = "vs140" |
| 104 | + elif(os.getenv("VS120COMNTOOLS")): # Visual Studio 2013 |
| 105 | + pathToTools = os.getenv("VS120COMNTOOLS") |
| 106 | + defaultPlatformToolset = "vs120" |
| 107 | + elif(os.getenv("VS110COMNTOOLS")): # Visual Studio 2012 |
| 108 | + pathToTools = os.getenv("VS110COMNTOOLS") |
| 109 | + defaultPlatformToolset = "vs110" |
| 110 | + elif(os.getenv("VS100COMNTOOLS")): # Visual Studio 2010 |
| 111 | + pathToTools = os.getenv("VS100COMNTOOLS") |
| 112 | + defaultPlatformToolset = "vs100" |
| 113 | + envSetupBat = "vsvars32.bat" |
| 114 | + #elif(os.getenv("VS90COMNTOOLS")): # Visual Studio 2008 |
| 115 | + # pathToTools = os.getenv("VS90COMNTOOLS") |
| 116 | + # defaultPlatformToolset = "vs90" |
| 117 | + # envSetupBat = "vsvars32.bat" |
| 118 | + #elif(os.getenv("VS80COMNTOOLS")): # Visual Studio 2005 |
| 119 | + # pathToTools = os.getenv("VS80COMNTOOLS") |
| 120 | + # defaultPlatformToolset = "vs80" |
| 121 | + # envSetupBat = "vsvars32.bat" |
| 122 | + else: |
| 123 | + logging.error("No compatible version of Visual Studio found!") |
| 124 | + exit() |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + # Compile code (tools too, if required) |
| 129 | + build_tools_win.Run() |
| 130 | + logging.info("") |
| 131 | + |
| 132 | + logging.info("Starting project build process...") |
| 133 | + logging.info("Force rebuild: " + str(defaultForceRebuild)) |
| 134 | + logging.info("Build configuration: " + defaultBuildConfiguration) |
| 135 | + logging.info("Architecture: " + defaultArchitecture) |
| 136 | + logging.info("Platform toolset: " + defaultPlatformToolset) |
| 137 | + logging.info("") |
| 138 | + |
| 139 | + startProjectBuild = time.clock() |
| 140 | + if utils.BuildSLN(projectName, pathToTools, defaultPlatformToolset, envSetupBat, defaultArchitecture, defaultBuildConfiguration, defaultForceRebuild) != 0: |
| 141 | + logging.error("Could not complete project build process") |
| 142 | + exit() |
| 143 | + else: |
| 144 | + logging.info( \ |
| 145 | + "Done building " + projectName + \ |
| 146 | + " (" + defaultBuildConfiguration + "|" + defaultArchitecture + ") in " + \ |
| 147 | + str(time.clock() - startProjectBuild) + " seconds.") |
| 148 | + logging.info("") |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | + # Compile data |
| 153 | + build_data_win.Run() |
| 154 | + logging.info("") |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + # Copy and organize build files |
| 159 | + logging.info("Configuring build:") |
| 160 | + |
| 161 | + # Create directory structure |
| 162 | + logging.info("Creating directory structure...") |
| 163 | + rootBuildDir = "Windows/" + projectName |
| 164 | + utils.MakeDir(rootBuildDir + "/bin/" + |
| 165 | + ("" if (defaultBuildConfiguration == "Release") else (defaultBuildConfiguration + "/")) + |
| 166 | + defaultArchitecture) |
| 167 | + utils.MakeDir(rootBuildDir + "/data") |
| 168 | + |
| 169 | + # Copy binaries |
| 170 | + logging.info("Copying binaries...") |
| 171 | + pathToBinaries = [ |
| 172 | + "../Bin/" + defaultArchitecture + "/" + defaultBuildConfiguration + "/" + projectName + "/", |
| 173 | + rootBuildDir + "/bin/" + |
| 174 | + ("" if (defaultBuildConfiguration == "Release") else (defaultBuildConfiguration + "/")) + |
| 175 | + defaultArchitecture |
| 176 | + ] |
| 177 | + utils.CopyFiles(pathToBinaries[0], pathToBinaries[1], "*.exe") |
| 178 | + utils.CopyFiles(pathToBinaries[0], pathToBinaries[1], "*.dll") |
| 179 | + |
| 180 | + # Copy data |
| 181 | + logging.info("Copying data...") |
| 182 | + utils.CopyTree("../Data/", rootBuildDir + "/data") |
| 183 | + |
| 184 | + # Create batch file |
| 185 | + logging.info("Creating batch file...") |
| 186 | + startBat = open( |
| 187 | + rootBuildDir + "/run_" + |
| 188 | + ("" if (defaultBuildConfiguration == "Release") else (defaultBuildConfiguration.lower() + "_")) + |
| 189 | + defaultArchitecture.lower() + ".bat", "w" |
| 190 | + ) |
| 191 | + |
| 192 | + startBat.write("\ |
| 193 | + @echo off\n\ |
| 194 | + :A\n\ |
| 195 | + cls\n\ |
| 196 | + cd %~dp0/data\n\ |
| 197 | + start %1../bin/" + |
| 198 | + ("" if (defaultBuildConfiguration == "Release") else (defaultBuildConfiguration + "/")) + |
| 199 | + defaultArchitecture + "/" + |
| 200 | + projectName + ".exe\n\ |
| 201 | + exit" |
| 202 | + ) |
| 203 | + startBat.close() |
| 204 | + |
| 205 | + logging.info("") |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + # Done! Print some info. |
| 210 | + logging.info( |
| 211 | + "Done building project " + projectName + |
| 212 | + " (" + defaultBuildConfiguration + "|" + defaultArchitecture + ") in " + |
| 213 | + str(time.clock() - start) + " seconds." |
| 214 | + ) |
| 215 | + |
| 216 | + return 0 |
| 217 | + |
| 218 | +######## |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | +############## |
| 223 | +# Run script # |
| 224 | +############## |
| 225 | + |
| 226 | +if __name__ == "__main__": |
| 227 | + utils.SetupLogging("ProjectBuild") |
| 228 | + Run() |
0 commit comments