Restore accidental deletion of common.psm1

This commit is contained in:
Nate McMaster 2018-12-20 17:34:06 -08:00
parent c3beb1f9b1
commit 92b40a4dbc
No known key found for this signature in database
GPG Key ID: A778D9601BD78810
3 changed files with 124 additions and 2 deletions

122
eng/scripts/common.psm1 Normal file
View File

@ -0,0 +1,122 @@
$ErrorActionPreference = 'Stop'
# Update the default TLS support to 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
function Invoke-Block([scriptblock]$cmd, [string]$WorkingDir = $null) {
if ($WorkingDir) {
Push-Location $WorkingDir
}
try {
$cmd | Out-String | Write-Verbose
& $cmd
# Need to check both of these cases for errors as they represent different items
# - $?: did the powershell script block throw an error
# - $lastexitcode: did a windows command executed by the script block end in error
if ((-not $?) -or ($lastexitcode -ne 0)) {
if ($error -ne $null)
{
Write-Warning $error[0]
}
throw "Command failed to execute: $cmd"
}
}
finally {
if ($WorkingDir) {
Pop-Location
}
}
}
function SaveXml([xml]$xml, [string]$path) {
Write-Verbose "Saving to $path"
$ErrorActionPreference = 'stop'
$settings = New-Object System.XML.XmlWriterSettings
$settings.OmitXmlDeclaration = $true
$settings.Encoding = New-Object System.Text.UTF8Encoding( $true )
$writer = [System.XML.XMLTextWriter]::Create($path, $settings)
$xml.Save($writer)
$writer.Close()
}
function LoadXml([string]$path) {
Write-Verbose "Reading from $path"
$ErrorActionPreference = 'stop'
$obj = new-object xml
$obj.PreserveWhitespace = $true
$obj.Load($path)
return $obj
}
function Get-MSBuildPath {
param(
[switch]$Prerelease,
[string[]]$Requires
)
$vsInstallDir = $null
if ($env:VSINSTALLDIR -and (Test-Path $env:VSINSTALLDIR)) {
$vsInstallDir = $env:VSINSTALLDIR
Write-Verbose "Using VSINSTALLDIR=$vsInstallDir"
}
else {
$vswhere = "${env:ProgramFiles(x86)}/Microsoft Visual Studio/Installer/vswhere.exe"
Write-Verbose "Using vswhere.exe from $vswhere"
if (-not (Test-Path $vswhere)) {
Write-Error "Missing prerequisite: could not find vswhere"
}
[string[]] $vswhereArgs = @()
if ($Prerelease) {
$vswhereArgs += '-prerelease'
}
if ($Requires) {
foreach ($r in $Requires) {
$vswhereArgs += '-requires', $r
}
}
$installs = & $vswhere -format json -version '[15.0, 16.0)' -latest -products * @vswhereArgs | ConvertFrom-Json
if (!$installs) {
Write-Error "Missing prerequisite: could not find any installations of Visual Studio"
}
$vs = $installs | Select-Object -First 1
$vsInstallDir = $vs.installationPath
Write-Host "Using $($vs.displayName)"
}
$msbuild = Join-Path $vsInstallDir 'MSBuild/15.0/bin/msbuild.exe'
if (!(Test-Path $msbuild)) {
Write-Error "Missing prerequisite: could not find msbuild.exe"
}
return $msbuild
}
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath) {
if ($RemotePath -notlike 'http*') {
Copy-Item $RemotePath $LocalPath
return
}
$retries = 10
while ($retries -gt 0) {
$retries -= 1
try {
Invoke-WebRequest -UseBasicParsing -Uri $RemotePath -OutFile $LocalPath
return
}
catch {
Write-Verbose "Request failed. $retries retries remaining"
}
}
Write-Error "Download failed: '$RemotePath'."
}

View File

@ -20,7 +20,7 @@ param(
$ErrorActionPreference = 'Stop'
$repoRoot = Resolve-Path "$PSScriptRoot/../../../"
Import-Module -Scope Local "$repoRoot/scripts/common.psm1" -Force
Import-Module -Scope Local "$repoRoot/eng/scripts/common.psm1" -Force
$msbuild = Get-MSBuildPath -Prerelease -requires 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
$harvestRoot = "$repoRoot/obj/sfx/"

View File

@ -51,7 +51,7 @@ $ErrorActionPreference = 'Stop'
Set-StrictMode -Version 1
$repoRoot = Resolve-Path "$PSScriptRoot/../../"
Import-Module "$repoRoot/scripts/common.psm1" -Scope Local -Force
Import-Module "$repoRoot/eng/scripts/common.psm1" -Scope Local -Force
# This ID corresponds to the ProdCon build number
Write-Host "ProductBuildId: $env:PRODUCTBUILDID"