Skip to content

Commit b0838ea

Browse files
a-sivaCommit Queue
authored andcommitted
[dartdev] Fix for issue #60988
Parse and accumulate VM options only for the 'run' and 'test' commands. TEST=ci Change-Id: I50a4c7e12d5b212723ce6b17e0c1882b172a3a7d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437128 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent 593da80 commit b0838ea

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

pkg/dartdev/test/commands/language_server_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,18 @@ void defineLanguageServerTests() {
7777
return runWithLsp(['language-server', '--use-aot-snapshot']);
7878
});
7979

80+
test('--use-aot-snapshot --enable-experiment=foo', () async {
81+
return runWithLsp(['language-server', '--use-aot-snapshot', '--enable-experiment=foo']);
82+
});
83+
8084
test('--no-use-aot-snapshot', () async {
8185
return runWithLsp(['language-server', '--no-use-aot-snapshot']);
8286
});
8387

88+
test('--no-use-aot-snapshot --enable-experiment=foo', () async {
89+
return runWithLsp(['language-server', '--no-use-aot-snapshot', '--enable-experiment=foo']);
90+
});
91+
8492
test('protocol analyzer', () async {
8593
project = utils.project();
8694

runtime/bin/dartdev_isolate.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ bool DartDevIsolate::ShouldParseCommand(const char* script_uri) {
8181
(strncmp(script_uri, "google3://", 10) != 0)));
8282
}
8383

84+
bool DartDevIsolate::ShouldParseVMOptions(const char* command) {
85+
// If command is 'run' or 'test' parse the VM options as we need to pass
86+
// it down to the VM that executes these commands.
87+
return (strcmp(command, "run") == 0) || (strcmp(command, "test") == 0);
88+
}
89+
8490
CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(const char* filename) {
8591
auto try_resolve_path = [&](CStringUniquePtr dir_prefix) {
8692
// First assume we're in dart-sdk/bin.

runtime/bin/dartdev_isolate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class DartDevIsolate {
3636
// not an HTTP resource.
3737
static bool ShouldParseCommand(const char* script_uri);
3838

39+
// Returns true if VM options need to be recorded and passed to the VM
40+
// that executes the command (this is true only for dart CL commands like
41+
// 'run' and 'test'.
42+
static bool ShouldParseVMOptions(const char* command);
43+
3944
static void set_should_run_dart_dev(bool enable) {
4045
should_run_dart_dev_ = enable;
4146
}

runtime/bin/main_options.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,14 @@ bool Options::ParseArguments(int argc,
719719
ASSERT(i == argc);
720720
return true;
721721
}
722-
#endif // !defined(DART_PRECOMPILED_RUNTIME)
723722

724723
// If running with dartdev, attempt to parse VM flags which are part of the
725724
// dartdev command (e.g., --enable-vm-service, --observe, etc).
726-
if (!run_script) {
725+
bool record_vm_options = false;
726+
if ((i < argc) && DartDevIsolate::ShouldParseVMOptions(argv[i])) {
727+
record_vm_options = true;
728+
}
729+
if (!run_script && record_vm_options) {
727730
// Skip the command.
728731
int tmp_i = i + 1;
729732
while (tmp_i < argc) {
@@ -736,14 +739,9 @@ bool Options::ParseArguments(int argc,
736739
OptionProcessor::TryProcess(argv[tmp_i], vm_options);
737740
tmp_i++;
738741
}
739-
#if !defined(DART_PRECOMPILED_RUNTIME)
740-
if (Options::disable_dart_dev()) {
741-
Syslog::PrintErr(
742-
"Attempted to use --disable-dart-dev with a Dart CLI command.\n");
743-
Platform::Exit(kErrorExitCode);
744-
}
745-
#endif // !defined(DART_PRECOMIPLED_RUNTIME)
746742
}
743+
#endif // !defined(DART_PRECOMPILED_RUNTIME)
744+
747745
bool first_option = true;
748746
// Parse out options to be passed to dart main.
749747
while (i < argc) {
@@ -754,6 +752,13 @@ bool Options::ParseArguments(int argc,
754752
!IsOption(argv[i], "enable-vm-service")) {
755753
dart_options->AddArgument(argv[i]);
756754
}
755+
#if !defined(DART_PRECOMPILED_RUNTIME)
756+
if (IsOption(argv[i], "disable-dart-dev")) {
757+
Syslog::PrintErr(
758+
"Attempted to use --disable-dart-dev with a Dart CLI command.\n");
759+
Platform::Exit(kErrorExitCode);
760+
}
761+
#endif // !defined(DART_PRECOMIPLED_RUNTIME)
757762
i++;
758763
// Add DDS specific flags immediately after the dartdev command.
759764
if (first_option) {

0 commit comments

Comments
 (0)