Remove type_name and function_name from host

Custom hosting code was refactored to take a path to an assembly instead
of an assembly name coupled with a type and function to
execute. Instead, the host now directly executes the given assembly,
calling its Main function.

The path is resolved relative to the current directory, as should be
expected.
This commit is contained in:
Andrew Schwartzmeyer 2015-08-21 17:39:52 -07:00
parent 1a34c0de9a
commit 440cf6a236

View file

@ -16,7 +16,7 @@ void printHelp()
{
std::cerr << "PS CoreCLR host" << std::endl;
std::cerr << "Usage: host_cmdline [-c coreclr_path] [-alc load_context_assembly] [-s search_paths]" << std::endl;
std::cerr << " [-b base_path] assembly_name type_name function_name [...]" << std::endl;
std::cerr << " [-b base_path] assembly [...]" << std::endl;
std::cerr << std::endl;
std::cerr << "What it does:" << std::endl;
std::cerr << "- by default the host assumes that CoreCLR is located in the same folder" << std::endl;
@ -28,8 +28,8 @@ void printHelp()
std::cerr << " + a custom assembly containing the PowerShellAssemblyLoadContext can" << std::endl;
std::cerr << " be provided with the -alc command line argument" << std::endl;
std::cerr << "- all additional parameters at the end of the command line are forwarded" << std::endl;
std::cerr << " to the specified entry function in the assembly" << std::endl;
std::cerr << "- the host will execute the specified entry function in the specified assembly" << std::endl;
std::cerr << " to the Main function in the assembly" << std::endl;
std::cerr << "- the host will execute the Main function in the specified assembly" << std::endl;
std::cerr << " + this assembly has to be located in the search path" << std::endl;
std::cerr << "- by default the host will add the current working directory to the assembly search path" << std::endl;
std::cerr << " + this can be overridden with the -s command line argument" << std::endl;
@ -37,8 +37,8 @@ void printHelp()
std::cerr << "- by default the host assumes the PS base path for the assembly load context is the current" << std::endl;
std::cerr << " working directory" << std::endl;
std::cerr << " + this can be overridden with the -b command line argument" << std::endl;
std::cerr << "- the function signature of the function that gets executed must be:" << std::endl;
std::cerr << " public static int UnmanagedMain(int argc, [MarshalAs(UnmanagedType.LPArray,ArraySubType=UnmanagedType.LPStr,SizeParamIndex=0)] String[] argv)" << std::endl;
std::cerr << "- the function signature of the Main function that gets executed must be:" << std::endl;
std::cerr << " static void Main(string[] args)" << std::endl;
std::cerr << std::endl;
std::cerr << "Options:" << std::endl;
std::cerr << "-c, --clr-path path to libcoreclr.so and the managed CLR assemblies" << std::endl;
@ -50,13 +50,10 @@ void printHelp()
std::cerr << " separated by :" << std::endl;
std::cerr << " unless part of the same folder as CoreCLR, the main assembly referenced with the assembly_name" << std::endl;
std::cerr << " argument, must always be added to the TPA list with this parameter" << std::endl;
std::cerr << "assembly_name the assembly name of the assembly to execute" << std::endl;
std::cerr << " must be available in the search path" << std::endl;
std::cerr << "type_name the type name where the function can be found" << std::endl;
std::cerr << "function_name the function to execute (must have the function signature described above!)" << std::endl;
std::cerr << "assembly the path of the assembly to execute relative to current directory" << std::endl;
std::cerr << std::endl;
std::cerr << "Example:" << std::endl;
std::cerr << "./host_cmdline -c /test/coreclr -alc /test/ps/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -s /test/ps -b /test/ps -tpa /test/ps/powershell-simple.exe 'powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null' 'ps_hello_world.Program' 'UnmanagedMain' 'get-process'" << std::endl;
std::cerr << "./host_cmdline -c /test/coreclr -alc /test/ps/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -s /test/ps -b /test/ps -tpa /test/ps/powershell-simple.exe 'powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null' 'get-process'" << std::endl;
}
struct Args
@ -73,9 +70,7 @@ struct Args
std::string searchPaths;
std::string basePath;
std::string tpaList;
std::string entryAssemblyName;
std::string entryTypeName;
std::string entryFunctionName;
std::string entryAssemblyPath;
int argc;
char** argv;
bool verbose;
@ -88,9 +83,7 @@ struct Args
std::cerr << "- searchPaths " << searchPaths << std::endl;
std::cerr << "- basePath " << basePath << std::endl;
std::cerr << "- tpaList " << tpaList << std::endl;
std::cerr << "- entryAssemblyName " << entryAssemblyName << std::endl;
std::cerr << "- entryTypeName " << entryTypeName << std::endl;
std::cerr << "- entryFunctionName " << entryFunctionName << std::endl;
std::cerr << "- entryAssemblyPath " << entryAssemblyPath << std::endl;
std::cerr << "- argc " << argc << std::endl;
std::cerr << "- verbose " << (verbose ? "true" : "false") << std::endl;
}
@ -141,17 +134,9 @@ bool parseCmdline(const int argc, char** argv, Args& args)
{
args.verbose = true;
}
else if (args.entryAssemblyName == "")
else if (args.entryAssemblyPath == "")
{
args.entryAssemblyName = arg;
}
else if (args.entryTypeName == "")
{
args.entryTypeName = arg;
}
else if (args.entryFunctionName == "")
{
args.entryFunctionName = arg;
args.entryAssemblyPath = arg;
}
else
{
@ -165,18 +150,10 @@ bool parseCmdline(const int argc, char** argv, Args& args)
}
// check for mandatory parameters
if (args.entryAssemblyName == "")
if (args.entryAssemblyPath == "")
{
std::cerr << "error: assembly_name argument missing" << std::endl;
}
if (args.entryTypeName == "")
{
std::cerr << "error: type_name argument missing" << std::endl;
}
if (args.entryFunctionName == "")
{
std::cerr << "error: function_name argument missing" << std::endl;
}
return true;
}
@ -414,7 +391,7 @@ int main(int argc, char** argv)
unsigned int exitCode;
executeAssembly(hostHandle, domainId, args.argc,
(const char**)args.argv,
(currentDirAbsolutePath+"/powershell-simple.exe").c_str(),
(currentDirAbsolutePath+"/"+args.entryAssemblyPath).c_str(),
&exitCode);
// shutdown CoreCLR