Skip to content

Change PSES to be buildable as a standalone #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2018
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ docs/_site/
docs/_repo/
docs/metadata/
tools/
*.zip

# quickbuild.exe
/VersionGeneratingLogs/
Expand Down Expand Up @@ -67,4 +68,4 @@ module/PowerShellEditorServices/Commands/en-US/*-help.xml
module/PowerShellEditorServices/Third\ Party\ Notices.txt

# Visual Studio for Mac generated file
*.userprefs
*.userprefs
72 changes: 70 additions & 2 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@

param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug"
[string]$Configuration = "Debug",

[string]$PsesSubmodulePath = "$PSScriptRoot/module",

[string]$ModulesJsonPath = "$PSScriptRoot/modules.json",

[string]$DefaultModuleRepository = "PSGallery"
)

#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}

$script:IsCIBuild = $env:APPVEYOR -ne $null
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
$script:TargetFrameworksParam = "/p:TargetFrameworks=\`"$(if (!$script:IsUnix) { "net451;" })netstandard1.6\`""
$script:SaveModuleSupportsAllowPrerelease = (Get-Command Save-Module).Parameters.ContainsKey("AllowPrerelease")

if ($PSVersionTable.PSEdition -ne "Core") {
Add-Type -Assembly System.IO.Compression.FileSystem
Expand Down Expand Up @@ -179,7 +186,7 @@ task TestProtocol -If { !$script:IsUnix} {
task TestHost -If { !$script:IsUnix} {
Set-Location .\test\PowerShellEditorServices.Test.Host\
exec { & $script:dotnetExe build -c $Configuration -f net452 }
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild -x86 }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I have no idea what the consequences of this change could be. Because I'm not sure why that was there originally.

Copy link
Member

Choose a reason for hiding this comment

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

I suspect it's because VSCode use to only be 32bit but now it has a 64bit version so we can probably safely remove this.

exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
}

task CITest ?Test, {
Expand Down Expand Up @@ -220,6 +227,67 @@ task LayoutModule -After Build {
}
}

task RestorePsesModules -After Build {
$submodulePath = (Resolve-Path $PsesSubmodulePath).Path + [IO.Path]::DirectorySeparatorChar
Write-Host "`nRestoring EditorServices modules..."

# Read in the modules.json file as a hashtable so it can be splatted
$moduleInfos = @{}

(Get-Content -Raw $ModulesJsonPath | ConvertFrom-Json).PSObject.Properties | ForEach-Object {
$name = $_.Name
$body = @{
Name = $name
MinimumVersion = $_.Value.MinimumVersion
MaximumVersion = $_.Value.MaximumVersion
Repository = if ($_.Value.Repository) { $_.Value.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
}

if (-not $name)
{
throw "EditorServices module listed without name in '$ModulesJsonPath'"
}

if ($script:SaveModuleSupportsAllowPrerelease)
{
$body += @{ AllowPrerelease = $_.Value.AllowPrerelease }
}

$moduleInfos.Add($name, $body)
}

# Save each module in the modules.json file
foreach ($moduleName in $moduleInfos.Keys)
Copy link
Member

Choose a reason for hiding this comment

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

We have two foreach's one right after the other. Any chance we can combine those?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only problem is that if there's a bad field in the json file, we'll install half the things and then abort.

Ideally, we could have an explicit failure line after the first foreach, but I'm not sure what the best way to detect a failure is or what the best way to fail in a task is.

Copy link
Member

Choose a reason for hiding this comment

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

eh. Not worth implementing. What you have is good :)

{
if (Test-Path -Path (Join-Path -Path $submodulePath -ChildPath $moduleName))
{
Write-Host "`tModule '${moduleName}' already detected. Skipping"
continue
}

$moduleInstallDetails = $moduleInfos[$moduleName]

$splatParameters = @{
Name = $moduleName
MinimumVersion = $moduleInstallDetails.MinimumVersion
MaximumVersion = $moduleInstallDetails.MaximumVersion
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
Path = $submodulePath
}

if ($script:SaveModuleSupportsAllowPrerelease)
{
$splatParameters += @{ AllowPrerelease = $moduleInstallDetails.AllowPrerelease }
}

Write-Host "`tInstalling module: ${moduleName}"

Save-Module @splatParameters
}
Write-Host "`n"
}

task BuildCmdletHelp {
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US -Force
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,9 @@
# canonical version of this script at the PowerShell Editor
# Services GitHub repository:
#
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/Start-EditorServices.ps1
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/PowerShellEditorServices/Start-EditorServices.ps1

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

[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
Expand Down Expand Up @@ -97,6 +92,13 @@ function ExitWithError($errorString) {
exit 1;
}

function WriteSessionFile($sessionInfo) {
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
Log "Writing session file with contents:"
Log $sessionInfoJson
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
}

# Are we running in PowerShell 2 or earlier?
if ($PSVersionTable.PSVersion.Major -le 2) {
# No ConvertTo-Json on PSv2 and below, so write out the JSON manually
Expand All @@ -106,12 +108,6 @@ if ($PSVersionTable.PSVersion.Major -le 2) {
ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled."
}

function WriteSessionFile($sessionInfo) {
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
Log "Writing session file with contents:"
Log $sessionInfoJson
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
}

if ($host.Runspace.LanguageMode -eq 'ConstrainedLanguage') {
WriteSessionFile @{
Expand Down Expand Up @@ -244,32 +240,11 @@ if ((Test-ModuleAvailable "PowerShellGet") -eq $false) {
# TODO: WRITE ERROR
}

# Check if the expected version of the PowerShell Editor Services
# module is installed
$parsedVersion = New-Object System.Version @($EditorServicesVersion)
if ((Test-ModuleAvailable "PowerShellEditorServices" $parsedVersion) -eq $false) {
if ($ConfirmInstall -and $isPS5orLater) {
# TODO: Check for error and return failure if necessary
LogSection "Install PowerShellEditorServices"
Install-Module "PowerShellEditorServices" -RequiredVersion $parsedVersion -Confirm
}
else {
# Indicate to the client that the PowerShellEditorServices module
# needs to be installed
Write-Output "needs_install"
}
}

try {
LogSection "Start up PowerShellEditorServices"
Log "Importing PowerShellEditorServices"

if ($isPS5orLater) {
Import-Module PowerShellEditorServices -RequiredVersion $parsedVersion -ErrorAction Stop
}
else {
Import-Module PowerShellEditorServices -Version $parsedVersion -ErrorAction Stop
}
Import-Module PowerShellEditorServices -ErrorAction Stop

# Locate available port numbers for services
Log "Searching for available socket port for the language service"
Expand Down
12 changes: 12 additions & 0 deletions modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"PSScriptAnalyzer":{
"MinimumVersion":"1.6",
"MaximumVersion":"1.99",
"AllowPrerelease":false
},
"Plaster":{
"MinimumVersion":"1.0",
"MaximumVersion":"1.99",
"AllowPrerelease":false
}
}
Loading