Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
114 changes: 109 additions & 5 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function Start-PSBuild {
[switch]$ResGen,
[switch]$TypeGen,
[switch]$Clean,
[switch]$PSModuleRestore,

# this switch will re-build only System.Management.Automation.dll
# it's useful for development, to do a quick changes in the engine
Expand Down Expand Up @@ -397,6 +398,16 @@ cmd.exe /C cd /d "$location" "&" "$($vcVarsPath)\vcvarsall.bat" "$NativeHostArch
} finally {
Pop-Location
}

if($PSModuleRestore)
{
# downloading the PackageManagement module
# $Options.Output is pointing to something like "...\src\powershell-win-core\bin\Debug\netcoreapp1.0\win10-x64\publish\powershell.exe",
# so we need to get its parent directory
$publishPath = Split-Path $Options.Output -Parent
log "Restore PowerShell modules to $publishPath"
Restore-PSModule -Name @('PackageManagement','PowerShellGet') -Destination (Join-Path -Path $publishPath -ChildPath "Modules")
}
}

function Compress-TestContent {
Expand Down Expand Up @@ -993,10 +1004,11 @@ function Start-PSBootstrap {
$Deps += "openssl"

# Install dependencies
Start-NativeExecution { brew install $Deps }
# ignore exitcode, because they may be already installed
Start-NativeExecution { brew install $Deps } -IgnoreExitcode

# Install patched version of curl
Start-NativeExecution { brew install curl --with-openssl }
Start-NativeExecution { brew install curl --with-openssl } -IgnoreExitcode
}

# Install [fpm](https://github.com/jordansissel/fpm) and [ronn](https://github.com/rtomayko/ronn)
Expand Down Expand Up @@ -2104,15 +2116,15 @@ function script:Convert-PSObjectToHashtable {

# this function wraps native command Execution
# for more information, read https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right/
function script:Start-NativeExecution([scriptblock]$sb)
function script:Start-NativeExecution([scriptblock]$sb, [switch]$IgnoreExitcode)
{
$backupEAP = $script:ErrorActionPreference
$script:ErrorActionPreference = "Continue"
try {
& $sb
# note, if $sb doesn't have a native invocation, $LASTEXITCODE will
# point to the obsolete value
if ($LASTEXITCODE -ne 0) {
if ($LASTEXITCODE -ne 0 -and -not $IgnoreExitcode) {
throw "Execution of {$sb} failed with exit code $LASTEXITCODE"
}
} finally {
Expand Down Expand Up @@ -2477,7 +2489,6 @@ function Start-CrossGen {
"Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll",
"Microsoft.PowerShell.CoreCLR.Eventing.dll",
"Microsoft.PowerShell.ConsoleHost.dll",
"Microsoft.PowerShell.PackageManagement.dll",
"Microsoft.PowerShell.PSReadLine.dll",
"System.Management.Automation.dll"
)
Expand Down Expand Up @@ -2538,6 +2549,99 @@ function Clear-PSRepo
}
}

# Install PowerShell modules such as PackageManagement, PowerShellGet
function Restore-PSModule
{
[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
)

$needRegister = $true
$RepositoryName = "mygetpsmodule"

# Check if the PackageManagement works in the base-oS or PowerShellCore
Get-PackageProvider -Name NuGet -ForceBootstrap -Verbose:$VerbosePreference
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($needRegister)
{
$regVar = PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue
if($regVar)
{
PowerShellGet\UnRegister-PSRepository -Name $RepositoryName
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed as we are registering only if we there is no existing repo with the same source location.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the repository exists, $needRegister is false. This code won't get executed.
Only the case when the same repo exists but is pointing to some other source location.


In reply to: 88761457 [](ancestors = 88761457)


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)
}
}

log ("Name='{0}', Destination='{1}', Repository='{2}'" -f $Name, $Destination, $RepositoryName)

$Name | ForEach-Object {

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

if($RequiredVersion)
{
$command.Add("RequiredVersion", $RequiredVersion)
}

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

# 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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simplified with below
log "Unregistering PSRepository with name: $RepositoryName"
PowerShellGet\Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue | PowerShellGet\UnRegister-PSRepository -Name $RepositoryName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. Will integrate it


In reply to: 88761662 [](ancestors = 88761662)

}
}


$script:RESX_TEMPLATE = @'
<?xml version="1.0" encoding="utf-8"?>
Expand Down

This file was deleted.

This file was deleted.

Loading