|
4 | 4 |
|
5 | 5 | import 'dart:async'; |
6 | 6 | import 'dart:io'; |
| 7 | +import 'dart:isolate'; |
7 | 8 |
|
8 | 9 | import 'package:args/args.dart'; |
9 | 10 | import 'package:dart2native/generate.dart'; |
@@ -87,41 +88,48 @@ class CompileJSCommand extends CompileSubcommandCommand { |
87 | 88 |
|
88 | 89 | @override |
89 | 90 | FutureOr<int> run() async { |
90 | | - if (!Sdk.checkArtifactExists(sdk.librariesJson)) { |
91 | | - return genericErrorExitCode; |
| 91 | + if (!Sdk.checkArtifactExists(sdk.dart2jsSnapshot) || |
| 92 | + !Sdk.checkArtifactExists(sdk.librariesJson)) { |
| 93 | + return 255; |
92 | 94 | } |
| 95 | + |
93 | 96 | final args = argResults!; |
94 | | - var snapshot = sdk.dart2jsAotSnapshot; |
95 | | - var runtime = sdk.dartAotRuntime; |
96 | | - if (!Sdk.checkArtifactExists(snapshot, logError: false)) { |
97 | | - // AOT snapshots cannot be generated on IA32, so we need this fallback |
98 | | - // branch until support for IA32 is dropped (https://dartbug.com/49969). |
99 | | - snapshot = sdk.dart2jsSnapshot; |
100 | | - runtime = sdk.dart; |
101 | | - if (!Sdk.checkArtifactExists(snapshot)) { |
102 | | - return genericErrorExitCode; |
103 | | - } |
104 | | - } |
105 | | - final dart2jsCommand = [ |
106 | | - runtime, |
107 | | - snapshot, |
| 97 | + |
| 98 | + // Build arguments. |
| 99 | + final buildArgs = <String>[ |
108 | 100 | '--libraries-spec=${sdk.librariesJson}', |
109 | 101 | '--cfe-invocation-modes=compile', |
110 | 102 | '--invoker=dart_cli', |
111 | 103 | // Add the remaining arguments. |
112 | 104 | if (args.rest.isNotEmpty) ...args.rest.sublist(0), |
113 | 105 | ]; |
| 106 | + |
| 107 | + var retval = 0; |
| 108 | + final result = Completer<int>(); |
| 109 | + final exitPort = ReceivePort() |
| 110 | + ..listen((msg) { |
| 111 | + result.complete(0); |
| 112 | + }); |
| 113 | + final errorPort = ReceivePort() |
| 114 | + ..listen((error) { |
| 115 | + log.stderr(error.toString()); |
| 116 | + result.complete(255); |
| 117 | + }); |
114 | 118 | try { |
115 | | - final exitCode = await runProcessInheritStdio(dart2jsCommand); |
116 | | - return exitCode; |
| 119 | + await Isolate.spawnUri(Uri.file(sdk.dart2jsSnapshot), buildArgs, null, |
| 120 | + onExit: exitPort.sendPort, onError: errorPort.sendPort); |
| 121 | + retval = await result.future; |
117 | 122 | } catch (e, st) { |
118 | 123 | log.stderr('Error: JS compilation failed'); |
119 | 124 | log.stderr(e.toString()); |
120 | 125 | if (verbose) { |
121 | 126 | log.stderr(st.toString()); |
122 | 127 | } |
123 | | - return compileErrorExitCode; |
| 128 | + retval = compileErrorExitCode; |
124 | 129 | } |
| 130 | + errorPort.close(); |
| 131 | + exitPort.close(); |
| 132 | + return retval; |
125 | 133 | } |
126 | 134 | } |
127 | 135 |
|
|
0 commit comments