Skip to content

Honor BundledModulesPath when loading modules in PowerShellContextService #1516

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

Closed

Conversation

dkattan
Copy link
Contributor

@dkattan dkattan commented Jun 28, 2021

No description provided.

@andyleejordan
Copy link
Member

I like this approach a lot better than my own, which was a bit of a hack.

@dkattan dkattan changed the title Added BundledModulesPath to HostStartupInfo object so it can be honored in PowerShellContextService Honor BundledModulesPath when loading modules in PowerShellContextService Jun 30, 2021
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
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 is impetus for the change. We are referencing a path relative to the executing assembly instead of honoring the BundledModulePath parameter.

@@ -190,7 +198,10 @@ public RunspaceDetails CurrentRunspace
HostStartupInfo hostStartupInfo)
{
Validate.IsNotNull(nameof(hostStartupInfo), hostStartupInfo);

s_bundledModulesPath = !string.IsNullOrEmpty(hostStartupInfo.BundledModulePath) && Directory.Exists(hostStartupInfo.BundledModulePath)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here if a valid path was specified, we use it, otherwise we fallback to the previous logic.

@dkattan dkattan marked this pull request as ready for review July 6, 2021 11:21
@dkattan dkattan requested a review from rjmholt as a code owner July 6, 2021 11:21
@dkattan dkattan marked this pull request as draft July 6, 2021 11:28
@@ -160,6 +160,7 @@ public async Task CanGetPSReadLineProxy()
"..",
"module"
);
System.Console.WriteLine($"Attempting to import {s_bundledModulesPath}");
Copy link
Member

Choose a reason for hiding this comment

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

Just FYI I am debugging this test on Windows right now, really want to know why it worked everywhere but there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, me too. I think this last change fixed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this PR should be the first to go in. It made sense to bring in the Changes from #1520 so I'll close that PR as this handles both issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah maybe not, PowerShell 7 | Windows 10 has already failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

macOS:
executingAssembly /Users/runner/work/1/s/test/PowerShellEditorServices.Test/bin/Debug/netcoreapp3.1/Microsoft.PowerShell.EditorServices.Test.dll

Windows: executingAssembly C:\Users\VssAdministrator\AppData\Local\Temp\b5b3251f-c622-45f2-bc10-c8a646797337\b5b3251f-c622-45f2-bc10-c8a646797337\assembly\dl3\e3727c32\64017e66_b772d701\Microsoft.PowerShell.EditorServices.Test.dll

https://stackoverflow.com/questions/8309411/what-is-cache-appdata-local-assembly-dl3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Evidently we shouldn't be using GetExecutingAssembly().Location as this can return a Volume Shadow Copy cached version of the DLL. We're using it in 9 other places...

Code File Line
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); test\PowerShellEditorServices.Test.E2E\DebugAdapterProtocolMessageTests.cs 26
: Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); src\PowerShellEditorServices.Hosting\Commands\StartEditorServicesCommand.cs 302
Assembly.GetExecutingAssembly().Location, src\PowerShellEditorServices.Hosting\Commands\StartEditorServicesCommand.cs 344
private static readonly string s_psesBaseDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); src\PowerShellEditorServices.Hosting\EditorServicesLoader.cs 34
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), src\PowerShellEditorServices.Hosting\EditorServicesLoader.cs 39
private static string s_bundledModulesPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", ".."); src\PowerShellEditorServices\Services\PowerShellContext\PowerShellContextService.cs 35
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); test\PowerShellEditorServices.Test.E2E\LanguageServerProtocolMessageTests.cs 36
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); test\PowerShellEditorServices.Test.E2E\LSPTestsFixures.cs 31
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); test\PowerShellEditorServices.Test.E2E\Processes\PsesStdioProcess.cs 19

var type = assemblies?.ExportedTypes?.FirstOrDefault(a => a.FullName == "Microsoft.PowerShell.PSConsoleReadLine");
if(type is not null)
{
System.Console.WriteLine("Found PSConsoleReadLine in loaded assemblies.");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andschwa I didn't think this was going to be necessary, but upon inspecting the logs from the most recent build, it appears it is:
https://dev.azure.com/powershell/PowerShellEditorServices/_build/results?buildId=81345&view=logs&j=5aed7330-0c52-5e0f-84aa-a17a2c59b4c4&t=c5143455-bea5-57f2-b80c-f2c098a4d98c&l=928

Attempting to import D:\a\1\s\module\PSReadLine
psReadLineType is null, searching loaded assemblies...
Found PSConsoleReadLine in loaded assemblies.

@dkattan dkattan marked this pull request as ready for review July 6, 2021 23:37
var type = assemblies?.ExportedTypes?.FirstOrDefault(a => a.FullName == "Microsoft.PowerShell.PSConsoleReadLine");
if(type is not null)
{
logger.LogInformation("Found PSConsoleReadLine in loaded assemblies.");
Copy link
Member

Choose a reason for hiding this comment

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

In your testing has it ever been found in the loaded assemblies?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like it. Hmm...

@dkattan
Copy link
Contributor Author

dkattan commented Jul 13, 2021

This was corrected in #1522

@dkattan dkattan closed this Jul 13, 2021
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.

2 participants