-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcpp-compiler-build-results.js
More file actions
188 lines (164 loc) · 6.85 KB
/
cpp-compiler-build-results.js
File metadata and controls
188 lines (164 loc) · 6.85 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const pug = require('pug');
const {DynamoDBClient, QueryCommand} = require('@aws-sdk/client-dynamodb');
const TABLE_NAME = 'library-build-history';
const COMPILER_INDEX = 'compiler-library-index';
function parse_library_key(library_str) {
const parts = library_str.split('#');
return {
library: parts[0],
library_version: parts[1],
commit_hash: parts[2],
};
}
function parse_compiler_key(compiler_str) {
const parts = compiler_str.split('#');
return {
compiler: parts[0],
compiler_version: parts[1],
arch: parts[2],
libcxx: parts[3],
};
}
async function query_all_pages(ddbClient, params) {
const items = [];
let lastEvaluatedKey;
do {
const result = await ddbClient.send(new QueryCommand({...params, ExclusiveStartKey: lastEvaluatedKey}));
items.push(...(result.Items || []));
lastEvaluatedKey = result.LastEvaluatedKey;
} while (lastEvaluatedKey);
return items;
}
async function fetch_compiler_variants_from_canonicals(ddbClient, canonical_library_keys) {
const variants_by_id = new Map();
for (const lib_key of canonical_library_keys) {
try {
const items = await query_all_pages(ddbClient, {
TableName: TABLE_NAME,
ProjectionExpression: '#c',
KeyConditionExpression: '#l = :lib_key',
ExpressionAttributeNames: {'#l': 'library', '#c': 'compiler'},
ExpressionAttributeValues: {':lib_key': {S: lib_key}},
});
for (const item of items) {
const compiler_str = item.compiler.S;
const {compiler_version} = parse_compiler_key(compiler_str);
if (!compiler_version) continue;
if (!variants_by_id.has(compiler_version)) {
variants_by_id.set(compiler_version, new Set());
}
variants_by_id.get(compiler_version).add(compiler_str);
}
} catch (e) {
console.error(`Failed to query canonical library ${lib_key}: ${e.message}`);
}
}
const result = new Map();
for (const [id, set] of variants_by_id) {
result.set(id, [...set]);
}
return result;
}
class CompilerVariantsCache {
constructor(canonical_library_keys) {
this.ddbClient = new DynamoDBClient({region: 'us-east-1'});
this.canonical_library_keys = canonical_library_keys;
this.variants_by_id = new Map();
}
async refresh() {
this.variants_by_id = await fetch_compiler_variants_from_canonicals(this.ddbClient, this.canonical_library_keys);
}
get_variants(compiler_id) {
return this.variants_by_id.get(compiler_id) || [];
}
}
class CppCompilerBuildResultsView {
constructor(compilernames, compilersemvers, variantsCache) {
this.results_view = pug.compileFile('views/compiler_build_results.pug');
this.compilernames = compilernames;
this.compilersemvers = compilersemvers;
this.variantsCache = variantsCache;
this.ddbClient = new DynamoDBClient({region: 'us-east-1'});
}
async query_rows_for_variant(compiler_str) {
return query_all_pages(this.ddbClient, {
TableName: TABLE_NAME,
IndexName: COMPILER_INDEX,
ProjectionExpression: '#l,#c,success',
KeyConditionExpression: '#c = :c',
ExpressionAttributeNames: {'#l': 'library', '#c': 'compiler'},
ExpressionAttributeValues: {':c': {S: compiler_str}},
});
}
async get(compiler_id) {
const variant_strs = this.variantsCache.get_variants(compiler_id);
const all_items = (await Promise.all(variant_strs.map(v => this.query_rows_for_variant(v)))).flat();
const variant_set = new Set();
const grouped = new Map();
for (const item of all_items) {
const lib = parse_library_key(item.library.S);
const comp = parse_compiler_key(item.compiler.S);
if (comp.compiler_version !== compiler_id) continue;
const variant_key = `${comp.arch}|${comp.libcxx}`;
variant_set.add(variant_key);
const row_key = `${lib.library}#${lib.library_version}#${lib.commit_hash}`;
if (!grouped.has(row_key)) {
grouped.set(row_key, {
library: lib.library,
library_version: lib.library_version,
commit_hash: lib.commit_hash,
cells: {},
});
}
grouped.get(row_key).cells[variant_key] = {
success: item.success.BOOL ? 'ok' : 'failed',
arch: comp.arch,
libcxx: comp.libcxx,
logging_url: item.success.BOOL ? '' :
`/getlogging_forcommit/${lib.library}/${lib.library_version}/${lib.commit_hash}/${compiler_id}/${comp.arch || ' '}/${comp.libcxx || ' '}`,
package_url: item.success.BOOL ?
`/downloadpkg/${lib.library}/${lib.library_version}/${compiler_id}/${comp.arch || ' '}/${comp.libcxx || ' '}` : '',
};
}
const variants = [...variant_set].map(k => {
const [arch, libcxx] = k.split('|');
return {key: k, arch, libcxx};
}).sort((a, b) => (a.arch + a.libcxx).localeCompare(b.arch + b.libcxx));
const rows = [...grouped.values()]
.sort((a, b) => {
if (a.library !== b.library) return a.library.localeCompare(b.library);
if (a.library_version !== b.library_version) return a.library_version.localeCompare(b.library_version);
return a.commit_hash.localeCompare(b.commit_hash);
})
.map(row => ({
...row,
cells: variants.map(v => row.cells[v.key] || null),
}));
const total_cells = rows.reduce((n, r) => n + r.cells.filter(c => c).length, 0);
const succeeded_cells = rows.reduce((n, r) => n + r.cells.filter(c => c && c.success === 'ok').length, 0);
const distinct_libs_succeeded = new Set(
rows.filter(r => r.cells.some(c => c && c.success === 'ok')).map(r => r.library)
).size;
const distinct_libs_total = new Set(rows.map(r => r.library)).size;
return await this.results_view({
compiler: {
id: compiler_id,
name: this.compilernames[compiler_id] || compiler_id,
semver: this.compilersemvers[compiler_id] || '',
},
variants,
rows,
summary: {
total_cells,
succeeded_cells,
failed_cells: total_cells - succeeded_cells,
distinct_libs_succeeded,
distinct_libs_total,
},
});
}
}
module.exports = {
CompilerVariantsCache,
CppCompilerBuildResultsView
};