Skip to content

Commit

Permalink
Correct handling of paths with spaces and ampersands when building on…
Browse files Browse the repository at this point in the history
… windows.

Fixes #178
  • Loading branch information
poizan42 committed Feb 11, 2015
1 parent 8deb2ba commit 832291f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 52 deletions.
70 changes: 36 additions & 34 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
@echo off
setlocal
setlocal EnableDelayedExpansion

:: Set the default arguments for build
set __BuildArch=x64
set __BuildType=debug

:: Set the various build properties here so that CMake and MSBuild can pick them up
set __ProjectDir=%~dp0
set __ProjectFilesDir=%~dp0
set __SourceDir=%__ProjectDir%\src
set __PackagesDir=%__SourceDir%\.nuget
set __RootBinDir=%__ProjectDir%\binaries
set __LogsDir=%__RootBinDir%\Logs
set __CMakeSlnDir=%__RootBinDir%\CMake
set "__ProjectDir=%~dp0"
:: remove trailing slash
if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
set "__ProjectFilesDir=%__ProjectDir%"
set "__SourceDir=%__ProjectDir%\src"
set "__PackagesDir=%__SourceDir%\.nuget"
set "__RootBinDir=%__ProjectDir%\binaries"
set "__LogsDir=%__RootBinDir%\Logs"
set "__CMakeSlnDir=%__RootBinDir%\CMake"
set __MSBCleanBuildArgs=

:Arg_Loop
Expand All @@ -36,18 +38,18 @@ echo Commencing CoreCLR Repo build
echo.

:: Set the remaining variables based upon the determined build configuration
set __BinDir=%__RootBinDir%\Product\%__BuildArch%\%__BuildType%
set __PackagesBinDir=%__BinDir%\.nuget
set __ToolsDir=%__RootBinDir%\tools
set __TestWorkingDir=%__RootBinDir%\tests\%__BuildArch%\%__BuildType%
set __IntermediatesDir=%__RootBinDir%\intermediates\%__BuildArch%\%__BuildType%
set "__BinDir=%__RootBinDir%\Product\%__BuildArch%\%__BuildType%"
set "__PackagesBinDir=%__BinDir%\.nuget"
set "__ToolsDir=%__RootBinDir%\tools"
set "__TestWorkingDir=%__RootBinDir%\tests\%__BuildArch%\%__BuildType%"
set "__IntermediatesDir=%__RootBinDir%\intermediates\%__BuildArch%\%__BuildType%"

:: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
set __CMakeBinDir=%__BinDir%
set "__CMakeBinDir=%__BinDir%"
set "__CMakeBinDir=%__CMakeBinDir:\=/%"

:: Switch to clean build mode if the binaries output folder does not exist
if not exist %__RootBinDir% set __CleanBuild=1
if not exist "%__RootBinDir%" set __CleanBuild=1

:: Configure environment if we are doing a clean build.
if not defined __CleanBuild goto CheckPrereqs
Expand All @@ -58,19 +60,19 @@ echo.
set __MSBCleanBuildArgs=/t:rebuild

:: Cleanup the binaries drop folder
if exist %__BinDir% rd /s /q %__BinDir%
md %__BinDir%
if exist "%__BinDir%" rd /s /q "%__BinDir%"
md "%__BinDir%"

:: Cleanup the CMake folder
if exist %__CMakeSlnDir% rd /s /q %__CMakeSlnDir%
md %__CMakeSlnDir%
if exist "%__CMakeSlnDir%" rd /s /q "%__CMakeSlnDir%"
md "%__CMakeSlnDir%"

:: Cleanup the logs folder
if exist %__LogsDir% rd /s /q %__LogsDir%
md %__LogsDir%
if exist "%__LogsDir%" rd /s /q "%__LogsDir%"
md "%__LogsDir%"

::Cleanup intermediates folder
if exist %__IntermediatesDir% rd /s /q %__IntermediatesDir%
if exist "%__IntermediatesDir%" rd /s /q "%__IntermediatesDir%"

:: Check prerequisites
:CheckPrereqs
Expand Down Expand Up @@ -126,21 +128,21 @@ goto :eof

:GenVSSolution
:: Regenerate the VS solution
pushd %__CMakeSlnDir%
call %__SourceDir%\pal\tools\gen-buildsys-win.bat %__ProjectDir%
pushd "%__CMakeSlnDir%"
call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%"
popd

:BuildComponents
if exist %__CMakeSlnDir%\install.vcxproj goto BuildCoreCLR
if exist "%__CMakeSlnDir%\install.vcxproj" goto BuildCoreCLR
echo Failed to generate native component build project!
goto :eof

REM Build CoreCLR
:BuildCoreCLR
set __CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildArch%__%__BuildType%.log
%_msbuildexe% %__CMakeSlnDir%\install.vcxproj %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% /fileloggerparameters:Verbosity=diag;LogFile="%__CoreCLRBuildLog%"
set "__CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildArch%__%__BuildType%.log"
%_msbuildexe% "%__CMakeSlnDir%\install.vcxproj" %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% /fileloggerparameters:Verbosity=diag;LogFile="%__CoreCLRBuildLog%"
IF NOT ERRORLEVEL 1 goto PerformMScorlibBuild
echo Native component build failed. Refer %__CoreCLRBuildLog% for details.
echo Native component build failed. Refer !__CoreCLRBuildLog! for details.
goto :eof

:PerformMScorlibBuild
Expand All @@ -157,14 +159,14 @@ if defined __UnixMscorlibOnly set __AdditionalMSBuildArgs=/p:OS=Unix /p:BuildNug
call "%VS120COMNTOOLS%\VsDevCmd.bat"
echo Commencing build of mscorlib for %__BuildArch%/%__BuildType%
echo.
set __MScorlibBuildLog=%__LogsDir%\MScorlib_%__BuildArch%__%__BuildType%.log
%_msbuildexe% "%__ProjectFilesDir%build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__MScorlibBuildLog%" %__AdditionalMSBuildArgs%
set "__MScorlibBuildLog=%__LogsDir%\MScorlib_%__BuildArch%__%__BuildType%.log"
%_msbuildexe% "%__ProjectFilesDir%\build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__MScorlibBuildLog%" %__AdditionalMSBuildArgs%
IF NOT ERRORLEVEL 1 (
if defined __UnixMscorlibOnly goto :eof
goto PerformTestBuild
)

echo MScorlib build failed. Refer %__MScorlibBuildLog% for details.
echo MScorlib build failed. Refer !__MScorlibBuildLog! for details.
goto :eof

:PerformTestBuild
Expand All @@ -173,15 +175,15 @@ echo Commencing build of tests for %__BuildArch%/%__BuildType%
echo.
call tests\buildtest.cmd
IF NOT ERRORLEVEL 1 goto SuccessfulBuild
echo Test binaries build failed. Refer %__MScorlibBuildLog% for details.
echo Test binaries build failed. Refer !__MScorlibBuildLog! for details.
goto :eof

:SuccessfulBuild
::Build complete
echo Repo successfully built.
echo.
echo Product binaries are available at %__BinDir%
echo Test binaries are available at %__TestWorkingDir%
echo Product binaries are available at !__BinDir!
echo Test binaries are available at !__TestWorkingDir!
goto :eof

:Usage
Expand Down
2 changes: 1 addition & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<Target Name="BuildNuGetPackages" AfterTargets="Build" Condition="'$(BuildNugetPackage)' != 'false'">
<MakeDir Directories="$(PackagesBinDir)" Condition="!Exists('$(PackagesBinDir)')" />
<Copy SourceFiles="@(NuSpecSrcs)" DestinationFolder="$(PackagesBinDir)" />
<Exec Command="$(NuGetToolPath) pack &quot;%(NuSpecs.Identity)&quot; -NoPackageAnalysis -NoDefaultExcludes -OutputDirectory &quot;$(PackagesBinDir)&quot;" />
<Exec Command="&quot;$(NuGetToolPath)&quot; pack &quot;%(NuSpecs.Identity)&quot; -NoPackageAnalysis -NoDefaultExcludes -OutputDirectory &quot;$(PackagesBinDir)&quot;" />
</Target>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/mscorlib/GenerateSplitStringResources.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Internal_ResGenDefines Include="%(SplitTextStringResource.ResGenDefines)" />
</ItemGroup>

<Exec Command="&quot;$(ResGenCommand)&quot; %(SplitTextStringResource.Identity) $(IntermediateOutputPath)%(SplitTextStringResource.Filename).resources /D:INCLUDE_DEBUG /D:INCLUDE_RUNTIME @(Internal_ResGenDefines->'/D:%(Identity)', ' ')" />
<Exec Command="&quot;$(ResGenCommand)&quot; &quot;%(SplitTextStringResource.Identity)&quot; &quot;$(IntermediateOutputPath)%(SplitTextStringResource.Filename).resources&quot; /D:INCLUDE_DEBUG /D:INCLUDE_RUNTIME @(Internal_ResGenDefines->'/D:%(Identity)', ' ')" />

<ItemGroup>
<EmbeddedResource Include="@(SplitTextStringResource->'$(IntermediateOutputPath)%(Filename).resources')">
Expand Down
2 changes: 1 addition & 1 deletion src/mscorlib/Tools/BclRewriter/BclRewriter.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Target Name="RewriteWithBclRewriter"
Inputs="@(AnnotatedAssembly)" Outputs="@(RewrittenAssembly)">

<Exec Command="$(BclRewriterCommand) @(AnnotatedAssembly) /out:$(BclRewriterOutput) /include:$(BclRewriterModelFile) /platform:win /architecture:$(Platform) /flavor:$(_BuildType) /define:$(DefineConstants) /keepTempFiles+" StandardOutputImportance="Normal" />
<Exec Command="&quot;$(BclRewriterCommand)&quot; &quot;@(AnnotatedAssembly)&quot; &quot;/out:$(BclRewriterOutput)&quot; &quot;/include:$(BclRewriterModelFile)&quot; /platform:win /architecture:$(Platform) /flavor:$(_BuildType) /define:$(DefineConstants) /keepTempFiles+" StandardOutputImportance="Normal" />

<!-- Update the location of the symbol file-->
<PropertyGroup>
Expand Down
12 changes: 9 additions & 3 deletions src/pal/tools/gen-buildsys-win.bat
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
@echo off
rem
rem This file invokes cmake and generates the build system for windows.

echo off

set argC=0
for %%x in (%*) do Set /A argC+=1

if NOT %argC%==1 GOTO :USAGE
if %1=="/?" GOTO :USAGE

cmake -DCMAKE_USER_MAKE_RULES_OVERRIDE=%1\src\pal\tools\windows-compiler-override.txt -G "Visual Studio 12 2013 Win64" %1
setlocal
set basePath=%1
:: remove quotes
set "basePath=%basePath:"=%"
:: remove trailing slash
if %basePath:~-1%==\ set "basePath=%basePath:~0,-1%"
cmake "-DCMAKE_USER_MAKE_RULES_OVERRIDE=%basePath%\src\pal\tools\windows-compiler-override.txt" -G "Visual Studio 12 2013 Win64" %1
endlocal
GOTO :DONE

:USAGE
Expand Down
4 changes: 2 additions & 2 deletions src/vm/wks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ endif()
add_custom_command(
# The AsmConstants.inc will be built in the pre-build phase of the cee_wks build
TARGET cee_wks PRE_BUILD
COMMAND ${POWERSHELL} -NoProfile -ExecutionPolicy Bypass ${VM_DIR}/h2inc.ps1 ${VM_DIR}/amd64/asmconstants.h >${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp
COMMAND ${CMAKE_CXX_COMPILER} ${DEFINITIONS} /EP ${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp >${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc
COMMAND ${POWERSHELL} -NoProfile -ExecutionPolicy Bypass \"& \"\"${VM_DIR}/h2inc.ps1\"\"\" \"\"\"${VM_DIR}/amd64/asmconstants.h\"\"\" >"${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp"
COMMAND ${CMAKE_CXX_COMPILER} ${DEFINITIONS} /EP "${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.tmp" >"${CMAKE_CURRENT_BINARY_DIR}/AsmConstants.inc"
)

endif (WIN32)
20 changes: 10 additions & 10 deletions tests/buildtest.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
setlocal
setlocal EnableDelayedExpansion

set __ProjectFilesDir=%~dp0
set "__ProjectFilesDir=%~dp0"
:Arg_Loop
if "%1" == "" goto ArgsDone
if /i "%1" == "x64" (set __BuildArch=x64&shift&goto Arg_Loop)
Expand All @@ -19,16 +19,16 @@ goto Usage

if not defined __BuildArch set __BuildArch=x64
if not defined __BuildType set __BuildType=debug
if not defined __TestWorkingDir set __TestWorkingDir=%__ProjectFilesDir%\..\binaries\tests\%__BuildArch%\%__BuildType%
if not defined __TestWorkingDir set "__TestWorkingDir=%__ProjectFilesDir%\..\binaries\tests\%__BuildArch%\%__BuildType%"

if not defined __LogsDir set __LogsDir=%__ProjectFilesDir%..\binaries\Logs
if not defined __LogsDir set "__LogsDir=%__ProjectFilesDir%..\binaries\Logs"

set __TestBuildLog=%__LogsDir%\Tests_%__BuildArch%__%__BuildType%.log
set __XunitWrapperBuildLog=%__LogsDir%\Tests_XunitWrapper_%__BuildArch%__%__BuildType%.log
set "__TestBuildLog=%__LogsDir%\Tests_%__BuildArch%__%__BuildType%.log"
set "__XunitWrapperBuildLog=%__LogsDir%\Tests_XunitWrapper_%__BuildArch%__%__BuildType%.log"

:: Switch to clean build mode if the binaries output folder does not exist
if not exist %__TestWorkingDir% set __CleanBuild=1
if not exist %__LogsDir% md %__LogsDir%
if not exist "%__TestWorkingDir%" set __CleanBuild=1
if not exist "%__LogsDir%" md "%__LogsDir%"

:: Configure environment if we are doing a clean build.
if not defined __CleanBuild goto CheckPrereqs
Expand All @@ -39,7 +39,7 @@ echo.
set __MSBCleanBuildArgs=/t:rebuild

:: Cleanup the binaries drop folder
if exist %__TestWorkingDir% rd /s /q %__TestWorkingDir%
if exist "%__TestWorkingDir%" rd /s /q "%__TestWorkingDir%"


:: Note: We've disabled node reuse because it causes file locking issues.
Expand Down Expand Up @@ -87,7 +87,7 @@ goto :eof
:build

%_buildprefix% %_msbuildexe% "%__ProjectFilesDir%build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=diag;LogFile="%__TestBuildLog%";Append %* %_buildpostfix%
IF ERRORLEVEL 1 echo Test build failed. Refer %__TestBuildLog% for details && exit /b 1
IF ERRORLEVEL 1 echo Test build failed. Refer !__TestBuildLog! for details && exit /b 1



Expand Down

0 comments on commit 832291f

Please sign in to comment.