flutter / flutter/devtools

dt run on Windows crashes horribly with ProcessException: The system cannot find the file specified

Aperta
#9,717 5 commenti 1 reazione 0 assegnatari Vedi su GitHub
bug infra P3
Lingua principale
Dart
Stelle
1.7k
Fork
404
Merge medio
6g 17h
PR unite (30g)
18

Descrizione

After setting up devtools on Windows properly, running dt run in the root directory to start the devtools server and frontend fails horribly with the following:

```
[serve] running gclient sync in the local dart sdk
C:\Users\User\Downloads\VSCode\dart-lang\sdk > gclient sync
ProcessException: The system cannot find the file specified (at ../../runtime/bin/process_win.cc:577)
Command: gclient sync
#0 _ProcessImpl._start (dart:io-patch/process_patch.dart:411:33)
#1 Process.start (dart:io-patch/process_patch.dart:42:20)
#2 ProcessManager.spawn (package:io/src/process_manager.dart:78:32)
#3 DevToolsProcessManagerExtension.runProcess (package:devtools_tool/utils.dart:143:27)
#4 ServeCommand.run (package:devtools_tool/commands/serve.dart:246:26)
#5 CommandRunner.runCommand (package:args/command_runner.dart:212:27)
#6 DevToolsCommandRunner.runCommand (package:devtools_tool/devtools_command_runner.dart:92:18)
#7 CommandRunner.run. (package:args/command_runner.dart:122:25)
#8 new Future.sync (dart:async/future.dart:325:27)
#9 CommandRunner.run (package:args/command_runner.dart:122:14)
#10 main (file:///C:/Users/User/Downloads/VSCode/devtools/tool/bin/dt.dart:15:10)
#11 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:312:33)
#12 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)

ProcessException: Failed with exit code: 1.
Command: C:\Users\User\Downloads\VSCode\devtools\tool\flutter-sdk\bin\dart.bat C:\Users\User\Downloads\VSCode\devtools\tool\bin\dt.dart serve --run-app
#0 DevToolsProcessManagerExtension.runProcess (package:devtools_tool/utils.dart:152:7)

#1 RunCommand.run (package:devtools_tool/commands/run.dart:34:21)

#2 CommandRunner.runCommand (package:args/command_runner.dart:212:13)

#3 SharedStdIn.terminate (package:io/src/shared_stdin.dart:91:3)

#4 main (file:///C:/Users/User/Downloads/VSCode/devtools/tool/bin/dt.dart:14:28)

```

I debugged this for quite a while and it appears that the code at https://github.com/flutter/devtools/blob/cac09a934e33e7e4b18cf3af5d4c9514fafd2077/tool/lib/commands/serve.dart#L247 attempts to run gclient sync as a process, which is ultimately implemented as a CreateProcessW call in the deepest darkest parts of the Dart VM. It's important to note that in this case, the gclient executable we are trying to run is a batch file (As depot\_tools does not support running the gclient executable in anything but cmd on Windows, meaning the shell script version can be disregarded, although even if it was supported, there would be no difference, as is later explained). However, the Windows documentation states

> To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.

The reason for this becomes apparent once you realize that CreateProcessW, regardless of the several different ways you can call it, only ever expects exe files when no file extension is given. So when that runProcess call is executed during dt run, what Windows is actually looking for is a gclient.exe, not gclient.bat as is actually intended. This in turn ends up making the attempt to run the gclient process explode. Tracking the CreateProcessW call from the Dart VM confirms this, as the paths shown are all variants of C:\\Users\\User\\Downloads\\VSCode\\depot_tools\\gclient.exe or C:\\Users\\User\\Downloads\\VSCode\\depot_tools\\gclient sync.exe for every entry in PATH, since Windows is trying and failing to find gclient.exe in each directory listed in PATH (The latter is because Windows is desperately trying to find an executable to make the user code happy, and in its desperation, since the application name parameter is not specified to CreateProcessW by the Dart VM, it interprets the entire gclient sync command as the executable name itself)

I don't know how best to fix this. The optimal fix would be to run cmd.exe /c gclient.bat as the CreateProcessW documentation suggests, but the Dart VM does not expose any way for the first parameter of the CreateProcessW call to be set from Dart, instead hardcoding it to nullptr while it uses the second process arguments parameter as the name of the process itself. Maybe a hack could be put in place for Windows in the devtools, given that a full fix requires rearchitecting the Dart VM's process code and the API it exposes quite a bit.

One other thing I also noticed is that the documention for devtools for running both server and frontend implies that simply cloning the Dart SDK is enough, but the actual code suggests something very different, namely that you seem to need depot\_tools, particularly gclient, as well as having cloned Dart using fetch from depot\_tools rather than just regular git clone.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with tool/lib/commands/serve.dart around line 247 and reproduce dt run on Windows after following the documented Dart SDK setup. Trace how the gclient sync command is launched and compare that behavior with Windows batch-file requirements; done means dt run can start the server and frontend without the ProcessException, with the required setup documented.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
dart
Ambito
cli, devtools, operating-systems
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.