Skip to content

Commit beffdcf

Browse files
lzybkrTravisEz13
authored andcommitted
Pull PSReadLine from PSGallery (PowerShell#5759)
Instead of building PSReadLine from this repo, pull it from the gallery using nuget cache. This pulls v2.0 of PSReadLine which does have documented breaking changes from v1.2, but the risk is small - the features that have changed are typically only used in a profile and aren't used all that often anyway. Fix PowerShell#996 Hardcodes version of modules pulled from PSGallery
1 parent 65a4002 commit beffdcf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+57
-17523
lines changed

PowerShell-Win.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Management.Infras
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.Commands.Diagnostics", "src\Microsoft.PowerShell.Commands.Diagnostics\Microsoft.PowerShell.Commands.Diagnostics.csproj", "{439A24FC-8E0A-48B6-8227-44C297311F49}"
2323
EndProject
24-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.PSReadLine", "src\Microsoft.PowerShell.PSReadLine\Microsoft.PowerShell.PSReadLine.csproj", "{07BFD271-8992-4F34-9091-6CFC3E224A24}"
2524
EndProject
2625
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.WSMan.Management", "src\Microsoft.WSMan.Management\Microsoft.WSMan.Management.csproj", "{8F63D134-E413-4181-936D-D82F3F5F1D85}"
2726
EndProject

build.psm1

Lines changed: 42 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,7 @@ Fix steps:
521521

522522
# handle Restore
523523
if ($Restore -or -not (Test-Path "$($Options.Top)/obj/project.assets.json")) {
524-
log "Run dotnet restore"
525-
526-
$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen")
524+
$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen", "$PSScriptRoot/src/Modules/PSGalleryModules.csproj")
527525
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | ForEach-Object { [System.IO.Path]::GetDirectoryName($_) }
528526

529527
$RestoreArguments = @("--verbosity")
@@ -533,7 +531,11 @@ Fix steps:
533531
$RestoreArguments += "quiet"
534532
}
535533

536-
($srcProjectDirs + $testProjectDirs) | ForEach-Object { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
534+
($srcProjectDirs + $testProjectDirs) | ForEach-Object {
535+
log "Run dotnet restore $_ $RestoreArguments"
536+
537+
Start-NativeExecution { dotnet restore $_ $RestoreArguments }
538+
}
537539
}
538540

539541
# handle ResGen
@@ -646,17 +648,11 @@ function Restore-PSModuleToBuild
646648
$CI
647649
)
648650

649-
$ProgressPreference = "SilentlyContinue"
650651
log "Restore PowerShell modules to $publishPath"
651652

652653
$modulesDir = Join-Path -Path $publishPath -ChildPath "Modules"
653654

654-
# Restore modules from powershellgallery feed
655-
Restore-PSModule -Destination $modulesDir -Name @(
656-
# PowerShellGet depends on PackageManagement module, so PackageManagement module will be installed with the PowerShellGet module.
657-
'PowerShellGet'
658-
'Microsoft.PowerShell.Archive'
659-
) -SourceLocation "https://www.powershellgallery.com/api/v2/"
655+
Copy-PSGalleryModules -Destination $modulesDir
660656

661657
if($CI.IsPresent)
662658
{
@@ -675,6 +671,7 @@ function Restore-PSPester
675671

676672
Restore-GitModule -Destination $Destination -Uri 'https://github.com/PowerShell/psl-pester' -Name Pester -CommitSha '1f546b6aaa0893e215e940a14f57c96f56f7eff1'
677673
}
674+
678675
function Compress-TestContent {
679676
[CmdletBinding()]
680677
param(
@@ -2355,7 +2352,6 @@ function Start-CrossGen {
23552352
"Microsoft.PowerShell.Security.dll",
23562353
"Microsoft.PowerShell.CoreCLR.Eventing.dll",
23572354
"Microsoft.PowerShell.ConsoleHost.dll",
2358-
"Microsoft.PowerShell.PSReadLine.dll",
23592355
"System.Management.Automation.dll"
23602356
)
23612357

@@ -2464,102 +2460,56 @@ function Restore-GitModule
24642460
}
24652461

24662462
# Install PowerShell modules such as PackageManagement, PowerShellGet
2467-
function Restore-PSModule
2463+
function Copy-PSGalleryModules
24682464
{
24692465
[CmdletBinding()]
24702466
param(
24712467
[Parameter(Mandatory=$true)]
24722468
[ValidateNotNullOrEmpty()]
2473-
[string[]]$Name,
2474-
2475-
[Parameter(Mandatory=$true)]
2476-
[ValidateNotNullOrEmpty()]
2477-
[string]$Destination,
2478-
2479-
[string]$SourceLocation="https://powershell.myget.org/F/powershellmodule/api/v2/",
2480-
2481-
[string]$RequiredVersion
2469+
[string]$Destination
24822470
)
24832471

2484-
$needRegister = $true
2485-
$RepositoryName = "mygetpsmodule"
2486-
2487-
# Check if the PackageManagement works in the base-oS or PowerShellCore
2488-
$null = Get-PackageProvider -Name NuGet -ForceBootstrap -Verbose:$VerbosePreference
2489-
$null = Get-PackageProvider -Name PowerShellGet -Verbose:$VerbosePreference
2490-
2491-
# Get the existing registered PowerShellGet repositories
2492-
$psrepos = PowerShellGet\Get-PSRepository
2493-
2494-
foreach ($repo in $psrepos)
2495-
{
2496-
if(($repo.SourceLocation -eq $SourceLocation) -or ($repo.SourceLocation.TrimEnd("/") -eq $SourceLocation.TrimEnd("/")))
2497-
{
2498-
# found a registered repository that matches the source location
2499-
$needRegister = $false
2500-
$RepositoryName = $repo.Name
2501-
break
2502-
}
2472+
if (!$Destination.EndsWith("Modules")) {
2473+
throw "Installing to an unexpected location"
25032474
}
25042475

2505-
if($needRegister)
2506-
{
2507-
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
2508-
if($regVar)
2509-
{
2510-
PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
2511-
}
2512-
2513-
log "Registering PSRepository with name: $RepositoryName and sourcelocation: $SourceLocation"
2514-
PowerShellGet\Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -ErrorVariable ev -verbose
2515-
if($ev)
2516-
{
2517-
throw ("Failed to register repository '{0}'" -f $RepositoryName)
2518-
}
2519-
2520-
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName
2521-
if(-not $regVar)
2522-
{
2523-
throw ("'{0}' is not registered" -f $RepositoryName)
2524-
}
2476+
$cache = dotnet nuget locals global-packages -l
2477+
if ($cache -match "info : global-packages: (.*)") {
2478+
$nugetCache = $matches[1]
2479+
}
2480+
else {
2481+
throw "Can't find nuget global cache"
25252482
}
25262483

2527-
log ("Name='{0}', Destination='{1}', Repository='{2}'" -f ($Name -join ','), $Destination, $RepositoryName)
2484+
$psGalleryProj = [xml](Get-Content -Raw $PSScriptRoot\src\Modules\PSGalleryModules.csproj)
25282485

2529-
# do not output progress
2530-
$ProgressPreference = "SilentlyContinue"
2531-
$Name | ForEach-Object {
2486+
foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference) {
2487+
$name = $m.Include
2488+
$version = $m.Version
2489+
log "Name='$Name', Version='$version', Destination='$Destination'"
25322490

2533-
$command = @{
2534-
Name=$_
2535-
Path = $Destination
2536-
Repository =$RepositoryName
2537-
}
2538-
2539-
if($RequiredVersion)
2540-
{
2541-
$command.Add("RequiredVersion", $RequiredVersion)
2491+
# Remove the build revision from the src (nuget drops it).
2492+
$srcVer = if ($version -match "(\d+.\d+.\d+).\d+") {
2493+
$matches[1]
2494+
} else {
2495+
$version
25422496
}
2543-
2544-
# pull down the module
2545-
log "running save-module $_"
2546-
PowerShellGet\Save-Module @command -Force
2547-
2548-
# Remove PSGetModuleInfo.xml file
2549-
Find-Module -Name $_ -Repository $RepositoryName -IncludeDependencies | ForEach-Object {
2550-
Remove-Item -Path $Destination\$($_.Name)\*\PSGetModuleInfo.xml -Force
2497+
#
2498+
# Remove semantic version in the destination directory
2499+
$destVer = if ($version -match "(\d+.\d+.\d+)-.+") {
2500+
$matches[1]
2501+
} else {
2502+
$version
25512503
}
2552-
}
25532504

2554-
# Clean up
2555-
if($needRegister)
2556-
{
2557-
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
2558-
if($regVar)
2559-
{
2560-
log "Unregistering PSRepository with name: $RepositoryName"
2561-
PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
2562-
}
2505+
# Nuget seems to always use lowercase in the cache
2506+
$src = "$nugetCache/$($name.ToLower())/$srcVer"
2507+
$dest = "$Destination/$name/$destVer"
2508+
2509+
Remove-Item -Force -ErrorAction Ignore -Recurse "$Destination/$name"
2510+
New-Item -Path $dest -ItemType Directory -Force -ErrorAction Stop > $null
2511+
$dontCopy = '*.nupkg', '*.nupkg.sha512', '*.nuspec', 'System.Runtime.InteropServices.RuntimeInformation.dll'
2512+
Copy-Item -Exclude $dontCopy -Recurse $src/* $dest
25632513
}
25642514
}
25652515

docs/building/internals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ We are calling `dotnet` tool build for `$Top` directory
1616
### Dummy dependencies
1717

1818
We use dummy dependencies between projects to leverage `dotnet` build functionality.
19-
For example, `src\powershell-win-core\powershell-win-core.csproj` has dependency on `Microsoft.PowerShell.PSReadLine`,
19+
For example, `src\powershell-win-core\powershell-win-core.csproj` has dependency on `Microsoft.PowerShell.Commands.Diagnostics.csproj`,
2020
but in reality, there is no build dependency.
2121

2222
Dummy dependencies allows us to build just `$Top` folder, instead of building several folders.

docs/testing-guidelines/CodeCoverageAnalysis.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ The following table shows the status for the above commit, dated 06/18/2017
1919
| Microsoft.PowerShell.CoreCLR.AssemblyLoadContext | 97.65% |
2020
| Microsoft.PowerShell.CoreCLR.Eventing | 29.91% |
2121
| Microsoft.PowerShell.LocalAccounts | 86.35% |
22-
| Microsoft.PowerShell.PSReadLine | 10.18% |
2322
| Microsoft.PowerShell.Security | 44.44% |
2423
| Microsoft.WSMan.Management | 4.91% |
2524
| System.Management.Automation | 50.42% |
@@ -52,10 +51,6 @@ The following table shows the status for the above commit, dated 06/18/2017
5251

5352
- [ ] Add tests for ETW events. [#4156](https://github.com/PowerShell/PowerShell/issues/4156)
5453

55-
### Microsoft.PowerShell.PSReadLine
56-
57-
- [ ] We need tests from PSReadline repo or ignore coverage data for this module. (This will be filtered out.)
58-
5954
### Microsoft.PowerShell.Security
6055

6156
- [ ] Add tests for *-Acl cmdlets. [4157] (https://github.com/PowerShell/PowerShell/issues/4157)

nuget.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
66
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
77
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
8+
<add key="PSGallery" value="https://www.powershellgallery.com/api/v2/" />
89
</packageSources>
910
</configuration>

src/Microsoft.PowerShell.PSReadLine/AssemblyInfo.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)