Script xalt_generate_linkdata_in_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 from __future__ import print_function
27 import os, sys, re, json, subprocess
28
29 dirNm, execName = os.path.split(os.path.realpath(sys.argv[0]))
30 sys.path.insert(1,os.path.realpath(os.path.join(dirNm, "../libexec")))
31 sys.path.insert(1,os.path.realpath(os.path.join(dirNm, "../site")))
32
33 from xalt_util import *
34 from xalt_transmission_factory import XALT_transmission_factory
35 from xalt_global import *
36
37 logger = config_logger()
38 parenPat = re.compile(r'.*\((.*)\).*')
39 tmpObjPat = re.compile(r'/tmp/[_a-zA-Z0-9-]+.o')
40
42 """
43 cleanup the output of ld --trace
44 @param xaltobj: The name of the XALT object file.
45 @param fn: The file path that contains the ld --trace output.
46 """
47 f = open(fn,"r")
48 lines = f.readlines()
49 d = {}
50 for s in lines:
51
52
53 if (s.find(":") != -1):
54 continue
55
56
57 if (s.find(xaltobj) != -1):
58 continue
59
60
61 m = tmpObjPat.search(s)
62 if (m):
63 continue
64
65
66
67 m = parenPat.search(s)
68 if (m):
69 s = os.path.realpath(m.group(1))
70 d[s] = True
71 continue
72
73
74 idx = s.find("\n")
75 if (idx != -1):
76 s = s[:idx]
77
78 s = os.path.realpath(s)
79 d[s] = True
80
81
82 sA = d.keys()
83
84 sA = sorted(sA)
85
86 sB = []
87 for lib in sA:
88 hash_line = capture(['sha1sum', lib])
89 if (hash_line.find("No such file or directory") != -1):
90 continue
91 else:
92 v = hash_line.split()[0]
93 sB.append([lib, v])
94
95 return sB
96
98 """
99 Built a json output of the ld --trace data.
100 """
101 User = os.environ.get("USER", "unknown")
102 Host = os.environ.get("HOSTNAME","unknown")
103
104 XALT_Stack.push("User: " + User)
105 XALT_Stack.push("Host: " + Host)
106 sA = []
107 sA.append("CommandLine:")
108 for v in sys.argv:
109 sA.append('"'+v+'"')
110
111 s = " ".join(sA)
112 XALT_Stack.push(s)
113
114 try:
115 uuid = sys.argv[ 1]
116 status = sys.argv[ 2]
117 wd = sys.argv[ 3]
118 syshost = sys.argv[ 4]
119 pstree = sys.argv[ 5]
120 execname = sys.argv[ 6]
121 xaltobj = sys.argv[ 7]
122 build_epoch = sys.argv[ 8]
123 linklineFn = sys.argv[ 9]
124 resultFn = sys.argv[10]
125
126 if (execname.find("conftest") != -1):
127 return 1
128
129 hash_line = capture(['sha1sum', execname])
130 if (hash_line.find("No such file or directory") != -1):
131 return 1
132 hash_id = hash_line.split()[0]
133
134
135 sA = cleanup(xaltobj, linklineFn)
136
137 resultT = {}
138 resultT['uuid'] = uuid
139 resultT['link_program'] = extract_compiler(pstree)
140 resultT['build_user'] = User
141 resultT['exit_code'] = status
142 resultT['build_epoch'] = build_epoch
143 resultT['exec_path'] = os.path.abspath(execname)
144 resultT['hash_id'] = hash_id
145 resultT['wd'] = wd
146 resultT['build_syshost'] = syshost
147 resultT['linkA'] = sA
148
149 xfer = XALT_transmission_factory.build(XALT_TRANSMISSION_STYLE,
150 syshost, "link", resultFn)
151 xfer.save(resultT)
152
153 except Exception as e:
154 print("XALT_EXCEPTION(xalt_generate_linkdata.py): ",e)
155 logger.exception("XALT_EXCEPTION:xalt_generate_linkdata"+XALT_Stack.contents())
156
157 return 0
158
159 if ( __name__ == '__main__'):
160 iret = main()
161 sys.exit(iret)
162