|
1 | | -#!/usr/bin/env python2 |
| 1 | +#!/usr/bin/env python |
2 | 2 |
|
3 | | -''' |
4 | | -emar - ar helper script |
5 | | -======================= |
| 3 | +# This script should work in python 2 *or* 3. It loads emar.py, which needs python 2. |
6 | 4 |
|
7 | | -This script acts as a frontend replacement for ar. See emcc. |
8 | | -''' |
9 | 5 |
|
10 | | -import os, subprocess, sys |
11 | | -from tools import shared |
| 6 | +import sys |
12 | 7 |
|
13 | | -DEBUG = os.environ.get('EMCC_DEBUG') |
14 | | -if DEBUG == "0": |
15 | | - DEBUG = None |
16 | 8 |
|
17 | | -newargs = [shared.LLVM_AR] + sys.argv[1:] |
18 | | - |
19 | | -if DEBUG: |
20 | | - print >> sys.stderr, 'emar:', sys.argv, ' ==> ', newargs |
21 | | - |
22 | | -if len(newargs) > 2: |
23 | | - to_delete = [] |
24 | | - if 'r' in newargs[1]: |
25 | | - # we are adding files to the archive. |
26 | | - # find the .a; everything after it is an input file. |
27 | | - # we add a hash to each input, to make them unique as |
28 | | - # possible, as llvm-ar cannot extract duplicate names |
29 | | - # (and only the basename is used!) |
30 | | - i = 1 |
31 | | - while i < len(newargs): |
32 | | - if newargs[i].endswith('.a'): |
33 | | - import hashlib, shutil |
34 | | - for j in range(i+1, len(newargs)): |
35 | | - orig_name = newargs[j] |
36 | | - full_name = os.path.abspath(orig_name) |
37 | | - dir_name = os.path.dirname(full_name) |
38 | | - base_name = os.path.basename(full_name) |
39 | | - h = hashlib.md5(full_name).hexdigest()[:8] |
40 | | - parts = base_name.split('.') |
41 | | - parts[0] += '_' + h |
42 | | - newname = '.'.join(parts) |
43 | | - full_newname = os.path.join(dir_name, newname) |
44 | | - if not os.path.exists(full_newname): |
45 | | - try: # it is ok to fail here, we just don't get hashing |
46 | | - shutil.copyfile(orig_name, full_newname) |
47 | | - newargs[j] = full_newname |
48 | | - to_delete.append(full_newname) |
49 | | - except: |
50 | | - pass |
51 | | - break |
52 | | - i += 1 |
53 | | - subprocess.call(newargs) |
54 | | - for d in to_delete: |
55 | | - shared.try_delete(d) |
56 | 9 |
|
| 10 | +if sys.version_info.major == 2: |
| 11 | + import emar |
| 12 | + if __name__ == '__main__': |
| 13 | + emar.run() |
| 14 | +else: |
| 15 | + import os, subprocess |
| 16 | + if __name__ == '__main__': |
| 17 | + sys.exit(subprocess.call(['python2', os.path.join(os.path.dirname(__file__), 'emar.py')] + sys.argv[1:])) |
0 commit comments