Skip to content

Commit 1426601

Browse files
authored
use incremental compilation in the tool/test.dart script (#3075)
1 parent 9954f85 commit 1426601

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

tool/test.dart

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,21 @@
1515
import 'dart:io';
1616
import 'package:path/path.dart' as path;
1717

18+
import 'package:pub/src/dart.dart';
19+
import 'package:pub/src/exceptions.dart';
20+
1821
Future<void> main(List<String> args) async {
19-
final pubSnapshotFilename = path.join(
20-
(await Directory.systemTemp.createTemp()).path,
21-
'pub.dart.snapshot.dart2');
22+
final pubSnapshotFilename = path.absolute(path.join(
23+
'.dart_tool', '_pub', 'pub.dart.snapshot.dart2'));
24+
final pubSnapshotIncrementalFilename = '$pubSnapshotFilename.incremental';
2225
try {
2326
print('Building snapshot');
24-
final stopwatch = Stopwatch()..start();
25-
final root = path.dirname(path.dirname(Platform.script.path));
26-
final compilationResult = await Process.run(Platform.resolvedExecutable, [
27-
'--snapshot=$pubSnapshotFilename',
28-
path.join(root, 'bin', 'pub.dart')
29-
]);
30-
stopwatch.stop();
31-
if (compilationResult.exitCode != 0) {
32-
print(
33-
'Failed building snapshot: ${compilationResult.stdout} ${compilationResult.stderr}');
34-
exitCode = compilationResult.exitCode;
35-
return;
36-
}
37-
print('Took ${stopwatch.elapsedMilliseconds} milliseconds');
27+
await precompile(
28+
executablePath: path.join('bin', 'pub.dart'),
29+
outputPath: pubSnapshotFilename,
30+
incrementalDillOutputPath: pubSnapshotIncrementalFilename,
31+
name: 'bin/pub.dart',
32+
packageConfigPath: path.join('.dart_tool', 'package_config.json'));
3833
final extension = Platform.isWindows ? '.bat' : '';
3934
final testProcess = await Process.start(
4035
path.join(path.dirname(Platform.resolvedExecutable), 'pub$extension'),
@@ -45,6 +40,8 @@ Future<void> main(List<String> args) async {
4540
testProcess.stderr.pipe(stderr),
4641
]);
4742
exitCode = await testProcess.exitCode;
43+
} on ApplicationException catch (_) {
44+
exitCode = 1;
4845
} finally {
4946
try {
5047
await File(pubSnapshotFilename).delete();

0 commit comments

Comments
 (0)