OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 # | 6 # |
7 # This script takes libcmt.lib for VS2013 and removes the allocation related | 7 # This script takes libcmt.lib for VS2013 and removes the allocation related |
8 # functions from it. | 8 # functions from it. |
9 # | 9 # |
10 # Usage: prep_libc.py <VCLibDir> <OutputDir> <arch> | 10 # Usage: prep_libc.py <VCLibDir> <OutputDir> <arch> [<environment_file>] |
11 # | 11 # |
12 # VCLibDir is the path where VC is installed, something like: | 12 # VCLibDir is the path where VC is installed, something like: |
13 # C:\Program Files\Microsoft Visual Studio 8\VC\lib | 13 # C:\Program Files\Microsoft Visual Studio 8\VC\lib |
| 14 # |
14 # OutputDir is the directory where the modified libcmt file should be stored. | 15 # OutputDir is the directory where the modified libcmt file should be stored. |
15 # arch is one of: 'ia32', 'x86' or 'x64'. ia32 and x86 are synonyms. | 16 # arch is one of: 'ia32', 'x86' or 'x64'. ia32 and x86 are synonyms. |
| 17 # |
| 18 # If the environment_file argument is set, the environment variables in the |
| 19 # given file will be used to execute the VC tools. This file is in the same |
| 20 # format as the environment block passed to CreateProcess. |
16 | 21 |
17 import os | 22 import os |
18 import shutil | 23 import shutil |
19 import subprocess | 24 import subprocess |
20 import sys | 25 import sys |
21 | 26 |
22 def run(command): | 27 def run(command, env_dict): |
23 """Run |command|. If any lines that match an error condition then | 28 """Run |command|. If any lines that match an error condition then |
24 terminate.""" | 29 terminate. |
| 30 |
| 31 The env_dict, will be used for the environment. None can be used to get the |
| 32 default environment.""" |
25 error = 'cannot find member object' | 33 error = 'cannot find member object' |
| 34 # Need shell=True to search the path in env_dict for the executable. |
26 popen = subprocess.Popen( | 35 popen = subprocess.Popen( |
27 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 36 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, |
| 37 env=env_dict) |
28 out, _ = popen.communicate() | 38 out, _ = popen.communicate() |
29 for line in out.splitlines(): | 39 for line in out.splitlines(): |
30 print line | 40 print line |
31 if error and line.find(error) != -1: | 41 if error and line.find(error) != -1: |
32 print 'prep_libc.py: Error stripping object from C runtime.' | 42 print 'prep_libc.py: Error stripping object from C runtime.' |
33 sys.exit(1) | 43 sys.exit(1) |
34 | 44 |
35 def main(): | 45 def main(): |
36 bindir = 'SELF_X86' | 46 bindir = 'SELF_X86' |
37 objdir = 'INTEL' | 47 objdir = 'INTEL' |
38 vs_install_dir = sys.argv[1] | 48 vs_install_dir = sys.argv[1] |
39 outdir = sys.argv[2] | 49 outdir = sys.argv[2] |
40 if "x64" in sys.argv[3]: | 50 if "x64" in sys.argv[3]: |
41 bindir = 'SELF_64_amd64' | 51 bindir = 'SELF_64_amd64' |
42 objdir = 'amd64' | 52 objdir = 'amd64' |
43 vs_install_dir = os.path.join(vs_install_dir, 'amd64') | 53 vs_install_dir = os.path.join(vs_install_dir, 'amd64') |
| 54 |
| 55 if len(sys.argv) == 5: |
| 56 env_pairs = open(sys.argv[4]).read()[:-2].split('\0') |
| 57 env_dict = dict([item.split('=', 1) for item in env_pairs]) |
| 58 else: |
| 59 env_dict = None # Use the default environment. |
| 60 |
44 output_lib = os.path.join(outdir, 'libcmt.lib') | 61 output_lib = os.path.join(outdir, 'libcmt.lib') |
45 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.lib'), output_lib) | 62 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.lib'), output_lib) |
46 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.pdb'), | 63 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.pdb'), |
47 os.path.join(outdir, 'libcmt.pdb')) | 64 os.path.join(outdir, 'libcmt.pdb')) |
48 cvspath = 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ | 65 cvspath = 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ |
49 '\\crt\\prebuild\\build\\' + objdir + '\\mt_obj\\nativec\\\\'; | 66 '\\crt\\prebuild\\build\\' + objdir + '\\mt_obj\\nativec\\\\'; |
50 cppvspath = 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ | 67 cppvspath = 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ |
51 '\\crt\\prebuild\\build\\' + objdir + '\\mt_obj\\nativecpp\\\\'; | 68 '\\crt\\prebuild\\build\\' + objdir + '\\mt_obj\\nativecpp\\\\'; |
52 | 69 |
53 cobjfiles = ['malloc', 'free', 'realloc', 'heapinit', 'calloc', 'recalloc', | 70 cobjfiles = ['malloc', 'free', 'realloc', 'heapinit', 'calloc', 'recalloc', |
54 'calloc_impl'] | 71 'calloc_impl'] |
55 cppobjfiles = ['new', 'new2', 'delete', 'delete2', 'new_mode', 'newopnt', | 72 cppobjfiles = ['new', 'new2', 'delete', 'delete2', 'new_mode', 'newopnt', |
56 'newaopnt'] | 73 'newaopnt'] |
57 for obj in cobjfiles: | 74 for obj in cobjfiles: |
58 cmd = ('lib /nologo /ignore:4006,4221 /remove:%s%s.obj %s' % | 75 cmd = ('lib /nologo /ignore:4006,4221 /remove:%s%s.obj %s' % |
59 (cvspath, obj, output_lib)) | 76 (cvspath, obj, output_lib)) |
60 run(cmd) | 77 run(cmd, env_dict) |
61 for obj in cppobjfiles: | 78 for obj in cppobjfiles: |
62 cmd = ('lib /nologo /ignore:4006,4221 /remove:%s%s.obj %s' % | 79 cmd = ('lib /nologo /ignore:4006,4221 /remove:%s%s.obj %s' % |
63 (cppvspath, obj, output_lib)) | 80 (cppvspath, obj, output_lib)) |
64 run(cmd) | 81 run(cmd, env_dict) |
65 | 82 |
66 if __name__ == "__main__": | 83 if __name__ == "__main__": |
67 sys.exit(main()) | 84 sys.exit(main()) |
OLD | NEW |