-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expand file tree
/
Copy pathbuild.js
More file actions
108 lines (96 loc) · 3 KB
/
Copy pathbuild.js
File metadata and controls
108 lines (96 loc) · 3 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
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
import type {EnvironmentOverrides} from '../utils';
import {createBundle} from '../bundling';
import {isCI} from '../EnvironmentOptions';
import {build as buildHermesCompiler} from '../executables/hermesc';
import {build as buildFantomTester} from '../executables/tester';
import {NATIVE_BUILD_OUTPUT_PATH} from '../paths';
import {HermesVariant} from '../utils';
// $FlowExpectedError[untyped-import]
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
async function tryOrLog(
fn: () => void | Promise<void>,
message: string,
): Promise<void> {
try {
await fn();
} catch (e) {
// Sandcastle fails to parse the test output if we log stuff to stdout/stderr.
if ((process.env.SANDCASTLE ?? '') !== '') {
console.error(
'Global warmup failed. Tests will continue to run but will likely fail. Details:\n',
message,
e,
);
}
}
}
export default async function build(
enableCoverage: boolean,
env: EnvironmentOverrides,
): Promise<void> {
try {
fs.rmSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});
} catch {}
fs.mkdirSync(NATIVE_BUILD_OUTPUT_PATH, {recursive: true});
if (isCI) {
// When `enableCoverage` is true (CI coverage runs), we still need the
// non-coverage tester binaries because some tests opt out of coverage
// (benchmarks via filename, or tests with the `@fantom_disable_coverage`
// pragma — see `runner/coverageUtils.js`). Without these, those tests
// would fail to spawn with ENOENT.
const coverageVariants = enableCoverage ? [false, true] : [false];
for (const enableOptimized of [false, true]) {
for (const hermesVariant of HermesVariant.members()) {
for (const variantEnableCoverage of coverageVariants) {
buildFantomTester(
{
enableOptimized,
hermesVariant,
enableCoverage: variantEnableCoverage,
},
env,
);
}
buildHermesCompiler({enableOptimized, hermesVariant, enableCoverage});
}
}
await tryOrLog(() => warmUpMetro(false), 'Error warming up Metro (dev)');
await tryOrLog(() => warmUpMetro(true), 'Error warming up Metro (opt)');
}
}
async function warmUpMetro(isOptimizedMode: boolean): Promise<void> {
const entrypointPath = path.resolve(
__dirname,
'..',
'..',
'runtime',
'WarmUpEntryPoint.js',
);
const bundlePath = path.join(
os.tmpdir(),
`fantom-warmup-bundle-${Date.now()}.js`,
);
await createBundle({
testPath: '(warmup bundle - no test path)',
entry: entrypointPath,
out: bundlePath,
platform: 'android',
minify: isOptimizedMode,
dev: !isOptimizedMode,
customTransformOptions: undefined,
});
try {
fs.unlinkSync(bundlePath);
} catch {}
}