-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Port GetProcessorArchitecture() #11046
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
Port GetProcessorArchitecture() #11046
Conversation
|
@SteveL-MSFT Do you agree to merge the PR before GA? |
|
@adityapatwardhan Please review the PR again. After looking in depth how the method is used I very wonder that we implement the conversion of these two enums if we can request current value from an assembly using Reflection. |
src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Outdated
Show resolved
Hide resolved
|
@iSazonov , can you please double check that currently
|
|
@anmenaga If the name confuses you we could remove the method at all because it is used in one place/scenario. Th scenario is a module loading. We read ProcessorArchitecture parameter from the module manifest and check that we can load the module. The check is to compare the ProcessorArchitecture parameter and ProcessorArchitecture property from current assembly. And we can do this directly. I pulled the commit. |
|
@anmenaga Please update your review. |
|
@anmenaga Could you please continue? |
|
@SteveL-MSFT @anmenaga I think the PR could be in 7.0. |
|
@SteveL-MSFT Sorry, I did not saw the issue. New tests are added. |
|
@SteveL-MSFT It seems I need help to fix tests on Unix-s. :-( I guess SMA compiled to MSIL on Unix-s. In the case I don't know how make functional tests on Unix-s. |
| Get-TP -ErrorAction SilentlyContinue | Should -BeExactly "$arch" | ||
|
|
||
| Remove-Module "TP_$arch" | ||
| Remove-Item -LiteralPath $testFolder -Recurse -Force -ErrorAction SilentlyContinue > $null |
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.
Should have in finally to ensure this cleans up if test fails for some reason
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.
Done.
| Add-Type -TypeDefinition $a -CompilerOptions "/platform:$roslynArch" -OutputAssembly $assemblyPath | ||
| New-ModuleManifest -Path $modulePath -NestedModules "TP_$arch.dll" -RequiredAssemblies "TP_$arch.dll" -ProcessorArchitecture $arch -CmdletsToExport "Get-TP" | ||
| Import-Module $modulePath | ||
|
|
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.
Extra whitespace
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.
Done.
|
@iSazonov You can probably not even worry about Add-Type, the module manifest issue was at validation time when it is imported so you can just generate the module manifest with ProcessorArchitecture and it should succeed on compatible arch and fail on not-compatible arch |
|
@SteveL-MSFT I try to create functional tests to ensure that scenario like #6533 really works. But test failures show that perhaps the PR doesn't fix #6533 in general (the PR only removes broken p/invoke but do not ensure that import-module works) because Roslyn works in another way on Unix-s and probably loader too. Now I set to skip new tests on Unix-s. |
|
Notice. The code was not covered by tests. Now only Windows on Intel is covered. Unix-s and Arm are not covered. |
|
🎉 Handy links: |
PR Summary
Fix #4474
Fix #6533
Before the change GetProcessorArchitecture() call Windows P/Invoke so on Unix it would throw if user loaded a module with ProcessorArchitecture value in the module manifest. Now we use ProcessorArchitecture from current assembly.
PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.