Skip to content

Commit

Permalink
Merge pull request #1410 from thomaslevesque/exclude-package-version
Browse files Browse the repository at this point in the history
Exclude package versions from tool package folders
  • Loading branch information
blairconrad committed Aug 19, 2018
2 parents 35d5a21 + e4b5235 commit 169b809
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@ artifacts
packages
src/VersionInfo.cs
src/FakeItEasy.nuspec
tools/packages.config.sha1

*.*proj.user
*.lock.json
Expand Down
2 changes: 1 addition & 1 deletion build.cmd
@@ -1 +1 @@
@call %~dp0\tools\run-csx.cmd %~dp0\tools\build.csx %*
@powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "%~dp0\tools\run-csx.ps1 %~dp0\tools\build.csx %*"
12 changes: 6 additions & 6 deletions tools/build.csx
@@ -1,5 +1,5 @@
#r "packages/Bullseye.1.1.0-rc.2/lib/netstandard2.0/Bullseye.dll"
#r "packages/SimpleExec.2.2.0/lib/netstandard2.0/SimpleExec.dll"
#r "packages/Bullseye/lib/netstandard2.0/Bullseye.dll"
#r "packages/SimpleExec/lib/netstandard1.3/SimpleExec.dll"

using System.Runtime.CompilerServices;
using static Bullseye.Targets;
Expand Down Expand Up @@ -51,12 +51,12 @@ var testSuites = new Dictionary<string, string[]>
// tool locations

static var toolsPackagesDirectory = Path.Combine(GetCurrentScriptDirectory(), "packages");
var vswhere = $"{toolsPackagesDirectory}/vswhere.1.0.62/tools/vswhere.exe";
var gitversion = $"{toolsPackagesDirectory}/GitVersion.CommandLine.4.0.0-beta0012/tools/GitVersion.exe";
var vswhere = $"{toolsPackagesDirectory}/vswhere/tools/vswhere.exe";
var gitversion = $"{toolsPackagesDirectory}/GitVersion.CommandLine/tools/GitVersion.exe";
var msBuild = $"{GetVSLocation()}/MSBuild/15.0/Bin/MSBuild.exe";
var nuget = $"{GetCurrentScriptDirectory()}/.nuget/NuGet.exe";
var pdbGit = $"{toolsPackagesDirectory}/pdbGit.3.0.41/tools/PdbGit.exe";
static var xunit = $"{toolsPackagesDirectory}/xunit.runner.console.2.0.0/tools/xunit.console.exe";
var pdbGit = $"{toolsPackagesDirectory}/pdbGit/tools/PdbGit.exe";
static var xunit = $"{toolsPackagesDirectory}/xunit.runner.console/tools/xunit.console.exe";

// artifact locations
var logsDirectory = "./artifacts/logs";
Expand Down
2 changes: 1 addition & 1 deletion tools/prepare_release.cmd
@@ -1 +1 @@
@call %~dp0\run-csx.cmd %~dp0\prepare_release.csx %*
@powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "%~dp0\tools\run-csx.ps1 %~dp0\tools\prepare-release.csx %*"
2 changes: 1 addition & 1 deletion tools/prepare_release.csx
@@ -1,4 +1,4 @@
#r ".\packages\Octokit.0.26.0\lib\net45\Octokit.dll"
#r ".\packages\Octokit\lib\net45\Octokit.dll"

using System.Linq;
using System.Runtime.CompilerServices;
Expand Down
35 changes: 0 additions & 35 deletions tools/run-csx.cmd

This file was deleted.

99 changes: 99 additions & 0 deletions tools/run-csx.ps1
@@ -0,0 +1,99 @@
# Treat all errors as terminating
$ErrorActionPreference = "Stop"

$ToolsDir = $PSScriptRoot
$RepoRoot = "$ToolsDir\.."
$NuGetVersion = "4.1.0"
$NuGetCacheDir = "$($Env:LOCALAPPDATA)\.nuget\v$NuGetVersion"
$NuGetCacheFile = "$NuGetCacheDir\NuGet.exe"
$NuGetDir = "$ToolsDir\.nuget"
$NuGetExe = "$NuGetDir\NuGet.exe"
$PackagesDir = "$ToolsDir\packages"
$PackagesConfig = "$ToolsDir\packages.config"
$PackagesHashFile = "$ToolsDir\packages.config.sha1"
$CsiExe = "$PackagesDir\Microsoft.Net.Compilers\tools\csi.exe"

function EnsureDirectoryExists($path)
{
if (!(Test-Path $path -PathType Container)) {
New-Item -ItemType Directory $path | Out-Null
}
}

function DownloadNuGetToCache()
{
$NuGetUrl = "https://dist.nuget.org/win-x86-commandline/v$NuGetVersion/NuGet.exe"
if (!(Test-Path $NuGetCacheFile)) {
EnsureDirectoryExists($NuGetCacheDir)
Write-Host "Downloading '$NuGetUrl' to '$NuGetCacheFile'..."
Invoke-WebRequest $NuGetUrl -OutFile $NuGetCacheFile
}
}

function CopyNuGetLocally()
{
EnsureDirectoryExists($NuGetDir)
Copy-Item $NuGetCacheFile $NuGetExe
}

function ReadPreviousPackagesHash()
{
if (Test-Path $PackagesHashFile)
{
(Get-Content $PackagesHashFile).Trim()
}
else
{
""
}
}

function WritePackagesHash($hash)
{
Set-Content $PackagesHashFile $hash
}

function ComputePackagesHash()
{
(Get-FileHash -Algorithm SHA1 -Path $PackagesConfig).Hash
}

function ClearPackagesDir()
{
if (Test-Path -Path $PackagesDir -PathType Container)
{
Write-Host "$PackagesConfig has changed, clearing packages to force reinstall..."
Remove-Item -Recurse -Force $PackagesDir
}
}

function ClearPackagesIfChanged()
{
# check if packages.config have changed
$PreviousPackagesHash = ReadPreviousPackagesHash
$PackagesHash = ComputePackagesHash
if ($PackagesHash -ne $PreviousPackagesHash) {
# if packages.config has changed, clear packages and store new hash
ClearPackagesDir
WritePackagesHash($PackagesHash)
}
}

function RestorePackages()
{
& $NuGetExe install $PackagesConfig -OutputDirectory $PackagesDir -Verbosity quiet -ExcludeVersion
}

# change working directory to the repository root
Push-Location $RepoRoot

DownloadNuGetToCache
CopyNuGetLocally
ClearPackagesIfChanged
RestorePackages

# run build script
& $CsiExe $args

# return to original working directory
Pop-Location

0 comments on commit 169b809

Please sign in to comment.