-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Skip compiling the non-supported cmdlets in System.Management.Automation.dll #6939
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
iSazonov
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.
Leave 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.
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?
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'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:
- Keeps *nix and Windows totally separate
- Means we can avoid
#ifaltogether - .NET Core does it with
X.Unix.csandX.Windows.cspartial classes: https://github.com/dotnet/corefx/blob/aeda0b030144b478d82e245e39d2a4acb022c501/src/Common/src/System/Net/SocketProtocolSupportPal.Unix.cs - Makes the code a lot more maintainable
- Still get things like monomorphism optimisations in the JIT
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.
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.
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.
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...
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.
My question was only about the file. The rule was already disabled in PR #6930.
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.
@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.
|
Can we close #1998? |
BrucePay
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
rjmholt
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.
Oh no I never submitted my review before!
All looks good to me.
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'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:
- Keeps *nix and Windows totally separate
- Means we can avoid
#ifaltogether - .NET Core does it with
X.Unix.csandX.Windows.cspartial classes: https://github.com/dotnet/corefx/blob/aeda0b030144b478d82e245e39d2a4acb022c501/src/Common/src/System/Net/SocketProtocolSupportPal.Unix.cs - Makes the code a lot more maintainable
- Still get things like monomorphism optimisations in the JIT
|
@daxian-dbw Please fix CI Appveyor issues. |
|
@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
|
@iSazonov I had to rebase the branch to build. The new changes are only in the second commit. |
|
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'm happy to move I opened the issue #7008 to track the work to properly disable all code related to session connection/disconnection for the Unix build. |
|
I'll give this a try on my Ubuntu machine later just to check everything |
|
@rjmholt Congratulations on your first review! :-) |
|
Tests all pass (except for 4 known problems) on Ubuntu 16.04 in Debug configuration. No assertion failures |
|
@rjmholt Thank you! |
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 -Cleanon Linux starts to use the debug configuration by default, which reveals another issue on Linux build -- we use a cache inInitialSessionStateto 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:QueryRunspacesand enumSessionFilterStatefromConnectPSSession.csPSSessionOptionand enumProxyAccessTypefromNewPSSessionOptionCommand.csCheckIfPowerShellVersionIsInstalledandCheckPSVersionfromCustomShellCommands.csto classRemotingCommandUtilsinPSRemotingCmdlet.csPR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests