@echo off
setlocal enabledelayedexpansion

rem ================================================================================
rem Virtio-win master build script
rem
rem Usage: build.bat <project_or_solution_file_path> <target_os_versions> [<args>]
rem
rem where args can be one or more of
rem   Debug, dbg, chk       .. to build Debug rather than the default release flavor
rem   amd64, x64, 64        .. to build only 64-bit driver
rem   x86, 32               .. to build only 32-bit driver
rem   /Option               .. build command to pass to VS, for example /Rebuild
rem   Win7, Win8, Win10..   .. target OS version
rem
rem By default the script performs an incremental build of both 32-bit and 64-bit
rem release drivers for all supported target OSes.
rem
rem To do a Static Driver Verifier build, append _SDV to the target OS version, for
rem example Win10_SDV.
rem ================================================================================

rem This is a list of supported build target specifications A_B where A is the
rem VS project configuration name and B is the corresponding platform identifier
rem used in log file names and intermediate directory names. Either of the two can
rem be used in the <target_os_version> command line argument.
set SUPPORTED_BUILD_SPECS=Win8_win8 Win8.1_win81 Win10_win10

set BUILD_TARGETS=%~2
set BUILD_DIR=%~dp1
set BUILD_FILE=%~nx1
set BUILD_NAME=%~n1

rem We do an incremental Release build for all specs and all archs by default
set BUILD_FLAVOR=Release
set BUILD_COMMAND=/Build
set BUILD_SPEC=
set BUILD_ARCH=
set BUILD_FAILED=

rem Parse arguments
:argloop
shift /2
if "%2"=="" goto argend
set ARG=%2
if "%ARG:~0,1%"=="/" set BUILD_COMMAND=%ARG%& goto :argloop

if /I "%ARG%"=="Debug" set BUILD_FLAVOR=Debug& goto :argloop
if /I "%ARG%"=="dbg" set BUILD_FLAVOR=Debug& goto :argloop
if /I "%ARG%"=="chk" set BUILD_FLAVOR=Debug& goto :argloop

if /I "%ARG%"=="amd64" set BUILD_ARCH=amd64& goto :argloop
if /I "%ARG%"=="64" set BUILD_ARCH=amd64& goto :argloop
if /I "%ARG%"=="x64" set BUILD_ARCH=amd64& goto :argloop
if /I "%ARG%"=="32" set BUILD_ARCH=x86& goto :argloop
if /I "%ARG%"=="x86" set BUILD_ARCH=x86& goto :argloop
if /I "%ARG%"=="ARM64" set BUILD_ARCH=ARM64& goto :argloop

rem Assume that this is target OS version and split off the tag
call :split_target_tag "%ARG%"

rem Verify that this target OS is supported and valid
for %%N in (%SUPPORTED_BUILD_SPECS%) do (
  set T=%%N
  set CANDIDATE_SPEC=
  set FOUND_MATCH=

  for %%A in ("!T:_=" "!") do (
    if /I %%A=="%TARGET%" set CANDIDATE_SPEC=!T!!TAG!
    for %%B in (%BUILD_TARGETS%) do (
      if /I %%B==%%~A!TAG! set FOUND_MATCH=1
    )
  )

  if not "!FOUND_MATCH!"=="" if not "!CANDIDATE_SPEC!"=="" (
    set BUILD_SPEC=!CANDIDATE_SPEC!
    goto :argloop
  )
)

rem Silently exit if the build target could not be matched
rem
rem The reason for ignoring build target mismatch are projects
rem like NetKVM, viostor, and vioscsi, which build different
rem sln/vcxproj for different targets. Higher level script
rem does not have information about specific sln/vcproj and
rem platform bindings, therefore it invokes this script once
rem for each sln/vcproj to make it decide when the actual build
rem should be invoked.

goto :eof

rem Figure out which targets we're building
:argend
if "%BUILD_SPEC%"=="" (
  for %%B in (%BUILD_TARGETS%) do (
    call :split_target_tag "%%B"
    for %%N in (%SUPPORTED_BUILD_SPECS%) do (
      set T=%%N
      set BUILD_SPEC=
      for %%A in ("!T:_=" "!") do (
        if /I %%A=="!TARGET!" set BUILD_SPEC=!T!!TAG!
      )
      if not "!BUILD_SPEC!"=="" (
        call :build_target !BUILD_SPEC!
        if not "!BUILD_FAILED!"=="" goto :fail
      )
    )
  )
) else (
  call :build_target %BUILD_SPEC%
)
goto :eof

rem Figure out which archs we're building
:build_target
if "%BUILD_ARCH%"=="" (
  call :build_arch %1 x86
  if not "!BUILD_FAILED!"=="" goto :eof
  call :build_arch %1 amd64
) else (
  call :build_arch %1 %BUILD_ARCH%
)
goto :eof

rem Invoke Visual Studio
:build_arch
setlocal
set BUILD_ARCH=%2
set TAG=
for /f "tokens=1 delims=_" %%T in ("%1") do (
  set TARGET_PROJ_CONFIG=%%T
)
for /f "tokens=2 delims=_" %%T in ("%1") do (
  set TARGET_PLATFORM=%%T
)
for /f "tokens=3 delims=_" %%T in ("%1") do (
  set TAG=%%T
)

if /I "!TAG!"=="SDV" (
  rem There is no 32-bit SDV build
  if %BUILD_ARCH%==x86 goto :eof
  rem Check the SDV build suppression variable
  if not "%_BUILD_DISABLE_SDV%"=="" (
    echo Skipping %TARGET_PROJ_CONFIG% SDV build because _BUILD_DISABLE_SDV is set
    goto :eof
  )
)

rem Compose build log file name
if %BUILD_FLAVOR%=="Debug" (
  set BUILD_LOG_FILE=buildchk
) else (
  set BUILD_LOG_FILE=buildfre
)
set BUILD_LOG_FILE=%BUILD_LOG_FILE%_%TARGET_PLATFORM%_%BUILD_ARCH%.log

if %BUILD_ARCH%==amd64 set BUILD_ARCH=x64
set TARGET_VS_CONFIG="%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%|%BUILD_ARCH%"

pushd %BUILD_DIR%
call "%~dp0\SetVsEnv.bat" x86

if /I "!TAG!"=="SDV" (
  echo Running SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
  call :runsdv "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
  if exist "%CODEQL_BIN%" (
    if "%TARGET_PROJ_CONFIG%"=="Win10" (
      echo Running CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
      call :runql "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
    ) else (
      echo Skipping CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
    )
  ) else (
      echo CodeQL binary is missing!
  )
  call :runca "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
  call :rundvl "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
) else (
  echo Building %BUILD_FILE%, configuration %TARGET_VS_CONFIG%, command %BUILD_COMMAND%
  call :runbuild "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
)
popd
endlocal

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)
goto :eof

:runbuild:
:: %1 - configuration (as "Win10 Release")
:: %2 - platform      (as x64)
:: %3 - build command (as "/Build")
set __TARGET__=%BUILD_COMMAND:/=%
::(n)ormal(d)etailed,(disg)nostic
set __VERBOSITY__=n
msbuild.exe %BUILD_FILE% /t:%__TARGET__% /p:Configuration="%~1" /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__%;LogFile=%BUILD_LOG_FILE%
goto :eof

:runsdv
msbuild.exe %BUILD_FILE% /t:clean /p:Configuration="%~1" /P:Platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

msbuild.exe %BUILD_FILE% /t:sdv /p:inputs="/clean" /p:Configuration="%~1" /P:platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

msbuild.exe %BUILD_FILE% /t:sdv /p:inputs="/check /devenv" /p:Configuration="%~1" /P:platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:runql

echo "Removing previously created rules database"
rmdir /s/q codeql_db

echo call "%~dp0\SetVsEnv.bat" x86 > %~dp1\codeql.build.bat
echo msbuild.exe %~dp1\%BUILD_FILE% /t:rebuild /p:Configuration="%~1" /P:Platform=%2 >> %~dp1\codeql.build.bat

call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c "%~dp1\codeql.build.bat" %~dp1\codeql_db -j 0

IF ERRORLEVEL 1 (
  set CODEQL_FAILED=1
  set BUILD_FAILED=1
)

IF "%CODEQL_FAILED%" NEQ "1" (
  call %CODEQL_BIN% database analyze %~dp1\codeql_db windows_driver_recommended.qls --format=sarifv2.1.0 --output=%~dp1\%BUILD_NAME%.sarif -j 0
)

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:runca
msbuild.exe %BUILD_FILE% /p:Configuration="%~1" /P:Platform=%2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile=%~dp1\%BUILD_NAME%.CodeAnalysis.log

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:rundvl
msbuild.exe %BUILD_FILE% /t:dvl /p:Configuration="%~1" /P:platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:split_target_tag
set TARGET=
set TAG=
for /f "tokens=1 delims=_" %%T in (%1) do (
    set TARGET=%%T
)
for /f "tokens=2 delims=_" %%T in (%1) do (
    set TAG=_%%T
)
goto :eof

:fail

exit /B 1

@echo off
setlocal enabledelayedexpansion

rem ================================================================================
rem Virtio-win master build script
rem
rem Usage: build.bat <project_or_solution_file_path> <target_os_versions> [<args>]
rem
rem where args can be one or more of
rem   Debug, dbg, chk       .. to build Debug rather than the default release flavor
rem   amd64, x64, 64        .. to build only 64-bit driver
rem   x86, 32               .. to build only 32-bit driver
rem   /Option               .. build command to pass to VS, for example /Rebuild
rem   Win8, Win8.1, Win10   .. target OS version
rem
rem By default the script performs an incremental build of both 32-bit and 64-bit
rem release drivers for all supported target OSes.
rem
rem To do a Static Driver Verifier build, append _SDV to the target OS version, for
rem example Win10_SDV.
rem ================================================================================

rem This is a list of supported build target specifications A_B where A is the
rem VS project configuration name and B is the corresponding platform identifier
rem used in log file names and intermediate directory names. Either of the two can
rem be used in the <target_os_version> command line argument.
set SUPPORTED_BUILD_SPECS=Win8_win8 Win8.1_win81 Win10_win10

set BUILD_TARGETS=%~2
set BUILD_DIR=%~dp1
set BUILD_FILE=%~nx1
set BUILD_NAME=%~n1

rem We do an incremental Release build for all specs and all archs by default
set BUILD_FLAVOR=Release
set BUILD_COMMAND=/Build
set BUILD_SPEC=
set BUILD_ARCH=
set BUILD_FAILED=

rem Parse arguments
:argloop
shift /2
if "%2"=="" goto argend
set ARG=%2
if "%ARG:~0,1%"=="/" set BUILD_COMMAND=%ARG%& goto :argloop

if /I "%ARG%"=="Debug" set BUILD_FLAVOR=Debug& goto :argloop
if /I "%ARG%"=="dbg" set BUILD_FLAVOR=Debug& goto :argloop
if /I "%ARG%"=="chk" set BUILD_FLAVOR=Debug& goto :argloop

if /I "%ARG%"=="amd64" set BUILD_ARCH=amd64& goto :argloop
if /I "%ARG%"=="64" set BUILD_ARCH=amd64& goto :argloop
if /I "%ARG%"=="x64" set BUILD_ARCH=amd64& goto :argloop
if /I "%ARG%"=="32" set BUILD_ARCH=x86& goto :argloop
if /I "%ARG%"=="x86" set BUILD_ARCH=x86& goto :argloop
if /I "%ARG%"=="ARM64" set BUILD_ARCH=ARM64& goto :argloop

rem Assume that this is target OS version and split off the tag
call :split_target_tag "%ARG%"

rem Verify that this target OS is supported and valid
for %%N in (%SUPPORTED_BUILD_SPECS%) do (
  set T=%%N
  set CANDIDATE_SPEC=
  set FOUND_MATCH=

  for %%A in ("!T:_=" "!") do (
    if /I %%A=="%TARGET%" set CANDIDATE_SPEC=!T!!TAG!
    for %%B in (%BUILD_TARGETS%) do (
      if /I %%B==%%~A!TAG! set FOUND_MATCH=1
    )
  )

  if not "!FOUND_MATCH!"=="" if not "!CANDIDATE_SPEC!"=="" (
    set BUILD_SPEC=!CANDIDATE_SPEC!
    goto :argloop
  )
)

rem Silently exit if the build target could not be matched
rem
rem The reason for ignoring build target mismatch are projects
rem like NetKVM, viostor, and vioscsi, which build different
rem sln/vcxproj for different targets. Higher level script
rem does not have information about specific sln/vcproj and
rem platform bindings, therefore it invokes this script once
rem for each sln/vcproj to make it decide when the actual build
rem should be invoked.

goto :eof

rem Figure out which targets we're building
:argend
if "%BUILD_SPEC%"=="" (
  for %%B in (%BUILD_TARGETS%) do (
    call :split_target_tag "%%B"
    for %%N in (%SUPPORTED_BUILD_SPECS%) do (
      set T=%%N
      set BUILD_SPEC=
      for %%A in ("!T:_=" "!") do (
        if /I %%A=="!TARGET!" set BUILD_SPEC=!T!!TAG!
      )
      if not "!BUILD_SPEC!"=="" (
        call :build_target !BUILD_SPEC!
        if not "!BUILD_FAILED!"=="" goto :fail
      )
    )
  )
) else (
  call :build_target %BUILD_SPEC%
)
goto :eof

rem Figure out which archs we're building
:build_target
if "%BUILD_ARCH%"=="" (
  call :build_arch %1 x86
  if not "!BUILD_FAILED!"=="" goto :eof
  call :build_arch %1 amd64
) else (
  call :build_arch %1 %BUILD_ARCH%
)
goto :eof

rem Invoke Visual Studio
:build_arch
setlocal
set BUILD_ARCH=%2
set TAG=
for /f "tokens=1 delims=_" %%T in ("%1") do (
  set TARGET_PROJ_CONFIG=%%T
)
for /f "tokens=2 delims=_" %%T in ("%1") do (
  set TARGET_PLATFORM=%%T
)
for /f "tokens=3 delims=_" %%T in ("%1") do (
  set TAG=%%T
)

if /I "!TAG!"=="SDV" (
  rem There is no 32-bit SDV build
  if %BUILD_ARCH%==x86 goto :eof
  rem Check the SDV build suppression variable
  if not "%_BUILD_DISABLE_SDV%"=="" (
    echo Skipping %TARGET_PROJ_CONFIG% SDV build because _BUILD_DISABLE_SDV is set
    goto :eof
  )
)

rem Compose build log file name
if %BUILD_FLAVOR%=="Debug" (
  set BUILD_LOG_FILE=buildchk
) else (
  set BUILD_LOG_FILE=buildfre
)
set BUILD_LOG_FILE=%BUILD_LOG_FILE%_%TARGET_PLATFORM%_%BUILD_ARCH%.log

if %BUILD_ARCH%==amd64 set BUILD_ARCH=x64
set TARGET_VS_CONFIG="%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%|%BUILD_ARCH%"

pushd %BUILD_DIR%
call "%~dp0\SetVsEnv.bat" x86

if /I "!TAG!"=="SDV" (
  echo Running SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
  call :runsdv "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
  if exist "%CODEQL_BIN%" (
    if "%TARGET_PROJ_CONFIG%"=="Win10" (
      echo Running CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
      call :runql "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
    ) else (
      echo Skipping CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
    )
  ) else (
      echo CodeQL binary is missing!
  )
  call :runca "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
  call :rundvl "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
) else (
  echo Building %BUILD_FILE%, configuration %TARGET_VS_CONFIG%, command %BUILD_COMMAND%
  call :runbuild "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
)
popd
endlocal

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)
goto :eof

:runbuild:
:: %1 - configuration (as "Win10 Release")
:: %2 - platform      (as x64)
:: %3 - build command (as "/Build")
set __TARGET__=%BUILD_COMMAND:/=%
::(n)ormal(d)etailed,(disg)nostic
set __VERBOSITY__=n
msbuild.exe -maxCpuCount %BUILD_FILE% /t:%__TARGET__% /p:Configuration="%~1" /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__%;LogFile=%BUILD_LOG_FILE%
goto :eof

:runsdv
msbuild.exe -maxCpuCount %BUILD_FILE% /t:clean /p:Configuration="%~1" /P:Platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/clean" /p:Configuration="%~1" /P:platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/check /devenv" /p:Configuration="%~1" /P:platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:runql

echo "Removing previously created rules database"
rmdir /s/q codeql_db

echo call "%~dp0\SetVsEnv.bat" x86 > %~dp1\codeql.build.bat
echo msbuild.exe -maxCpuCount %~dp1\%BUILD_FILE% /t:rebuild /p:Configuration="%~1" /P:Platform=%2 >> %~dp1\codeql.build.bat

call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c "%~dp1\codeql.build.bat" %~dp1\codeql_db -j 0

IF ERRORLEVEL 1 (
  set CODEQL_FAILED=1
  set BUILD_FAILED=1
)

IF "%CODEQL_FAILED%" NEQ "1" (
  call %CODEQL_BIN% database analyze %~dp1\codeql_db windows_driver_recommended.qls --format=sarifv2.1.0 --output=%~dp1\%BUILD_NAME%.sarif -j 0
)

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:runca
msbuild.exe -maxCpuCount %BUILD_FILE% /p:Configuration="%~1" /P:Platform=%2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile=%~dp1\%BUILD_NAME%.CodeAnalysis.log

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:rundvl
msbuild.exe -maxCpuCount %BUILD_FILE% /t:dvl /p:Configuration="%~1" /P:platform=%2

IF ERRORLEVEL 1 (
  set BUILD_FAILED=1
)

goto :eof

:split_target_tag
set TARGET=
set TAG=
for /f "tokens=1 delims=_" %%T in (%1) do (
    set TARGET=%%T
)
for /f "tokens=2 delims=_" %%T in (%1) do (
    set TAG=_%%T
)
goto :eof

:fail

exit /B 1

enable msbuild maxCpuCount

build: enable msbuild maxCpuCount

build.bat will build the entire solution set one by one, which is single
threaded. On multi-processor builders in a CI/CD system, this is a bit
sluggish.

Enable msbuild -maxCpuCount on all msbuild commands, which will parallelize
msbuild actions where possible.

On an Azure Standard_DS2_v2 (i.e. a 2 vcpu builder) this change reduces
build_AllNoSdv.bat time from 12 min to 8 min.

Also, fix minor nit in top of file comments to reflect supported build targets,
which removes Win7, adds Win8.1.

Signed-off-by: Jon Kohler <44f878afe53efc66b76772bd845eb65944ed8232@nutanix.com>


SET NUNITRUNNER=%USERPROFILE%\.nuget\packages\nunit.consolerunner\3.11.1\tools\nunit3-console.exe
SET COVERALLS=%USERPROFILE%\.nuget\packages\coveralls.net\tools
SET OPENCOVER=%USERPROFILE%\.nuget\packages\opencover\4.7.922\tools

regsvr32 %OPENCOVER%\OpenCover.Profiler.dll

%OPENCOVER%\OpenCover.Console.exe -filter:"+[MimeKit]* -[UnitTests]* -[submodules]* -[Mono.Data.Sqlite]*" -target:"%NUNITRUNNER%" -targetargs:"/domain:single UnitTests\bin\Debug\UnitTests.dll" -output:opencover.xml

%COVERALLS%\csmacnz.Coveralls.exe --opencover -i opencover.xml --repoToken %COVERALLS_REPO_TOKEN% --useRelativePaths --basePath .\UnitTests\bin\Debug --commitId %APPVEYOR_REPO_COMMIT% --commitBranch %APPVEYOR_REPO_BRANCH% --commitAuthor %APPVEYOR_REPO_COMMIT_AUTHOR% --commitEmail %APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL% --commitMessage %APPVEYOR_REPO_COMMIT_MESSAGE% --jobId %APPVEYOR_BUILD_NUMBER% --serviceName appveyor

SET NUNITRUNNER=%USERPROFILE%\.nuget\packages\nunit.consolerunner\3.11.1\tools\nunit3-console.exe
SET COVERALLS=%USERPROFILE%\.nuget\packages\coveralls.net\0.7.0\tools
SET OPENCOVER=%USERPROFILE%\.nuget\packages\opencover\4.7.922\tools
SET OUTPUTDIR=UnitTests\bin\Debug\net48

%OPENCOVER%\OpenCover.Console.exe -filter:"+[MimeKit]* -[UnitTests]* -[submodules]* -[Mono.Data.Sqlite]*" -target:"%NUNITRUNNER%" -targetargs:"/domain:single %OUTPUTDIR%\UnitTests.dll" -output:opencover.xml

%COVERALLS%\csmacnz.Coveralls.exe --opencover -i opencover.xml --repoToken %COVERALLS_REPO_TOKEN% --useRelativePaths --basePath %OUTPUTDIR% --commitId %APPVEYOR_REPO_COMMIT% --commitBranch %APPVEYOR_REPO_BRANCH% --commitAuthor %APPVEYOR_REPO_COMMIT_AUTHOR% --commitEmail %APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL% --commitMessage %APPVEYOR_REPO_COMMIT_MESSAGE% --jobId %APPVEYOR_BUILD_NUMBER% --serviceName appveyor

Update appveyor.bat

Update appveyor.bat


Make run_webkit_test.bat workable even if we execute it
on a directory other than webkit\tools\layout_tests\.

%~dp0 means Drive name + Path name of the 0th argument (the bat file).

Original patch by tkent@google.com.
See http://codereview.chromium.org/113389
r=ojan

TEST=None
BUG=None

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@16838 0039d316-1c4b-4281-b951-d872f2087c98


@echo off

rem This will make my life easier while converting to Batch
set dirname=%CD%
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"
set project=Porekit

GOTO :begin

:pore_help
    echo Usage^: %0 ^<command^>
    echo Available commands^:
	echo.
    echo   help - Show this help page.
    echo   update - Update the submodules and apply the Porekit patches.
    echo   patches - Rebuild the Porekit patches.
GOTO :EOF

:apply_patches
    rem Based on https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse/applyPatches.sh#7
    set source=%1
    for /F %%i in ("%source%") do set repo=%%~ni
    set target=%2
    set patchdir=%3
    if !"%4"==""! (
	    set branch="%4"
	)
	if "%4"=="" (
		set branch="origin/master"
	)

    cd "%dirname%\%source%"
    git reset --hard "%branch%" > NUL
    git branch -f upstream > NUL

    cd "%dirname%"
    if not exist "%dirname%\%target%" ( git clone "%source%" "%target%" -b upstream )

    cd "%dirname%\%target%"

    echo ^>^> Resetting %target% to %repo%...
    git remote rm upstream > NUL 2>&1
    git remote add upstream "..\%source%" > NUL 2>&1
    git checkout master > NUL 2>&1
    git fetch upstream > NUL 2>&1
    git reset --hard upstream/upstream

    echo ^>^> Applying patches to %target%...
    git am --abort > NUL 2>&1
	set files=

	for /f %%i in ('dir /b "%dirname%\%patchdir%\*.patch"') do call :add_file %dirname%\%patchdir%\%%i
    git am --3way %files% || echo ^>^> Failed to apply patches to %target% ^(from %source%^)

    echo ^>^> Successfully applied patches to %repo%
GOTO :EOF

:pore_update
    echo ^> Updating submodules...
    git submodule update --init
    echo ^> Updating %project%...
    call :apply_patches lib\Bukkit %project% patches
GOTO :EOF

:clean_patches
    rem Based on https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse/rebuildPatches.sh#7
	setlocal enableDelayedExpansion
    for /r %%p in (%1\*.patch) do (
		for /f "delims=" %%c in (%%p) do (
			if !%%c==""! (
				set gitver=%%c
			)
		)
        for /f %%i in ('git diff --staged %%p ^| findstr /R "^(\+^|\-)" ^| findstr /R /V "(From [a-z0-9]{32,}^|\-\-\- a^|\+\+\+ b^|.index)"') do set diffs=%%i
		for /f %%i in ('call :tail "%diffs%" 2 ^| findstr /R /V "^$"') do set tmpStore=%%i
		for /f %%i in ('call :tail "%tmpStore%" 1 ^| findstr "%gitver%"') do set testver=%%i
        if !"x%testver%"=="x"! (
            for /f %%i in ('call :head "%diffs%" 2') do set diffs=%%i
        )

        if "x%diffs%"=="x" (
            git reset HEAD %%p > NUL
            git checkout -- %%p > NUL
        )
	)
	endlocal
GOTO :EOF

:make_patches
    rem Based on https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse/rebuildPatches.sh#26
    set source=%1
    for /F %%i in ("%source%") do set repo=%%~ni
    set target=%2
    set patchdir=%3

    echo ^>^> Creating patches from %repo% to %target%...
    cd "%dirname%\%target%"
    git format-patch --no-stat -N -o "%dirname%\%patchdir%" upstream/upstream
    cd "%dirname%"
    git add -A "%dirname%\%patchdir%"
    call :clean_patches "%dirname%\%patchdir%"
    echo ^>^> Successfully saved patches for %repo%!
GOTO :EOF

:pore_patches
    echo ^> Recreating patches for %project%...
    call :make_patches lib\Bukkit %project% patches
GOTO :EOF

if !%1==! (
    call :pore_help
    GOTO :EOF
)

:head
setlocal EnableDelayedExpansion
set /a counter=0

for /f ^"usebackq^ eol^=^

^ delims^=^" %%a in (%1) do (
        if "!counter!"=="%2" goto :eof
        echo %%a
        set /a counter+=1
)
goto :eof

:tail
SETlocal EnableExtensions
SET tailCount=%%2
SET fileName=del_temp.log
SET output=value.log
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %fileName%`) DO (call SET find_lc=%%l)
SET /a linenumber = %find_lc% – %tailCount%
IF %linenumber% LSS 1 (
more +0 %fileName% >> %output%
) ELSE (
more +%linenumber% %fileName% >> %output%
)
endLocal
GOTO :EOF

:add_file
    set files=%files% %1
GOTO :EOF

:begin
rem TODO: Improve this, just a little bit lazy right now
findstr /i /r /c:"^[ ]*:pore_%1\>" "%~f0" > NUL || GOTO unknown_command
call :pore_%1
cd %dirname%
GOTO :EOF
:unknown_command
>&2 echo Unknown command: '%1'. Type '%0 help' for more information.

@echo off

rem This will make my life easier while converting to Batch
set dirname=%CD%
for /F "delims=" %%i in (%filepath%) do set filename="%%~nxi"
for /F "delims=" %%i in (%filepath%) do set basename="%%~ni"
set project=Porekit

GOTO :begin

:pore_help
    echo Usage^: %0 ^<command^>
    echo Available commands^:
	echo.
    echo   help - Show this help page.
    echo   update - Update the submodules and apply the Porekit patches.
    echo   patches - Rebuild the Porekit patches.
GOTO :EOF

:apply_patches
    rem Based on https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse/applyPatches.sh#7
    set source=%1
    for /F %%i in ("%source%") do set repo=%%~ni
    set target=%2
    set patchdir=%3
    if !"%4"==""! (
	    set branch="%4"
	)
	if "%4"=="" (
		set branch="origin/master"
	)

    cd "%dirname%\%source%"
    git reset --hard "%branch%" > NUL
    git branch -f upstream > NUL

    cd "%dirname%"
    if not exist "%dirname%\%target%" ( git clone "%source%" "%target%" -b upstream )

    cd "%dirname%\%target%"

    echo ^>^> Resetting %target% to %repo%...
    git remote rm upstream > NUL 2>&1
    git remote add upstream "..\%source%" > NUL 2>&1
    git checkout master > NUL 2>&1
    git fetch upstream > NUL 2>&1
    git reset --hard upstream/upstream

    echo ^>^> Applying patches to %target%...
    git am --abort > NUL 2>&1
	set files=

	for /f %%i in ('dir /b "%dirname%\%patchdir%\*.patch"') do call :add_file %dirname%\%patchdir%\%%i
    git am --3way %files% || echo ^>^> Failed to apply patches to %target% ^(from %source%^)

    echo ^>^> Successfully applied patches to %repo%
GOTO :EOF

:pore_update
    echo ^> Updating submodules...
    git submodule update --init
    echo ^> Updating %project%...
    call :apply_patches lib\Bukkit %project% patches
GOTO :EOF

:clean_patches
    rem Based on https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse/rebuildPatches.sh#7
	setlocal enableDelayedExpansion
    for /f %%p in ('dir /b /s %1\*.patch') do (
		SET gitver=tail -n 2 %%p | grep -ve "^$" | tail -n 1
        SET diffs=git diff --staged %%p | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index)"

        SET testver=echo "%diffs%" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "%gitver%"
        if !"x%testver%"=="x"! (
            SET diffs=echo "%diffs%" | head -n -2
        )

        if "x%diffs%"=="x" (
            git reset HEAD %%p > NUL
            git checkout -- %%p > NUL
        )
	)
	endlocal
GOTO :EOF

:make_patches
    rem Based on https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse/rebuildPatches.sh#26
    set source=%1
    for /F %%i in ("%source%") do set repo=%%~ni
    set target=%2
    set patchdir=%3

    echo ^>^> Creating patches from %repo% to %target%...
    cd "%dirname%\%target%"
    git format-patch --no-stat -N -o "%dirname%\%patchdir%" upstream/upstream
    cd "%dirname%"
    git add -A "%dirname%\%patchdir%"
    call :clean_patches "%dirname%\%patchdir%"
    echo ^>^> Successfully saved patches for %repo%!
GOTO :EOF

:pore_patches
    echo ^> Recreating patches for %project%...
    call :make_patches lib\Bukkit %project% patches
GOTO :EOF

if !%1==! (
    call :pore_help
    GOTO :EOF
)

:head
setlocal EnableDelayedExpansion
set /a counter=0

for /f ^"usebackq^ eol^=^

^ delims^=^" %%a in (%1) do (
        if "!counter!"=="%2" goto :eof
        echo %%a
        set /a counter+=1
)
goto :eof

:tail
SETlocal EnableExtensions
SET tailCount=%%2
SET fileName=del_temp.log
SET output=value.log
FOR /F "usebackq tokens=3,3 delims= " %%l IN (`find /c /v "" %fileName%`) DO (call SET find_lc=%%l)
SET /a linenumber = %find_lc% – %tailCount%
IF %linenumber% LSS 1 (
more +0 %fileName% >> %output%
) ELSE (
more +%linenumber% %fileName% >> %output%
)
endLocal
GOTO :EOF

:add_file
    set files=%files% %1
GOTO :EOF

:begin
rem TODO: Improve this, just a little bit lazy right now
findstr /i /r /c:"^[ ]*:pore_%1\>" "%~f0" > NUL || GOTO unknown_command
call :pore_%1
cd %dirname%
GOTO :EOF
:unknown_command
>&2 echo Unknown command: '%1'. Type '%0 help' for more information.

Fix clean_patches function in poredev.bat


@setlocal enabledelayedexpansion

REM Parse Arguments.

set RoslynRoot=%~dp0
set BuildConfiguration=Debug

REM Because override the C#/VB toolset to build against our LKG package, it is important
REM that we do not reuse MSBuild nodes from other jobs/builds on the machine. Otherwise,
REM we'll run into issues such as https://github.com/dotnet/roslyn/issues/6211.
set MSBuildAdditionalCommandLineArgs=/nologo /m /nodeReuse:false /consoleloggerparameters:Verbosity=minimal /filelogger /fileloggerparameters:Verbosity=normal

:ParseArguments
if "%1" == "" goto :DoneParsing
if /I "%1" == "/?" call :Usage && exit /b 1
if /I "%1" == "/debug" set BuildConfiguration=Debug&&shift&& goto :ParseArguments
if /I "%1" == "/release" set BuildConfiguration=Release&&shift&& goto :ParseArguments
if /I "%1" == "/test32" set Test64=false&&shift&& goto :ParseArguments
if /I "%1" == "/test64" set Test64=true&&shift&& goto :ParseArguments
if /I "%1" == "/testDeterminism" set TestDeterminism=true&&shift&& goto :ParseArguments
if /I "%1" == "/testBuildCorrectness" set TestBuildCorrectness=true&&shift&& goto :ParseArguments
if /I "%1" == "/testPerfCorrectness" set TestPerfCorrectness=true&&shift&& goto :ParseArguments
if /I "%1" == "/testPerfRun" set TestPerfRun=true&&shift&& goto :ParseArguments
if /I "%1" == "/testVsi" set TestVsi=true&&shift&& goto :ParseArguments

REM /buildTimeLimit is the time limit, measured in minutes, for the Jenkins job that runs
REM the build. The Jenkins script netci.groovy passes the time limit to this script.
if /I "%1" == "/buildTimeLimit" set BuildTimeLimit=%2&&shift&&shift&& goto :ParseArguments

call :Usage && exit /b 1
:DoneParsing

REM This script takes the presence of the /buildTimeLimit option as an indication that it
REM should run the tests under the control of the ProcessWatchdog, which, if the tests
REM exceed the time limit, will take a screenshot, obtain memory dumps from the test
REM process and all its descendants, and shut those processes down.
REM
REM Developers building from the command line will presumably not pass /buildTimeLimit,
REM and so the tests will not run under the ProcessWatchdog.
if not "%BuildTimeLimit%" == "" (
    set CurrentDate=%date%
    set CurrentTime=%time: =0%
    set BuildStartTime=!CurrentDate:~-4!-!CurrentDate:~-10,2!-!CurrentDate:~-7,2!T!CurrentTime!
    set RunProcessWatchdog=true
) else (
    set RunProcessWatchdog=false
)

REM Restore the NuGet packages
call "%RoslynRoot%\Restore.cmd" || goto :BuildFailed
call "%RoslynRoot%SetDevCommandPrompt.cmd" || goto :BuildFailed

REM Ensure the binaries directory exists because msbuild can fail when part of the path to LogFile isn't present.
set bindir=%RoslynRoot%Binaries
if not exist "%bindir%" mkdir "%bindir%" || goto :BuildFailed

if defined testBuildCorrectness (
    powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\test-build-correctness.ps1" %RoslynRoot% "%bindir%\%BuildConfiguration%" || goto :BuildFailed
    call :TerminateBuildProcesses
    exit /b 0
)

REM Output the commit that we're building, for reference in Jenkins logs
echo Building this commit:
git show --no-patch --pretty=raw HEAD

REM Build with the real assembly version, since that's what's contained in the bootstrap compiler redirects
msbuild %MSBuildAdditionalCommandLineArgs% /p:UseShippingAssemblyVersion=true /p:InitialDefineConstants=BOOTSTRAP "%RoslynRoot%build\Toolset\Toolset.csproj" /p:NuGetRestorePackages=false /p:Configuration=%BuildConfiguration% /fileloggerparameters:LogFile="%bindir%\Bootstrap.log" || goto :BuildFailed
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\check-msbuild.ps1" "%bindir%\Bootstrap.log" || goto :BuildFailed

if not exist "%bindir%\Bootstrap" mkdir "%bindir%\Bootstrap" || goto :BuildFailed
move "Binaries\%BuildConfiguration%\Exes\Toolset\*" "%bindir%\Bootstrap" || goto :BuildFailed

REM Clean the previous build
msbuild %MSBuildAdditionalCommandLineArgs% /t:Clean build/Toolset/Toolset.csproj /p:Configuration=%BuildConfiguration%  /fileloggerparameters:LogFile="%bindir%\BootstrapClean.log" || goto :BuildFailed

call :TerminateBuildProcesses || goto :BuildFailed

if defined TestDeterminism (
    powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\test-determinism.ps1" "%bindir%\Bootstrap" || goto :BuildFailed
    call :TerminateBuildProcesses || goto :BuildFailed
    exit /b 0
)

if defined TestPerfCorrectness (
    msbuild %MSBuildAdditionalCommandLineArgs% Roslyn.sln /p:Configuration=%BuildConfiguration% /p:DeployExtension=false || goto :BuildFailed
    .\Binaries\%BuildConfiguration%\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe --ci-test || goto :BuildFailed
    exit /b 0
)

if defined TestPerfRun (
    msbuild %MSBuildAdditionalCommandLineArgs% Roslyn.sln /p:Configuration=%BuildConfiguration% /p:DeployExtension=false || goto :BuildFailed

    if defined GIT_BRANCH (
        REM Check if we have credentials to upload to benchview
        if defined BV_UPLOAD_SAS_TOKEN (
            set "EXTRA_PERF_RUNNER_ARGS=--report-benchview --branch "%GIT_BRANCH%""

            REM Check if we are in a PR or this is a rolling submission
            if defined ghprbPullTitle (
                set "EXTRA_PERF_RUNNER_ARGS=!EXTRA_PERF_RUNNER_ARGS! --benchview-submission-name ""[%ghprbPullAuthorLogin%] PR %ghprbPullId%: %ghprbPullTitle%"" --benchview-submission-type private"
            ) else (
                set "EXTRA_PERF_RUNNER_ARGS=!EXTRA_PERF_RUNNER_ARGS! --benchview-submission-type rolling"
            )
            mkdir ".\Binaries\%BuildConfiguration%\tools\"
            REM Get the benchview tools - Place alongside Roslyn.Test.Performance.Runner.exe
            call "%RoslynRoot%\build\scripts\install_benchview_tools.cmd" ".\Binaries\%BuildConfiguration%\tools\" || goto :BuildFailed
            dir ".\Binaries\%BuildConfiguration%\"
        )
    )

    call :TerminateBuildProcesses || goto :BuildFailed

    .\Binaries\%BuildConfiguration%\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe --no-trace-upload !EXTRA_PERF_RUNNER_ARGS! || goto :BuildFailed
    exit /b 0
)

msbuild %MSBuildAdditionalCommandLineArgs% /p:BootstrapBuildPath="%bindir%\Bootstrap" BuildAndTest.proj /p:Configuration=%BuildConfiguration% /p:Test64=%Test64% /p:TestVsi=%TestVsi% /p:RunProcessWatchdog=%RunProcessWatchdog% /p:BuildStartTime=%BuildStartTime% /p:"ProcDumpExe=%ProcDumpExe%" /p:BuildTimeLimit=%BuildTimeLimit% /p:PathMap="%RoslynRoot%=q:\roslyn" /p:Feature=pdb-path-determinism /fileloggerparameters:LogFile="%bindir%\Build.log";verbosity=diagnostic /p:DeployExtension=false || goto :BuildFailed
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\check-msbuild.ps1" "%bindir%\Build.log" || goto :BuildFailed

call :TerminateBuildProcesses || goto :BuildFailed

REM Ensure caller sees successful exit.
exit /b 0

:Usage
@echo Usage: cibuild.cmd [/debug^|/release] [/test32^|/test64] [/restore]
@echo   /debug   Perform debug build.  This is the default.
@echo   /release Perform release build.
@echo   /test32  Run unit tests in the 32-bit runner.  This is the default.
@echo   /test64  Run units tests in the 64-bit runner.
@echo.
@goto :eof

:BuildFailed
echo Build failed with ERRORLEVEL %ERRORLEVEL%
call :TerminateBuildProcesses
exit /b 1

:TerminateBuildProcesses
@REM Kill any instances VBCSCompiler.exe to release locked files, ignoring stderr if process is not open
@REM This prevents future CI runs from failing while trying to delete those files.
@REM Kill any instances of msbuild.exe to ensure that we never reuse nodes (e.g. if a non-roslyn CI run
@REM left some floating around).

@REM An error-level of 1 means that the process was found, but could not be killed.
echo Killing all build-related processes
taskkill /F /IM msbuild.exe > nul
if %ERRORLEVEL% == 1 exit /b 1

taskkill /F /IM vbcscompiler.exe > nul
if %ERRORLEVEL% == 1 exit /b 1

exit /b 0

@setlocal enabledelayedexpansion

REM Parse Arguments.

set RoslynRoot=%~dp0
set BuildConfiguration=Debug

REM Because override the C#/VB toolset to build against our LKG package, it is important
REM that we do not reuse MSBuild nodes from other jobs/builds on the machine. Otherwise,
REM we'll run into issues such as https://github.com/dotnet/roslyn/issues/6211.
set MSBuildAdditionalCommandLineArgs=/nologo /m /nodeReuse:false /consoleloggerparameters:Verbosity=minimal /filelogger /fileloggerparameters:Verbosity=normal
set BuildAndTestBuildTarget=BuildAndTest

:ParseArguments
if "%1" == "" goto :DoneParsing
if /I "%1" == "/?" call :Usage && exit /b 1
if /I "%1" == "/debug" set BuildConfiguration=Debug&&shift&& goto :ParseArguments
if /I "%1" == "/release" set BuildConfiguration=Release&&shift&& goto :ParseArguments
if /I "%1" == "/test32" set Test64=false&&shift&& goto :ParseArguments
if /I "%1" == "/test64" set Test64=true&&shift&& goto :ParseArguments
if /I "%1" == "/testDeterminism" set TestDeterminism=true&&shift&& goto :ParseArguments
if /I "%1" == "/testBuildCorrectness" set TestBuildCorrectness=true&&shift&& goto :ParseArguments
if /I "%1" == "/testPerfCorrectness" set TestPerfCorrectness=true&&shift&& goto :ParseArguments
if /I "%1" == "/testPerfRun" set TestPerfRun=true&&shift&& goto :ParseArguments
if /I "%1" == "/testVsi" set TestVsi=true&&shift&& goto :ParseArguments
if /I "%1" == "/skipTests" set BuildAndTestBuildTarget=Build&&shift&&goto :ParseArguments

REM /buildTimeLimit is the time limit, measured in minutes, for the Jenkins job that runs
REM the build. The Jenkins script netci.groovy passes the time limit to this script.
if /I "%1" == "/buildTimeLimit" set BuildTimeLimit=%2&&shift&&shift&& goto :ParseArguments

call :Usage && exit /b 1
:DoneParsing

REM This script takes the presence of the /buildTimeLimit option as an indication that it
REM should run the tests under the control of the ProcessWatchdog, which, if the tests
REM exceed the time limit, will take a screenshot, obtain memory dumps from the test
REM process and all its descendants, and shut those processes down.
REM
REM Developers building from the command line will presumably not pass /buildTimeLimit,
REM and so the tests will not run under the ProcessWatchdog.
if not "%BuildTimeLimit%" == "" (
    set CurrentDate=%date%
    set CurrentTime=%time: =0%
    set BuildStartTime=!CurrentDate:~-4!-!CurrentDate:~-10,2!-!CurrentDate:~-7,2!T!CurrentTime!
    set RunProcessWatchdog=true
) else (
    set RunProcessWatchdog=false
)

REM Restore the NuGet packages
call "%RoslynRoot%\Restore.cmd" || goto :BuildFailed
call "%RoslynRoot%SetDevCommandPrompt.cmd" || goto :BuildFailed

REM Ensure the binaries directory exists because msbuild can fail when part of the path to LogFile isn't present.
set bindir=%RoslynRoot%Binaries
if not exist "%bindir%" mkdir "%bindir%" || goto :BuildFailed

if defined testBuildCorrectness (
    powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\test-build-correctness.ps1" %RoslynRoot% "%bindir%\%BuildConfiguration%" || goto :BuildFailed
    call :TerminateBuildProcesses
    exit /b 0
)

REM Output the commit that we're building, for reference in Jenkins logs
echo Building this commit:
git show --no-patch --pretty=raw HEAD

REM Build with the real assembly version, since that's what's contained in the bootstrap compiler redirects
msbuild %MSBuildAdditionalCommandLineArgs% /p:UseShippingAssemblyVersion=true /p:InitialDefineConstants=BOOTSTRAP "%RoslynRoot%build\Toolset\Toolset.csproj" /p:NuGetRestorePackages=false /p:Configuration=%BuildConfiguration% /fileloggerparameters:LogFile="%bindir%\Bootstrap.log" || goto :BuildFailed
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\check-msbuild.ps1" "%bindir%\Bootstrap.log" || goto :BuildFailed

if not exist "%bindir%\Bootstrap" mkdir "%bindir%\Bootstrap" || goto :BuildFailed
move "Binaries\%BuildConfiguration%\Exes\Toolset\*" "%bindir%\Bootstrap" || goto :BuildFailed

REM Clean the previous build
msbuild %MSBuildAdditionalCommandLineArgs% /t:Clean build/Toolset/Toolset.csproj /p:Configuration=%BuildConfiguration%  /fileloggerparameters:LogFile="%bindir%\BootstrapClean.log" || goto :BuildFailed

call :TerminateBuildProcesses || goto :BuildFailed

if defined TestDeterminism (
    powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\test-determinism.ps1" "%bindir%\Bootstrap" || goto :BuildFailed
    call :TerminateBuildProcesses || goto :BuildFailed
    exit /b 0
)

if defined TestPerfCorrectness (
    msbuild %MSBuildAdditionalCommandLineArgs% Roslyn.sln /p:Configuration=%BuildConfiguration% /p:DeployExtension=false || goto :BuildFailed
    .\Binaries\%BuildConfiguration%\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe --ci-test || goto :BuildFailed
    exit /b 0
)

if defined TestPerfRun (
    msbuild %MSBuildAdditionalCommandLineArgs% Roslyn.sln /p:Configuration=%BuildConfiguration% /p:DeployExtension=false || goto :BuildFailed

    if defined GIT_BRANCH (
        REM Check if we have credentials to upload to benchview
        if defined BV_UPLOAD_SAS_TOKEN (
            set "EXTRA_PERF_RUNNER_ARGS=--report-benchview --branch "%GIT_BRANCH%""

            REM Check if we are in a PR or this is a rolling submission
            if defined ghprbPullTitle (
                set "EXTRA_PERF_RUNNER_ARGS=!EXTRA_PERF_RUNNER_ARGS! --benchview-submission-name ""[%ghprbPullAuthorLogin%] PR %ghprbPullId%: %ghprbPullTitle%"" --benchview-submission-type private"
            ) else (
                set "EXTRA_PERF_RUNNER_ARGS=!EXTRA_PERF_RUNNER_ARGS! --benchview-submission-type rolling"
            )
            mkdir ".\Binaries\%BuildConfiguration%\tools\"
            REM Get the benchview tools - Place alongside Roslyn.Test.Performance.Runner.exe
            call "%RoslynRoot%\build\scripts\install_benchview_tools.cmd" ".\Binaries\%BuildConfiguration%\tools\" || goto :BuildFailed
            dir ".\Binaries\%BuildConfiguration%\"
        )
    )

    call :TerminateBuildProcesses || goto :BuildFailed

    .\Binaries\%BuildConfiguration%\Exes\Perf.Runner\Roslyn.Test.Performance.Runner.exe --no-trace-upload !EXTRA_PERF_RUNNER_ARGS! || goto :BuildFailed
    exit /b 0
)

msbuild %MSBuildAdditionalCommandLineArgs% /p:BootstrapBuildPath="%bindir%\Bootstrap" BuildAndTest.proj /t:%BuildAndTestBuildTarget% /p:Configuration=%BuildConfiguration% /p:Test64=%Test64% /p:TestVsi=%TestVsi% /p:RunProcessWatchdog=%RunProcessWatchdog% /p:BuildStartTime=%BuildStartTime% /p:"ProcDumpExe=%ProcDumpExe%" /p:BuildTimeLimit=%BuildTimeLimit% /p:PathMap="%RoslynRoot%=q:\roslyn" /p:Feature=pdb-path-determinism /fileloggerparameters:LogFile="%bindir%\Build.log";verbosity=diagnostic /p:DeployExtension=false || goto :BuildFailed
powershell -noprofile -executionPolicy RemoteSigned -file "%RoslynRoot%\build\scripts\check-msbuild.ps1" "%bindir%\Build.log" || goto :BuildFailed

call :TerminateBuildProcesses || goto :BuildFailed

REM Ensure caller sees successful exit.
exit /b 0

:Usage
@echo Usage: cibuild.cmd [/debug^|/release] [/test32^|/test64] [/restore]
@echo   /debug   Perform debug build.  This is the default.
@echo   /release Perform release build.
@echo   /test32  Run unit tests in the 32-bit runner.  This is the default.
@echo   /test64  Run units tests in the 64-bit runner.
@echo.
@goto :eof

:BuildFailed
echo Build failed with ERRORLEVEL %ERRORLEVEL%
call :TerminateBuildProcesses
exit /b 1

:TerminateBuildProcesses
@REM Kill any instances VBCSCompiler.exe to release locked files, ignoring stderr if process is not open
@REM This prevents future CI runs from failing while trying to delete those files.
@REM Kill any instances of msbuild.exe to ensure that we never reuse nodes (e.g. if a non-roslyn CI run
@REM left some floating around).

@REM An error-level of 1 means that the process was found, but could not be killed.
echo Killing all build-related processes
taskkill /F /IM msbuild.exe > nul
if %ERRORLEVEL% == 1 exit /b 1

taskkill /F /IM vbcscompiler.exe > nul
if %ERRORLEVEL% == 1 exit /b 1

exit /b 0

Add "/skiptests" to cibuild.cmd

Add "/skiptests" to cibuild.cmd


@echo on

:: Download Meson and Ninja, create install directory
mkdir _build
mkdir graphene-shared-%MSVC_PLATFORM%
cd _build
curl -LsSO https://github.com/mesonbuild/meson/releases/download/0.47.1/meson-0.47.1.tar.gz
7z x meson-0.47.1.tar.gz
move dist\meson-0.47.1.tar .
7z x meson-0.47.1.tar
rmdir dist
del meson-0.47.1.tar meson-0.47.1.tar.gz
curl -LsSO https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip
7z x ninja-win.zip
del ninja-win.zip
cd ..

:: Build and install
cd _build
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %MSVC_PLATFORM%
@echo on
C:\Python36\python.exe meson-0.47.1\meson.py .. . --backend=ninja --prefix=%APPVEYOR_BUILD_FOLDER%\graphene-shared-%MSVC_PLATFORM% || goto :error
ninja || goto :error
ninja test || goto :error
ninja install || goto :error
cd ..

:: Copy license into install directory and create .zip file
copy LICENSE graphene-shared-%MSVC_PLATFORM% || goto :error
dir graphene-shared-%MSVC_PLATFORM% /s /b || goto :error
7z a -tzip graphene-shared-%MSVC_PLATFORM%.zip graphene-shared-%MSVC_PLATFORM% || goto :error

goto :EOF

:error
exit /b 1

@echo on

:: Download Meson and Ninja, create install directory
mkdir _build
mkdir graphene-shared-%MSVC_PLATFORM%
cd _build
curl -LsSO https://github.com/mesonbuild/meson/releases/download/0.49.0/meson-0.49.0.tar.gz
7z x meson-0.49.0.tar.gz
move dist\meson-0.49.0.tar .
7z x meson-0.49.0.tar
rmdir dist
del meson-0.49.0.tar meson-0.49.0.tar.gz
curl -LsSO https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip
7z x ninja-win.zip
del ninja-win.zip
cd ..

:: Build and install
cd _build
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %MSVC_PLATFORM%
@echo on
C:\Python36\python.exe meson-0.49.0\meson.py .. . --backend=ninja --prefix=%APPVEYOR_BUILD_FOLDER%\graphene-shared-%MSVC_PLATFORM% || goto :error
ninja || goto :error
ninja test || goto :error
ninja install || goto :error
cd ..

:: Copy license into install directory and create .zip file
copy LICENSE graphene-shared-%MSVC_PLATFORM% || goto :error
dir graphene-shared-%MSVC_PLATFORM% /s /b || goto :error
7z a -tzip graphene-shared-%MSVC_PLATFORM%.zip graphene-shared-%MSVC_PLATFORM% || goto :error

goto :EOF

:error
exit /b 1

Update AppVeyor's MSVC script

ci: Update AppVeyor's MSVC script

We depend on a newer version of Meson, but let's use the latest stable
to give us some leeway.


@rem ------------------------------------------------------
@rem batch file to build tcc using mingw, msvc or tcc itself
@rem ------------------------------------------------------

@echo off
setlocal
if (%1)==(-clean) goto :cleanup
set CC=gcc
set /p VERSION= < ..\VERSION
set INST=
set BIN=
set DOC=no
set EXES_ONLY=no
goto :a0
:a2
shift
:a3
shift
:a0
if not (%1)==(-c) goto :a1
set CC=%~2
if (%2)==(cl) set CC=@call :cl
goto :a2
:a1
if (%1)==(-t) set T=%2&& goto :a2
if (%1)==(-v) set VERSION=%~2&& goto :a2
if (%1)==(-i) set INST=%2&& goto :a2
if (%1)==(-b) set BIN=%2&& goto :a2
if (%1)==(-d) set DOC=yes&& goto :a3
if (%1)==(-x) set EXES_ONLY=yes&& goto :a3
if (%1)==() goto :p1
:usage
echo usage: build-tcc.bat [ options ... ]
echo options:
echo   -c prog              use prog (gcc/tcc/cl) to compile tcc
echo   -c "prog options"    use prog with options to compile tcc
echo   -t 32/64             force 32/64 bit default target
echo   -v "version"         set tcc version
echo   -i tccdir            install tcc into tccdir
echo   -b bindir            optionally install binaries into bindir elsewhere
echo   -d                   create tcc-doc.html too (needs makeinfo)
echo   -x                   just create the executables
echo   -clean               delete all previously produced files and directories
exit /B 1

@rem ------------------------------------------------------
@rem sub-routines

:cleanup
set LOG=echo
%LOG% removing files:
for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f
for %%f in (..\config.h ..\config.texi) do call :del_file %%f
for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f
for %%f in (*.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
%LOG% removing directories:
for %%f in (doc libtcc) do call :del_dir %%f
%LOG% done.
exit /B 0
:del_file
if exist %1 del %1 && %LOG%   %1
exit /B 0
:del_dir
if exist %1 rmdir /Q/S %1 && %LOG%   %1
exit /B 0

:cl
@echo off
set CMD=cl
:c0
set ARG=%1
set ARG=%ARG:.dll=.lib%
if (%1)==(-shared) set ARG=-LD
if (%1)==(-o) shift && set ARG=-Fe%2
set CMD=%CMD% %ARG%
shift
if not (%1)==() goto :c0
echo on
%CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
@exit /B %ERRORLEVEL%

@rem ------------------------------------------------------
@rem main program

:p1
if not %T%_==_ goto :p2
set T=32
if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
:p2
if "%CC:~-3%"=="gcc" set CC=%CC% -Os -s -static
set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
set P32=i386-win32
set P64=x86_64-win32
if %T%==64 goto :t64
set D=%D32%
set DX=%D64%
set PX=%P64%
goto :p3
:t64
set D=%D64%
set DX=%D32%
set PX=%P32%
goto :p3

:p3
@echo on

:config.h
echo>..\config.h #define TCC_VERSION "%VERSION%"
echo>> ..\config.h #ifdef TCC_TARGET_X86_64
echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
echo>> ..\config.h #else
echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
echo>> ..\config.h #endif

for %%f in (*tcc.exe *tcc.dll) do @del %%f

:compiler
%CC% -o libtcc.dll -shared ..\libtcc.c %D% -DLIBTCC_AS_DLL
@if errorlevel 1 goto :the_end
%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
%CC% -o %PX%-tcc.exe ..\tcc.c %DX%

@if (%EXES_ONLY%)==(yes) goto :files-done

if not exist libtcc mkdir libtcc
if not exist doc mkdir doc
copy>nul ..\include\*.h include
copy>nul ..\tcclib.h include
copy>nul ..\libtcc.h libtcc
copy>nul ..\tests\libtcc_test.c examples
copy>nul tcc-win32.txt doc

.\tcc -impdef libtcc.dll -o libtcc\libtcc.def
@if errorlevel 1 goto :the_end

:libtcc1.a
@set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
.\tcc -m32 -c ../lib/libtcc1.c
.\tcc -m32 -c lib/crt1.c
.\tcc -m32 -c lib/crt1w.c
.\tcc -m32 -c lib/wincrt1.c
.\tcc -m32 -c lib/wincrt1w.c
.\tcc -m32 -c lib/dllcrt1.c
.\tcc -m32 -c lib/dllmain.c
.\tcc -m32 -c lib/chkstk.S
.\tcc -m32 -c ../lib/alloca86.S
.\tcc -m32 -c ../lib/alloca86-bt.S
.\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
@if errorlevel 1 goto :the_end
.\tcc -m64 -c ../lib/libtcc1.c
.\tcc -m64 -c lib/crt1.c
.\tcc -m64 -c lib/crt1w.c
.\tcc -m64 -c lib/wincrt1.c
.\tcc -m64 -c lib/wincrt1w.c
.\tcc -m64 -c lib/dllcrt1.c
.\tcc -m64 -c lib/dllmain.c
.\tcc -m64 -c lib/chkstk.S
.\tcc -m64 -c ../lib/alloca86_64.S
.\tcc -m64 -c ../lib/alloca86_64-bt.S
.\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
@if errorlevel 1 goto :the_end
.\tcc -m%T% -c ../lib/bcheck.c -o lib/bcheck.o -g
.\tcc -m%T% -c ../lib/bt-exe.c -o lib/bt-exe.o
.\tcc -m%T% -c ../lib/bt-log.c -o lib/bt-log.o
.\tcc -m%T% -c ../lib/bt-dll.c -o lib/bt-dll.o

:tcc-doc.html
@if not (%DOC%)==(yes) goto :doc-done
echo>..\config.texi @set VERSION %VERSION%
cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
:doc-done

:files-done
for %%f in (*.o *.def) do @del %%f

:copy-install
@if (%INST%)==() goto :the_end
if not exist %INST% mkdir %INST%
@if (%BIN%)==() set BIN=%INST%
if not exist %BIN% mkdir %BIN%
for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f
@if not exist %INST%\lib mkdir %INST%\lib
for %%f in (lib\*.a lib\*.o lib\*.def) do @copy>nul %%f %INST%\%%f
for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f

:the_end
exit /B %ERRORLEVEL%

@rem ------------------------------------------------------
@rem batch file to build tcc using mingw, msvc or tcc itself
@rem ------------------------------------------------------

@echo off
setlocal
if (%1)==(-clean) goto :cleanup
set CC=gcc
set /p VERSION= < ..\VERSION
set INST=
set BIN=
set DOC=no
set EXES_ONLY=no
goto :a0
:a2
shift
:a3
shift
:a0
if not (%1)==(-c) goto :a1
set CC=%~2
if (%2)==(cl) set CC=@call :cl
goto :a2
:a1
if (%1)==(-t) set T=%2&& goto :a2
if (%1)==(-v) set VERSION=%~2&& goto :a2
if (%1)==(-i) set INST=%2&& goto :a2
if (%1)==(-b) set BIN=%2&& goto :a2
if (%1)==(-d) set DOC=yes&& goto :a3
if (%1)==(-x) set EXES_ONLY=yes&& goto :a3
if (%1)==() goto :p1
:usage
echo usage: build-tcc.bat [ options ... ]
echo options:
echo   -c prog              use prog (gcc/tcc/cl) to compile tcc
echo   -c "prog options"    use prog with options to compile tcc
echo   -t 32/64             force 32/64 bit default target
echo   -v "version"         set tcc version
echo   -i tccdir            install tcc into tccdir
echo   -b bindir            optionally install binaries into bindir elsewhere
echo   -d                   create tcc-doc.html too (needs makeinfo)
echo   -x                   just create the executables
echo   -clean               delete all previously produced files and directories
exit /B 1

@rem ------------------------------------------------------
@rem sub-routines

:cleanup
set LOG=echo
%LOG% removing files:
for %%f in (*tcc.exe libtcc.dll lib\*.a) do call :del_file %%f
for %%f in (..\config.h ..\config.texi) do call :del_file %%f
for %%f in (include\*.h) do @if exist ..\%%f call :del_file %%f
for %%f in (include\tcclib.h examples\libtcc_test.c) do call :del_file %%f
for %%f in (lib\*.o *.o *.obj *.def *.pdb *.lib *.exp *.ilk) do call :del_file %%f
%LOG% removing directories:
for %%f in (doc libtcc) do call :del_dir %%f
%LOG% done.
exit /B 0
:del_file
if exist %1 del %1 && %LOG%   %1
exit /B 0
:del_dir
if exist %1 rmdir /Q/S %1 && %LOG%   %1
exit /B 0

:cl
@echo off
set CMD=cl
:c0
set ARG=%1
set ARG=%ARG:.dll=.lib%
if (%1)==(-shared) set ARG=-LD
if (%1)==(-o) shift && set ARG=-Fe%2
set CMD=%CMD% %ARG%
shift
if not (%1)==() goto :c0
echo on
%CMD% -O1 -W2 -Zi -MT -GS- -nologo -link -opt:ref,icf
@exit /B %ERRORLEVEL%

@rem ------------------------------------------------------
@rem main program

:p1
if not %T%_==_ goto :p2
set T=32
if %PROCESSOR_ARCHITECTURE%_==AMD64_ set T=64
if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
:p2
if "%CC:~-3%"=="gcc" set CC=%CC% -Os -s -static
set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
set P32=i386-win32
set P64=x86_64-win32
if %T%==64 goto :t64
set D=%D32%
set DX=%D64%
set PX=%P64%
goto :p3
:t64
set D=%D64%
set DX=%D32%
set PX=%P32%
goto :p3

:p3
@echo on

:config.h
echo>..\config.h #define TCC_VERSION "%VERSION%"
echo>> ..\config.h #ifdef TCC_TARGET_X86_64
echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
echo>> ..\config.h #else
echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
echo>> ..\config.h #endif

for %%f in (*tcc.exe *tcc.dll) do @del %%f

:compiler
%CC% -o libtcc.dll -shared ..\libtcc.c %D% -DLIBTCC_AS_DLL
@if errorlevel 1 goto :the_end
%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
%CC% -o %PX%-tcc.exe ..\tcc.c %DX%

@if (%EXES_ONLY%)==(yes) goto :files-done

if not exist libtcc mkdir libtcc
if not exist doc mkdir doc
copy>nul ..\include\*.h include
copy>nul ..\tcclib.h include
copy>nul ..\libtcc.h libtcc
copy>nul ..\tests\libtcc_test.c examples
copy>nul tcc-win32.txt doc

.\tcc -impdef libtcc.dll -o libtcc\libtcc.def
@if errorlevel 1 goto :the_end

:libtcc1.a
@set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
.\tcc -m32 -c ../lib/libtcc1.c
.\tcc -m32 -c lib/crt1.c
.\tcc -m32 -c lib/crt1w.c
.\tcc -m32 -c lib/wincrt1.c
.\tcc -m32 -c lib/wincrt1w.c
.\tcc -m32 -c lib/dllcrt1.c
.\tcc -m32 -c lib/dllmain.c
.\tcc -m32 -c lib/chkstk.S
.\tcc -m32 -c ../lib/alloca86.S
.\tcc -m32 -c ../lib/alloca86-bt.S
.\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
@if errorlevel 1 goto :the_end
.\tcc -m64 -c ../lib/libtcc1.c
.\tcc -m64 -c lib/crt1.c
.\tcc -m64 -c lib/crt1w.c
.\tcc -m64 -c lib/wincrt1.c
.\tcc -m64 -c lib/wincrt1w.c
.\tcc -m64 -c lib/dllcrt1.c
.\tcc -m64 -c lib/dllmain.c
.\tcc -m64 -c lib/chkstk.S
.\tcc -m64 -c ../lib/alloca86_64.S
.\tcc -m64 -c ../lib/alloca86_64-bt.S
.\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
@if errorlevel 1 goto :the_end
.\tcc -m%T% -c ../lib/bcheck.c -o lib/bcheck.o -g
.\tcc -m%T% -c ../lib/bt-exe.c -o lib/bt-exe.o
.\tcc -m%T% -c ../lib/bt-log.c -o lib/bt-log.o
.\tcc -m%T% -c ../lib/bt-dll.c -o lib/bt-dll.o

:tcc-doc.html
@if not (%DOC%)==(yes) goto :doc-done
echo>..\config.texi @set VERSION %VERSION%
cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
:doc-done

:files-done
for %%f in (*.o *.def) do @del %%f

:copy-install
@if (%INST%)==() goto :the_end
if not exist %INST% mkdir %INST%
@if (%BIN%)==() set BIN=%INST%
if not exist %BIN% mkdir %BIN%
for %%f in (*tcc.exe *tcc.dll) do @copy>nul %%f %BIN%\%%f
@if not exist %INST%\lib mkdir %INST%\lib
for %%f in (lib\*.a lib\*.o lib\*.def) do @copy>nul %%f %INST%\%%f
for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f

:the_end
exit /B %ERRORLEVEL%

clean .o in win32/lib

win32/build-tcc.bat: clean .o in win32/lib

commit ef42295fe802c881a42c8983f1638ff302e63a6c intrduced 4 .o files to
win32/lib. But they (bcheck.o, bt-dll.o, bt-exe.o and bt-log.o) are not
removed by "win32/build-tcc.bat -clean". This commit should fix it.


nexe -t windows-x64-6.11.4 src\server.js -o dist\server-win
nexe -t mac-x64-6.11.4 src\server.js -o dist\server-mac

call nexe -t windows-x64-6.11.4 src\server.js -o dist\server-win
call nexe -t mac-x64-6.11.4 src\server.js -o dist\server-mac

add call so it runs both commands

add call so it runs both commands


Add build script

Add build script


@echo Off
set config=%1
if "%config%" == "" (
   set config=Release
)

set version=
if not "%BuildCounter%" == "" (
   set version=--version-suffix ci-%BuildCounter%
)

REM (optional) build.bat is in the root of our repo, cd to the correct folder where sources/projects are
echo %cd%

REM Restore
call dotnet restore
if not "%errorlevel%"=="0" goto failure

REM Build
REM - Option 1: Run dotnet build for every source folder in the project
REM   e.g. call dotnet build <path> --configuration %config%
REM - Option 2: Let msbuild handle things and build the solution
"%programfiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" Nugety.sln /p:Configuration="%config%" /m /v:M /fl /flp:LogFile=msbuild.log;Verbosity=Normal /nr:false
REM call dotnet build --configuration %config%
if not "%errorlevel%"=="0" goto failure

REM Unit tests
rem cd Nugety\src\Tests\Nugety.Tests
rem call dotnet test  --configuration %config%
rem if not "%errorlevel%"=="0" goto failure

:success
exit 0

:failure
exit -1

@echo Off
set config=%1
if "%config%" == "" (
   set config=Release
)

set version=
if not "%BuildCounter%" == "" (
   set version=--version-suffix ci-%BuildCounter%
)

REM (optional) build.bat is in the root of our repo, cd to the correct folder where sources/projects are
echo %cd%

REM Restore
call dotnet restore
if not "%errorlevel%"=="0" goto failure

REM Build
REM - Option 1: Run dotnet build for every source folder in the project
REM   e.g. call dotnet build <path> --configuration %config%
REM - Option 2: Let msbuild handle things and build the solution
"%programfiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" Nugety.sln /p:Configuration="%config%" /m /v:M /fl /flp:LogFile=msbuild.log;Verbosity=Normal /nr:false
REM call dotnet build --configuration %config%
if not "%errorlevel%"=="0" goto failure

REM Unit tests
cd src\Tests\Nugety.Tests
call dotnet test  --configuration %config%
if not "%errorlevel%"=="0" goto failure

:success
exit 0

:failure
exit -1

Fix unit test location

Fix unit test location


@Echo OFF
SET PATH=C:\Program Files (x86)\MSBuild\14.0\Bin

MSbuild "src\Atata\Atata.csproj" /p:Configuration=Release
Echo Build process completed

..\nuget pack src\Atata.nuspec
Echo NuGet package created

Set /p Wait=Press Enter to continue...

@Echo OFF
SET PATH=D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin

MSbuild "src\Atata\Atata.csproj" /p:Configuration=Release
Echo Build process completed

..\nuget pack src\Atata.nuspec
Echo NuGet package created

Set /p Wait=Press Enter to continue...

Update build.bat

Update build.bat


@echo off
cd %~dp0

SETLOCAL
SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe
SET BUILDCMD_KOREBUILD_VERSION=""
SET BUILDCMD_DNX_VERSION=""

IF EXIST %CACHED_NUGET% goto copynuget
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"

:copynuget
IF EXIST .nuget\nuget.exe goto restore
md .nuget
copy %CACHED_NUGET% .nuget\nuget.exe > nul

:restore
IF EXIST packages\KoreBuild goto run
IF %BUILDCMD_KOREBUILD_VERSION%=="" (
	.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
) ELSE (
	.nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre
)
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion

IF "%SKIP_DNX_INSTALL%"=="1" goto run
IF %BUILDCMD_DNX_VERSION%=="" (
	CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86
) ELSE (
	CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -a default
)
CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86

:run
CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

@echo off
cd %~dp0

SETLOCAL
SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe
SET BUILDCMD_KOREBUILD_VERSION=""
SET BUILDCMD_DNX_VERSION=""

IF EXIST %CACHED_NUGET% goto copynuget
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"

:copynuget
IF EXIST .nuget\nuget.exe goto restore
md .nuget
copy %CACHED_NUGET% .nuget\nuget.exe > nul

:restore
IF EXIST packages\KoreBuild goto run
IF %BUILDCMD_KOREBUILD_VERSION%=="" (
	.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
) ELSE (
	.nuget\NuGet.exe install KoreBuild -version %BUILDCMD_KOREBUILD_VERSION% -ExcludeVersion -o packages -nocache -pre
)
.nuget\NuGet.exe install Sake -ExcludeVersion -Source https://www.nuget.org/api/v2/ -Out packages

IF "%SKIP_DNX_INSTALL%"=="1" goto run
IF %BUILDCMD_DNX_VERSION%=="" (
	CALL packages\KoreBuild\build\dnvm upgrade -runtime CLR -arch x86
) ELSE (
	CALL packages\KoreBuild\build\dnvm install %BUILDCMD_DNX_VERSION% -runtime CLR -arch x86 -a default
)
CALL packages\KoreBuild\build\dnvm install default -runtime CoreCLR -arch x86

:run
CALL packages\KoreBuild\build\dnvm use default -runtime CLR -arch x86
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

Update 'build.cmd' to pull Sake from v2 NuGet feed.


cl /O2 /W3 /WX /I "\Program Files\Java\jdk1.5.0_11\include" /I "\Program Files\Java\jdk1.5.0_11\include\win32"  NucleotideLikelihoodCore.c /LD /FeNucleotideLikelihoodCore.dll

build script for Windows version of native library


mkdir build
cd build

cmake ^
    -G "Ninja" ^
    -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% ^
    -DCMAKE_BUILD_TYPE=Release ^
    -DBUILD_TESTING=ON ^
    -DIDYNTREE_USES_IPOPT:BOOL=ON ^
    -DIDYNTREE_USES_OSQPEIGEN:BOOL=ON ^
    -DIDYNTREE_USES_IRRLICHT:BOOL=ON ^
    -DIDYNTREE_USES_MATLAB:BOOL=OFF ^
    -DIDYNTREE_USES_PYTHON:BOOL=ON ^
    -DIDYNTREE_USES_OCTAVE:BOOL=OFF ^
    -DIDYNTREE_USES_LUA:BOOL=OFF ^
    -DIDYNTREE_COMPILES_YARP_TOOLS:BOOL=OFF ^
    -DIDYNTREE_DETECT_ACTIVE_PYTHON_SITEPACKAGES:BOOL=ON ^
    %SRC_DIR%
if errorlevel 1 exit 1

:: Build.
cmake --build . --config Release
if errorlevel 1 exit 1

:: Install.
cmake --build . --config Release --target install
if errorlevel 1 exit 1

:: Test.
ctest --output-on-failure -C Release
if errorlevel 1 exit 1

Create bld.bat

Create bld.bat


ECHO OFF

SET RUN_FOLDER=%CD%

CD /D %~dp0..\ || exit /b 1

ECHO.
ECHO ----------------------------------------
ECHO Install node.js module spellCheck (nodehun)
ECHO ----------------------------------------

call npm install express@2.5.8 || exit /b 1
call npm install sockjs || exit /b 1
call npm install log4js || exit /b 1

call npm install -g node-gyp || exit /b 1
call npm install nodehun@0.0.5 || exit /b 1

COPY nodehun\nodehun.cpp node_modules\nodehun\src\nodehun.cpp
COPY nodehun\replist.hxx node_modules\nodehun\src\hunspell\src\hunspell\replist.hxx

cd /D node_modules\nodehun\src || exit /b 1
call node-gyp configure || exit /b 1
call node-gyp build	|| exit /b 1

CD /D %RUN_FOLDER% || exit /b 1

exit /b 0

ECHO OFF

SET RUN_FOLDER=%CD%

CD /D %~dp0..\ || exit /b 1

ECHO.
ECHO ----------------------------------------
ECHO Install node.js module spellCheck (nodehun)
ECHO ----------------------------------------

call npm install express@2.5.8 || exit /b 1
call npm install sockjs || exit /b 1

call npm install -g node-gyp || exit /b 1
call npm install nodehun@0.0.5 || exit /b 1

COPY sources\nodehun\nodehun.cpp node_modules\nodehun\src\nodehun.cpp
COPY sources\nodehun\replist.hxx node_modules\nodehun\src\hunspell\src\hunspell\replist.hxx

cd /D node_modules\nodehun\src || exit /b 1
call node-gyp configure || exit /b 1
call node-gyp build	|| exit /b 1

cd /D ..\..\..\..\Common || exit /b 1
call npm install log4js || exit /b 1

CD /D %RUN_FOLDER% || exit /b 1

exit /b 0

update install spellCheck

update install spellCheck

git-svn-id: 8e6dadeb865701f38789a88d039ad73f285cd5d0@48232 954022d7-b5bf-4e40-9824-e11837661b57


REM Generic batch script to execute powershell scripts along with positional parameters
REM Pass path to PS1 script as well as any parameters you want to pass
REM Spaces are not supported in script path
REM Ex. "PSScript.bat c:\scripts\test.ps1 value"

powershell.exe -ExecutionPolicy RemoteSigned -File %*

REM Generic batch script to execute powershell scripts along with positional parameters
REM Pass path to PS1 script as well as any parameters you want to pass
REM Spaces are not supported in script path
REM Also, in testing, powershell script must use positional parameters. Results may vary
REM Ex. "./Scripts/PSScript.bat c:\scripts\test.ps1 value"

powershell.exe -ExecutionPolicy RemoteSigned -File %*

Update PSScript.bat

Update PSScript.bat


@echo off

echo Checking for the existence of variables.bat
if NOT EXIST "variables.bat" (
    rem No variable file defined
    shutdown -s -t 0
    exit
)

echo Loading variables.bat
rem Source variables
call %~dp0\variables.bat
if "%reportURLFile%"=="" (
    rem No report URL file defined
    shutdown -s -t 0
    exit
)
if "%srcDir%"=="" (
    rem No source dir defined
    shutdown -s -t 0
    exit
)

SET /P reportURL=<%reportURLFile%
SET userAgent="CCX/CI_BOT"
SET logFile="%reportFolder%/log.html"

echo Copy files over to local disk
call :postStatus "preparation" "Copy testsuite to local folder"
rem robocopy returns a non-zero exit code even on success (https://ss64.com/nt/robocopy-exit.html), so we cannot use executeCommand
call robocopy %suiteSrcDir% %suiteDstDir% /e >> "%logFile%"

call :postStatus "preparation" "Copy code to local folder"
call robocopy %srcDir% %dstDir% /e >> "%logFile%"
call :executeCommand cd %dstDir%

echo Compile CCX
call :postStatus "building" "Compiling CCExtractor"
rem Go to Windows build folder
call :executeCommand cd windows
rem Build CCExtractor using the sln script
call :executeCommand "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild" ccextractor.sln
rem check whether installation successful
if EXIST Debug\ccextractorwin.exe (
    cd Debug
    rem Run testsuite
    echo Run tests
    call :postStatus "testing" "Running tests"
    call :executeCommand cd %suiteDstDir%
    call :executeCommand "%tester%" --entries "%testFile%" --executable "%dstDir%\windows\Debug\ccextractorwin.exe" --tempfolder "%tempFolder%" --timeout 3000 --reportfolder "%reportFolder%" --resultfolder "%resultFolder%" --samplefolder "%sampleFolder%" --method Server --url "%reportURL%"
    call :postStatus "completed" "Ran all tests"
    rem Shut down
    echo Done running tests
    shutdown -s -t 0
)
else
(
    call :haltAndCatchFire "build"
)
echo End
EXIT %ERRORLEVEL%
rem Functions to shorten the script

rem Fail when the exit status is not equal to 0
:executeCommand
echo %* >> "%logFile%"
%* >> "%logFile%"
SET /A status=%ERRORLEVEL%
IF %status% NEQ 0 (
    echo Command exited with %status% >> "%logFile%"
    rem No message needed as we post before anyway
    call :haltAndCatchFire ""
)
EXIT /B 0

rem Post status to the server
:postStatus
curl -s -A "%userAgent%" --data "type=progress&status=%~1&message=%~2" -w "\n" "%reportURL%" >> "%logFile%"
EXIT /B 0

rem Exit script and post abort status
:haltAndCatchFire
call :postStatus "canceled" %~1 >> "%logFile%"
rem Shut down, but only in 5 seconds, to give the time to finish the post status
shutdown -s -t 5
EXIT 0

@echo off

echo Checking for the existence of variables.bat
if NOT EXIST "variables.bat" (
    rem No variable file defined
    shutdown -s -t 0
    exit
)

echo Loading variables.bat
rem Source variables
call %~dp0\variables.bat
if "%reportURLFile%"=="" (
    rem No report URL file defined
    shutdown -s -t 0
    exit
)
if "%srcDir%"=="" (
    rem No source dir defined
    shutdown -s -t 0
    exit
)

SET /P reportURL=<%reportURLFile%
SET userAgent="CCX/CI_BOT"
SET logFile="%reportFolder%/log.html"

echo Copy files over to local disk
call :postStatus "preparation" "Copy testsuite to local folder"
rem robocopy returns a non-zero exit code even on success (https://ss64.com/nt/robocopy-exit.html), so we cannot use executeCommand
call robocopy %suiteSrcDir% %suiteDstDir% /e >> "%logFile%"

call :postStatus "preparation" "Copy code to local folder"
call robocopy %srcDir% %dstDir% /e >> "%logFile%"
call :executeCommand cd %dstDir%

echo Compile CCX
call :postStatus "building" "Compiling CCExtractor"
rem Go to Windows build folder
call :executeCommand cd windows
rem Build CCExtractor using the sln script
call :executeCommand "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild" ccextractor.sln
rem check whether installation successful
if EXIST Debug\ccextractorwin.exe (
    cd Debug
    rem Run testsuite
    echo Run tests
    call :postStatus "testing" "Running tests"
    call :executeCommand cd %suiteDstDir%
    call :executeCommand "%tester%" --entries "%testFile%" --executable "%dstDir%\windows\Debug\ccextractorwin.exe" --tempfolder "%tempFolder%" --timeout 3000 --reportfolder "%reportFolder%" --resultfolder "%resultFolder%" --samplefolder "%sampleFolder%" --method Server --url "%reportURL%"
    call :postStatus "completed" "Ran all tests"
    echo Done running tests
    rem Shut down
    timeout 5
    shutdown -s -t 0
)
else
(
    call :haltAndCatchFire "build"
)
echo End
EXIT %ERRORLEVEL%
rem Functions to shorten the script

rem Fail when the exit status is not equal to 0
:executeCommand
echo %* >> "%logFile%"
%* >> "%logFile%"
SET /A status=%ERRORLEVEL%
IF %status% NEQ 0 (
    echo Command exited with %status% >> "%logFile%"
    rem No message needed as we post before anyway
    call :haltAndCatchFire ""
)
EXIT /B 0

rem Post status to the server
:postStatus
curl -s -A "%userAgent%" --data "type=progress&status=%~1&message=%~2" -w "\n" "%reportURL%" >> "%logFile%"
EXIT /B 0

rem Exit script and post abort status
:haltAndCatchFire
echo Halt and catch fire (reason: %~1)
call :postStatus "canceled" %~1 >> "%logFile%"
echo Post log
curl -s -A "%userAgent%" --form "type=logupload" --form "file=@%logFile%" -w "\n" "%reportURL%"
rem Shut down, but only in 10 seconds, to give the time to finish the post status
timeout 10
shutdown -s -t 0
EXIT 0

Update runCI to fix #83 and fix #84

Update runCI to fix #83 and fix #84

Closes #83, closes #84 by updating the runCI bat script.


REM test_programs_manager_api.bat
REM -------------------------------------------

curl http://localhost:4000/programs_manager/test  1> test_programs_manager_api.log 2>&1

curl http://localhost:4000/programs_manager/get_one_row  1>> test_programs_manager_api.log 2>>&1

Create test_programs_manager_api.bat

Create test_programs_manager_api.bat


@echo off

::Ensure we have administrative privileges in order to install files and set environment variables
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' == '0' (
    ::If no error is encountered, we have administrative privileges
    goto GotAdminPrivileges
)
echo Requesting administrative privileges...
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadminprivileges.vbs"
set params = %*:"=""
echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadminprivileges.vbs"
"%temp%\getadminprivileges.vbs"
exit /B
:GotAdminPrivileges
if exist "%temp%\getadminprivileges.vbs" ( del "%temp%\getadminprivileges.vbs" )
pushd "%CD%"
cd /D "%~dp0"

title Install Java

set jdk_version=10.0.2
set jdk_filename=openjdk-%jdk_version%_windows-x64_bin
set jdk_url=https://download.java.net/java/GA/jdk10/%jdk_version%/19aef61b38124481863b1413dce1855f/13/%jdk_filename%.tar.gz

if exist "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%" (
    echo %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% already exists, skipping install
    goto SetEnvVars
)

echo Downloading required files to %TEMP%
powershell -Command "Invoke-WebRequest %jdk_url% -OutFile $env:temp\%jdk_filename%.tar.gz"
::Download 7zip (command line version) in order to extract the tar.gz file since there is no native support in Windows
powershell -Command "Invoke-WebRequest https://www.7-zip.org/a/7za920.zip -OutFile $env:temp\7za920.zip"
powershell -Command "Expand-Archive $env:temp\7za920.zip -DestinationPath $env:temp\7za920 -Force"

echo Extracting and installing JDK to %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%
"%TEMP%\7za920\7za.exe" x "%TEMP%\%jdk_filename%.tar.gz" -o"%TEMP%" -r -y
"%TEMP%\7za920\7za.exe" x "%TEMP%\%jdk_filename%.tar" -o"%TEMP%\openjdk-%jdk_version%" -r -y
md "%PROGRAMFILES%\Java\openjdk"
move "%TEMP%\openjdk-%jdk_version%\jdk-%jdk_version%" "%PROGRAMFILES%\Java\openjdk"

echo Removing downloaded files
rmdir /S /Q %TEMP%\7za920
del /Q %TEMP%\7za920.zip
rmdir /S /Q %TEMP%\openjdk-%jdk_version%
del /Q %TEMP%\%jdk_filename%.tar
del /Q %TEMP%\%jdk_filename%.tar.gz

:SetEnvVars
echo Setting environment variables
setx /M JAVA_HOME "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%"
set java_bin=%%JAVA_HOME%%\bin
echo %PATH%|find /i "%java_bin%">nul  || setx /M PATH "%PATH%;%java_bin%"

pause

@echo off

:: Ensure we have administrative privileges in order to install files and set environment variables
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' == '0' (
    ::If no error is encountered, we have administrative privileges
    goto GotAdminPrivileges
)
echo Requesting administrative privileges...
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadminprivileges.vbs"
set params = %*:"=""
echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadminprivileges.vbs"
"%temp%\getadminprivileges.vbs"
exit /B
:GotAdminPrivileges
if exist "%temp%\getadminprivileges.vbs" ( del "%temp%\getadminprivileges.vbs" )
pushd "%CD%"
cd /D "%~dp0"

title Install Java

set jdk_version=10.0.2
set jdk_filename=openjdk-%jdk_version%_windows-x64_bin
set jdk_url=https://download.java.net/java/GA/jdk10/%jdk_version%/19aef61b38124481863b1413dce1855f/13/%jdk_filename%.tar.gz

if exist "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%" (
    echo %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% already exists, skipping install
    goto SetEnvVars
)

echo Downloading required files to %TEMP%
powershell -Command "Invoke-WebRequest %jdk_url% -OutFile $env:temp\%jdk_filename%.tar.gz"
:: Download 7zip (command line version) in order to extract the tar.gz file since there is no native support in Windows
powershell -Command "Invoke-WebRequest https://www.7-zip.org/a/7za920.zip -OutFile $env:temp\7za920.zip"
powershell -Command "Expand-Archive $env:temp\7za920.zip -DestinationPath $env:temp\7za920 -Force"

echo Extracting and installing JDK to %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%
"%TEMP%\7za920\7za.exe" x "%TEMP%\%jdk_filename%.tar.gz" -o"%TEMP%" -r -y
"%TEMP%\7za920\7za.exe" x "%TEMP%\%jdk_filename%.tar" -o"%TEMP%\openjdk-%jdk_version%" -r -y
md "%PROGRAMFILES%\Java\openjdk"
move "%TEMP%\openjdk-%jdk_version%\jdk-%jdk_version%" "%PROGRAMFILES%\Java\openjdk"

echo Removing downloaded files
rmdir /S /Q %TEMP%\7za920
del /Q %TEMP%\7za920.zip
rmdir /S /Q %TEMP%\openjdk-%jdk_version%
del /Q %TEMP%\%jdk_filename%.tar
del /Q %TEMP%\%jdk_filename%.tar.gz

:SetEnvVars
echo Setting environment variables
powershell -Command "[Environment]::SetEnvironmentVariable('JAVA_HOME', '%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%', 'Machine')"
set java_bin=%%JAVA_HOME%%\bin
echo %PATH%|find /i "%java_bin%">nul || powershell -Command "[Environment]::SetEnvironmentVariable('PATH', '%PATH%;%java_bin%', 'Machine')"

echo Done!
pause

Fix when setting long PATH environment variable

Avoid using setx to append to the PATH environment variable as it will
truncate to 1024 characters. Instead, use SetEnvironmentVariable
in powershell.


@echo off
setlocal

:: set batch file directory as current
pushd "%~dp0"

set SHARPMAKE_EXECUTABLE=bin\debug\Sharpmake.Application.exe

if not defined VS140COMNTOOLS (
    echo ERROR: Cannot determine the location of the VS Common Tools folder.
    goto error
)

call "%VS140COMNTOOLS%VsMSBuildCmd.bat"

call :NugetRestore Sharpmake/Sharpmake.csproj
call :BuildCsproj Sharpmake.Application/Sharpmake.Application.csproj Debug AnyCPU

set SM_CMD=%SHARPMAKE_EXECUTABLE% /sources("Sharpmake.Main.sharpmake.cs") /verbose
echo %SM_CMD%
%SM_CMD%

echo Sharpmake solution generated.
goto end

:: NUGET RESTORE
:NugetRestore
echo Restoring nuget packages for %~1
nuget restore "%~1"
if errorlevel 1 (
    echo ERROR: Failed to restore nuget package for %~1
    goto error
)
exit /b 0

@REM -----------------------------------------------------------------------
:BuildCsproj
echo Compiling %~1 in "%~2|%~3"...

msbuild /nologo /verbosity:quiet /p:Configuration="%~2" /p:Platform="%~3" "%~1"
if errorlevel 1 (
    echo ERROR: Failed to compile %~1 in "%~2|%~3".
    goto error
)
exit /b 0

@REM -----------------------------------------------------------------------
:end
:: restore caller current directory
popd
COLOR
exit /b 0

@REM -----------------------------------------------------------------------
:error
:: restore caller current directory
popd
COLOR 4F
pause
exit /b 1

@echo off
setlocal

:: set batch file directory as current
pushd "%~dp0"

set SHARPMAKE_EXECUTABLE=bin\debug\Sharpmake.Application.exe

if not defined VS140COMNTOOLS (
    echo ERROR: Cannot determine the location of the VS Common Tools folder.
    goto error
)

call "%VS140COMNTOOLS%VsMSBuildCmd.bat"

call :NugetRestore Sharpmake/Sharpmake.csproj
call :BuildCsproj Sharpmake.Application/Sharpmake.Application.csproj Debug AnyCPU

set SM_CMD=%SHARPMAKE_EXECUTABLE% /sources("Sharpmake.Main.sharpmake.cs") /verbose
echo %SM_CMD%
%SM_CMD%

echo Sharpmake solution generated.
goto end

@REM -----------------------------------------------------------------------
:NugetRestore
echo Restoring nuget packages for %~1
dotnet restore "%~1"
if errorlevel 1 (
    echo ERROR: Failed to restore nuget package for %~1
    goto error
)
exit /b 0

@REM -----------------------------------------------------------------------
:BuildCsproj
echo Compiling %~1 in "%~2|%~3"...

msbuild /nologo /verbosity:quiet /p:Configuration="%~2" /p:Platform="%~3" "%~1"
if errorlevel 1 (
    echo ERROR: Failed to compile %~1 in "%~2|%~3".
    goto error
)
exit /b 0

@REM -----------------------------------------------------------------------
:end
:: restore caller current directory
popd
COLOR
exit /b 0

@REM -----------------------------------------------------------------------
:error
:: restore caller current directory
popd
COLOR 4F
pause
exit /b 1

Use dotnet restore instead of nuget restore in boostrap.


@REM Copyright (c) Microsoft. All rights reserved.
@REM Licensed under the MIT license. See LICENSE file in the project root for full license information.

setlocal

set build-root=%~dp0..
rem // resolve to fully qualified path
for %%i in ("%build-root%") do set build-root=%%~fi

REM -- C# --
cd %build-root%\csharp\build
call build.cmd
if errorlevel 1 goto :eof
cd %build-root%

REM -- C# Service SDK --
cd %build-root%\csharp\service\build
call build.cmd
if errorlevel 1 goto :eof
cd %build-root%

Update windows_csharp.cmd to also build csharp service sdk


@echo off
setlocal enableextensions

goto entry

:usage
  echo usage: jsc dev      [-c^|--config CONFIG_JS] [BOOTSTRAP_TARGET]
  echo     or jsc compile  [-c^|--config CONFIG_JS] MODULE_FILE ... COMPILE_TARGET
  echo     or jsc identify MODULE_FILE
  echo     or jsc inline   [-c^|--config CONFIG_JS] [-n^|--invoke-main MAIN_MODULE] [-r^|--register] COMPILE_FILE ... LINK_TARGET
  echo     or jsc link     [-c^|--config CONFIG_JS] COMPILE_FILE ... LINK_TARGET
  echo     or jsc help
  echo.
  echo arguments:
  echo   BOOTSTRAP_TARGET file to generate for running in dev mode, this defaults
  echo                    to a file called bootstrap.js in the same directory as
  echo                    the config file
  echo   MODULE_FILE      file containing an uncompiled module
  echo   COMPILE_TARGET   file to generate when compiling, will contain the set of
  echo                    modules and their dependencies
  echo   COMPILE_FILE     file produced by compilation to use as input to linking,
  echo                    COMPILE_FILE must have corresponding 'COMPILE_TARGET.meta'
  echo   LINK_TARGET      file to generate when linking, will contain bootstrap
  echo                    information: bolt, install and configuration
  echo.
  echo options:
  echo   -c^|--config CONFIG_JS          override bolt configuration file
  echo                                    default: config/bolt/prod.js
  echo   -o^|--output OUTPUT_DIR         override compilation output directory
  echo                                    default: scratch/main/js/compile
  echo   -n^|--invoke-main MAIN_MODULE   specify main module of inline scripts
  echo   -r^|--register                  register modules in global namespace
  echo.

  exit /b 0

:fail_usage
  echo.
  call :usage
  exit /b 1

:fail
  exit /b 1

:entry

set base=%~dp0

if "%~1"=="" echo error: must specify mode. && goto fail_usage

set mode=%~1
shift

if "%mode%"=="dev" goto done_mode_validation
if "%mode%"=="compile" goto done_mode_validation
if "%mode%"=="identify" goto done_mode_validation
if "%mode%"=="inline" goto done_mode_validation
if "%mode%"=="link" goto done_mode_validation
if "%mode%"=="help" goto done_mode_validation

echo invalid mode [%mode%], must be one of dev^|compile^|identify^|inline^|link^|help
goto fail_usage

:done_mode_validation

if "%mode%"=="help" call :usage && exit /b 0

:parse_flags
  set flag=%~1
  if not "%flag:~0,1%"=="-" goto done_parse_flags
  shift

  if "%flag%"=="-c" goto parse_config
  if "%flag%"=="--config" goto parse_config
  if "%flag%"=="-o" goto parse_output
  if "%flag%"=="--output" goto parse_output
  if "%flag%"=="-n" goto parse_invoke
  if "%flag%"=="--invoke-main" goto parse_invoke
  if "%flag%"=="-r" goto parse_register
  if "%flag%"=="--register" goto parse_register
  if "%flag%"=="--" goto done_parse_flags
  echo invalid flag [%flag%] && goto fail_usage

  goto parse_flags

  :parse_config
    if "%~1"=="" echo %flag% requires an argument to be specified && goto fail_usage
    set config_js=%~1
    shift
  goto parse_flags

  :parse_output
    if "%~1"=="" echo %flag% requires an argument to be specified && goto fail_usage
    set output_dir=%~1
    shift
  goto parse_flags

  :parse_invoke
    if "%~1"=="" echo %flag% requires an argument to be specified && goto fail_usage
    set invoke_main=true
    set main=%~1
    shift
  goto parse_flags

  :parse_register
    set register_modules=true
  goto parse_flags

:done_parse_flags

if "%config_js%"=="" set config_js=config/bolt/prod.js
if "%output_dir%"=="" set output_dir=scratch/main/js/compile
if "%register_modules%"=="" set register_modules=false
if "%invoke_main%"=="" set invoke_main=false

if not exist "%config_js%" echo %config_js% does not exist or is not a file && goto fail
for %%i in ("%config_js%") do if exist %%~si\NUL echo %config_js% does not exist or is not a file && goto fail

for %%i in (node.exe) do set node=%%~$PATH:i
if "%node%"=="" echo error: node.js is not on the system path && goto fail

if "%mode%"=="dev" goto jsc_dev
if "%mode%"=="compile" goto jsc_compile
if "%mode%"=="identify" goto jsc_identify
if "%mode%"=="inline" goto jsc_inline
if "%mode%"=="link" goto jsc_link
exit /b 0

:jsc_dev
  if "%~1"=="" for %%F in ("%config_js%") do (set bootstrap=%%~dpFbootstrap.js) && goto exec_jsc_dev
  if "%~2"=="" set bootstrap=%~1 && goto exec_jsc_dev
  echo invalid number of arguments for jsc %mode%
  goto fail_usage

  :exec_jsc_dev
    "%node%" "%base%jsc.js" "%mode%" "%bootstrap%" "%config_js%"
exit /b 0

:jsc_compile
  goto jsc_x

:jsc_identify
  if "%~1"=="" echo invalid number of arguments for jsc %mode% && goto fail_usage
  if not "%~2"=="" echo invalid number of arguments for jsc %mode% && goto fail_usage
  "%node%" "%base%jsc.js" "%mode%" "%~1"
exit /b 0

:jsc_inline
  if "%~1"=="" echo invalid number of arguments for jsc %mode% && goto fail_usage
  if "%~2"=="" echo invalid number of arguments for jsc %mode% && goto fail_usage

  :jsc_inline_remaining
  if "%~1"=="" goto end_jsc_inline_remaining
  set remaining=%remaining% "%~1"
  shift
  goto :jsc_inline_remaining
  :end_jsc_inline_remaining

  "%node%" "%base%jsc.js" "%mode%" "%config_js%" "%invoke_main%" "%main%" "%register_modules%" %remaining%
exit /b 0

:jsc_link
  goto jsc_x

:jsc_x
  if "%~1"=="" echo invalid number of arguments for jsc %mode% && goto fail_usage
  if "%~2"=="" echo invalid number of arguments for jsc %mode% && goto fail_usage

  :jsc_x_remaining
  if "%~1"=="" goto end_jsc_x_remaining
  set remaining=%remaining% "%~1"
  shift
  goto :jsc_x_remaining
  :end_jsc_x_remaining

  "%node%" "%base%jsc.js" "%mode%" "%config_js%" %remaining%
exit /b 0

Add batch file implementation of jsc

Add batch file implementation of jsc


::
:: Windows build script for libhmsbeagle
:: Derived from a similar script for Mauve
:: (c)2008-2009 aaron darling
:: See the file COPYING.LESSER for details
::
::

SET devenv="devenv.exe"
SET vcvars="C:\Progra~2\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"

del errlog.txt

::
:: build 64-bit libs
::
call %vcvars% amd64
@ECHO ON
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Release|x64" /project libhmsbeagle /UseEnv /Out errlog.txt
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Debug|x64" /project libhmsbeagle /UseEnv /Out errlog.txt

::
:: build 32-bit libs
::
call %vcvars% x86
@ECHO ON
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Release|Win32" /project libhmsbeagle /UseEnv /Out errlog.txt
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Debug|Win32" /project libhmsbeagle /UseEnv /Out errlog.txt

::
:: build installer for 32 and 64-bit
::
start /wait "" %devenv% libhmsbeagle_vc90.sln /build "Release|Win32" /project "hmsbeagle library" /UseEnv /Out errlog.txt

::
:: Windows build script for libhmsbeagle
:: Derived from a similar script for Mauve
:: (c)2008-2009 aaron darling
:: See the file COPYING.LESSER for details
::
:: Usage: set devenv and vcvars to values appropriate for your system
::

SET devenv="devenv.exe"
SET vcvars="C:\Progra~2\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"

del errlog.txt

::
:: build 64-bit libs
::
call %vcvars% amd64
@ECHO ON
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Release|x64" /project libhmsbeagle /UseEnv /Out errlog.txt
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Debug|x64" /project libhmsbeagle /UseEnv /Out errlog.txt

::
:: build 32-bit libs
::
call %vcvars% x86
@ECHO ON
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Release|Win32" /project libhmsbeagle /UseEnv /Out errlog.txt
start /wait "" %devenv% libhmsbeagle_vc90.sln /rebuild "Debug|Win32" /project libhmsbeagle /UseEnv /Out errlog.txt

::
:: build installer for 32 and 64-bit
::
start /wait "" %devenv% libhmsbeagle_vc90.sln /build "Release|Win32" /project "hmsbeagle library" /UseEnv /Out errlog.txt

fix for wrong project name in installer build


@echo off

set _MACHINE="ultra3d"
set _EXTRUDER="left"
set _MATERIAL="inland_pla"

set _INFILE=%1
set _OUTFILE=%_INFILE:.stl=_s.gcode%

shift
set params=%1
:loop
shift
if [%1]==[] goto afterloop
set params=%params% %1
goto loop
:afterloop

shiv.exe -c configs\global -c "configs\\%_MACHINE%\\%_MACHINE%" -c "configs\\%_MACHINE%\\%_EXTRUDER%" -c "configs\\%_MACHINE%\\%_MATERIAL%" -o "%_OUTFILE%" %params% "%_INFILE%"

@echo off

if not defined _MACHINE set _MACHINE="ultra3d"
if not defined _EXTRUDER set _EXTRUDER="left"
if not defined _MATERIAL set _MATERIAL="inland_pla"

set _INFILE=%1
set _OUTFILE=%_INFILE:.stl=_s.gcode%

shift
set params=%1
:loop
shift
if [%1]==[] goto afterloop
set params=%params% %1
goto loop
:afterloop

shiv.exe -c configs\global -c "configs\\%_MACHINE%\\%_MACHINE%" -c "configs\\%_MACHINE%\\%_EXTRUDER%" -c "configs\\%_MACHINE%\\%_MATERIAL%" -o "%_OUTFILE%" %params% "%_INFILE%"

shiv_export.bat: Allow setting %_MACHINE%, %_EXTRUDER%, and %_MATERIAL% through environment variables.


"%sdkverpath%" -q -version:"%sdkver%"
call setenv /x64

rem install python packages
pip install numpy
rem builds currently fail
rem pip install numexpr
rem pip install tables >= 3.1.1
pip install enum34>=1.0.4
pip install stevedore>=1.2.0
pip install click>=3.3
pip install pyyaml>=3.11
pip install sphinx>=1.3.1
pip install tabulate>=0.7.4
pip install mock==1.0.1
pip install coverage
pip install flake8

rem install simphony-common
python setup.py develop
if %errorlevel% neq 0 exit /b %errorlevel%
cd examples/plugin
python setup.py develop
if %errorlevel% neq 0 exit /b %errorlevel%
cd ..

"%sdkverpath%" -q -version:"%sdkver%"
call setenv /x64

rem install python packages
pip install numpy
rem builds currently fail
rem pip install numexpr
rem pip install tables >= 3.1.1
pip install enum34>=1.0.4
pip install stevedore>=1.2.0
pip install click>=3.3
pip install pyyaml>=3.11
pip install sphinx>=1.3.1
pip install tabulate>=0.7.4
pip install mock==1.0.1
pip install coverage
pip install flake8
pip install hypothesis

rem install simphony-common
python setup.py develop
if %errorlevel% neq 0 exit /b %errorlevel%
cd examples/plugin
python setup.py develop
if %errorlevel% neq 0 exit /b %errorlevel%
cd ..

add hypothesis to appveyor-install.cmd

add hypothesis to appveyor-install.cmd


# Copyright 2009 The Go Authors.  All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# ugly hack to deal with whitespaces in $GOROOT
nullstring :=
space := $(nullstring) # a space at the end
QUOTED_GOROOT:=$(subst $(space),\ ,$(GOROOT))

include $(QUOTED_GOROOT)/src/Make.common

PREREQ+=$(patsubst %,%.make,$(DEPS))

all: $(TARG)

$(TARG): _go_.$O $(OFILES)
	$(QUOTED_GOBIN)/$(LD) -o $@ _go_.$O $(OFILES)

_go_.$O: $(GOFILES) $(PREREQ)
	$(QUOTED_GOBIN)/$(GC) -o $@ $(GOFILES)

install: $(QUOTED_GOBIN)/$(TARG)

$(QUOTED_GOBIN)/$(TARG): $(TARG)
	cp -f $(TARG) $(QUOTED_GOBIN)

CLEANFILES+=$(TARG)

nuke: clean
	rm -f $(QUOTED_GOBIN)/$(TARG)

# Copyright 2009 The Go Authors.  All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

all: $(TARG)

# ugly hack to deal with whitespaces in $GOROOT
nullstring :=
space := $(nullstring) # a space at the end
QUOTED_GOROOT:=$(subst $(space),\ ,$(GOROOT))

include $(QUOTED_GOROOT)/src/Make.common

PREREQ+=$(patsubst %,%.make,$(DEPS))

$(TARG): _go_.$O $(OFILES)
	$(QUOTED_GOBIN)/$(LD) -o $@ _go_.$O $(OFILES)

_go_.$O: $(GOFILES) $(PREREQ)
	$(QUOTED_GOBIN)/$(GC) -o $@ $(GOFILES)

install: $(QUOTED_GOBIN)/$(TARG)

$(QUOTED_GOBIN)/$(TARG): $(TARG)
	cp -f $(TARG) $(QUOTED_GOBIN)

CLEANFILES+=$(TARG)

nuke: clean
	rm -f $(QUOTED_GOBIN)/$(TARG)

Make.cmd: make 'all' the default target (was 'clean': BUG)

R=rsc
CC=golang-dev
https://golang.org/cl/661041


:: Copyright 2012 The Go Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style
:: license that can be found in the LICENSE file.
@echo off

:: Keep environment variables within this script
:: unless invoked with --no-local.
if x%1==x--no-local goto nolocal
if x%2==x--no-local goto nolocal
setlocal
:nolocal

set GOBUILDFAIL=0

:: we disallow local import for non-local packages, if %GOROOT% happens
:: to be under %GOPATH%, then some tests below will fail
set GOPATH=

rem TODO avoid rebuild if possible

if x%1==x--no-rebuild goto norebuild
echo # Building packages and commands.
go install -a -v std
if errorlevel 1 goto fail
echo.
:norebuild

:: we must unset GOROOT_FINAL before tests, because runtime/debug requires
:: correct access to source code, so if we have GOROOT_FINAL in effect,
:: at least runtime/debug test will fail.
set GOROOT_FINAL=

:: get CGO_ENABLED
go env > env.bat
if errorlevel 1 goto fail
call env.bat
del env.bat
echo.

echo # Testing packages.
go test std -short -timeout=120s
if errorlevel 1 goto fail
echo.

echo # runtime -cpu=1,2,4
go test runtime -short -timeout=120s -cpu=1,2,4
if errorlevel 1 goto fail
echo.

echo # sync -cpu=10
go test sync -short -timeout=120s -cpu=10
if errorlevel 1 goto fail
echo.

if not "%GOHOSTOS%-%GOOS%-%GOARCH%-%CGO_ENABLED%" == "windows-windows-amd64-1" goto norace
echo # Testing race detector.
go test -race -i flag
if errorlevel 1 goto fail
go test -race -short flag
if errorlevel 1 goto fail
echo.
:norace

echo # ..\misc\dashboard\builder ..\misc\goplay
go build ..\misc\dashboard\builder ..\misc\goplay
if errorlevel 1 goto fail
echo.

echo # ..\test\bench\go1
go test ..\test\bench\go1
if errorlevel 1 goto fail
echo.

:: cgo tests
if x%CGO_ENABLED% == x0 goto nocgo
echo # ..\misc\cgo\life
go run "%GOROOT%\test\run.go" - ..\misc\cgo\life
if errorlevel 1 goto fail
echo.

echo # ..\misc\cgo\stdio
go run "%GOROOT%\test\run.go" - ..\misc\cgo\stdio
if errorlevel 1 goto fail
echo.

echo # ..\misc\cgo\test
go test ..\misc\cgo\test
if errorlevel 1 goto fail
echo.
:nocgo

echo # ..\doc\progs
go run "%GOROOT%\test\run.go" - ..\doc\progs
if errorlevel 1 goto fail
echo.

:: TODO: The other tests in run.bash.

set OLDGOMAXPROCS=%GOMAXPROCS%

echo # ..\test
cd ..\test
set FAIL=0
set GOMAXPROCS=
go run run.go
if errorlevel 1 set FAIL=1
cd ..\src
echo.
if %FAIL%==1 goto fail

set GOMAXPROCS=%OLDGOMAXPROCS%
set OLDGOMAXPROCS=

echo # Checking API compatibility.
go tool api -c ..\api\go1.txt -next ..\api\next.txt -except ..\api\except.txt
if errorlevel 1 goto fail
echo.

echo ALL TESTS PASSED
goto end

:fail
set GOBUILDFAIL=1

:end

:: Copyright 2012 The Go Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style
:: license that can be found in the LICENSE file.
@echo off

:: Keep environment variables within this script
:: unless invoked with --no-local.
if x%1==x--no-local goto nolocal
if x%2==x--no-local goto nolocal
setlocal
:nolocal

set GOBUILDFAIL=0

:: we disallow local import for non-local packages, if %GOROOT% happens
:: to be under %GOPATH%, then some tests below will fail
set GOPATH=

rem TODO avoid rebuild if possible

if x%1==x--no-rebuild goto norebuild
echo # Building packages and commands.
go install -a -v std
if errorlevel 1 goto fail
echo.
:norebuild

:: we must unset GOROOT_FINAL before tests, because runtime/debug requires
:: correct access to source code, so if we have GOROOT_FINAL in effect,
:: at least runtime/debug test will fail.
set GOROOT_FINAL=

:: get CGO_ENABLED
go env > env.bat
if errorlevel 1 goto fail
call env.bat
del env.bat
echo.

echo # Testing packages.
go test std -short -timeout=120s
if errorlevel 1 goto fail
echo.

echo # runtime -cpu=1,2,4
go test runtime -short -timeout=240s -cpu=1,2,4
if errorlevel 1 goto fail
echo.

echo # sync -cpu=10
go test sync -short -timeout=120s -cpu=10
if errorlevel 1 goto fail
echo.

if not "%GOHOSTOS%-%GOOS%-%GOARCH%-%CGO_ENABLED%" == "windows-windows-amd64-1" goto norace
echo # Testing race detector.
go test -race -i flag
if errorlevel 1 goto fail
go test -race -short flag
if errorlevel 1 goto fail
echo.
:norace

echo # ..\misc\dashboard\builder ..\misc\goplay
go build ..\misc\dashboard\builder ..\misc\goplay
if errorlevel 1 goto fail
echo.

echo # ..\test\bench\go1
go test ..\test\bench\go1
if errorlevel 1 goto fail
echo.

:: cgo tests
if x%CGO_ENABLED% == x0 goto nocgo
echo # ..\misc\cgo\life
go run "%GOROOT%\test\run.go" - ..\misc\cgo\life
if errorlevel 1 goto fail
echo.

echo # ..\misc\cgo\stdio
go run "%GOROOT%\test\run.go" - ..\misc\cgo\stdio
if errorlevel 1 goto fail
echo.

echo # ..\misc\cgo\test
go test ..\misc\cgo\test
if errorlevel 1 goto fail
echo.
:nocgo

echo # ..\doc\progs
go run "%GOROOT%\test\run.go" - ..\doc\progs
if errorlevel 1 goto fail
echo.

:: TODO: The other tests in run.bash.

set OLDGOMAXPROCS=%GOMAXPROCS%

echo # ..\test
cd ..\test
set FAIL=0
set GOMAXPROCS=
go run run.go
if errorlevel 1 set FAIL=1
cd ..\src
echo.
if %FAIL%==1 goto fail

set GOMAXPROCS=%OLDGOMAXPROCS%
set OLDGOMAXPROCS=

echo # Checking API compatibility.
go tool api -c ..\api\go1.txt -next ..\api\next.txt -except ..\api\except.txt
if errorlevel 1 goto fail
echo.

echo ALL TESTS PASSED
goto end

:fail
set GOBUILDFAIL=1

:end

run.bat: make windows runtime test timeout same as other os

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/8551043