forked from dart-lang/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_offsets_extractor.dart
executable file
·96 lines (84 loc) · 2.9 KB
/
run_offsets_extractor.dart
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
#!tools/sdks/dart-sdk/bin/dart
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:pool/pool.dart';
final pool = Pool(Platform.numberOfProcessors);
main() async {
final sdkRoot = Platform.script.resolve('../').toFilePath();
Directory.current = Directory(sdkRoot);
final extractedOffsetsFile =
'runtime/vm/compiler/runtime_offsets_extracted.h';
final old = File(extractedOffsetsFile).readAsStringSync();
final header = old.substring(0, old.indexOf('\n#if '));
final footer = old.substring(old.lastIndexOf('\n#endif '));
// Build all configurations
await forAllConfigurationsMode(
(String buildDir, String mode, String arch) async {
print('Building $buildDir');
await run([
'tools/build.py',
'-a$arch',
'-m$mode',
'offsets_extractor',
'offsets_extractor_precompiled_runtime'
]);
print('Building $buildDir - done');
});
final (jit, aot) = await (
forAllConfigurationsMode((String buildDir, _, __) async {
return await run(['$buildDir/offsets_extractor']);
}).then<String>((lines) => lines.join('\n')),
forAllConfigurationsMode((String buildDir, _, __) async {
return await run(['$buildDir/offsets_extractor_precompiled_runtime']);
}).then<String>((lines) => lines.join('\n')),
).wait;
if (exitCode == 0) {
final output = StringBuffer();
output.writeln(header);
output.writeln(jit);
output.writeln(aot);
output.writeln(footer);
File(extractedOffsetsFile).writeAsStringSync(output.toString());
print('Written $extractedOffsetsFile');
print('Running `git cl format $extractedOffsetsFile');
await run(['git', 'cl', 'format', extractedOffsetsFile]);
}
}
Future<List<T>> forAllConfigurationsMode<T>(
Future<T> Function(String buildDir, String mode, String arch) fun) async {
final archs = [
'simarm',
'x64',
'ia32',
'simarm64',
'x64c',
'simarm64c',
'simriscv32',
'simriscv64',
];
final futures = <Future<T>>[];
for (final mode in ['release', 'product']) {
for (final arch in archs) {
final buildDir = 'out/${mode.capitalized}${arch.upper}/';
futures.add(pool.withResource(() => fun(buildDir, mode, arch)));
}
}
return await Future.wait(futures);
}
Future<String> run(List<String> args) async {
final result =
await Process.run(args.first, args.skip(1).toList(), runInShell: true);
if (result.exitCode != 0) {
exitCode = result.exitCode;
print('Running ${args.join(' ')} has failed with exit code $exitCode:');
print('${result.stdout}');
print('${result.stderr}');
}
return result.stdout;
}
extension on String {
String get capitalized => substring(0, 1).toUpperCase() + substring(1);
String get upper => toUpperCase();
}