-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtoolchain.py
154 lines (126 loc) · 4.93 KB
/
toolchain.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import json
import csv
import re
import os
from collections import OrderedDict
OBSOLETE_ARCHITECTURES = []
class Toolchain(object):
def __init__(self, file_name):
toolchain_name = file_name.split(".tar.")[0]
arch, libc, version = toolchain_name.split("--")
version = version.split('-20')[0]
self.arch = arch
self.libc = libc
self.version = version
self.name = toolchain_name
self.tarball_name = None
def set_tarball_name(self, tarball_name):
self.tarball_name = tarball_name
def set_test_result(self, arch_path, toolchain_name):
# Newer toolchains have a <toolchain-name>-test-result.txt
result_txt = os.path.join(arch_path, "test_results",
toolchain_name + "-test-result.txt")
if os.path.exists(result_txt):
with open(result_txt) as f:
self.test_result = f.read().strip()
# Older toolchains have the test result direclty in the
# readme.txt file
else:
readme_txt = os.path.join(arch_path, "readmes",
toolchain_name + ".txt")
with open(readme_txt) as f:
readme = f.read()
test_result = re.search(r"FLAG: (\S*)", readme)
self.test_result = test_result.group(1)
def set_summary(self, f):
summary_list = ['gdb', 'gcc', 'linux', 'uclibc', 'musl', 'glibc', 'binutils']
found_list = []
summary = []
s = csv.reader(f, delimiter=",", quotechar='"')
for row in s:
row[0] = row[0].replace("gcc-final", "gcc")
if any(e in row[0] for e in summary_list if e not in found_list):
summary.append([row[0], row[1]])
found_list.append(row[0])
self.summary = sorted(summary, key=lambda e: e[0])
def get_binutils_version(self):
for e in self.summary:
if e[0] == 'binutils':
return e[1]
def get_libc_version(self):
for e in self.summary:
if e[0] == self.libc:
return e[1]
def get_linux_version(self):
for e in self.summary:
if e[0] == 'linux-headers':
return e[1]
def get_gdb_version(self):
for e in self.summary:
if e[0] == 'gdb':
return e[1]
def get_gcc_version(self):
for e in self.summary:
if e[0] == 'gcc':
return e[1]
def as_dict(self):
return {
'name': self.name,
'arch': self.arch,
'libc': self.libc,
'version': self.version,
'test_result': self.test_result,
'summary': self.summary,
'tarball-name': self.tarball_name,
}
class ToolchainEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Toolchain):
return obj.as_dict()
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
class ToolchainSet(object):
def __init__(self):
self.archs = {}
self.libcs = {}
self.versions = {}
self.tree = OrderedDict()
self.list_by_release = {}
def add(self, release, t):
if release not in self.list_by_release:
self.list_by_release[release] = {}
if release not in self.tree:
self.tree[release] = OrderedDict()
if release not in self.archs:
self.archs[release] = set()
if release not in self.libcs:
self.libcs[release] = set()
if release not in self.versions:
self.versions[release] = set()
self.archs[release].add(t.arch)
self.libcs[release].add(t.libc)
self.versions[release].add(t.version)
if t.arch not in self.tree[release]:
self.tree[release][t.arch] = OrderedDict()
if t.libc not in self.tree[release][t.arch]:
self.tree[release][t.arch][t.libc] = OrderedDict()
if t.version not in self.tree[release][t.arch][t.libc]:
self.tree[release][t.arch][t.libc][t.version] = []
self.tree[release][t.arch][t.libc][t.version].append(t)
self.list_by_release[release][t.name] = t
def arch_list(self, release):
return sorted(list(self.archs[release]))
def libc_list(self, release):
return sorted(list(self.libcs[release]))
def version_list(self, release):
return sorted(list(self.libcs[release]))
def release_list(self):
return sorted(list(self.tree.keys()))
def get_tree(self, release):
return self.tree[release]
def get_by_arch_and_libc(self, release, arch, libc):
toolchain_list = []
if libc in self.tree[release][arch]:
for v in self.tree[release][arch][libc]:
toolchain_list += self.tree[release][arch][libc][v]
return toolchain_list