Completed
Pull Request — develop (#115)
by Wu
01:09
created

main()   B

Complexity

Conditions 6

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 19
rs 8
cc 6
1
""" Fuse real (not symlinks to) libraries with same name
2
"""
3
4
from __future__ import print_function
5
6
USAGE = """\
7
fuse_suff_real_libs.py <lib_dir_out> <lib_dir_in1> <lib_dir_in2>
8
"""
9
10
import os
11
from os.path import (splitext, join as pjoin, split as psplit, islink, isfile,
12
                     abspath, realpath)
13
import sys
14
import shutil
15
from subprocess import check_call
16
17
LIB_EXTS = ('.a', '.so', '.dylib')
18
19
20
def main():
21
    try:
22
        lib_dir_out, lib_dir_in1, lib_dir_in2 = sys.argv[1:]
23
    except (IndexError, ValueError):
24
        print(USAGE)
25
        sys.exit(-1)
26
    for fname in os.listdir(lib_dir_in1):
27
        if not splitext(fname)[1] in LIB_EXTS:
28
            continue
29
        lib_path = pjoin(lib_dir_in1, fname)
30
        out_path = pjoin(lib_dir_out, fname)
31
        if islink(lib_path):
32
            continue
33
        lib_path_2 = pjoin(lib_dir_in2, fname)
34
        if not isfile(lib_path_2):
35
            continue
36
        # Fuse and copy library
37
        check_call(['lipo', '-create', lib_path, lib_path_2,
38
                    '-output', out_path])
39
40
41
if __name__ == '__main__':
42
    main()
43