@@ -38,6 +38,7 @@ DartDevIsolate::DartDevRunner DartDevIsolate::runner_ =
38
38
DartDevIsolate::DartDevRunner ();
39
39
bool DartDevIsolate::should_run_dart_dev_ = false ;
40
40
bool DartDevIsolate::print_usage_error_ = false ;
41
+ CommandLineOptions* DartDevIsolate::vm_options_ = nullptr ;
41
42
Monitor* DartDevIsolate::DartDevRunner::monitor_ = new Monitor();
42
43
DartDevIsolate::DartDev_Result DartDevIsolate::DartDevRunner::result_ =
43
44
DartDevIsolate::DartDev_Result_Unknown;
@@ -138,7 +139,7 @@ void DartDevIsolate::DartDevRunner::Run(
138
139
Thread::Start (" DartDev Runner" , RunCallback, reinterpret_cast <uword>(this ));
139
140
monitor_->WaitMicros (Monitor::kNoTimeout );
140
141
141
- if (result_ == DartDevIsolate::DartDev_Result_Run ) {
142
+ if (result_ == DartDevIsolate::DartDev_Result_RunJIT ) {
142
143
// Clear the DartDev dart_options and replace them with the processed
143
144
// options provided by DartDev.
144
145
dart_options_->Reset ();
@@ -157,8 +158,8 @@ void DartDevIsolate::DartDevRunner::DartDevResultCallback(
157
158
ASSERT (message->type == Dart_CObject_kArray);
158
159
int32_t type = GetArrayItem (message, 0 )->value .as_int32 ;
159
160
switch (type) {
160
- case DartDevIsolate::DartDev_Result_Run : {
161
- result_ = DartDevIsolate::DartDev_Result_Run ;
161
+ case DartDevIsolate::DartDev_Result_RunJIT : {
162
+ result_ = DartDevIsolate::DartDev_Result_RunJIT ;
162
163
ASSERT (GetArrayItem (message, 1 )->type == Dart_CObject_kString);
163
164
auto item2 = GetArrayItem (message, 2 );
164
165
@@ -204,6 +205,86 @@ void DartDevIsolate::DartDevRunner::DartDevResultCallback(
204
205
}
205
206
break ;
206
207
}
208
+ case DartDevIsolate::DartDev_Result_RunAOT: {
209
+ result_ = DartDevIsolate::DartDev_Result_RunAOT;
210
+ ASSERT (GetArrayItem (message, 1 )->type == Dart_CObject_kString);
211
+ auto item2 = GetArrayItem (message, 2 );
212
+
213
+ ASSERT (item2->type == Dart_CObject_kString ||
214
+ item2->type == Dart_CObject_kNull);
215
+
216
+ auto item3 = GetArrayItem (message, 3 );
217
+
218
+ ASSERT (item3->type == Dart_CObject_kBool);
219
+ const bool mark_main_isolate_as_system_isolate = item3->value .as_bool ;
220
+ if (mark_main_isolate_as_system_isolate) {
221
+ Options::set_mark_main_isolate_as_system_isolate (true );
222
+ }
223
+
224
+ if (*script_ != nullptr ) {
225
+ free (*script_);
226
+ }
227
+ if (*package_config_override_ != nullptr ) {
228
+ free (*package_config_override_);
229
+ *package_config_override_ = nullptr ;
230
+ }
231
+ *script_ = Utils::StrDup (GetArrayItem (message, 1 )->value .as_string );
232
+
233
+ if (item2->type == Dart_CObject_kString) {
234
+ *package_config_override_ = Utils::StrDup (item2->value .as_string );
235
+ }
236
+
237
+ intptr_t num_vm_options = 0 ;
238
+ const char ** vm_options = nullptr ;
239
+ ASSERT (GetArrayItem (message, 4 )->type == Dart_CObject_kArray);
240
+ Dart_CObject* args = GetArrayItem (message, 4 );
241
+ intptr_t argc = args->value .as_array .length ;
242
+ Dart_CObject** dart_args = args->value .as_array .values ;
243
+
244
+ if (vm_options_ != nullptr ) {
245
+ num_vm_options = vm_options_->count ();
246
+ vm_options = vm_options_->arguments ();
247
+ }
248
+ auto deleter = [](char ** args) {
249
+ for (intptr_t i = 0 ; i < argc_; ++i) {
250
+ free (args[i]);
251
+ }
252
+ delete[] args;
253
+ };
254
+ // Total count of arguments to be passed to the script being execed.
255
+ argc_ = argc + num_vm_options + 1 ;
256
+
257
+ // Array of arguments to be passed to the script being execed.
258
+ argv_ = std::unique_ptr<char *[], void (*)(char **)>(new char *[argc_ + 1 ],
259
+ deleter);
260
+
261
+ intptr_t idx = 0 ;
262
+ // Copy in name of the script to run (dartaotruntime).
263
+ argv_[0 ] = Utils::StrDup (GetArrayItem (message, 1 )->value .as_string );
264
+ idx += 1 ;
265
+ // Copy in any vm options that need to be passed to the execed process.
266
+ for (intptr_t i = 0 ; i < num_vm_options; ++i) {
267
+ argv_[i + idx] = Utils::StrDup (vm_options[i]);
268
+ }
269
+ idx += num_vm_options;
270
+ // Copy in the dart options that need to be passed to the command.
271
+ for (intptr_t i = 0 ; i < argc; ++i) {
272
+ argv_[i + idx] = Utils::StrDup (dart_args[i]->value .as_string );
273
+ }
274
+ // Null terminate the argv array.
275
+ argv_[argc + idx] = nullptr ;
276
+
277
+ // Exec the script to be run and pass the arguments.
278
+ char err_msg[256 ];
279
+ err_msg[0 ] = ' \0 ' ;
280
+ int ret = Process::Exec (nullptr , *script_,
281
+ const_cast <const char **>(argv_.get ()), argc_,
282
+ nullptr , err_msg, sizeof (err_msg));
283
+ if (ret != 0 ) {
284
+ ProcessError (err_msg, kErrorExitCode );
285
+ }
286
+ break ;
287
+ }
207
288
case DartDevIsolate::DartDev_Result_Exit: {
208
289
ASSERT (GetArrayItem (message, 1 )->type == Dart_CObject_kInt32);
209
290
int32_t dartdev_exit_code = GetArrayItem (message, 1 )->value .as_int32 ;
@@ -314,7 +395,9 @@ DartDevIsolate::DartDev_Result DartDevIsolate::RunDartDev(
314
395
Dart_IsolateGroupCreateCallback create_isolate,
315
396
char ** packages_file,
316
397
char ** script,
398
+ CommandLineOptions* vm_options,
317
399
CommandLineOptions* dart_options) {
400
+ vm_options_ = vm_options;
318
401
runner_.Run (create_isolate, packages_file, script, dart_options);
319
402
return runner_.result ();
320
403
}
0 commit comments