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

build.cmd fails if path contains a space #42397

Open
verdie-g opened this issue Sep 17, 2020 · 33 comments · Fixed by #42671
Open

build.cmd fails if path contains a space #42397

verdie-g opened this issue Sep 17, 2020 · 33 comments · Fixed by #42671

Comments

@verdie-g
Copy link
Contributor

My username is abc def and I get an error running build.cmd.

PS> .\build.cmd
  Determining projects to restore...
  Tool 'coverlet.console' (version '1.7.2') was restored. Available commands: coverlet
  Tool 'dotnet-reportgenerator-globaltool' (version '4.5.8') was restored. Available commands: reportgenerator
  Tool 'microsoft.dotnet.xharness.cli' (version '1.0.0-prerelease.20403.2') was restored. Available commands: xharness

  Restore was successful.
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  Restored C:\Users\abc def\Documents\dotnet-runtime\src\installer\pkg\projects\netcoreapp\pkg\legacy\Microsoft.NETCore.App.pkgproj (in 162 ms).
  1 of 2 projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  Restored C:\Users\abc def\Documents\dotnet-runtime\src\installer\pkg\projects\netcoreapp\pkg\workaround\Microsoft.NETCore.App.pkgproj (in 43 ms).
  Determining projects to restore...
  All projects are up-to-date for restore.
  Determining projects to restore...
  All projects are up-to-date for restore.
  System.Private.CoreLib -> C:\Users\abc def\Documents\dotnet-runtime\artifacts\bin\coreclr\Windows_NT.x64.Debug\IL\System.Private.CoreLib.dll
  BUILD: Starting Build at 20:07:06.52
  '""C:\Users\abc' is not recognized as an internal or external command,
  operable program or batch file.
C:\Users\abc def\Documents\dotnet-runtime\src\coreclr\runtime.proj(37,5): error MSB3073: The command ""C:\Users\abc def\Documents\dotnet-runtime\src\coreclr\build-runtime.cmd" -x64 -debug" exited with code 1.

Build FAILED.

C:\Users\abc def\Documents\dotnet-runtime\src\coreclr\runtime.proj(37,5): error MSB3073: The command ""C:\Users\abc def\Documents\dotnet-runtime\src\coreclr\build-runtime.cmd" -x64 -debug" exited with code 1.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:50.88
Build failed.
Some builds failed:
        Configuration: Debug, Architecture: x64

After removing the line @if not defined _echo @echo off in build-runtime.cmd and running the file I get the same error but with more details.

PS C:\Users\abc def\Documents\dotnet-runtime2> .\src\coreclr\build-runtime.cmd -x64 -release -enforcegpo
C:\Users\abc def\Documents\dotnet-runtime2>setlocal EnableDelayedExpansion EnableExtensions
C:\Users\abc def\Documents\dotnet-runtime2>set "__MsgPrefix=BUILD: "
C:\Users\abc def\Documents\dotnet-runtime2>echo BUILD: Starting Build at 20:11:03.01
BUILD: Starting Build at 20:11:03.01
C:\Users\abc def\Documents\dotnet-runtime2>set __ThisScriptFull="C:\Users\abc def\Documents\dotnet-runtime2\src\coreclr\build-runtime.cmd"
C:\Users\abc def\Documents\dotnet-runtime2>set __ThisScriptDir="C:\Users\abc def\Documents\dotnet-runtime2\src\coreclr\"
C:\Users\abc def\Documents\dotnet-runtime2>call ""C:\Users\abc def\Documents\dotnet-runtime2\src\coreclr\""\setup_vs_tools.cmd
'""C:\Users\abc' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\abc def\Documents\dotnet-runtime2>if NOT '1' == '0' goto ExitWithError
C:\Users\abc def\Documents\dotnet-runtime2>exit /b 1

It seems like there is an issue with quotes at the line call ""C:\Users\abc def\Documents\dotnet-runtime2\src\coreclr\""\setup_vs_tools.cmd.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-Infrastructure-coreclr untriaged New issue has not been triaged by the area owner labels Sep 17, 2020
@danmoseley
Copy link
Member

I think these

set __ThisScriptFull="%~f0"
set __ThisScriptDir="%~dp0"

should probably not add quotes and instead the quotes should be applied where they are used
call "%__ThisScriptDir%"\setup_vs_tools.cmd

may help to copy its "DIA SDK" folder into "%VSINSTALLDIR%" manually, then try again.

Same in crossgen-corelib.cmd.

Can you try that and see how it works?

Building the repo when there's a space in the path breaks periodically because we dont have a test to protect it and apparently nobody that works on the repo day to day has this configuration.

@verdie-g
Copy link
Contributor Author

Adding some quotes at the right place allowed to execute few more lines without errors until the same issue happened again. I think quotes are missing at many places in the scripts and I don't feel comfortable doing the PR. It should be easy to reproduce by adding a space in the project folder though.

@danmoseley
Copy link
Member

Too bad thanks for trying. Realistically this is going to keep breaking regularly and probably not a high priority. Can you place the repo another location?

@verdie-g
Copy link
Contributor Author

Building the repo when there's a space in the path breaks periodically because we dont have a test to protect it

this is going to keep breaking regularly

Is having a test with a space in the path not possible?

Can you place the repo another location?

I have the student version of Windows 10 which forces $"{firstName} {lastName}" as a username so I'll move the folder to C: or maybe it's time to get a real license 👍

@danmoseley
Copy link
Member

We could modify one of our CI legs potentially (cc @safern) but it's probably not a priority because the workaround is pretty easy. I put my repo for example in C:\git\runtime

@verdie-g
Copy link
Contributor Author

the workaround is pretty easy. I put my repo for example in C:\git\runtime

After putting the repository in C:\dev\dotnet-runtime I get the same error. It seems like it's searching for files under my user folder.

CROSSGEN-CORELIB: Starting Build at 20:36:04.41
  CROSSGEN-CORELIB: Searching for Visual Studio installation
  CROSSGEN-CORELIB: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\Tools\VsDevCmd.bat"
  **********************************************************************
  ** Visual Studio 2019 Developer Command Prompt v16.8.0-pre.3.0
  ** Copyright (c) 2020 Microsoft Corporation
  **********************************************************************
  CROSSGEN-CORELIB: Using environment: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\Tools\\..\..\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
  **********************************************************************
  ** Visual Studio 2019 Developer Command Prompt v16.8.0-pre.3.0
  ** Copyright (c) 2020 Microsoft Corporation
  **********************************************************************
  [vcvarsall.bat] Environment initialized for: 'x86_x64'
  CROSSGEN-CORELIB: Generating native image of System.Private.CoreLib for Windows_NT.x64.Release. Logging to "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\log\CrossgenCoreLib_Windows_NT__x64__Release.log".
  "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.DiaSymReader.Native.amd64.dll"
  "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\Microsoft.DiaSymReader.Native.amd64.dll"
  CROSSGEN-CORELIB: "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release\crossgen.exe" /nologo  /Platform_Assemblies_Paths "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release\IL" /out "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release\System.Private.CoreLib.dll" "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release\IL\System.Private.CoreLib.dll"
  CROSSGEN-CORELIB: "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release\crossgen.exe" /nologo /Platform_Assemblies_Paths "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release" /CreatePdb "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release\PDB" "C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release\System.Private.CoreLib.dll"
  CROSSGEN-CORELIB: Crossgenning of System.Private.CoreLib succeeded.  Finished at 20:36:13.13
  CROSSGEN-CORELIB: Product binaries are available at C:\Dev\dotnet-runtime\src\coreclr\..\..\artifacts\bin\coreclr\Windows_NT.x64.Release
  ILCompiler.DependencyAnalysisFramework -> C:\Dev\dotnet-runtime\artifacts\bin\ILCompiler.DependencyAnalysisFramework\x64\Release\ILCompiler.DependencyAnalysisFramework.dll
  ILCompiler.TypeSystem.ReadyToRun -> C:\Dev\dotnet-runtime\artifacts\bin\ILCompiler.TypeSystem.ReadyToRun\x64\Release\ILCompiler.TypeSystem.ReadyToRun.dll
  ILCompiler.ReadyToRun -> C:\Dev\dotnet-runtime\artifacts\bin\ILCompiler.ReadyToRun\x64\Release\ILCompiler.ReadyToRun.dll
  crossgen2 -> C:\Dev\dotnet-runtime\artifacts\bin\coreclr\Windows_NT.x64.Release\crossgen2\crossgen2.dll
  CoreTestAssembly -> C:\Dev\dotnet-runtime\artifacts\bin\CoreTestAssembly\x64\Release\CoreTestAssembly.dll
  'C:\Users\abc' is not recognized as an internal or external command,
  operable program or batch file.
C:\Users\abc def\.nuget\packages\microsoft.net.sdk.il\5.0.0-preview.8.20359.4\targets\Microsoft.NET.Sdk.IL.targets(138,5): error MSB3073: The command "C:\Users\abc def\.nuget\packages\\runtime.win-x64.microsoft.netcore.ilasm\5.0.0-preview.8.20359.4\runtimes\win-x64\native/ilasm -QUIET -NOLOGO -OPTIMIZE -DLL  -OUTPUT="C:\Dev\dotnet-runtime\artifacts\obj\coreclr\ILTestAssembly\x64\Release\ILTestAssembly.dll"  Main.il ILDisassembler.il InstanceFieldLayout.il StaticFieldLayout.il VirtualFunctionOverride.il Signature.il MethodImplOverride1.il" exited with code 9009. [C:\Dev\dotnet-runtime\src\coreclr\src\tools\aot\ILCompiler.TypeSystem.ReadyToRun.Tests\ILTestAssembly\ILTestAssembly.ilproj]

Build FAILED.

C:\Users\abc def\.nuget\packages\microsoft.net.sdk.il\5.0.0-preview.8.20359.4\targets\Microsoft.NET.Sdk.IL.targets(138,5): error MSB3073: The command "C:\Users\abc def\.nuget\packages\\runtime.win-x64.microsoft.netcore.ilasm\5.0.0-preview.8.20359.4\runtimes\win-x64\native/ilasm -QUIET -NOLOGO -OPTIMIZE -DLL  -OUTPUT="C:\Dev\dotnet-runtime\artifacts\obj\coreclr\ILTestAssembly\x64\Release\ILTestAssembly.dll"  Main.il ILDisassembler.il InstanceFieldLayout.il StaticFieldLayout.il VirtualFunctionOverride.il Signature.il MethodImplOverride1.il" exited with code 9009. [C:\Dev\dotnet-runtime\src\coreclr\src\tools\aot\ILCompiler.TypeSystem.ReadyToRun.Tests\ILTestAssembly\ILTestAssembly.ilproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:10:32.52
Build failed.
Some builds failed:
        Configuration: Debug, Architecture: x64

@safern
Copy link
Member

safern commented Sep 22, 2020

It seems like we need to add quotes to usages of _ILasmDir:

<Exec Command="$(_IlasmDir)ilasm $(_IlasmSwitches) $(_OutputTypeArgument) $(IlasmFlags) -OUTPUT=&quot;@(IntermediateAssembly)&quot; $(_KeyFileArgument) @(Compile, ' ')">

and also to usages of _ILdasmDir:

<_IldasmCommand>$(_IldasmDir)ildasm</_IldasmCommand>

@trylek trylek added this to the 6.0.0 milestone Sep 22, 2020
@trylek trylek removed the untriaged New issue has not been triaged by the area owner label Sep 22, 2020
@trylek
Copy link
Member

trylek commented Sep 22, 2020

I suspect this will blow up in multiple places in the scripts as we're generally not too consistent about quoting everything. I'm adding this to the infra backlog project as it definitely merits fixing, it's just likely to have quite a bit of a bug tail.

@mangod9
Copy link
Member

mangod9 commented Sep 24, 2020

I have a partial fix I am validating here: #42671.

C:\With Space\runtime>build -subset clr+libs should now work if the targets fix is manually applied.

@danmoseley
Copy link
Member

I suspect this will blow up in multiple places in the scripts as we're generally not too consistent about quoting everything

This has come up and been fixed again a number of times. I suggest to either protect the next fix with CI or just document it doesn't work.

@trylek
Copy link
Member

trylek commented Sep 24, 2020

I agree we should introduce lab validation for the fix, I talked with Manish about it yesterday, it's just unclear to me right now how do to that as AFAIK both the AzDO build system and Helix use an internally hardcoded scheme for the root path (that naturally doesn't contain any whitespace). In the worst case we can create a dedicated pipeline that will manually copy over the cloned repo into a new path containing blanks. Speaking about which, we might want to expand this envisioned testing to other similar cases that also tend to cause trouble like paths containing accented letters and / or Chinese / Japanese Kanji symbols.

@mangod9
Copy link
Member

mangod9 commented Sep 24, 2020

not sure about the ROI of adding a dedicated pipeline for validating this, unless this has been raised very frequently.

@mangod9
Copy link
Member

mangod9 commented Sep 24, 2020

I wonder whether we could clone the repo to a folder with spaces for the build leg, say here:

git clone $(Pipeline.Workspace)/Checkout_bundle/Checkout.bundle .
?

@trylek
Copy link
Member

trylek commented Sep 24, 2020

By "dedicated pipeline" I didn't mean any heavyweight machinery, I think I rather wanted to point out that it probably doesn't make sense to add this to regular PR / CI pipeline as these are already "too complex"; so I would put this either to outerloop or to some "special obscurity tests" that should suffice to run once a week or so; not sure if we already have something like that (some of the stress tests run once a week but I don't think they are the ideal place for this).

Cloning the repo to a different location is certainly an option but I suspect it's relatively costly in terms of implementation as today all pipelines assume that $(Build.SourcesDirectory) is the repo root so that would need fixing globally. I guess it also depends on the envisioned scope of such testing i.o.w. whether we want just a simple canary run verifying that CoreCLR / mono / libraries build in such scenario or whether we want to e.g. build and run tests, possibly in varying configurations, in this case.

@mangod9
Copy link
Member

mangod9 commented Sep 24, 2020

ah, yeah some outerloop scenario would make sense.

@danmoseley
Copy link
Member

Do we need to fix this though? We could just update the build script (at the start, where we already validate some dependencies) to fail out with a helpful error if there's a space in the path, so folks can relocate their clone before they get very far. This assumes there aren't users who are in a locked down environment where they have to put their files under ...\Documents, though. If that turns out to be the case, then we could fix it then.

I don't have a preference myself, just pointing out the work (and ongoing CI maintenance) may not be the best use of time.

@verdie-g
Copy link
Contributor Author

similar cases that also tend to cause trouble like paths containing accented letters and / or Chinese / Japanese Kanji symbols

So, I've reinstalled my Windows but this time with only my first name as a username but unfortunately it contains a "é" which makes the build fail 😭

@trylek
Copy link
Member

trylek commented Sep 24, 2020

That's exactly the problem, I'm afraid people will continue hitting this. I think the CI cost is relatively low, at least w.r.t. validating that we can build CoreCLR+libraries in one configuration, with a bit of hand waving that should basically boil down to putting a modification of this line in some suitable pipeline (after the checkout to a non-default folder):

- script: $(Build.SourcesDirectory)$(dir)build$(scriptExt) -ci -arch ${{ parameters.archType }} $(_osParameter) ${{ parameters.buildArgs }} $(_officialBuildParameter) $(_crossBuildPropertyArg) $(_cxx11Parameter)

@danmoseley
Copy link
Member

Ah. I missed that it affects non-ASCII directories as well..

@mangod9
Copy link
Member

mangod9 commented Sep 25, 2020

I tried to validate my PR with a folder named With Spacé, but the c++ compiler complains about it
C:\With Spacé\runtime\artifacts\obj\coreclr\Windows_NT.x64.Debug\src\inc\idls_out\xcordebug_i.c(1,1): warning C4828: The file contains a character starting at offset 0x104 that is illegal in the current source character set (codepage 65001).

Believe this will require some CMAKE related changes, unless its just a machine config thing.

@mangod9
Copy link
Member

mangod9 commented Sep 25, 2020

This is since midl adds the full path to the idl as a comment in generated code which trips up the c++ compiler:

Running this

C:\With Spacé\runtime>midl /lcid 1036 "C:\With Spacé\runtimesrc\coreclr\src\inc\clrinternal.idl" -I "C:\With Spacé\runtime\src\coreclr\src\inc"

generates clrinternal.h with this (the lcid specified doesnt seem to have any effect on the output):

/* Compiler settings for C:\With Spac�\runtime\src\coreclr\src\inc\clrinternal.idl:
    Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.01.0622 
    protocol : dce , ms_ext, c_ext, robust
    error checks: allocation ref bounds_check enum stub_data 
    VC __declspec() decoration level: 
         __declspec(uuid()), __declspec(selectany), __declspec(novtable)
         DECLSPEC_UUID(), MIDL_INTERFACE()
*/

One potential workaround could be to specify a relative path to midl which would avoid the special chars in the full path but not sure if that is achievable in cmake.

@mangod9
Copy link
Member

mangod9 commented Sep 26, 2020

Ok getting closer. After a tip from @davidwrighton we were able to avoid the full file path from midl. After a similar fix to python eventpipe generator I am now able to build using build-runtime.cmd. For some reason build.cmd -> build-runtime.cmd transition is messing with the codepage configured using chcp. But this is now working:

1. C:\With Spacé\runtime>chcp 1250
2. C:\With Spacé\runtime>src\coreclr\build-runtime.cmd
3. C:\With Spacé\runtime>build -subset libs

So I propose to merge the PR, and I am also testing some changes in CI to build x86 with a non-standard folder.

@mangod9
Copy link
Member

mangod9 commented Sep 27, 2020

Ok, looks like this msbuild issue is probably causing the issue where current chcp is not honored: dotnet/msbuild#5724. But after enabling Beta: Use Unicode UTF-8 for worldwide language support in region settings I got something like this building

C:\_Àß©Déб\runtime>build.cmd
<--build-log skipped-->
Build succeeded.
    0 Warning(s)
    0 Error(s)

@verdie-g if you please try whether this PR: #42671 gets things working for you we can get that merged. Thx!

@verdie-g
Copy link
Contributor Author

I've reinstalled everything and got rid of any space or non-ascii character so I won't be able to test the PR sorry

@mangod9
Copy link
Member

mangod9 commented Sep 27, 2020

Ok no worries, will validate with a few variations and merge if that goes well.

@mangod9
Copy link
Member

mangod9 commented Sep 28, 2020

keeping this open so we can track the CI changes to ensure this doesnt regress, but that will have to wait for the il.targets to propagate to sdk and back.

@mangod9 mangod9 reopened this Sep 28, 2020
@lkempf
Copy link

lkempf commented Nov 11, 2020

I have found a regression of this issue. Executing ./build.cmd -subset clr -ninja fails when the build path contains spaces as of commit e8bba0b. This is caused by missing quotes in build-runtime.cmd around %__IntermediatesDir%.

There also is a problem with generating timestamps which I have not been able to pinpoint yet.

  FAILED: src/dlls/mscoree/coreclr/inject_debug_resources.timestamp
  src\dlls\mscoree\coreclr\CMakeFiles\inject_debug_resources.timestamp-7773978.bat 645c5eb38508e330
  Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29333 for x64
  Copyright (C) Microsoft Corporation.  All rights reserved.

  daccess.cpp
  'C:\Users\bla\Documents\Visual' is not recognized as an internal or external command,
  operable program or batch file.
  Batch file failed at line 4 with errorcode 1
  ninja: build stopped: subcommand failed.

@mangod9
Copy link
Member

mangod9 commented Nov 11, 2020

Hey @lkempf, thanks for reporting the issue. Would you like to submit a PR, assuming its a simple fix? Else will take a look later this week, we also plan to add verification for this within the CI.

@trylek
Copy link
Member

trylek commented Nov 11, 2020

FYI @jkoritzinsky

@lkempf
Copy link

lkempf commented Nov 11, 2020

I've created #44540 to fix the issue I could pinpoint.

@ViktorHofer
Copy link
Member

@mangod9 as you are assigned to the issue, do you know what's remaining here? CI protection or an infra fix?

@mangod9
Copy link
Member

mangod9 commented May 5, 2021

primarily CI protection, I had a fix made a few months ago, but there is a good possibility things have since regressed.

@ivdiazsa
Copy link
Member

This is still a thing in as noted in #73327. I wrote a deeper explanation here #73327 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

9 participants