-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix Start-PSBuild on WSL if repository was already built on Windows #5346
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
Conversation
Note that the '-Runtime' parameter needs to be passed in this case.
|
This should slot in nicely with my tweak to build.psm1 #5341 |
|
I think you need to update this .gitignore file to make it handle the platform specific inc files: I was noticing that Git thought I had a new file with powershell_win.inc. |
… because the file can now optionally end in the runtime prefix.
|
Thanks. Well spotted, I updated it to ignore now |
|
@bergmeister Because this ignore rule doesn't apply to anywhere else in the repository, just keeping it simple 😄 |
|
@andschwa My thinking is rather that if there will never be any other |
build.psm1
Outdated
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe our guidance is to put the comment on a separate line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could replace the seperation character.... not sure it's needed though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right about the comment. I noticed that only after the commit but I will fix that. The separation character is only for readability because to me powershell_win or powerhell_lin is easier and faster to read than powershellwin or powershelllin
TravisEz13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with minor comments.
@daxian-dbw and/or @iSazonov should review as well.
|
NB: The build was red because NuGet has a global outage (see here) |
build.psm1
Outdated
| # 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")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use $incFileName).inc so many times so make sense add:
$incFileName = ($incFileName).incThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have addressed that.
|
I'd prefer to fix the issue more natively like #3870. Also I'm not sure that's the only runtime addiction. Should we clean up if our files contains "#if UNIX"? |
…ication 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
Outdated
| # handle TypeGen | ||
| if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs")) { | ||
| $incFileName = 'powershell.inc' | ||
| if (-not [string]::IsNullOrEmpty($Runtime)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use $Options.Runtime? When -Runtime is not specified, we will figure out the current RID via dotnet --info, which will be captured by $Options.Runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The $Options.Runtime will always be 'NotNullOrEmpty', so maybe you can have:
$incFileName = "powershell_$($Runtime.Substring(0,3)).inc"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Yes, we can use $Options.Runtime indeed instead. I was not aware that you already figure it out automatically when it is not being provided. Shall I maybe add this information as a comment to the $Runtime parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the -Runtime parameter of Start-PSBuild? Sure you can add a comment there.
build.psm1
Outdated
| $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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
characters fo the Runtime
A typo.
otherwise dotnet will crash due to the separation characters
Could you please share more information on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting the typo and thanks for coming back about the crash. When I started out I was experimenting with different approaches (one of was to put the inc file into a runtime specific folder) and I actually cannot repro the crash anymore and will therefore use the full $Runtime string instead of the first 3 characters.
build.psm1
Outdated
| 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just use powershell_$($Runtime.Substring(0,3)).inc? Otherwise it would beome powershell.inc_xxx.inc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change has now been undone since we do not need that logic any more due to the usage of $Options.Runtime
build.psm1
Outdated
| # 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" | ||
| } | ||
| if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName)")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$($incFileName) can be replaced by $incFileName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is one of the gotchas about PowerShell string interpolation because PowerShell allows underscores for variable names. Therefore PowerShell would then look for a variable named incFileName_ instead of incFileName. As a general rule, I always wrap variables in a string inside $() because it also safeguards against cases like calling a property on an object...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of "$($incFileName)_xxx.inc", you can replace it with "${incFileName}_xxx.inc". PowerShell support the varialbe syntax ${var name}
build.psm1
Outdated
| ( | ||
| [Parameter(Mandatory=$true)] | ||
| [ValidateNotNullOrEmpty()] | ||
| $IncFileName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have 'powershell.inc' as the default value for this parameter, so that Start-TypeGen without parameter will continue to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that if people actually call Start-TypeGen? I always use the -ResGen swich on Start-PSBuild because the reason why I need update ResGen is because I need to build anyway. Instead of having the default, why not call New-PSOptions and grab the determined Runtime, which is what Start-PSBuild does as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not commonly needed, but when debugging anything about the type catalog, it's handy to just run Start-TypeGen without building the rest of the projects. For that purpose, a simple default value like powershell.inc would be sufficient, no need to call New-Options to figure out the runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a minor comment: the variable name you used in the rest of this function is incFileName, maybe it can be changed to IncFileName.
build.psm1
Outdated
| Push-Location "$PSScriptRoot/src/Microsoft.PowerShell.SDK" | ||
| try { | ||
| $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/powershell.inc" | ||
| $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/$($incFileName)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$($incFileName) can be replaced by $incFileName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we can do that but what do you think about my comment above where this is not always possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PowerShell support this syntax for variable: ${var name}, so you can use "${varname}_xxx.inc" in that case.
|
I'll address the comments next Monday when I'm back from travelling. |
… to be necessary.
…rmined if the $Runtime is not being provided.
|
@daxian-dbw Thanks for your useful feedback. I have addressed all issues and left comments there. But basically the 2 remaining questions are:
|
build.psm1
Outdated
| # 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)")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$($incFileName)
Subexpression is not needed here, you can just use $incFileName
build.psm1
Outdated
| # 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" | ||
| } | ||
| if ($TypeGen -or -not (Test-Path "$PSScriptRoot/TypeCatalogGen/$($incFileName)")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of "$($incFileName)_xxx.inc", you can replace it with "${incFileName}_xxx.inc". PowerShell support the varialbe syntax ${var name}
build.psm1
Outdated
| ( | ||
| [Parameter(Mandatory=$true)] | ||
| [ValidateNotNullOrEmpty()] | ||
| $IncFileName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not commonly needed, but when debugging anything about the type catalog, it's handy to just run Start-TypeGen without building the rest of the projects. For that purpose, a simple default value like powershell.inc would be sufficient, no need to call New-Options to figure out the runtime.
build.psm1
Outdated
| Push-Location "$PSScriptRoot/src/Microsoft.PowerShell.SDK" | ||
| try { | ||
| $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/powershell.inc" | ||
| $ps_inc_file = "$PSScriptRoot/src/TypeCatalogGen/$($incFileName)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PowerShell support this syntax for variable: ${var name}, so you can use "${varname}_xxx.inc" in that case.
|
@bergmeister For the two questions, I answered them in the corresponding comment threads: #5346 (comment) and #5346 (comment) |
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
|
@daxian-dbw Thanks for the review. I have addressed your comments. |
daxian-dbw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @bergmeister!
To fix #5194: Use the first 3 characters of the passed
-Runtimeparameter for the .inc file (the full runtime name could not be used since the separation characters ike e.g. the the hyphen would make dotnet crash when building).A separate issue is that the runtime does not get determined if is not being passed (which is OK since dotnet takes then care of choosing the right one) but maybe given this scenario would it make sense to determine and set it as a convenience?