Chromium Code Reviews| Index: tools/supalink/install_supalink.py |
| diff --git a/tools/supalink/install_supalink.py b/tools/supalink/install_supalink.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..621dea6bac77a1a4798521ba21361061b4765f89 |
| --- /dev/null |
| +++ b/tools/supalink/install_supalink.py |
| @@ -0,0 +1,82 @@ |
| +# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import os |
| +import shutil |
| +import subprocess |
| + |
| +VSVARS_PATH = "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\ |
| +\\Common7\\Tools\\vsvars32.bat" |
| + |
| +def run_with_vsvars(cmd): |
| + f = open("temp.bat", "w") |
|
bradn
2011/09/06 23:56:19
Please match the python style guide.
|
| + f.write("@echo off\n") |
| + f.write("call \"%s\"\n" % VSVARS_PATH) |
| + f.write(cmd + "\n") |
| + f.close() |
| + p = subprocess.Popen(["temp.bat"], shell=True, stdout=subprocess.PIPE) |
| + out, err = p.communicate() |
| + os.unlink("temp.bat") |
| + out = out.replace("\r", "") |
| + return p.returncode, out |
| + |
| + |
| +def get_vc_dir(): |
| + rc, out = run_with_vsvars("echo VCINSTALLDIR=%VCINSTALLDIR%") |
| + for line in out.split("\n"): |
| + if line.startswith("VCINSTALLDIR="): |
| + return line[len("VCINSTALLDIR="):] |
| + raise SystemExit("Couldn't get VCINSTALLDIR. Run vsvars32.bat?") |
| + |
| +def main(): |
| + if "VCINSTALLDIR" not in os.environ: |
| + vcdir = get_vc_dir() |
| + os.environ["PATH"] += ";" + os.path.join(vcdir, "bin") + \ |
| + ";" + os.path.join(vcdir, "../Common7/IDE") |
| + else: |
| + vcdir = os.environ["VCINSTALLDIR"] |
| + |
| + # Switch to our own dir. |
| + os.chdir(os.path.dirname(os.path.abspath(__file__))) |
| + |
| + # Verify that we can find link.exe. |
| + link = os.path.join(vcdir, "bin", "link.exe") |
| + link_backup = os.path.join(vcdir, "bin", "link.exe.supalink_orig.exe") |
| + if not os.path.exists(link): |
| + raise SystemExit("link.exe not found at %s" % link) |
| + |
| + # Don't re-backup link.exe, so only copy link.exe to backup if it's |
| + # not there already. |
| + if not os.path.exists(link_backup): |
| + try: |
| + print "Saving original link.exe..." |
| + shutil.copyfile(link, link_backup) |
|
bradn
2011/09/06 23:56:19
The bots don't run with admin privs, so this won't
|
| + except IOError: |
| + raise SystemExit("Wasn't able to back up %s to %s.\ |
| + Not running with Administrator privileges?" % (link, link_backup)) |
| + |
| + # Build supalink.exe but only if it's out of date. |
| + cpptime = os.path.getmtime("supalink.cpp") |
| + if (not os.path.exists("supalink.exe") |
| + or cpptime > os.path.getmtime("supalink.exe")): |
| + print "Building supalink.exe..." |
| + rc, out = run_with_vsvars("cl /nologo /Ox /Zi /W4 /WX\ |
| + /D_CRT_SECURE_NO_WARNINGS /EHsc supalink.cpp\ |
|
bradn
2011/09/06 23:56:19
Can we just check this program in?
|
| + /link /out:supalink.exe") |
| + if rc != 0: |
| + print out |
| + raise SystemExit("Failed to build supalink.exe") |
| + |
| + # Copy supalink into place if it's been updated since last time we ran. |
| + exetime = os.path.getmtime("supalink.exe") |
| + if exetime > os.path.getmtime(link): |
| + print "Copying supalink.exe over link.exe..." |
| + try: |
| + shutil.copyfile("supalink.exe", link) |
| + except IOError: |
| + raise SystemExit("Wasn't able to copy supalink.exe over %s.\ |
| + Not running with Administrator privileges?" % link) |
| + |
| +if __name__ == "__main__": |
| + main() |