-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.psm1
82 lines (71 loc) · 3.31 KB
/
build.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function Get-EnvironmentInformation {
$environment = @{}
try {
$Runtime = [System.Runtime.InteropServices.RuntimeInformation]
$OSPlatform = [System.Runtime.InteropServices.OSPlatform]
$environment += @{'IsCoreCLR' = 'Core' -eq $PSVersionTable.PSEdition}
$environment += @{'IsLinux' = $Runtime::IsOSPlatform($OSPlatform::Linux)}
$environment += @{'IsOSX' = $Runtime::IsOSPlatform($OSPlatform::OSX)}
$environment += @{'IsWindows' = $Runtime::IsOSPlatform($OSPlatform::Windows)}
}
catch {
$environment += @{'IsCoreCLR' = $false}
$environment += @{'IsLinux' = $false}
$environment += @{'IsOSX' = $false}
$environment += @{'IsWindows' = $true}
}
if ($Environment.IsWindows) {
$environment += @{'IsAdmin' = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)}
# Can't use $env:HOME - not available on older systems (e.g. in AppVeyor)
$environment += @{'nugetPackagesRoot' = "${env:HOMEDRIVE}${env:HOMEPATH}\.nuget\packages"}
}
else {
$environment += @{'nugetPackagesRoot' = "${env:HOME}/.nuget/packages"}
}
if ($Environment.IsLinux) {
$LinuxInfo = Get-Content /etc/os-release -Raw | ConvertFrom-StringData
$environment += @{'LinuxInfo' = $LinuxInfo}
$environment += @{'IsUbuntu' = $LinuxInfo.ID -match 'ubuntu'}
$environment += @{'IsUbuntu14' = $Environment.IsUbuntu -and $LinuxInfo.VERSION_ID -match '14.04'}
$environment += @{'IsUbuntu16' = $Environment.IsUbuntu -and $LinuxInfo.VERSION_ID -match '16.04'}
$environment += @{'IsCentOS' = $LinuxInfo.ID -match 'centos' -and $LinuxInfo.VERSION_ID -match '7'}
$environment += @{'IsFedora' = $LinuxInfo.ID -match 'fedora' -and $LinuxInfo.VERSION_ID -ge 24}
$environment += @{'IsOpenSUSE' = $LinuxInfo.ID -match 'opensuse'}
$environment += @{'IsOpenSUSE13' = $Environment.IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '13'}
$environment += @{'IsOpenSUSE42.1' = $Environment.IsOpenSUSE -and $LinuxInfo.VERSION_ID -match '42.1'}
$environment += @{'IsRedHatFamily' = $Environment.IsCentOS -or $Environment.IsFedora -or $Environment.IsOpenSUSE}
# Workaround for temporary LD_LIBRARY_PATH hack for Fedora 24
# https://github.com/PowerShell/PowerShell/issues/2511
if ($environment.IsFedora -and (Test-Path ENV:\LD_LIBRARY_PATH)) {
Remove-Item -Force ENV:\LD_LIBRARY_PATH
Get-ChildItem ENV:
}
}
return [PSCustomObject] $environment
}
function Find-Dotnet {
$OriginalPath = $env:PATH
$Environment = Get-EnvironmentInformation
$DotnetPath = if ($Environment.IsWindows) {
"$env:LocalAppData\Microsoft\dotnet"
}
else {
"$env:HOME/.dotnet"
}
if (-not (Test-DotnetExists)) {
"Could not find 'dotnet', appending $DotnetPath to PATH."
$env:PATH += [IO.Path]::PathSeparator + $dotnetPath
}
if (-not (Test-DotnetExists)) {
"Still could not find 'dotnet', restoring PATH."
$env:PATH = $originalPath
}
}
Function Test-DotnetExists {
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$True
}
else {
$False
}
}