Skip to content

Ifdefs to decouple PS Core plugin from Windows dependencies. #35

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/powershell-native/nativemsh/pwrshplugin/pwrshplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,16 @@ class PwrshPlugInMediator
return g_MANAGED_PLUGIN_ALREADY_LOADED;
}

// Not used for CORECLR plugins
#if !CORECLR

if ((NULL == wszVCLRVersion) || (NULL == wszVAppBase))
{
return g_INVALID_INPUT;
}

#endif

do
{
// Setting global AppBase and CLR Version
Expand Down Expand Up @@ -646,6 +651,10 @@ class PwrshPlugInMediator

void LoadPowerShell(PCWSTR version) throw (...)
{
unsigned int exitCode = EXIT_CODE_SUCCESS;

// PowerShell core plugin does not depend on registered Windows PowerShell version.
#if !CORECLR
// Verify incoming powershell version format.
int iPSMajorVersion = 0;
int iPSMinorVersion = 0;
Expand All @@ -671,16 +680,18 @@ class PwrshPlugInMediator
{
requestedMonadMajorVersion = 1;
}
#endif

wchar_t* wszMonadVersion = NULL; // Allocated via ConstructPowerShellVersion || GetRegistryInfo
wchar_t* wszTempCLRVersion = NULL; // Allocated via GetRegistryInfo
wchar_t* wszTempAppBase = NULL; // Allocated via GetRegistryInfo
PWSTR wszMgdPlugInFileName = NULL; // Allocated in CreateMgdPluginFileName
unsigned int exitCode = EXIT_CODE_SUCCESS;
PlugInException* pErrorMsg = NULL;

do
{
// PowerShell core plugin does not depend on registered Windows PowerShell version.
#if !CORECLR
exitCode = ConstructPowerShellVersion(iPSMajorVersion, iPSMinorVersion, &wszMonadVersion);
if (exitCode != EXIT_CODE_SUCCESS)
{
Expand Down Expand Up @@ -711,16 +722,19 @@ class PwrshPlugInMediator
{
break;
}
#endif

if (!bIsPluginLoaded)
{
// wszMgdPlugInFileName is ignored for CORECLR.
this->powerShellClrHost = PowerShellClrWorkerFactory(wszMgdPlugInFileName);
if (NULL == this->powerShellClrHost)
{
exitCode = ERROR_NOT_ENOUGH_MEMORY;
break;
}

// wszMonadVersion, wszTempCLRVersion ignored for CORECLR.
exitCode = powerShellClrHost->LaunchClr(wszMonadVersion, wszTempCLRVersion, "PwrshPlugin");
if (EXIT_CODE_SUCCESS != exitCode)
{
Expand All @@ -730,8 +744,10 @@ class PwrshPlugInMediator
break;
}

// wszMgdPlugInFileName, wszTempCLRVersion, wszTempAppBase ignored for CORECLR.
exitCode = LoadManagedPlugIn(wszMgdPlugInFileName, wszTempCLRVersion, wszTempAppBase, &pErrorMsg);
}
#if !CORECLR
else
{
if (requestedMonadMajorVersion != iMajorVersion)
Expand All @@ -747,6 +763,7 @@ class PwrshPlugInMediator
exitCode = g_OPTION_SET_APP_BASE_NOT_MATCH;
}
}
#endif
} while (false);

if (NULL != wszMonadVersion)
Expand Down