OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 # | 5 |
6 # This takes three command-line arguments: | 6 """This takes three command-line arguments: |
7 # MUNGE-PHDR-PROGRAM file name of program built from | 7 MUNGE-PHDR-PROGRAM file name of program built from |
8 # nacl_helper_bootstrap_munge_phdr.c | 8 nacl_helper_bootstrap_munge_phdr.c |
9 # INFILE raw linked ELF file name | 9 INFILE raw linked ELF file name |
10 # OUTFILE output file name | 10 OUTFILE output file name |
11 # | 11 |
12 # We just run the MUNGE-PHDR-PROGRAM on a copy of INFILE. | 12 We just run the MUNGE-PHDR-PROGRAM on a copy of INFILE. |
13 # That modifies the file in place. Then we move it to OUTFILE. | 13 That modifies the file in place. Then we move it to OUTFILE. |
14 # | 14 |
15 # We only have this wrapper script because nacl_helper_bootstrap_munge_phdr.c | 15 We only have this wrapper script because nacl_helper_bootstrap_munge_phdr.c |
16 # wants to modify a file in place (and it would be a much longer and more | 16 wants to modify a file in place (and it would be a much longer and more |
17 # fragile program if it created a fresh ELF output file instead). | 17 fragile program if it created a fresh ELF output file instead). |
| 18 """ |
18 | 19 |
19 import shutil | 20 import shutil |
20 import subprocess | 21 import subprocess |
21 import sys | 22 import sys |
22 | 23 |
23 | 24 |
24 def Main(argv): | 25 def Main(argv): |
25 if len(argv) != 4: | 26 if len(argv) != 4: |
26 print 'Usage: %s MUNGE-PHDR-PROGRAM INFILE OUTFILE' % argv[0] | 27 print 'Usage: %s MUNGE-PHDR-PROGRAM INFILE OUTFILE' % argv[0] |
27 sys.exit(1) | 28 return 1 |
28 [prog, munger, infile, outfile] = argv | 29 [prog, munger, infile, outfile] = argv |
29 tmpfile = outfile + '.tmp' | 30 tmpfile = outfile + '.tmp' |
30 shutil.copy(infile, tmpfile) | 31 shutil.copy(infile, tmpfile) |
31 segment_num = '2' | 32 segment_num = '2' |
32 subprocess.check_call([munger, tmpfile, segment_num]) | 33 subprocess.check_call([munger, tmpfile, segment_num]) |
33 shutil.move(tmpfile, outfile) | 34 shutil.move(tmpfile, outfile) |
| 35 return 0 |
| 36 |
34 | 37 |
35 if __name__ == '__main__': | 38 if __name__ == '__main__': |
36 Main(sys.argv) | 39 sys.exit(Main(sys.argv)) |
OLD | NEW |