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 VS2005/08/10/12/13 and removes the allocation | 7 # This script takes libcmt.lib for VS2013 and removes the allocation related |
8 # related 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> |
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 # OutputDir is the directory where the modified libcmt file should be stored. | 14 # 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. | 15 # arch is one of: 'ia32', 'x86' or 'x64'. ia32 and x86 are synonyms. |
16 | 16 |
17 import os | 17 import os |
18 import shutil | 18 import shutil |
19 import subprocess | 19 import subprocess |
20 import sys | 20 import sys |
21 | 21 |
22 def run(command, filter=None): | 22 def run(command): |
23 """Run |command|, removing any lines that match |filter|. The filter is | 23 """Run |command|. If any lines that match an error condition then |
24 to remove the echoing of input filename that 'lib' does.""" | 24 terminate.""" |
| 25 error = 'cannot find member object' |
25 popen = subprocess.Popen( | 26 popen = subprocess.Popen( |
26 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 27 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
27 out, _ = popen.communicate() | 28 out, _ = popen.communicate() |
28 for line in out.splitlines(): | 29 for line in out.splitlines(): |
29 if filter and line.strip() != filter: | 30 print line |
30 print line | 31 if error and line.find(error) != -1: |
31 return popen.returncode | 32 print 'prep_libc.py: Error stripping object from C runtime.' |
| 33 sys.exit(1) |
32 | 34 |
33 def main(): | 35 def main(): |
34 bindir = 'SELF_X86' | 36 bindir = 'SELF_X86' |
35 objdir = 'INTEL' | 37 objdir = 'INTEL' |
36 vs_install_dir = sys.argv[1] | 38 vs_install_dir = sys.argv[1] |
37 outdir = sys.argv[2] | 39 outdir = sys.argv[2] |
38 if "x64" in sys.argv[3]: | 40 if "x64" in sys.argv[3]: |
39 bindir = 'SELF_64_amd64' | 41 bindir = 'SELF_64_amd64' |
40 objdir = 'amd64' | 42 objdir = 'amd64' |
41 vs_install_dir = os.path.join(vs_install_dir, 'amd64') | 43 vs_install_dir = os.path.join(vs_install_dir, 'amd64') |
42 output_lib = os.path.join(outdir, 'libcmt.lib') | 44 output_lib = os.path.join(outdir, 'libcmt.lib') |
43 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.lib'), output_lib) | 45 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.lib'), output_lib) |
44 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.pdb'), | 46 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.pdb'), |
45 os.path.join(outdir, 'libcmt.pdb')) | 47 os.path.join(outdir, 'libcmt.pdb')) |
| 48 cvspath = 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ |
| 49 '\\crt\\prebuild\\build\\' + objdir + '\\mt_obj\\nativec\\\\'; |
| 50 cppvspath = 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ |
| 51 '\\crt\\prebuild\\build\\' + objdir + '\\mt_obj\\nativecpp\\\\'; |
46 | 52 |
47 vspaths = [ | 53 cobjfiles = ['malloc', 'free', 'realloc', 'align', 'msize', 'heapinit', |
48 'build\\intel\\mt_obj\\', | 54 'expand', 'heapchk', 'heapwalk', 'heapmin', 'calloc', 'recalloc', |
49 'f:\\dd\\vctools\\crt_bld\\' + bindir + \ | 55 'calloc_impl'] |
50 '\\crt\\src\\build\\' + objdir + '\\mt_obj\\', | 56 cppobjfiles = ['new', 'new2', 'delete', 'delete2', 'new_mode', 'newopnt', |
51 'F:\\dd\\vctools\\crt_bld\\' + bindir + \ | 57 'newaopnt'] |
52 '\\crt\\src\\build\\' + objdir + '\\mt_obj\\nativec\\\\', | 58 for obj in cobjfiles: |
53 'F:\\dd\\vctools\\crt_bld\\' + bindir + \ | 59 cmd = ('lib /nologo /ignore:4006,4221 /remove:%s%s.obj %s' % |
54 '\\crt\\src\\build\\' + objdir + '\\mt_obj\\nativecpp\\\\', | 60 (cvspath, obj, output_lib)) |
55 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ | 61 run(cmd) |
56 '\\crt\\prebuild\\build\\INTEL\\mt_obj\\cpp_obj\\\\', | 62 for obj in cppobjfiles: |
57 ] | 63 cmd = ('lib /nologo /ignore:4006,4221 /remove:%s%s.obj %s' % |
58 | 64 (cppvspath, obj, output_lib)) |
59 objfiles = ['malloc', 'free', 'realloc', 'new', 'delete', 'new2', 'delete2', | 65 run(cmd) |
60 'align', 'msize', 'heapinit', 'expand', 'heapchk', 'heapwalk', | |
61 'heapmin', 'sbheap', 'calloc', 'recalloc', 'calloc_impl', | |
62 'new_mode', 'newopnt', 'newaopnt'] | |
63 for obj in objfiles: | |
64 for vspath in vspaths: | |
65 cmd = ('lib /nologo /ignore:4006,4014,4221 /remove:%s%s.obj %s' % | |
66 (vspath, obj, output_lib)) | |
67 run(cmd, obj + '.obj') | |
68 | 66 |
69 if __name__ == "__main__": | 67 if __name__ == "__main__": |
70 sys.exit(main()) | 68 sys.exit(main()) |
OLD | NEW |