| 1 |
#!python |
| 2 |
|
| 3 |
# Copyright (c) 2016 Ryan Prichard |
| 4 |
# |
| 5 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
# of this software and associated documentation files (the "Software"), to |
| 7 |
# deal in the Software without restriction, including without limitation the |
| 8 |
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 |
# sell copies of the Software, and to permit persons to whom the Software is |
| 10 |
# furnished to do so, subject to the following conditions: |
| 11 |
# |
| 12 |
# The above copyright notice and this permission notice shall be included in |
| 13 |
# all copies or substantial portions of the Software. |
| 14 |
# |
| 15 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 |
# IN THE SOFTWARE. |
| 22 |
|
| 23 |
# |
| 24 |
# Run with native CPython 2.7. |
| 25 |
# |
| 26 |
# This script looks for MSVC using a version-specific environment variable, |
| 27 |
# such as VS140COMNTOOLS for MSVC 2015. |
| 28 |
# |
| 29 |
|
| 30 |
import common_ship |
| 31 |
|
| 32 |
import argparse |
| 33 |
import os |
| 34 |
import shutil |
| 35 |
import subprocess |
| 36 |
import sys |
| 37 |
|
| 38 |
os.chdir(common_ship.topDir) |
| 39 |
ZIP_TOOL = common_ship.requireExe("7z.exe", [ |
| 40 |
"C:\\Program Files\\7-Zip\\7z.exe", |
| 41 |
"C:\\Program Files (x86)\\7-Zip\\7z.exe", |
| 42 |
]) |
| 43 |
|
| 44 |
MSVC_VERSION_TABLE = { |
| 45 |
"2015" : { |
| 46 |
"package_name" : "msvc2015", |
| 47 |
"gyp_version" : "2015", |
| 48 |
"common_tools_env" : "VS140COMNTOOLS", |
| 49 |
"xp_toolset" : "v140_xp", |
| 50 |
}, |
| 51 |
"2013" : { |
| 52 |
"package_name" : "msvc2013", |
| 53 |
"gyp_version" : "2013", |
| 54 |
"common_tools_env" : "VS120COMNTOOLS", |
| 55 |
"xp_toolset" : "v120_xp", |
| 56 |
}, |
| 57 |
} |
| 58 |
|
| 59 |
ARCH_TABLE = { |
| 60 |
"x64" : { |
| 61 |
"msvc_platform" : "x64", |
| 62 |
}, |
| 63 |
"ia32" : { |
| 64 |
"msvc_platform" : "Win32", |
| 65 |
}, |
| 66 |
} |
| 67 |
|
| 68 |
def readArguments(): |
| 69 |
parser = argparse.ArgumentParser() |
| 70 |
parser.add_argument("--msvc-version", default="2015") |
| 71 |
ret = parser.parse_args() |
| 72 |
if ret.msvc_version not in MSVC_VERSION_TABLE: |
| 73 |
sys.exit("Error: unrecognized version: " + ret.msvc_version + ". " + |
| 74 |
"Versions: " + " ".join(sorted(MSVC_VERSION_TABLE.keys()))) |
| 75 |
return ret |
| 76 |
|
| 77 |
ARGS = readArguments() |
| 78 |
|
| 79 |
def checkoutGyp(): |
| 80 |
if os.path.isdir("build-gyp"): |
| 81 |
return |
| 82 |
subprocess.check_call([ |
| 83 |
"git.exe", |
| 84 |
"clone", |
| 85 |
"https://chromium.googlesource.com/external/gyp", |
| 86 |
"build-gyp" |
| 87 |
]) |
| 88 |
|
| 89 |
def cleanMsvc(): |
| 90 |
common_ship.rmrf(""" |
| 91 |
src/Release src/.vs src/gen |
| 92 |
src/*.vcxproj src/*.vcxproj.filters src/*.sln src/*.sdf |
| 93 |
""".split()) |
| 94 |
|
| 95 |
def build(arch, packageDir, xp=False): |
| 96 |
archInfo = ARCH_TABLE[arch] |
| 97 |
versionInfo = MSVC_VERSION_TABLE[ARGS.msvc_version] |
| 98 |
|
| 99 |
devCmdPath = os.path.join(os.environ[versionInfo["common_tools_env"]], "VsDevCmd.bat") |
| 100 |
if not os.path.isfile(devCmdPath): |
| 101 |
sys.exit("Error: MSVC environment script missing: " + devCmdPath) |
| 102 |
|
| 103 |
newEnv = os.environ.copy() |
| 104 |
newEnv["PATH"] = os.path.dirname(sys.executable) + ";" + common_ship.defaultPathEnviron |
| 105 |
commandLine = ( |
| 106 |
'"' + devCmdPath + '" && ' |
| 107 |
" vcbuild.bat" + |
| 108 |
" --gyp-msvs-version " + versionInfo["gyp_version"] + |
| 109 |
" --msvc-platform " + archInfo["msvc_platform"] + |
| 110 |
" --commit-hash " + common_ship.commitHash |
| 111 |
) |
| 112 |
|
| 113 |
subprocess.check_call(commandLine, shell=True, env=newEnv) |
| 114 |
|
| 115 |
archPackageDir = os.path.join(packageDir, arch) |
| 116 |
if xp: |
| 117 |
archPackageDir += "_xp" |
| 118 |
|
| 119 |
common_ship.mkdir(archPackageDir + "/bin") |
| 120 |
common_ship.mkdir(archPackageDir + "/lib") |
| 121 |
|
| 122 |
binSrc = os.path.join(common_ship.topDir, "src/Release", archInfo["msvc_platform"]) |
| 123 |
|
| 124 |
shutil.copy(binSrc + "/winpty.dll", archPackageDir + "/bin") |
| 125 |
shutil.copy(binSrc + "/winpty-agent.exe", archPackageDir + "/bin") |
| 126 |
shutil.copy(binSrc + "/winpty-debugserver.exe", archPackageDir + "/bin") |
| 127 |
shutil.copy(binSrc + "/winpty.lib", archPackageDir + "/lib") |
| 128 |
|
| 129 |
def buildPackage(): |
| 130 |
versionInfo = MSVC_VERSION_TABLE[ARGS.msvc_version] |
| 131 |
|
| 132 |
packageName = "winpty-%s-%s" % ( |
| 133 |
common_ship.winptyVersion, |
| 134 |
versionInfo["package_name"], |
| 135 |
) |
| 136 |
|
| 137 |
packageRoot = os.path.join(common_ship.topDir, "ship/packages") |
| 138 |
packageDir = os.path.join(packageRoot, packageName) |
| 139 |
packageFile = packageDir + ".zip" |
| 140 |
|
| 141 |
common_ship.rmrf([packageDir]) |
| 142 |
common_ship.rmrf([packageFile]) |
| 143 |
common_ship.mkdir(packageDir) |
| 144 |
|
| 145 |
checkoutGyp() |
| 146 |
cleanMsvc() |
| 147 |
build("ia32", packageDir, True) |
| 148 |
build("x64", packageDir, True) |
| 149 |
cleanMsvc() |
| 150 |
build("ia32", packageDir) |
| 151 |
build("x64", packageDir) |
| 152 |
|
| 153 |
topDir = common_ship.topDir |
| 154 |
|
| 155 |
common_ship.mkdir(packageDir + "/include") |
| 156 |
shutil.copy(topDir + "/src/include/winpty.h", packageDir + "/include") |
| 157 |
shutil.copy(topDir + "/src/include/winpty_constants.h", packageDir + "/include") |
| 158 |
shutil.copy(topDir + "/LICENSE", packageDir) |
| 159 |
shutil.copy(topDir + "/README.md", packageDir) |
| 160 |
shutil.copy(topDir + "/RELEASES.md", packageDir) |
| 161 |
|
| 162 |
subprocess.check_call([ZIP_TOOL, "a", packageFile, "."], cwd=packageDir) |
| 163 |
|
| 164 |
if __name__ == "__main__": |
| 165 |
buildPackage() |