Chromium Code Reviews| Index: src/trusted/validator_ragel/obtain_binutils.py |
| diff --git a/src/trusted/validator_ragel/obtain_binutils.py b/src/trusted/validator_ragel/obtain_binutils.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..867a682b4b545230d945204f29c47dfa77a17214 |
| --- /dev/null |
| +++ b/src/trusted/validator_ragel/obtain_binutils.py |
| @@ -0,0 +1,78 @@ |
| +#!/usr/bin/python |
|
Nick Bray
2012/08/08 18:24:44
Needs copyright header.
Vlad Shcherbina
2012/08/09 10:07:35
Done.
|
| + |
| +""" |
| +Usage: |
| + %s <objdump> <gas> |
|
Nick Bray
2012/08/08 18:24:44
It doesn't seem like this is really a docstring, i
Vlad Shcherbina
2012/08/09 10:07:35
Made it proper docstring instead.
|
| + |
| +Check out appropriate version of binutils, compile it and |
| +copy objdump and gas binaries to specified places. |
| +""" |
| + |
| +import sys |
|
Nick Bray
2012/08/08 18:24:44
Alphabetize.
Vlad Shcherbina
2012/08/09 10:07:35
Done.
|
| +import os |
| +import shutil |
| + |
| +CHECKOUT_DIR = '/dev/shm/binutils' |
| + |
| +BINUTILS_REPO = 'http://git.chromium.org/native_client/nacl-binutils.git' |
| +BINUTILS_REVISION = '6993545d5650fa77e75e9ae4b52c5703a53c53cc' |
| + |
| +# We need specific revision of binutils, and it have to include the |
| +# following patches: |
| +# Add prefetch_modified - non-canonical encoding of prefetch |
| +# |
| +# Properly handle data16+rex.w instructions, such as |
| +# 66 48 68 01 02 03 04 data32 pushq $0x4030201 |
| +# |
| +# We are not using head revision because decoder test depends |
| +# on precise format of objdump output. |
| + |
| + |
| +def Command(cmd): |
| + result = os.system(cmd) |
|
Nick Bray
2012/08/08 18:24:44
I have found that scripts like this benefit from:
Vlad Shcherbina
2012/08/09 10:07:35
Done.
|
| + if result != 0: |
| + print 'Command "%s" returned %s' % (cmd, result) |
| + exit(result) |
|
Nick Bray
2012/08/08 18:24:44
Use sys.exit instead - it is more standard and "ex
Vlad Shcherbina
2012/08/09 10:07:35
Oh, I never suspected that.
Done.
|
| + |
| + |
| +def main(): |
| + if len(sys.argv) != 3: |
| + print __doc__ % os.path.split(__file__)[1] |
| + exit(1) |
| + |
| + if os.path.exists(CHECKOUT_DIR): |
| + shutil.rmtree(CHECKOUT_DIR) |
| + |
| + Command('git clone %s %s' % (BINUTILS_REPO, CHECKOUT_DIR)) |
| + |
| + old_dir = os.getcwd() |
| + try: |
| + os.chdir(CHECKOUT_DIR) |
| + Command('git checkout %s' % BINUTILS_REVISION) |
| + |
| + # to please make, set the same modification time |
|
Nick Bray
2012/08/08 18:24:44
Capitalize, period at the end, possibly start the
Vlad Shcherbina
2012/08/09 10:07:35
I rechecked, and it's actually not needed. So I re
|
| + # for all files |
| + Command('find . -print0 | xargs -0 touch -r .') |
| + |
| + # they both are required to make binutils, |
|
Nick Bray
2012/08/08 18:24:44
Capitalize, period at end.
Vlad Shcherbina
2012/08/09 10:07:35
Done.
|
| + # and when they are missing binutils's make |
| + # error messages are cryptic |
| + Command('flex --version') |
| + Command('bison --version') |
| + |
| + Command('./configure') |
| + Command('make') |
| + finally: |
| + os.chdir(old_dir) |
|
Nick Bray
2012/08/08 18:24:44
Why? The process terminates in this case. You pr
Vlad Shcherbina
2012/08/09 10:07:35
You are right. But I also need to chdir back becau
|
| + |
| + objdump, gas = sys.argv[1:] |
| + shutil.copy(os.path.join(CHECKOUT_DIR, 'binutils', 'objdump'), objdump) |
| + shutil.copy(os.path.join(CHECKOUT_DIR, 'gas', 'as-new'), gas) |
| + |
| + shutil.rmtree(CHECKOUT_DIR) |
| + |
| + print 'ok' |
| + |
| + |
| +if __name__ == '__main__': |
| + main() |