-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdependency_builder.py
95 lines (72 loc) · 2.03 KB
/
dependency_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/local/bin/python2.7
import subprocess
import shutil
import getopt
import sys
import os
import re
def build_tree(dir):
abs = os.path.dirname(os.path.abspath(dir))
os.popen("chmod -R 777 "+abs)
if not os.path.exists(abs):
if not build_tree(abs):
return False
try:
if not os.path.exists(dir):
os.mkdir(dir)
except:
return False
return True
def extract_dependencies(src):
return re.findall("(/\S*(?<!:))", subprocess.Popen(["ldd", src], stdout=subprocess.PIPE).communicate()[0])
def export_lib(outdir, infiles):
pathmap = []
# print("outdir: {0}".format(outdir))
for infile in infiles:
print("infile: {0}".format(infile))
if not os.path.exists(infile):
print("file not found: {0}".format(infile))
continue
print("extracting dependencies ({0})".format(infile))
deps = extract_dependencies(infile)
for dep in deps:
if dep == infile:
continue
real_dep = os.path.realpath(dep)
print("\tdep: {0} -> {1}".format(dep, real_dep))
if pathmap.count(real_dep) == 0:
pathmap.append(real_dep)
for src in pathmap:
if not os.path.isfile(src):
return 2
dst = os.path.dirname(outdir + src)
print("building directory tree for {0}".format(dst))
if not build_tree(dst):
return 3
try:
print("copy '{0}' to '{1}'...".format(src, dst))
#shutil.copyfile(src, dst)
os.popen("cp -R "+src+" "+dst)
os.popen("chmod -R 777 "+dst)
except Exception as e:
print(e)
return 4
return 0
def main(argv):
outdir = "libexport"
infiles = []
try:
opts, args = getopt.getopt(argv, "hi:o:", ["in=", "out="])
except getopt.GetoptError:
print("dependency_builder.py -o outputdirectory -i inputfile1 -i inputfile2")
return 1
for opt, arg in opts:
if opt == "-h":
print("dependency_builder.py -o outputdirectory -i inputfile1 -i inputfile2")
elif opt in ("-i", "--in"):
infiles.append(os.path.abspath(arg))
elif opt in ("-o", "--out"):
outdir = arg
return export_lib(os.path.abspath(outdir), infiles)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))