Skip to content

Commit e6000d2

Browse files
committed
Remove dotnet bootstrap/installation code
We should not be doing this for the developer/user.
1 parent 9bd796b commit e6000d2

File tree

3 files changed

+5
-272
lines changed

3 files changed

+5
-272
lines changed

Tests/Build/BuildModule.tests.ps1

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -48,60 +48,6 @@ Describe "Build Module Tests" {
4848
}
4949
}
5050

51-
Context "Test-DotnetInstallation" {
52-
BeforeAll {
53-
$availableVersions = ConvertTo-PortableVersion -strVersion "2.2.400","2.2.401","2.2.405"
54-
$foundVersion = ConvertTo-PortableVersion -strVersion 2.2.402
55-
$missingVersion = ConvertTo-PortableVersion -strVersion 2.2.410
56-
}
57-
58-
It "Test-DotnetInstallation finds a good version" {
59-
Mock Get-InstalledCLIVersion { return $availableVersions }
60-
Mock Get-GlobalJSonSdkVersion { return $foundVersion }
61-
$result = Test-DotnetInstallation -requestedVersion (Get-GlobalJsonSdkVersion) -installedVersions (Get-InstalledCLIVersion)
62-
Assert-MockCalled "Get-InstalledCLIVersion" -Times 1
63-
Assert-MockCalled "Get-GlobalJsonSdkVersion" -Times 1
64-
$result | Should -Be $true
65-
}
66-
67-
It "Test-DotnetInstallation cannot find a good version should return false" {
68-
Mock Get-InstalledCLIVersion { return $availableVersions }
69-
Mock Get-GlobalJSonSdkVersion { return $missingVersion }
70-
$result = Test-DotnetInstallation -requestedVersion (Get-GlobalJsonSdkVersion) -installedVersions (Get-InstalledCLIVersion)
71-
Assert-MockCalled "Get-InstalledCLIVersion" -Times 1
72-
Assert-MockCalled "Get-GlobalJsonSdkVersion" -Times 1
73-
$result | Should -Be $false
74-
}
75-
}
76-
77-
Context "Receive-DotnetInstallScript" {
78-
79-
Mock -ModuleName Build Receive-File { new-item -type file TestDrive:/dotnet-install.sh }
80-
It "Downloads the proper non-Windows file" {
81-
try {
82-
push-location TestDrive:
83-
Receive-DotnetInstallScript -platform NonWindows
84-
"TestDrive:/dotnet-install.sh" | Should -Exist
85-
}
86-
finally {
87-
Pop-Location
88-
}
89-
}
90-
91-
Mock -ModuleName Build Receive-File { new-item -type file TestDrive:/dotnet-install.ps1 }
92-
It "Downloads the proper file Windows file" {
93-
try {
94-
push-location TestDrive:
95-
Receive-DotnetInstallScript -platform "Windows"
96-
"TestDrive:/dotnet-install.ps1" | Should -Exist
97-
}
98-
finally {
99-
Pop-Location
100-
}
101-
}
102-
103-
}
104-
10551
Context "Test result functions" {
10652
BeforeAll {
10753
$xmlFile = @'

build.ps1

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,11 @@ param(
3333
[Parameter(ParameterSetName='Test')]
3434
[switch] $InProcess,
3535

36-
[Parameter(ParameterSetName='Bootstrap')]
37-
[switch] $Bootstrap,
38-
3936
[Parameter(ParameterSetName='BuildAll')]
4037
[switch] $Catalog,
4138

4239
[Parameter(ParameterSetName='Package')]
43-
[switch] $BuildNupkg,
44-
45-
[Parameter(ParameterSetName='Package')]
46-
[switch] $CopyManifest,
47-
48-
[Parameter(ParameterSetName='Package')]
49-
[switch] $Signed
40+
[switch] $BuildNupkg
5041

5142
)
5243

@@ -90,15 +81,8 @@ END {
9081
}
9182
Start-ScriptAnalyzerBuild @buildArgs
9283
}
93-
"Bootstrap" {
94-
Install-DotNet
95-
return
96-
}
9784
"Package" {
98-
if($CopyManifest) {
99-
Copy-Manifest -signed:$Signed
100-
}
101-
Start-CreatePackage -signed:$Signed
85+
Start-CreatePackage
10286
}
10387
"Test" {
10488
Test-ScriptAnalyzer -InProcess:$InProcess

build.psm1

Lines changed: 3 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ $analyzerName = "PSScriptAnalyzer"
77

88
function Get-AnalyzerVersion
99
{
10-
$csprojPath = [io.path]::Combine($projectRoot,"Engine","Engine.csproj")
11-
$xml = [xml](Get-Content "${csprojPath}")
10+
[xml]$xml = Get-Content $([io.path]::Combine($projectRoot,"Engine","Engine.csproj"))
1211
$xml.SelectSingleNode(".//VersionPrefix")."#text"
1312
}
1413

@@ -29,61 +28,6 @@ function Publish-File
2928
}
3029
}
3130

32-
# attempt to get the users module directory
33-
function Get-UserModulePath
34-
{
35-
if ( $IsCoreCLR -and -not $IsWindows )
36-
{
37-
$platformType = "System.Management.Automation.Platform" -as [Type]
38-
if ( $platformType ) {
39-
${platformType}::SelectProductNameForDirectory("USER_MODULES")
40-
}
41-
else {
42-
throw "Could not determine users module path"
43-
}
44-
}
45-
else {
46-
"${HOME}/Documents/WindowsPowerShell/Modules"
47-
}
48-
}
49-
50-
51-
function Uninstall-ScriptAnalyzer
52-
{
53-
[CmdletBinding(SupportsShouldProcess)]
54-
param ( $ModulePath = $(Join-Path -Path (Get-UserModulePath) -ChildPath ${analyzerName}) )
55-
END {
56-
if ( $PSCmdlet.ShouldProcess("$modulePath") ) {
57-
Remove-Item -Recurse -Path "$ModulePath" -Force
58-
}
59-
}
60-
}
61-
62-
# install script analyzer, by default into the users module path
63-
function Install-ScriptAnalyzer
64-
{
65-
[CmdletBinding(SupportsShouldProcess)]
66-
param ( $ModulePath = $(Join-Path -Path (Get-UserModulePath) -ChildPath ${analyzerName}) )
67-
END {
68-
if ( $PSCmdlet.ShouldProcess("$modulePath") ) {
69-
Copy-Item -Recurse -Path "$script:destinationDir" -Destination "$ModulePath\." -Force
70-
}
71-
}
72-
}
73-
74-
# if script analyzer is installed, remove it
75-
function Uninstall-ScriptAnalyzer
76-
{
77-
[CmdletBinding(SupportsShouldProcess)]
78-
param ( $ModulePath = $(Join-Path -Path (Get-UserModulePath) -ChildPath ${analyzerName}) )
79-
END {
80-
if ((Test-Path $ModulePath) -and (Get-Item $ModulePath).PSIsContainer )
81-
{
82-
Remove-Item -Force -Recurse $ModulePath
83-
}
84-
}
85-
}
86-
8731
# Clean up the build location
8832
function Remove-Build
8933
{
@@ -157,9 +101,6 @@ function Start-ScriptAnalyzerBuild
157101

158102
BEGIN {
159103
# don't allow the build to be started unless we have the proper Cli version
160-
# this will not actually install dotnet if it's already present, but it will
161-
# install the proper version
162-
Install-Dotnet
163104
if ( -not (Test-SuitableDotnet) ) {
164105
$requiredVersion = $script:wantedVersion
165106
$foundVersion = Get-InstalledCLIVersion
@@ -431,49 +372,6 @@ function Get-TestFailures
431372
$results.SelectNodes(".//test-case[@result='Failure']")
432373
}
433374

434-
# BOOTSTRAPPING CODE FOR INSTALLING DOTNET
435-
# install dotnet cli tools based on the version mentioned in global.json
436-
function Install-Dotnet
437-
{
438-
[CmdletBinding(SupportsShouldProcess=$true)]
439-
param (
440-
[Parameter()][Switch]$Force,
441-
[Parameter()]$version = $( Get-GlobalJsonSdkVersion -Raw )
442-
)
443-
444-
if ( Test-DotnetInstallation -requestedversion $version ) {
445-
if ( $Force ) {
446-
Write-Verbose -Verbose "Installing again"
447-
}
448-
else {
449-
return
450-
}
451-
}
452-
453-
try {
454-
Push-Location $PSScriptRoot
455-
$installScriptPath = Receive-DotnetInstallScript
456-
$installScriptName = [System.IO.Path]::GetFileName($installScriptPath)
457-
If ( $PSCmdlet.ShouldProcess("$installScriptName for $version")) {
458-
& "${installScriptPath}" -c release -version $version -SkipNonVersionedFiles
459-
}
460-
# this may be the first time that dotnet has been installed,
461-
# set up the executable variable
462-
if ( -not $script:DotnetExe ) {
463-
$script:DotnetExe = Get-DotnetExe
464-
}
465-
}
466-
catch {
467-
throw $_
468-
}
469-
finally {
470-
if ( Test-Path $installScriptPath ) {
471-
Remove-Item $installScriptPath
472-
}
473-
Pop-Location
474-
}
475-
}
476-
477375
function Get-GlobalJsonSdkVersion {
478376
param ( [switch]$Raw )
479377
$json = Get-Content -raw (Join-Path $PSScriptRoot global.json) | ConvertFrom-Json
@@ -612,68 +510,6 @@ function Get-InstalledCLIVersion {
612510
return (ConvertTo-PortableVersion $installedVersions)
613511
}
614512

615-
function Test-DotnetInstallation
616-
{
617-
param (
618-
$requestedVersion = $script:wantedVersion,
619-
$installedVersions = $( Get-InstalledCLIVersion )
620-
)
621-
return (Test-SuitableDotnet -availableVersions $installedVersions -requiredVersion $requestedVersion )
622-
}
623-
624-
function Receive-File {
625-
param ( [Parameter(Mandatory,Position=0)]$uri )
626-
627-
# enable Tls12 for the request
628-
# -SslProtocol parameter for Invoke-WebRequest wasn't in PSv3
629-
$securityProtocol = [System.Net.ServicePointManager]::SecurityProtocol
630-
$tls12 = [System.Net.SecurityProtocolType]::Tls12
631-
try {
632-
if ( ([System.Net.ServicePointManager]::SecurityProtocol -band $tls12) -eq 0 ) {
633-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor $tls12
634-
}
635-
$null = Invoke-WebRequest -Uri ${uri} -OutFile "${installScriptName}"
636-
}
637-
finally {
638-
[System.Net.ServicePointManager]::SecurityProtocol = $securityProtocol
639-
}
640-
if ( (Test-Path Variable:IsWindows) -and -not $IsWindows ) {
641-
chmod +x $installScriptName
642-
}
643-
$installScript = Get-Item $installScriptName -ErrorAction Stop
644-
if ( -not $installScript ) {
645-
throw "Download failure of ${uri}"
646-
}
647-
return $installScript
648-
}
649-
650-
function Receive-DotnetInstallScript
651-
{
652-
# param '$platform' is a hook to enable forcing download of a specific
653-
# install script, generally it should not be used except in testing.
654-
param ( $platform = "" )
655-
656-
# if $platform has been set, it has priority
657-
# if it's not set to Windows or NonWindows, it will be ignored
658-
if ( $platform -eq "Windows" ) {
659-
$installScriptName = "dotnet-install.ps1"
660-
}
661-
elseif ( $platform -eq "NonWindows" ) {
662-
$installScriptName = "dotnet-install.sh"
663-
}
664-
elseif ( ((Test-Path Variable:IsWindows) -and -not $IsWindows) ) {
665-
# if the variable IsWindows exists and it is set to false
666-
$installScriptName = "dotnet-install.sh"
667-
}
668-
else { # the default case - we're running on a Windows system
669-
$installScriptName = "dotnet-install.ps1"
670-
}
671-
$uri = "https://dot.net/v1/${installScriptName}"
672-
673-
$installScript = Receive-File -Uri $uri
674-
return $installScript.FullName
675-
}
676-
677513
function Get-DotnetExe
678514
{
679515
param ( $version = $script:wantedVersion )
@@ -730,7 +566,7 @@ try {
730566
$script:DotnetExe = Get-DotnetExe
731567
}
732568
catch {
733-
Write-Warning "Could not find dotnet executable"
569+
Write-Warning "The dotnet CLI was not found, please install it: https://aka.ms/dotnet-cli"
734570
}
735571

736572
# Copies the built PSCompatibilityCollector module to the output destination for PSSA
@@ -780,44 +616,11 @@ function Copy-CrossCompatibilityModule
780616
}
781617
}
782618

783-
# copy the manifest into the module if is present
784-
function Copy-Manifest
785-
{
786-
param ( [switch]$signed )
787-
if ( $signed ) {
788-
$buildRoot = "signed"
789-
}
790-
else {
791-
$buildRoot = "out"
792-
}
793-
$analyzerVersion = Get-AnalyzerVersion
794-
# location where analyzer goes
795-
# debugging
796-
(Get-ChildItem -File -Recurse)|ForEach-Object {Write-Verbose -Verbose -Message $_}
797-
$modBaseDir = [io.path]::Combine($projectRoot,${buildRoot},"${analyzerName}", $analyzerVersion)
798-
# copy the manifest files
799-
Push-Location $buildRoot
800-
if ( Test-Path _manifest ) {
801-
Copy-Item -Recurse -Path _manifest -Destination $modBaseDir -Verbose
802-
}
803-
else {
804-
Write-Warning -Message "_manifest not found in $PWD"
805-
}
806-
Pop-Location
807-
}
808-
809619
# creates the nuget package which can be used for publishing to the gallery
810620
function Start-CreatePackage
811621
{
812-
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseCompatibleCommands', '')]
813-
param ( [switch]$signed )
814622
try {
815-
if ( $signed ) {
816-
$buildRoot = "signed"
817-
}
818-
else {
819-
$buildRoot = "out"
820-
}
623+
$buildRoot = "out"
821624
$repoName = [guid]::NewGuid().ToString()
822625
$nupkgDir = Join-Path $PSScriptRoot $buildRoot
823626
$null = Register-PSRepository -Name $repoName -InstallationPolicy Trusted -SourceLocation $nupkgDir

0 commit comments

Comments
 (0)