forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtargets.mts
More file actions
50 lines (43 loc) · 1.68 KB
/
Copy pathtargets.mts
File metadata and controls
50 lines (43 loc) · 1.68 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
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import path from 'path';
import {exec} from './utils.mjs';
/** Branded string representing a resolved Bazel benchmark target. */
export type ResolvedTarget = string & {
__resolvedTarget: true;
};
/** Finds all benchmark Bazel targets in the project. */
export async function findBenchmarkTargets(): Promise<string[]> {
return (
await exec('bazel', [
'query',
'--output=label',
`'kind("^web_test", //modules/...) intersect attr("name", "perf", //modules/...)'`,
])
)
.split(/\r?\n/)
.filter((t) => t !== '');
}
/** Gets the testlog path of a given Bazel target. */
export async function getTestlogPath(target: ResolvedTarget): Promise<string> {
return path.join(await bazelTestlogDir(), target.substring(2).replace(':', '/'));
}
/** Resolves a given benchmark Bazel target to the fully expanded label. */
export async function resolveTarget(target: string): Promise<ResolvedTarget> {
// If the target does not specify an explicit browser test target, we attempt
// to automatically add the Chromium suffix. This is necessary for e.g.
// resolving testlogs which would reside under the actual test target.
if (!target.endsWith('_chromium')) {
target = `${target}_chromium`;
}
return (await exec('bazel', ['query', '--output=label', target])).trim() as ResolvedTarget;
}
let testlogDir: string | null = null;
async function bazelTestlogDir(): Promise<string> {
return testlogDir ?? (testlogDir = (await exec('bazel', ['info', 'bazel-testlogs'])).trim());
}