3 # Copyright (c) 2016 Ryan Prichard
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:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
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
24 # Run with native CPython 2.7.
26 # This script looks for MSVC using a version-specific environment variable,
27 # such as VS140COMNTOOLS for MSVC 2015.
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",
44 MSVC_VERSION_TABLE = {
46 "package_name" : "msvc2015",
47 "gyp_version" : "2015",
48 "common_tools_env" : "VS140COMNTOOLS",
49 "xp_toolset" : "v140_xp",
52 "package_name" : "msvc2013",
53 "gyp_version" : "2013",
54 "common_tools_env" : "VS120COMNTOOLS",
55 "xp_toolset" : "v120_xp",
61 "msvc_platform" : "x64",
64 "msvc_platform" : "Win32",
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())))
77 ARGS = readArguments()
80 if os.path.isdir("build-gyp"):
82 subprocess.check_call([
85 "https://chromium.googlesource.com/external/gyp",
91 src/Release src/.vs src/gen
92 src/*.vcxproj src/*.vcxproj.filters src/*.sln src/*.sdf
95 def build(arch, packageDir, xp=False):
96 archInfo = ARCH_TABLE[arch]
97 versionInfo = MSVC_VERSION_TABLE[ARGS.msvc_version]
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)
103 newEnv = os.environ.copy()
104 newEnv["PATH"] = os.path.dirname(sys.executable) + ";" + common_ship.defaultPathEnviron
106 '"' + devCmdPath + '" && '
108 " --gyp-msvs-version " + versionInfo["gyp_version"] +
109 " --msvc-platform " + archInfo["msvc_platform"] +
110 " --commit-hash " + common_ship.commitHash
113 subprocess.check_call(commandLine, shell=True, env=newEnv)
115 archPackageDir = os.path.join(packageDir, arch)
117 archPackageDir += "_xp"
119 common_ship.mkdir(archPackageDir + "/bin")
120 common_ship.mkdir(archPackageDir + "/lib")
122 binSrc = os.path.join(common_ship.topDir, "src/Release", archInfo["msvc_platform"])
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")
130 versionInfo = MSVC_VERSION_TABLE[ARGS.msvc_version]
132 packageName = "winpty-%s-%s" % (
133 common_ship.winptyVersion,
134 versionInfo["package_name"],
137 packageRoot = os.path.join(common_ship.topDir, "ship/packages")
138 packageDir = os.path.join(packageRoot, packageName)
139 packageFile = packageDir + ".zip"
141 common_ship.rmrf([packageDir])
142 common_ship.rmrf([packageFile])
143 common_ship.mkdir(packageDir)
147 build("ia32", packageDir, True)
148 build("x64", packageDir, True)
150 build("ia32", packageDir)
151 build("x64", packageDir)
153 topDir = common_ship.topDir
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)
162 subprocess.check_call([ZIP_TOOL, "a", packageFile, "."], cwd=packageDir)
164 if __name__ == "__main__":