From b0838eac58308fc4e6654ca99eda75b30649c08f Mon Sep 17 00:00:00 2001 From: asiva Date: Fri, 27 Jun 2025 10:01:02 -0700 Subject: [PATCH] [dartdev] Fix for issue https://github.com/dart-lang/sdk/issues/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 Commit-Queue: Siva Annamalai --- .../test/commands/language_server_test.dart | 8 +++++++ runtime/bin/dartdev_isolate.cc | 6 +++++ runtime/bin/dartdev_isolate.h | 5 ++++ runtime/bin/main_options.cc | 23 +++++++++++-------- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/pkg/dartdev/test/commands/language_server_test.dart b/pkg/dartdev/test/commands/language_server_test.dart index e917248c6fa..201892d45f2 100644 --- a/pkg/dartdev/test/commands/language_server_test.dart +++ b/pkg/dartdev/test/commands/language_server_test.dart @@ -77,10 +77,18 @@ void defineLanguageServerTests() { return runWithLsp(['language-server', '--use-aot-snapshot']); }); + test('--use-aot-snapshot --enable-experiment=foo', () async { + return runWithLsp(['language-server', '--use-aot-snapshot', '--enable-experiment=foo']); + }); + test('--no-use-aot-snapshot', () async { return runWithLsp(['language-server', '--no-use-aot-snapshot']); }); + test('--no-use-aot-snapshot --enable-experiment=foo', () async { + return runWithLsp(['language-server', '--no-use-aot-snapshot', '--enable-experiment=foo']); + }); + test('protocol analyzer', () async { project = utils.project(); diff --git a/runtime/bin/dartdev_isolate.cc b/runtime/bin/dartdev_isolate.cc index f39c772db77..5602d6a18e2 100644 --- a/runtime/bin/dartdev_isolate.cc +++ b/runtime/bin/dartdev_isolate.cc @@ -81,6 +81,12 @@ bool DartDevIsolate::ShouldParseCommand(const char* script_uri) { (strncmp(script_uri, "google3://", 10) != 0))); } +bool DartDevIsolate::ShouldParseVMOptions(const char* command) { + // If command is 'run' or 'test' parse the VM options as we need to pass + // it down to the VM that executes these commands. + return (strcmp(command, "run") == 0) || (strcmp(command, "test") == 0); +} + CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(const char* filename) { auto try_resolve_path = [&](CStringUniquePtr dir_prefix) { // First assume we're in dart-sdk/bin. diff --git a/runtime/bin/dartdev_isolate.h b/runtime/bin/dartdev_isolate.h index dc0397f7c49..c5e476db8e5 100644 --- a/runtime/bin/dartdev_isolate.h +++ b/runtime/bin/dartdev_isolate.h @@ -36,6 +36,11 @@ class DartDevIsolate { // not an HTTP resource. static bool ShouldParseCommand(const char* script_uri); + // Returns true if VM options need to be recorded and passed to the VM + // that executes the command (this is true only for dart CL commands like + // 'run' and 'test'. + static bool ShouldParseVMOptions(const char* command); + static void set_should_run_dart_dev(bool enable) { should_run_dart_dev_ = enable; } diff --git a/runtime/bin/main_options.cc b/runtime/bin/main_options.cc index a08fa10196d..b94961c7239 100644 --- a/runtime/bin/main_options.cc +++ b/runtime/bin/main_options.cc @@ -719,11 +719,14 @@ bool Options::ParseArguments(int argc, ASSERT(i == argc); return true; } -#endif // !defined(DART_PRECOMPILED_RUNTIME) // If running with dartdev, attempt to parse VM flags which are part of the // dartdev command (e.g., --enable-vm-service, --observe, etc). - if (!run_script) { + bool record_vm_options = false; + if ((i < argc) && DartDevIsolate::ShouldParseVMOptions(argv[i])) { + record_vm_options = true; + } + if (!run_script && record_vm_options) { // Skip the command. int tmp_i = i + 1; while (tmp_i < argc) { @@ -736,14 +739,9 @@ bool Options::ParseArguments(int argc, OptionProcessor::TryProcess(argv[tmp_i], vm_options); tmp_i++; } -#if !defined(DART_PRECOMPILED_RUNTIME) - if (Options::disable_dart_dev()) { - Syslog::PrintErr( - "Attempted to use --disable-dart-dev with a Dart CLI command.\n"); - Platform::Exit(kErrorExitCode); - } -#endif // !defined(DART_PRECOMIPLED_RUNTIME) } +#endif // !defined(DART_PRECOMPILED_RUNTIME) + bool first_option = true; // Parse out options to be passed to dart main. while (i < argc) { @@ -754,6 +752,13 @@ bool Options::ParseArguments(int argc, !IsOption(argv[i], "enable-vm-service")) { dart_options->AddArgument(argv[i]); } +#if !defined(DART_PRECOMPILED_RUNTIME) + if (IsOption(argv[i], "disable-dart-dev")) { + Syslog::PrintErr( + "Attempted to use --disable-dart-dev with a Dart CLI command.\n"); + Platform::Exit(kErrorExitCode); + } +#endif // !defined(DART_PRECOMIPLED_RUNTIME) i++; // Add DDS specific flags immediately after the dartdev command. if (first_option) {