Skip to content

Commit

Permalink
Add standard build scripts
Browse files Browse the repository at this point in the history
Make our repo look like most others by having the standard:

- Restore.cmd
- Build.cmd
- Test.cmd
  • Loading branch information
jaredpar committed Mar 24, 2017
1 parent f7f5e67 commit 096e4fd
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\build.ps1" -build %*
2 changes: 1 addition & 1 deletion BuildAndTest.proj
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<RunTestsArgs>$(NuGetPackageRoot)\xunit.runner.console\$(xunitrunnerconsoleVersion)\tools $(RunTestArgs) @(TestAssemblies, ' ')</RunTestsArgs>
</PropertyGroup>

<Exec Condition="'$(TestVsi)' != 'true'" Command="&quot;$(CoreRunExe)&quot; $(CoreRunArgs)" />
<Exec Condition="'$(TestVsi)' != 'true' AND '$(SkipCoreClr)' != 'true'" Command="&quot;$(CoreRunExe)&quot; $(CoreRunArgs)" />

<Exec Command="&quot;$(RunTestsExe)&quot; $(RunTestsArgs)" />

Expand Down
4 changes: 2 additions & 2 deletions Restore.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@if not defined EchoOn @echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\restore-legacy.ps1" %*
@echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\build.ps1" -restore %*

2 changes: 2 additions & 0 deletions Test.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\build.ps1" -test %*
56 changes: 56 additions & 0 deletions build/scripts/build-utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,60 @@ function Get-VisualStudioDir() {
return $p
}

# Clear out the NuGet package cache
function Clear-PackageCache() {
$nuget = Ensure-NuGet
Exec { & $nuget locals all -clear }
}

# Restore a single project
function Restore-Project([string]$fileName, [string]$nuget, [string]$msbuildDir) {
$nugetConfig = Join-Path $repoDir "nuget.config"
$filePath = Join-Path $repoDir $fileName
Exec { & $nuget restore -verbosity quiet -configfile $nugetConfig -MSBuildPath $msbuildDir -Project2ProjectTimeOut 1200 $filePath }
}

# Restore all of the projects that the repo consumes
function Restore-Packages([switch]$clean = $false, [string]$msbuildDir = "", [string]$project = "") {
$nuget = Ensure-NuGet
if ($msbuildDir -eq "") {
$msbuildDir = Get-MSBuildDir
}

Write-Host "Restore using MSBuild at $msbuildDir"

if ($clean) {
Write-Host "Deleting project.lock.json files"
Get-ChildItem $repoDir -re -in project.lock.json | Remove-Item
}

if ($project -ne "") {
Write-Host "Restoring project $project"
Restore-Project -fileName $project -nuget $nuget -msbuildDir $msbuildDir
}
else {
$all = @(
"Toolsets:build\ToolsetPackages\project.json",
"Toolsets (Dev14 VS SDK build tools):build\ToolsetPackages\dev14.project.json",
"Toolsets (Dev15 VS SDK RC build tools):build\ToolsetPackages\dev15rc.project.json",
"Samples:src\Samples\Samples.sln",
"Templates:src\Setup\Templates\Templates.sln",
"Toolsets Compiler:build\Toolset\Toolset.csproj",
"Roslyn:Roslyn.sln",
"DevDivInsertionFiles:src\Setup\DevDivInsertionFiles\DevDivInsertionFiles.sln",
"DevDiv Roslyn Packages:src\Setup\DevDivPackages\Roslyn\project.json",
"DevDiv Debugger Packages:src\Setup\DevDivPackages\Debugger\project.json")

foreach ($cur in $all) {
$both = $cur.Split(':')
Write-Host "Restoring $($both[0])"
Restore-Project -fileName $both[1] -nuget $nuget -msbuildDir $msbuildDir
}
}
}

# Restore all of the projects that the repo consumes
function Restore-All([switch]$clean = $false, [string]$msbuildDir = "") {
Restore-Packages -clean:$clean -msbuildDir $msbuildDir
}

71 changes: 71 additions & 0 deletions build/scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Script to run standard developer operations: restore, build and test.
[CmdletBinding(PositionalBinding=$false)]
param (
[switch]$build = $false,
[switch]$restore = $false,
[switch]$test = $false,
[switch]$clean = $false,
[switch]$clearPackageCache = $false,
[string]$project = "",
[string]$msbuildDir = "")

Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"

function Print-Usage() {
Write-Host "Build.ps1"
Write-Host "`t-build Run a build operation (default false)"
Write-Hest "`t-restore Run a restore operation (default false)"
Write-Hest "`t-test Run tests (default false)"
Write-Host "`t-clean Do a clean build / restore (default false)"
Write-Host "`t-clearPackageCache Clear package cache before restoring"
Write-Host "`t-project <path> Project the build or restore should target"
Write-Host "`t-msbuildDir <path> MSBuild which should be used"
}

function Run-Build() {
$buildArgs = "/v:m /m"
if ($clean) {
$buildArgs = "$buildArgs /t:Rebuild"
}

$target = if ($project -ne "") { $project } else { Join-Path $repoDir "Roslyn.sln" }
$buildArgs = "$buildArgs $target"

Invoke-Expression "& `"$msbuild`" $buildArgs"
}

function Run-Test() {
$proj = Join-Path $repoDir "BuildAndTest.proj"
Invoke-Expression "& `"$msbuild`" /v:m /p:SkipCoreClr=true /t:Test $proj"
}

try {
. (Join-Path $PSScriptRoot "build-utils.ps1")

$nuget = Ensure-NuGet
if ($msbuildDir -eq "") {
$msbuildDir = Get-MSBuildDir
}
$msbuild = Join-Path $msbuildDir "msbuild.exe"

if ($restore) {
if ($clearPackageCache) {
Clear-PackageCache
}

Restore-Pacakages -clean:$clean -msbuildDir $msbuildDir -project:project
}

if ($build) {
Run-Build
}

if ($test) {
Run-Test
}
}
catch {
Write-Host $_
exit 1
}
2 changes: 1 addition & 1 deletion build/scripts/cibuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ try {

if (-not $skipRestore) {
Write-Host "Running restore"
& ".\build\scripts\restore.ps1" -msbuildDir $msbuildDir
Restore-All -msbuildDir $msbuildDir
}

# Ensure the binaries directory exists because msbuild can fail when part of the path to LogFile isn't present.
Expand Down

0 comments on commit 096e4fd

Please sign in to comment.