Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Nov 12, 2019

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

@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Nov 12, 2019
@iSazonov iSazonov added this to the 7.0.0-preview.6 milestone Nov 12, 2019
@iSazonov
Copy link
Collaborator Author

@SteveL-MSFT Do you agree to merge the PR before GA?

@iSazonov iSazonov self-assigned this Nov 14, 2019
@iSazonov
Copy link
Collaborator Author

iSazonov commented Nov 15, 2019

@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.
On my system typeof(object).Assembly.GetName().ProcessorArchitecture returns Amd64.

@daxian-dbw daxian-dbw requested a review from anmenaga November 15, 2019 20:18
@anmenaga
Copy link

@iSazonov , can you please double check that currently GetProcessorArchitecture() returns system-wide info and comment on this function is wrong?
If that's the case, then probably to avoid future confusion:

  1. current GetProcessorArchitecture() should be renamed across the code to something like GetSystemProcessorArchitecture(), and comment updated;
  2. since the functionality of getting current process arch is also needed, code of this PR should go into PsUtils as a separate method like GetCurrentProcessProcessorArchitecture().

@iSazonov
Copy link
Collaborator Author

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

@iSazonov
Copy link
Collaborator Author

@anmenaga Please update your review.

@iSazonov
Copy link
Collaborator Author

@anmenaga Could you please continue?

@iSazonov
Copy link
Collaborator Author

@SteveL-MSFT @anmenaga I think the PR could be in 7.0.

@SteveL-MSFT
Copy link
Member

@iSazonov can you add a test to cover #6533?

@iSazonov
Copy link
Collaborator Author

@SteveL-MSFT Sorry, I did not saw the issue. New tests are added.

@iSazonov
Copy link
Collaborator Author

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

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

Copy link
Collaborator Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Extra whitespace

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jan 10, 2020
@SteveL-MSFT
Copy link
Member

@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

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jan 11, 2020
@iSazonov
Copy link
Collaborator Author

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

@iSazonov iSazonov merged commit 0dfeeb5 into PowerShell:master Jan 14, 2020
@iSazonov iSazonov deleted the port-getprocessorarchitecture branch January 14, 2020 03:41
@iSazonov
Copy link
Collaborator Author

Notice. The code was not covered by tests. Now only Windows on Intel is covered. Unix-s and Arm are not covered.

daxian-dbw pushed a commit that referenced this pull request Jan 14, 2020
@daxian-dbw daxian-dbw modified the milestones: GA-approved, 7.0.0-rc.2 Jan 14, 2020
@ghost
Copy link

ghost commented Jan 16, 2020

🎉v7.0.0-rc.2 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module manifest .psd1 file on linux/mac doesn't support ProcessorArchitecture='AMD64' or 'x86' GetProcessorArchitecture in PSUtil.cs is not ported

7 participants