Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msbuild call failure with 'flutter run' on Windows #32792

Closed
stuartmorgan opened this issue May 16, 2019 · 18 comments · Fixed by #33443
Closed

msbuild call failure with 'flutter run' on Windows #32792

stuartmorgan opened this issue May 16, 2019 · 18 comments · Fixed by #33443
Assignees
Labels
a: desktop Running on desktop platform-windows Building on or for Windows specifically

Comments

@stuartmorgan
Copy link
Contributor

Splitting out from google/flutter-desktop-embedding#342 (comment)

Summarizing the error:

Build process failed

#0      throwToolExit (package:flutter_tools/src/base/common.dart:24:3)
#1      buildWindows (package:flutter_tools/src/windows/build_windows.dart:56:5)
[...]
[  +13 ms] 'C:\Program' is not recognized as an internal or external command,
[   +3 ms] operable program or batch file.

That looks very much like the vcvars64 path was split on spaces. What doesn't make sense about that is that this path pretty much always has spaces, so I don't understand why this would happen to someone else, but not be reproducible for me.

I'll make a branch tomorrow with some additional logging to make sure that's indeed what's happening (and not a strange issue with finding the vcvars64.bat path, for instance). Meanwhile, @contrix09 is there anything unusual about your CMD.exe configuration (e.g., something that might cause paths to be processed an extra time)?

@stuartmorgan stuartmorgan added platform-windows Building on or for Windows specifically a: desktop Running on desktop labels May 16, 2019
@stuartmorgan stuartmorgan self-assigned this May 16, 2019
@contrix09
Copy link

@stuartmorgan not that I'm aware of.

@stuartmorgan
Copy link
Contributor Author

I've set up a branch for debugging this. As a starting point, it just adds some logging to make sure I understand where the problem is; if you flutter run with that branch, what is printed starting with ### Running? (Feel free to obfuscate the path to Runner.vcxproj if you like, since that shouldn't be relevant.)

@contrix09
Copy link

Hi. How can I use your updated flutter_tools. It seems that running flutter run on your branch uses my currently installed flutter sdk. I can't see any output from flutter run starting with ### Running.

@stuartmorgan
Copy link
Contributor Author

Sorry, I thought checking out a different branch would be enough to trigger a rebuild, but it sounds like that's not the case. You can delete bin/cache/flutter_tools.* to force a rebuild.

@contrix09
Copy link

Here is the output:

### Running [C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat, &&, msbuild, PATH/TO/Runner.vcxproj, /p:Configuration=Release]

@stuartmorgan
Copy link
Contributor Author

Okay, so that rules out something weird happening with locating vcvars64.bat in the first place.

Can you try updating that branch and then running again? I've added quoting to the path; this breaks the build for me, but if it works for you that would be more evidence that it's being double-interpreted somehow. (If that's the case, maybe we'll need to think about generating a batch script that does the two steps, rather that passing through the shell, unless we can figure out why behavior is different.)

It would also be helpful if you could try running C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat manually in a command prompt to make sure that it works for you in general (i.e., that the error isn't actually from within that script on your machine, rather than in trying to run it).

@contrix09
Copy link

contrix09 commented May 17, 2019

Here's the output from your latest changes:

### Running ["C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat", &&, msbuild, PATH\TO\Runner.vcxproj, /p:Configuration=Release]
[...]
[  +13 ms] The filename, directory name, or volume label syntax is incorrect.

When I try to run the full path of vcvars64.bat:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

@stuartmorgan
Copy link
Contributor Author

When I try to run the full path of vcvars64.bat:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

That's when properly quoted for invoking it in the shell manually? I.e., the script is successfully invoked, but is logging that error internally?

@contrix09
Copy link

No, it was not quoted. But when quoted, i.e. "..\vcvars64.bat", it runs.

@stuartmorgan
Copy link
Contributor Author

So it's not from within the script then. I'm perplexed as to how invoking it could fail both when quoted and when not quoted. (And why so far this is specific to your environment.)

I think the next step is to try having the build process write a temporary .bat file that invokes (quoted) vcvars64.bat then runs the build. Without knowing what the cause of the problem is though, it's hard to guess whether that will fix it. It would let us avoid passing the invocation through shell interpretation though, which would eliminate a possible source of issues.

@SilentPenguin
Copy link

SilentPenguin commented May 25, 2019

Ok, I have had two issues wrt building on windows. Both of them are path related, of which this issue was one. I've managed to isolate their causes on my system.

The error discussed here is thrown when there's a space in the path to the example project. My username contains a space and I checked out the example desktop repo into my documents folder. Moving the repo to C:\src without a space resolves that issue and presents a second.

The second error reported is the input line is too long, the syntax of the command is incorrect. I found the only way I have been able to successfully build the example repo is by ensuring my git repo is checked out at the root of my drive.

Yeah, the error is absolutely bananas for what is going wrong, but hope this helps you to reproduce the issues your side.

@stuartmorgan
Copy link
Contributor Author

The error discussed here is thrown when there's a space in the path to the example project.

Interesting, the form of the error made it seem like the issue must be with the command rather than the project path. Thanks for tracking that down.

It seems like the easiest solution to both of these issues is to add a bat file as discussed above. We can design it so that it's intended to be run with the working directory set to the <project>/windows directory, so that the msbuild line can just use the project name instead of a full path. In that setup the vcvars64.bat invocation will be a separate line, so no individual command should be very long.

stuartmorgan added a commit to stuartmorgan/flutter that referenced this issue May 25, 2019
Invoking msbuild with runInShell makes handling path escaping more
error-prone, and substantially increases the chances of running into
maximum path limits. This replaces the direct call with a .bat wrapper
that calls vsvars64.bat then msbuild, and uses relative paths within the
script to keep command lengths short.

Fixes flutter#32792
@stuartmorgan
Copy link
Contributor Author

https://github.com/stuartmorgan/flutter/tree/msbuild-bat-wrapper has the first pass at a fix. I don't have a Windows machine at the moment so it was written on macOS, which means it's never actually been tested; there may well be typo in vs_build.bat.

I'll actually test it next week and get it landed, but you're welcome to try it out now and see if it works for you.

@SilentPenguin
Copy link

Happy to be of help.

I've been able to test this. My copy of your branch is located at C:\src\flutter.copy and my desktop example project is located at C:\Users\<username>\Documents\Code. My username contains 12 ASCII characters, one of which is a space.

While testing, I discovered one issue. The path join in build_windows.dart#L32 fails to create the correct path to the vs_build.bat. This line should read fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'bin', 'vs_build.bat') instead.

After that line was changed, calling C:\src\flutter.copy\bin\flutter run from the desktop example directory still fails to build correctly with the less than descriptive error build process failed. I did copy git repo locally to skip re-downloading everything, but I deleted the flutter_tools snapshot and stamp from the cache, so that shouldn't be the reason. I'll let you test yourself first before I dig any deeper, since I've not been able to track down a cause.

Let me know what your findings are when you have the chance to test.

@stuartmorgan
Copy link
Contributor Author

The path join in build_windows.dart#L32 fails to create the correct path to the vs_build.bat.

The hazards of writing a patch on a machine where I can't actually run it! Fix pushed to the branch.

fails to build correctly with the less than descriptive error build process failed.

That's just the Flutter tool output when the script returns non-zero; the actual error that caused it should be somewhere earlier in the output if you use -v. (Error display in non-verbose mode for Windows build hasn't been tuned at all.)

stuartmorgan added a commit to stuartmorgan/flutter-desktop-embedding that referenced this issue May 28, 2019
The arguments to the helper commands were being quoted, but not the
commands themselves, causing failures if the path to the project had
spaces in it.

Also re-adds the previously-dropped example/Runner.sln, to make the
workflow smoother when opening the project in Visual Studio (to avoid
being prompted to save the auto-synthesized solution on quit).

Part of the fix for flutter/flutter#32792
@stuartmorgan
Copy link
Contributor Author

The remaining problem with spaces is in the FDE example project rather than the Flutter tooling.

stuartmorgan added a commit to google/flutter-desktop-embedding that referenced this issue May 28, 2019
The arguments to the helper commands were being quoted, but not the
commands themselves, causing failures if the path to the project had
spaces in it.

Also re-adds the previously-dropped example/Runner.sln, to make the
workflow smoother when opening the project in Visual Studio (to avoid
being prompted to save the auto-synthesized solution on quit).

Part of the fix for flutter/flutter#32792
@SilentPenguin
Copy link

My mistake, I didn't scroll far enough to find the error, previously the error was in the line above build process failed. I suspected the remaining issue was outside the build path since I was able to run the commands the bat file was trying to run, with errors.

stuartmorgan added a commit that referenced this issue May 29, 2019
Invoking msbuild with runInShell makes handling path escaping more
error-prone, and substantially increases the chances of running into
maximum path limits. This replaces the direct call with a .bat wrapper
that calls vsvars64.bat then msbuild, and uses relative paths within the
script to keep command lengths short.

Fixes #32792
kiku-jw pushed a commit to kiku-jw/flutter that referenced this issue Jun 14, 2019
Invoking msbuild with runInShell makes handling path escaping more
error-prone, and substantially increases the chances of running into
maximum path limits. This replaces the direct call with a .bat wrapper
that calls vsvars64.bat then msbuild, and uses relative paths within the
script to keep command lengths short.

Fixes flutter#32792
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: desktop Running on desktop platform-windows Building on or for Windows specifically
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants