Skip to content

Commit

Permalink
Pull PSReadLine from PSGallery (#5759)
Browse files Browse the repository at this point in the history
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 #996

Hardcodes version of modules pulled from PSGallery
  • Loading branch information
lzybkr authored and TravisEz13 committed Jan 20, 2018
1 parent 65a4002 commit beffdcf
Show file tree
Hide file tree
Showing 59 changed files with 57 additions and 17,523 deletions.
1 change: 0 additions & 1 deletion PowerShell-Win.sln
Expand Up @@ -21,7 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Management.Infras
EndProject
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}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.PSReadLine", "src\Microsoft.PowerShell.PSReadLine\Microsoft.PowerShell.PSReadLine.csproj", "{07BFD271-8992-4F34-9091-6CFC3E224A24}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.WSMan.Management", "src\Microsoft.WSMan.Management\Microsoft.WSMan.Management.csproj", "{8F63D134-E413-4181-936D-D82F3F5F1D85}"
EndProject
Expand Down
134 changes: 42 additions & 92 deletions build.psm1
Expand Up @@ -521,9 +521,7 @@ Fix steps:

# handle Restore
if ($Restore -or -not (Test-Path "$($Options.Top)/obj/project.assets.json")) {
log "Run dotnet restore"

$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen")
$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen", "$PSScriptRoot/src/Modules/PSGalleryModules.csproj")
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | ForEach-Object { [System.IO.Path]::GetDirectoryName($_) }

$RestoreArguments = @("--verbosity")
Expand All @@ -533,7 +531,11 @@ Fix steps:
$RestoreArguments += "quiet"
}

($srcProjectDirs + $testProjectDirs) | ForEach-Object { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
($srcProjectDirs + $testProjectDirs) | ForEach-Object {
log "Run dotnet restore $_ $RestoreArguments"

Start-NativeExecution { dotnet restore $_ $RestoreArguments }
}
}

# handle ResGen
Expand Down Expand Up @@ -646,17 +648,11 @@ function Restore-PSModuleToBuild
$CI
)

$ProgressPreference = "SilentlyContinue"
log "Restore PowerShell modules to $publishPath"

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

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

if($CI.IsPresent)
{
Expand All @@ -675,6 +671,7 @@ function Restore-PSPester

Restore-GitModule -Destination $Destination -Uri 'https://github.com/PowerShell/psl-pester' -Name Pester -CommitSha '1f546b6aaa0893e215e940a14f57c96f56f7eff1'
}

function Compress-TestContent {
[CmdletBinding()]
param(
Expand Down Expand Up @@ -2355,7 +2352,6 @@ function Start-CrossGen {
"Microsoft.PowerShell.Security.dll",
"Microsoft.PowerShell.CoreCLR.Eventing.dll",
"Microsoft.PowerShell.ConsoleHost.dll",
"Microsoft.PowerShell.PSReadLine.dll",
"System.Management.Automation.dll"
)

Expand Down Expand Up @@ -2464,102 +2460,56 @@ function Restore-GitModule
}

# Install PowerShell modules such as PackageManagement, PowerShellGet
function Restore-PSModule
function Copy-PSGalleryModules
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string[]]$Name,

[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Destination,

[string]$SourceLocation="https://powershell.myget.org/F/powershellmodule/api/v2/",

[string]$RequiredVersion
[string]$Destination
)

$needRegister = $true
$RepositoryName = "mygetpsmodule"

# Check if the PackageManagement works in the base-oS or PowerShellCore
$null = Get-PackageProvider -Name NuGet -ForceBootstrap -Verbose:$VerbosePreference
$null = Get-PackageProvider -Name PowerShellGet -Verbose:$VerbosePreference

# Get the existing registered PowerShellGet repositories
$psrepos = PowerShellGet\Get-PSRepository

foreach ($repo in $psrepos)
{
if(($repo.SourceLocation -eq $SourceLocation) -or ($repo.SourceLocation.TrimEnd("/") -eq $SourceLocation.TrimEnd("/")))
{
# found a registered repository that matches the source location
$needRegister = $false
$RepositoryName = $repo.Name
break
}
if (!$Destination.EndsWith("Modules")) {
throw "Installing to an unexpected location"
}

if($needRegister)
{
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
if($regVar)
{
PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
}

log "Registering PSRepository with name: $RepositoryName and sourcelocation: $SourceLocation"
PowerShellGet\Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -ErrorVariable ev -verbose
if($ev)
{
throw ("Failed to register repository '{0}'" -f $RepositoryName)
}

$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName
if(-not $regVar)
{
throw ("'{0}' is not registered" -f $RepositoryName)
}
$cache = dotnet nuget locals global-packages -l
if ($cache -match "info : global-packages: (.*)") {
$nugetCache = $matches[1]
}
else {
throw "Can't find nuget global cache"
}

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

# do not output progress
$ProgressPreference = "SilentlyContinue"
$Name | ForEach-Object {
foreach ($m in $psGalleryProj.Project.ItemGroup.PackageReference) {
$name = $m.Include
$version = $m.Version
log "Name='$Name', Version='$version', Destination='$Destination'"

$command = @{
Name=$_
Path = $Destination
Repository =$RepositoryName
}

if($RequiredVersion)
{
$command.Add("RequiredVersion", $RequiredVersion)
# Remove the build revision from the src (nuget drops it).
$srcVer = if ($version -match "(\d+.\d+.\d+).\d+") {
$matches[1]
} else {
$version
}

# pull down the module
log "running save-module $_"
PowerShellGet\Save-Module @command -Force

# Remove PSGetModuleInfo.xml file
Find-Module -Name $_ -Repository $RepositoryName -IncludeDependencies | ForEach-Object {
Remove-Item -Path $Destination\$($_.Name)\*\PSGetModuleInfo.xml -Force
#
# Remove semantic version in the destination directory
$destVer = if ($version -match "(\d+.\d+.\d+)-.+") {
$matches[1]
} else {
$version
}
}

# Clean up
if($needRegister)
{
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
if($regVar)
{
log "Unregistering PSRepository with name: $RepositoryName"
PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
}
# Nuget seems to always use lowercase in the cache
$src = "$nugetCache/$($name.ToLower())/$srcVer"
$dest = "$Destination/$name/$destVer"

Remove-Item -Force -ErrorAction Ignore -Recurse "$Destination/$name"
New-Item -Path $dest -ItemType Directory -Force -ErrorAction Stop > $null
$dontCopy = '*.nupkg', '*.nupkg.sha512', '*.nuspec', 'System.Runtime.InteropServices.RuntimeInformation.dll'
Copy-Item -Exclude $dontCopy -Recurse $src/* $dest
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/building/internals.md
Expand Up @@ -16,7 +16,7 @@ We are calling `dotnet` tool build for `$Top` directory
### Dummy dependencies

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

Dummy dependencies allows us to build just `$Top` folder, instead of building several folders.
Expand Down
5 changes: 0 additions & 5 deletions docs/testing-guidelines/CodeCoverageAnalysis.md
Expand Up @@ -19,7 +19,6 @@ The following table shows the status for the above commit, dated 06/18/2017
| Microsoft.PowerShell.CoreCLR.AssemblyLoadContext | 97.65% |
| Microsoft.PowerShell.CoreCLR.Eventing | 29.91% |
| Microsoft.PowerShell.LocalAccounts | 86.35% |
| Microsoft.PowerShell.PSReadLine | 10.18% |
| Microsoft.PowerShell.Security | 44.44% |
| Microsoft.WSMan.Management | 4.91% |
| System.Management.Automation | 50.42% |
Expand Down Expand Up @@ -52,10 +51,6 @@ The following table shows the status for the above commit, dated 06/18/2017

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

### Microsoft.PowerShell.PSReadLine

- [ ] We need tests from PSReadline repo or ignore coverage data for this module. (This will be filtered out.)

### Microsoft.PowerShell.Security

- [ ] Add tests for *-Acl cmdlets. [4157] (https://github.com/PowerShell/PowerShell/issues/4157)
Expand Down
1 change: 1 addition & 0 deletions nuget.config
Expand Up @@ -5,5 +5,6 @@
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
<add key="PSGallery" value="https://www.powershellgallery.com/api/v2/" />
</packageSources>
</configuration>
19 changes: 0 additions & 19 deletions src/Microsoft.PowerShell.PSReadLine/AssemblyInfo.cs

This file was deleted.

0 comments on commit beffdcf

Please sign in to comment.