From e4fa4e8e942301bdb59fbfd96d4fb46d0b10b070 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 5 Nov 2017 18:00:26 +0000 Subject: [PATCH 1/7] Fix build on WSL if repository was already built on Windows. Note that the '-Runtime' parameter needs to be passed in this case. --- build.psm1 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/build.psm1 b/build.psm1 index 13afb79cbc2..6629df37e8c 100644 --- a/build.psm1 +++ b/build.psm1 @@ -489,9 +489,13 @@ Fix steps: } # handle TypeGen - if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs")) { + $incFileName = 'powershell' + if (-not [string]::IsNullOrEmpty($Runtime)) { + $incFileName = "$($incFileName)_$($Runtime.Substring(0,3))" # use the first 3 characters only because otherwise dotnet will crash due to the separation characters + } + if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName).inc")) { log "Run TypeGen (generating CorePsTypeCatalog.cs)" - Start-TypeGen + Start-TypeGen -IncFileName $incFileName } # Get the folder path where pwsh.exe is located. @@ -515,7 +519,7 @@ Fix steps: # publish netcoreapp2.0 reference assemblies try { Push-Location "$PSScriptRoot/src/TypeCatalogGen" - $refAssemblies = Get-Content -Path "powershell.inc" | Where-Object { $_ -like "*microsoft.netcore.app*" } | ForEach-Object { $_.TrimEnd(';') } + $refAssemblies = Get-Content -Path "$($incFileName).inc" | Where-Object { $_ -like "*microsoft.netcore.app*" } | ForEach-Object { $_.TrimEnd(';') } $refDestFolder = Join-Path -Path $publishPath -ChildPath "ref" if (Test-Path $refDestFolder -PathType Container) { @@ -1631,7 +1635,12 @@ function Start-DevPowerShell { function Start-TypeGen { [CmdletBinding()] - param() + param + ( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + $IncFileName + ) # Add .NET CLI tools to PATH Find-Dotnet @@ -1652,7 +1661,7 @@ function Start-TypeGen Push-Location "$PSScriptRoot/src/Microsoft.PowerShell.SDK" try { - $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/powershell.inc" + $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/$($incFileName).inc" dotnet msbuild .\Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$ps_inc_file" /nologo } finally { Pop-Location @@ -1660,7 +1669,7 @@ function Start-TypeGen Push-Location "$PSScriptRoot/src/TypeCatalogGen" try { - dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs powershell.inc + dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs "$($incFileName).inc" } finally { Pop-Location } From 8d4a8afef78669c72ba034017f71e4fb12958b56 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 5 Nov 2017 22:16:39 +0000 Subject: [PATCH 2/7] Update .gitignore to match powershell**.inc instead of powershell.inc because the file can now optionally end in the runtime prefix. --- src/TypeCatalogGen/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TypeCatalogGen/.gitignore b/src/TypeCatalogGen/.gitignore index d745414448b..64411cf195f 100644 --- a/src/TypeCatalogGen/.gitignore +++ b/src/TypeCatalogGen/.gitignore @@ -1 +1 @@ -powershell.inc +powershell**.inc From af094e3966464c0a4f1b34343d2bb016216f6547 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 6 Nov 2017 20:01:43 +0000 Subject: [PATCH 3/7] Put comment on single line as per style guide and add more comment details --- build.psm1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index 6629df37e8c..52068e3dbae 100644 --- a/build.psm1 +++ b/build.psm1 @@ -491,7 +491,9 @@ Fix steps: # handle TypeGen $incFileName = 'powershell' if (-not [string]::IsNullOrEmpty($Runtime)) { - $incFileName = "$($incFileName)_$($Runtime.Substring(0,3))" # use the first 3 characters only because otherwise dotnet will crash due to the separation characters + # File name must be different for Windows and Linux to allow build on Windows and WSL. + # Append the first 3 characters fo the Runtime only because otherwise dotnet will crash due to the separation characters. The underscore is only for better readability. + $incFileName = "$($incFileName)_$($Runtime.Substring(0,3))" } if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName).inc")) { log "Run TypeGen (generating CorePsTypeCatalog.cs)" From e1fde8f2174f495ed3cd28f13e95a88e8aa5efc2 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 7 Nov 2017 20:28:27 +0000 Subject: [PATCH 4/7] Include file extension in $incFileName variable to reduce '.inc' duplication as suggested in PR. Tested again that it still works when building on Windows first using 'Start-PSBuild' and then 'Start-PSBuild -Runtime linux-x64' on WSL (ubuntu16) --- build.psm1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.psm1 b/build.psm1 index 52068e3dbae..fc14389006c 100644 --- a/build.psm1 +++ b/build.psm1 @@ -489,13 +489,13 @@ Fix steps: } # handle TypeGen - $incFileName = 'powershell' + $incFileName = 'powershell.inc' if (-not [string]::IsNullOrEmpty($Runtime)) { # File name must be different for Windows and Linux to allow build on Windows and WSL. # Append the first 3 characters fo the Runtime only because otherwise dotnet will crash due to the separation characters. The underscore is only for better readability. - $incFileName = "$($incFileName)_$($Runtime.Substring(0,3))" + $incFileName = "$($incFileName)_$($Runtime.Substring(0,3)).inc" } - if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName).inc")) { + if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName)")) { log "Run TypeGen (generating CorePsTypeCatalog.cs)" Start-TypeGen -IncFileName $incFileName } @@ -521,7 +521,7 @@ Fix steps: # publish netcoreapp2.0 reference assemblies try { Push-Location "$PSScriptRoot/src/TypeCatalogGen" - $refAssemblies = Get-Content -Path "$($incFileName).inc" | Where-Object { $_ -like "*microsoft.netcore.app*" } | ForEach-Object { $_.TrimEnd(';') } + $refAssemblies = Get-Content -Path $incFileName | Where-Object { $_ -like "*microsoft.netcore.app*" } | ForEach-Object { $_.TrimEnd(';') } $refDestFolder = Join-Path -Path $publishPath -ChildPath "ref" if (Test-Path $refDestFolder -PathType Container) { @@ -1663,7 +1663,7 @@ function Start-TypeGen Push-Location "$PSScriptRoot/src/Microsoft.PowerShell.SDK" try { - $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/$($incFileName).inc" + $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/$($incFileName)" dotnet msbuild .\Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$ps_inc_file" /nologo } finally { Pop-Location @@ -1671,7 +1671,7 @@ function Start-TypeGen Push-Location "$PSScriptRoot/src/TypeCatalogGen" try { - dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs "$($incFileName).inc" + dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs $incFileName } finally { Pop-Location } From adcf8570c7e7b1050acf628fb91bbb3147d5b011 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 13 Nov 2017 20:16:19 +0000 Subject: [PATCH 5/7] Fix typo and do not trim the $Runtime string since this does not seem to be necessary. --- build.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index fc14389006c..78695261d86 100644 --- a/build.psm1 +++ b/build.psm1 @@ -492,8 +492,8 @@ Fix steps: $incFileName = 'powershell.inc' if (-not [string]::IsNullOrEmpty($Runtime)) { # File name must be different for Windows and Linux to allow build on Windows and WSL. - # Append the first 3 characters fo the Runtime only because otherwise dotnet will crash due to the separation characters. The underscore is only for better readability. - $incFileName = "$($incFileName)_$($Runtime.Substring(0,3)).inc" + # Append the first 3 characters for the Runtime only because otherwise dotnet will crash due to the separation characters. The underscore is only for better readability. + $incFileName = "$($incFileName)_$($Runtime).inc" } if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName)")) { log "Run TypeGen (generating CorePsTypeCatalog.cs)" From a78e0c03fa0294e79c01b19ddf70d755129096f7 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 13 Nov 2017 20:38:57 +0000 Subject: [PATCH 6/7] Use $Options.Runtime instead of $Runtime because the former gets determined if the $Runtime is not being provided. --- build.psm1 | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/build.psm1 b/build.psm1 index 78695261d86..64ef88bed9f 100644 --- a/build.psm1 +++ b/build.psm1 @@ -488,13 +488,9 @@ Fix steps: Start-ResGen } - # handle TypeGen - $incFileName = 'powershell.inc' - if (-not [string]::IsNullOrEmpty($Runtime)) { - # File name must be different for Windows and Linux to allow build on Windows and WSL. - # Append the first 3 characters for the Runtime only because otherwise dotnet will crash due to the separation characters. The underscore is only for better readability. - $incFileName = "$($incFileName)_$($Runtime).inc" - } + # Handle TypeGen + # .inc file name must be different for Windows and Linux to allow build on Windows and WSL. + $incFileName = "powershell_$($Options.Runtime).inc" if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName)")) { log "Run TypeGen (generating CorePsTypeCatalog.cs)" Start-TypeGen -IncFileName $incFileName From 4625d83f629ea090a12cbeefc55326ceee715131 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 14 Nov 2017 23:45:13 +0000 Subject: [PATCH 7/7] Addressed minor suggestions made in PR 5346. Use default value for Start-TypeGen for convenience and minor syntax changes. Tested again that it still works when building on Windows first and then on WSL --- build.psm1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.psm1 b/build.psm1 index 64ef88bed9f..858c3f59946 100644 --- a/build.psm1 +++ b/build.psm1 @@ -346,6 +346,7 @@ function Start-PSBuild { # These runtimes must match those in project.json # We do not use ValidateScript since we want tab completion + # If this parameter is not provided it will get determined automatically. [ValidateSet("win7-x64", "win7-x86", "osx.10.12-x64", @@ -491,7 +492,7 @@ Fix steps: # Handle TypeGen # .inc file name must be different for Windows and Linux to allow build on Windows and WSL. $incFileName = "powershell_$($Options.Runtime).inc" - if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName)")) { + if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$incFileName")) { log "Run TypeGen (generating CorePsTypeCatalog.cs)" Start-TypeGen -IncFileName $incFileName } @@ -1635,9 +1636,8 @@ function Start-TypeGen [CmdletBinding()] param ( - [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] - $IncFileName + $IncFileName = 'powershell.inc' ) # Add .NET CLI tools to PATH @@ -1659,7 +1659,7 @@ function Start-TypeGen Push-Location "$PSScriptRoot/src/Microsoft.PowerShell.SDK" try { - $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/$($incFileName)" + $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/$IncFileName" dotnet msbuild .\Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$ps_inc_file" /nologo } finally { Pop-Location @@ -1667,7 +1667,7 @@ function Start-TypeGen Push-Location "$PSScriptRoot/src/TypeCatalogGen" try { - dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs $incFileName + dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs $IncFileName } finally { Pop-Location }