Skip to content

Conversation

@bergmeister
Copy link
Contributor

@bergmeister bergmeister commented Nov 5, 2017

To fix #5194: Use the first 3 characters of the passed -Runtime parameter 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?

Note that the '-Runtime' parameter needs to be passed in this case.
@rkeithhill
Copy link
Collaborator

This should slot in nicely with my tweak to build.psm1 #5341

@rkeithhill
Copy link
Collaborator

I think you need to update this .gitignore file to make it handle the platform specific inc files:

40:121ms> gc .\src\TypeCatalogGen\.gitignore
powershell.inc

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.
@bergmeister
Copy link
Contributor Author

bergmeister commented Nov 5, 2017

Thanks. Well spotted, I updated it to ignore now powershell**.inc. I find it a bit odd that there is a special .gitignore file in this folder and am wondering if we can move this to the top level .gitignore file?
I see that @andschwa moved out ignoring the .inc file from the top level .gitignore file in this commit. What was the reasoning for this?

@andyleejordan
Copy link
Member

@bergmeister Because this ignore rule doesn't apply to anywhere else in the repository, just keeping it simple 😄

@bergmeister
Copy link
Contributor Author

@andschwa My thinking is rather that if there will never be any other .inc files somewhere else, it would be nice to put it into the top one to have a more central place, especially since there is only one entry in it. But this is probably more of a stylistic preference with no 'right' answer depending on how big the central place can become (to me the output of gci -Recurse .gitignore | % {cat $_} did not seem to be too long)... But I'll leave it then as it is if that's your preference.

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
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@TravisEz13 TravisEz13 left a 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.

@bergmeister
Copy link
Contributor Author

bergmeister commented Nov 6, 2017

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")) {
Copy link
Collaborator

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).inc

Copy link
Contributor Author

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.

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 7, 2017

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)) {
Copy link
Member

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

Copy link
Member

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"

Copy link
Contributor Author

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?

Copy link
Member

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.
Copy link
Member

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?

Copy link
Contributor Author

@bergmeister bergmeister Nov 13, 2017

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"
Copy link
Member

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

Copy link
Contributor Author

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)")) {
Copy link
Member

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

Copy link
Contributor Author

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...

Copy link
Member

@daxian-dbw daxian-dbw Nov 14, 2017

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
Copy link
Member

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.

Copy link
Contributor Author

@bergmeister bergmeister Nov 13, 2017

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.

Copy link
Member

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.

Copy link
Member

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)"
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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
Copy link
Contributor Author

I'll address the comments next Monday when I'm back from travelling.

@bergmeister
Copy link
Contributor Author

@daxian-dbw Thanks for your useful feedback. I have addressed all issues and left comments there. But basically the 2 remaining questions are:

  • Should we be strict about string interpolation (i.e. use $()) since there are gotchas as I pointed out?
  • Should Start-TypeGen have a default value for the new $IncFileName parameter or should we automatically determine it in there similarly as in Start-PSBuild?

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)")) {
Copy link
Member

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)")) {
Copy link
Member

@daxian-dbw daxian-dbw Nov 14, 2017

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
Copy link
Member

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)"
Copy link
Member

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.

@daxian-dbw
Copy link
Member

@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
@bergmeister
Copy link
Contributor Author

@daxian-dbw Thanks for the review. I have addressed your comments.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @bergmeister!

@daxian-dbw daxian-dbw self-assigned this Nov 15, 2017
@daxian-dbw daxian-dbw merged commit 019cfee into PowerShell:master Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building PowerShell Core on WSL generates error

6 participants