Skip to content

Commit 933e475

Browse files
committed
Enable Linux and macOS build with .build.ps1
1 parent cd3a1f4 commit 933e475

File tree

9 files changed

+94
-57
lines changed

9 files changed

+94
-57
lines changed

.build.ps1

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ param(
66
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}
77

88
$script:IsCIBuild = $env:APPVEYOR -ne $null
9+
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
10+
$script:TargetFrameworksParam = "/p:TargetFrameworks=\`"$(if (!$script:IsUnix) { "net451;" })netstandard1.6\`""
11+
12+
if ($PSVersionTable.PSEdition -ne "Core") {
13+
Add-Type -Assembly System.IO.Compression.FileSystem -ErrorAction SilentlyContinue
14+
}
915

1016
task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellApi {
1117

@@ -15,7 +21,7 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
1521
$requiredDotnetVersion = "1.0.0-preview4-004233"
1622
$needsInstall = $true
1723
$dotnetPath = "$PSScriptRoot/.dotnet"
18-
$dotnetExePath = "$dotnetPath/dotnet.exe"
24+
$dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
1925

2026
if (Test-Path $dotnetExePath) {
2127
$script:dotnetExe = $dotnetExePath
@@ -36,11 +42,21 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
3642

3743
Write-Host "`n### Installing .NET CLI $requiredDotnetVersion...`n" -ForegroundColor Green
3844

45+
# The install script is platform-specific
46+
$installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" }
47+
3948
# Download the official installation script and run it
40-
$installScriptPath = "$($env:TEMP)\dotnet-install.ps1"
41-
Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview4/scripts/obtain/dotnet-install.ps1" -OutFile $installScriptPath
42-
$env:DOTNET_INSTALL_DIR = "$PSScriptRoot\.dotnet"
43-
& $installScriptPath -Version $requiredDotnetVersion -InstallDir "$env:DOTNET_INSTALL_DIR"
49+
$installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt"
50+
Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview4/scripts/obtain/dotnet-install.$installScriptExt" -OutFile $installScriptPath
51+
$env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet"
52+
53+
if (!$script:IsUnix) {
54+
& $installScriptPath -Version $requiredDotnetVersion -InstallDir "$env:DOTNET_INSTALL_DIR"
55+
}
56+
else {
57+
& /bin/bash $installScriptPath -Version $requiredDotnetVersion -InstallDir "$env:DOTNET_INSTALL_DIR"
58+
$env:PATH = $dotnetExeDir + [System.IO.Path]::PathSeparator + $env:PATH
59+
}
4460

4561
Write-Host "`n### Installation complete." -ForegroundColor Green
4662
$script:dotnetExe = $dotnetExePath
@@ -60,11 +76,11 @@ task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellA
6076
}
6177

6278
task Restore {
63-
exec { & dotnet restore }
79+
exec { & $script:dotnetExe restore }
6480
}
6581

6682
task Clean {
67-
exec { & dotnet clean }
83+
exec { & $script:dotnetExe clean }
6884
Get-ChildItem -Recurse src\*.nupkg | Remove-Item -Force -ErrorAction Ignore
6985
Get-ChildItem module\*.zip | Remove-Item -Force -ErrorAction Ignore
7086
}
@@ -88,58 +104,59 @@ task GetProductVersion -Before PackageNuGet, PackageModule, UploadArtifacts {
88104

89105
function BuildForPowerShellVersion($version) {
90106
# Restore packages for the specified version
91-
exec { & dotnet restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- /p:PowerShellVersion=$version }
107+
exec { & $script:dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- /p:PowerShellVersion=$version }
92108

93109
Write-Host -ForegroundColor Green "`n### Testing API usage for PowerShell $version...`n"
94-
exec { & dotnet build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- /p:PowerShellVersion=$version }
110+
exec { & $script:dotnetExe build -f net451 .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- /p:PowerShellVersion=$version }
95111
}
96112

97-
task TestPowerShellApi {
113+
task TestPowerShellApi -If { !$script:IsUnix } {
98114
BuildForPowerShellVersion v3
99115
BuildForPowerShellVersion v4
100116
BuildForPowerShellVersion v5r1
101117

102118
# Do a final restore to put everything back to normal
103-
exec { & dotnet restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
119+
exec { & $script:dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
104120
}
105121

106122
task BuildHost {
107-
exec { & dotnet build -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
123+
exec { & $script:dotnetExe build -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -- $script:TargetFrameworksParam }
108124
}
109125

110126
task Build {
111-
exec { & dotnet build -c $Configuration .\PowerShellEditorServices.sln }
127+
exec { & $script:dotnetExe build -c $Configuration .\PowerShellEditorServices.sln -- $script:TargetFrameworksParam }
112128
}
113129

114-
task Test {
130+
task Test -If { !$script:IsUnix } {
115131
$testParams = @{}
116132
if ($env:APPVEYOR -ne $null) {
117133
$testParams = @{"l" = "appveyor"}
118134
}
119135

120-
exec { & dotnet test -c $Configuration @testParams .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
121-
exec { & dotnet test -c $Configuration @testParams .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
122-
exec { & dotnet test -c $Configuration @testParams .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
136+
exec { & $script:dotnetExe test -c $Configuration @testParams .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
137+
exec { & $script:dotnetExe test -c $Configuration @testParams .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
138+
exec { & $script:dotnetExe test -c $Configuration @testParams .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
123139
}
124140

125141
task LayoutModule -After Build, BuildHost {
126142
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\ -Type Directory | Out-Null
127143
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop -Type Directory | Out-Null
128144
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Core -Type Directory | Out-Null
129145

130-
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
131-
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\Newtonsoft.Json.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
146+
if (!$script:IsUnix) {
147+
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
148+
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\Newtonsoft.Json.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
149+
}
132150
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
133151
}
134152

135153
task PackageNuGet {
136-
exec { & dotnet pack -c $Configuration --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
137-
exec { & dotnet pack -c $Configuration --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj }
138-
exec { & dotnet pack -c $Configuration --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
154+
exec { & $script:dotnetExe pack -c $Configuration --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices\PowerShellEditorServices.csproj -- $script:TargetFrameworksParam }
155+
exec { & $script:dotnetExe pack -c $Configuration --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj -- $script:TargetFrameworksParam }
156+
exec { & $script:dotnetExe pack -c $Configuration --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -- $script:TargetFrameworksParam }
139157
}
140158

141159
task PackageModule {
142-
Add-Type -Assembly System.IO.Compression.FileSystem -ErrorAction Ignore
143160
[System.IO.Compression.ZipFile]::CreateFromDirectory(
144161
"$PSScriptRoot/module/PowerShellEditorServices",
145162
"$PSScriptRoot/module/PowerShellEditorServices-$($script:FullVersion).zip",
@@ -159,7 +176,6 @@ task UploadArtifacts -If ($script:IsCIBuild) {
159176
task UploadTestLogs -If ($script:IsCIBuild) {
160177
$testLogsZipPath = "$PSScriptRoot/TestLogs.zip"
161178

162-
Add-Type -Assembly System.IO.Compression.FileSystem -ErrorAction Ignore
163179
[System.IO.Compression.ZipFile]::CreateFromDirectory(
164180
"$PSScriptRoot/test/PowerShellEditorServices.Test.Host/bin/$Configuration/net451/logs",
165181
$testLogsZipPath)

src/PowerShellEditorServices.Channel.WebSocket/PowerShellEditorServices.Channel.WebSocket.csproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2-
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
3-
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
3+
44
<PropertyGroup>
55
<AssemblyTitle>PowerShell Editor Services WebSocket Protocol Channel</AssemblyTitle>
6-
<TargetFrameworks>net451</TargetFrameworks>
6+
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
77
<AssemblyName>Microsoft.PowerShell.EditorServices.Channel.WebSocket</AssemblyName>
88
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
99
</PropertyGroup>
1010

11-
<ItemGroup>
11+
<!-- This project currently doesn't work on netstandard1.6 so don't compile its source -->
12+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
1213
<Compile Include="**\*.cs" />
1314
<EmbeddedResource Include="**\*.resx" />
1415
<EmbeddedResource Include="compiler\resources\**\*" />
1516
</ItemGroup>
1617

17-
<ItemGroup>
18+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
1819
<ProjectReference Include="..\PowerShellEditorServices\PowerShellEditorServices.csproj" />
1920
<ProjectReference Include="..\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj" />
2021
</ItemGroup>
@@ -30,6 +31,9 @@
3031
<PackageReference Include="NETStandard.Library">
3132
<Version>1.6.1</Version>
3233
</PackageReference>
34+
</ItemGroup>
35+
36+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
3337
<PackageReference Include="CommonServiceLocator" Version="1.3" />
3438
<PackageReference Include="Microsoft.Owin" Version="3.0.0" />
3539
<PackageReference Include="Owin" Version="1.0" />

test/PowerShellEditorServices.Test.Channel.WebSocket/PowerShellEditorServices.Test.Channel.WebSocket.csproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2-
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
3-
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
3+
44
<PropertyGroup>
5-
<TargetFrameworks>net451</TargetFrameworks>
5+
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
66
<AssemblyName>Microsoft.PowerShell.EditorServices.Test.Channel.WebSocket</AssemblyName>
77
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
88
</PropertyGroup>
99

10-
<ItemGroup>
10+
<!-- This project currently doesn't work on netstandard1.6 so don't compile its source -->
11+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
1112
<Compile Include="**\*.cs" />
1213
<EmbeddedResource Include="**\*.resx" />
1314
<EmbeddedResource Include="compiler\resources\**\*" />
@@ -24,7 +25,7 @@
2425
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-*" />
2526
<PackageReference Include="Microsoft.TestPlatform.TestHost">
2627
<Version>15.0.0-*</Version>
27-
</PackageReference>
28+
</PackageReference>
2829
<PackageReference Include="xunit" Version="2.2.0-*" />
2930
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-*" />
3031
<PackageReference Include="Microsoft.NET.Sdk">
@@ -37,6 +38,9 @@
3738
<PackageReference Include="Microsoft.PowerShell.SDK">
3839
<Version>6.0.0-alpha13</Version>
3940
</PackageReference>
41+
</ItemGroup>
42+
43+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
4044
<PackageReference Include="CommonServiceLocator" Version="1.3" />
4145
<PackageReference Include="Microsoft.Owin" Version="3.0.0" />
4246
<PackageReference Include="Owin" Version="1.0" />

test/PowerShellEditorServices.Test.Host/DebugAdapterTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ namespace Microsoft.PowerShell.EditorServices.Test.Host
1616
public class DebugAdapterTests : ServerTestsBase, IAsyncLifetime
1717
{
1818
private DebugAdapterClient debugAdapterClient;
19-
private string DebugScriptPath =
19+
private string DebugScriptPath =
2020
Path.GetFullPath(@"..\..\..\..\PowerShellEditorServices.Test.Shared\Debugging\DebugTest.ps1");
2121

2222
public async Task InitializeAsync()
2323
{
2424
string testLogPath =
2525
Path.Combine(
26+
#if CoreCLR
27+
AppContext.BaseDirectory,
28+
#else
2629
AppDomain.CurrentDomain.BaseDirectory,
30+
#endif
2731
"logs",
2832
this.GetType().Name,
2933
Guid.NewGuid().ToString().Substring(0, 8) + ".log");
@@ -91,7 +95,7 @@ await this.SendRequest(
9195

9296
// Abort script execution
9397
Task terminatedEvent = this.WaitForEvent(TerminatedEvent.Type);
94-
await
98+
await
9599
Task.WhenAll(
96100
this.SendRequest(DisconnectRequest.Type, new object()),
97101
terminatedEvent);

test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public async Task InitializeAsync()
2727
{
2828
string testLogPath =
2929
Path.Combine(
30+
#if CoreCLR
31+
AppContext.BaseDirectory,
32+
#else
3033
AppDomain.CurrentDomain.BaseDirectory,
34+
#endif
3135
"logs",
3236
this.GetType().Name,
3337
Guid.NewGuid().ToString().Substring(0, 8) + ".log");
@@ -69,7 +73,7 @@ public async Task ServiceReturnsSyntaxErrors()
6973
await this.SendOpenFileEvent("TestFiles\\SimpleSyntaxError.ps1", false);
7074

7175
// Wait for the diagnostic event
72-
PublishDiagnosticsNotification diagnostics =
76+
PublishDiagnosticsNotification diagnostics =
7377
await this.WaitForEvent(
7478
PublishDiagnosticsNotification.Type);
7579

@@ -86,7 +90,7 @@ public async Task ServiceReturnsSemanticMarkers()
8690
await this.SendOpenFileEvent("TestFiles\\SimpleSemanticError.ps1", false);
8791

8892
// Wait for the diagnostic event
89-
PublishDiagnosticsNotification diagnostics =
93+
PublishDiagnosticsNotification diagnostics =
9094
await this.WaitForEvent(
9195
PublishDiagnosticsNotification.Type);
9296

@@ -102,7 +106,7 @@ public async Task ServiceReturnsNoErrorsForUsingRelativeModulePaths()
102106
await this.SendOpenFileEvent("TestFiles\\Module.psm1", false);
103107

104108
// Wait for the diagnostic event
105-
PublishDiagnosticsNotification diagnostics =
109+
PublishDiagnosticsNotification diagnostics =
106110
await this.WaitForEvent(
107111
PublishDiagnosticsNotification.Type);
108112

@@ -469,7 +473,7 @@ public async Task ServiceExecutesReplCommandAndReceivesOutput()
469473
{
470474
OutputReader outputReader = new OutputReader(this.protocolClient);
471475

472-
await
476+
await
473477
this.SendRequest(
474478
EvaluateRequest.Type,
475479
new EvaluateRequestArguments
@@ -568,7 +572,7 @@ public async Task ServiceExecutesReplCommandAndReceivesInputPrompt()
568572
Expression = promptScript,
569573
Context = "repl"
570574
});
571-
575+
572576
// Wait for the input prompt request and check expected values
573577
Tuple<ShowInputPromptRequest, RequestContext<ShowInputPromptResponse>> requestResponseContext = await inputPromptTask;
574578
ShowInputPromptRequest showInputPromptRequest = requestResponseContext.Item1;
@@ -641,8 +645,13 @@ public async Task ServiceLoadsProfilesOnDemand()
641645

642646
string currentUserCurrentHostPath =
643647
Path.Combine(
648+
#if !CoreCLR
644649
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
645650
"WindowsPowerShell",
651+
#else
652+
// TODO: This will need to be improved once we are running tests on CoreCLR
653+
"~/.powershell",
654+
#endif
646655
profileName);
647656

648657
// Copy the test profile to the current user's host profile path
@@ -727,7 +736,7 @@ private async Task SendOpenFileEvent(string filePath, bool waitForDiagnostics =
727736
if (waitForDiagnostics)
728737
{
729738
// Wait for the diagnostic event
730-
diagnosticWaitTask =
739+
diagnosticWaitTask =
731740
this.WaitForEvent(
732741
PublishDiagnosticsNotification.Type);
733742
}

test/PowerShellEditorServices.Test.Host/PowerShellEditorServices.Test.Host.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2-
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
3-
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
3+
44
<PropertyGroup>
5-
<TargetFrameworks>net451</TargetFrameworks>
5+
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
66
<AssemblyName>Microsoft.PowerShell.EditorServices.Test.Host</AssemblyName>
77
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
88
</PropertyGroup>
@@ -26,7 +26,7 @@
2626
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-*" />
2727
<PackageReference Include="Microsoft.TestPlatform.TestHost">
2828
<Version>15.0.0-*</Version>
29-
</PackageReference>
29+
</PackageReference>
3030
<PackageReference Include="xunit" Version="2.2.0-*" />
3131
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-*" />
3232
<PackageReference Include="Microsoft.NET.Sdk">

0 commit comments

Comments
 (0)