Skip to content

Conversation

@daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented May 25, 2018

PR Summary

Fix #6886
Our configuration definition 'Linux' caused our Linux build to be unoptimized, and we didn't realize until recently. This was fixed in #6853, which makes our Linux build adopts the same configuration settings as on Windows -- debug and release.

Start-PSBuild -Clean on Linux starts to use the debug configuration by default, which reveals another issue on Linux build -- we use a cache in InitialSessionState to initialize cmdlets from S.M.A.dll in order to speed up powershell startup and items in cache drifts from actual cmdlet types available in S.M.A.dll in Unix platforms.

This is because there are some cmdlets not supported on Unix, which are if/def'ed out in the cache code, but they are still compiled in S.M.A.dll on Unix. We have some code that only runs in debug configuration to check if the cache is in sync with the real status of S.M.A.dll, but we never got to run in debug configuration because of the 'Linux' configuration we used before.

This PR skips compiling the non-supported cmdlets in S.M.A.dll, to keep the cache in InitialSessionState in sync with the actually available cmdlet types in System.Management.Automation.dll.

Change Details

Note that some of the cmdlet source files contain codes that are used in other places outside the cmdlet. Those codes are moved out to PSRemotingCmdlet.cs, a more general place where base classes and helper classes for remoting command are located. The following type/methods are moved:

  1. Class QueryRunspaces and enum SessionFilterState from ConnectPSSession.cs
  2. Class PSSessionOption and enum ProxyAccessType from NewPSSessionOptionCommand.cs
  3. Methods CheckIfPowerShellVersionIsInstalled and CheckPSVersion from CustomShellCommands.cs to class RemotingCommandUtils in PSRemotingCmdlet.cs

PR Checklist

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

Leave a comment

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe split the file by classes and exclude a new file from compile on Unix?

If we look CodeFactor issues it recommends to use one-class-per-file - if we move code in the PR maybe follow this rule?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm personally in favour of this approach too. I know we've already taken the other path in most places, but there are some good factors:

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once-class-per-file is ridiculous. We have modern editors with all kinds of features for managing large files. I'm much happier navigating within a few files than having to deal with hundreds of tabs. I vote we suppress this rule.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree with @BrucePay in the general case of having multiple classes per file. Sometimes it's overkill to make a class nested, but it makes a lot more sense contextually to have it in the same file as a larger class. Enums are a good motivating example I find. Also, it's nice to feel like I've moved on from this historical holdover of Java and MATLAB...

Copy link
Collaborator

@iSazonov iSazonov Jun 2, 2018

Choose a reason for hiding this comment

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

My question was only about the file. The rule was already disabled in PR #6930.

Copy link
Member Author

Choose a reason for hiding this comment

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

@iSazonov The reason I was using #if !UNIX in this file is because the class SessionConfigurationUtils in this file is heavily used and only used in those two cmdlets (New-PSSessionConfigurationFile and New-PSRoleCapabilityFile), so it makes sense to keep them close to each other in the same file.

@iSazonov
Copy link
Collaborator

Can we close #1998?

Copy link
Collaborator

@BrucePay BrucePay left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

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

Oh no I never submitted my review before!

All looks good to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm personally in favour of this approach too. I know we've already taken the other path in most places, but there are some good factors:

@iSazonov iSazonov self-assigned this Jun 2, 2018
@iSazonov
Copy link
Collaborator

iSazonov commented Jun 2, 2018

@daxian-dbw Please fix CI Appveyor issues.

@daxian-dbw
Copy link
Member Author

@iSazonov Will fix the build today.

This is to keep the cache in InitialSessionState in sycn with the actual available cmdlet types in System.Management.Automation.dll
@daxian-dbw
Copy link
Member Author

@iSazonov I had to rebase the branch to build. The new changes are only in the second commit.

@PaulHigin
Copy link
Contributor

Class QueryRunspaces and enum SessionFilterState from ConnectPSSession.cs

QueryRunspaces is only used for session disconnect, which is only supported on Windows. PSRemotingCmdlets.cs is a heavily loaded file to support many remoting cmdlet base classes. Moving QueryRunspaces there just makes it more bloated and confusing in my opinion.
I feel that QueryRunspaces should be put into a separate utils file that can be skipped for Linux.
You should also #ifdef out its use in the Get-PSSession parameter set since it is not supported on Linux.

@daxian-dbw
Copy link
Member Author

QueryRunspaces is used in Connect-PSSession/Receive-PSSession/Get-PSSession and it's also directly used by the abstract class PSRunspaceCmdlet from PSRemotingCmdlet.cs, that's why I thought it probably fit in the "Helper Classes" region in PSRemotingCmdlet.cs.

I'm happy to move QueryRunspaces and SessionFilterState to a separate file, but we cannot skip compiling that file yet until all uses are properly diabled (if/def'ed out) for Unix platform. That work is out scope for this PR, as this PR is for fixing the crashing debug build on Unix platforms.

I opened the issue #7008 to track the work to properly disable all code related to session connection/disconnection for the Unix build.

@rjmholt
Copy link
Collaborator

rjmholt commented Jun 6, 2018

I'll give this a try on my Ubuntu machine later just to check everything

@iSazonov
Copy link
Collaborator

iSazonov commented Jun 6, 2018

@rjmholt Congratulations on your first review! :-)

@iSazonov iSazonov merged commit 2429b43 into PowerShell:master Jun 6, 2018
@daxian-dbw daxian-dbw deleted the fixdebug branch June 6, 2018 04:42
@rjmholt
Copy link
Collaborator

rjmholt commented Jun 6, 2018

Tests all pass (except for 4 known problems) on Ubuntu 16.04 in Debug configuration. No assertion failures

@daxian-dbw
Copy link
Member Author

@rjmholt Thank you!

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.

Assertion failure in master: "new Cmdlet added to System.Management.Automation.dll - update InitializeCoreCmdletsAndProviders"

5 participants