15
15
import 'dart:io' ;
16
16
import 'package:path/path.dart' as path;
17
17
18
+ import 'package:pub/src/dart.dart' ;
19
+ import 'package:pub/src/exceptions.dart' ;
20
+
18
21
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' ;
22
25
try {
23
26
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' ));
38
33
final extension = Platform .isWindows ? '.bat' : '' ;
39
34
final testProcess = await Process .start (
40
35
path.join (path.dirname (Platform .resolvedExecutable), 'pub$extension ' ),
@@ -45,6 +40,8 @@ Future<void> main(List<String> args) async {
45
40
testProcess.stderr.pipe (stderr),
46
41
]);
47
42
exitCode = await testProcess.exitCode;
43
+ } on ApplicationException catch (_) {
44
+ exitCode = 1 ;
48
45
} finally {
49
46
try {
50
47
await File (pubSnapshotFilename).delete ();
0 commit comments