unsafe static int Execute(int argc, char** argv, NativeBootstrapperContext* context) { Logger.TraceInformation($"[{nameof(DomainManager)}] Using CoreCLR"); // Pack arguments var arguments = new string[argc]; for (var i = 0; i < arguments.Length; i++) { arguments[i] = new string(argv[i]); } try { var bootstrapperContext = new BootstrapperContext(); bootstrapperContext.OperatingSystem = new string(context->OperatingSystem); bootstrapperContext.OsVersion = new string(context->OsVersion); bootstrapperContext.Architecture = new string(context->Architecture); bootstrapperContext.RuntimeDirectory = new string(context->RuntimeDirectory); bootstrapperContext.ApplicationBase = new string(context->ApplicationBase); bootstrapperContext.TargetFramework = new FrameworkName(FrameworkNames.LongNames.DnxCore, new Version(5, 0)); bootstrapperContext.RuntimeType = "CoreClr"; return RuntimeBootstrapper.Execute(arguments, bootstrapperContext); } catch (Exception ex) { return ex.HResult != 0 ? ex.HResult : 1; } }
public RuntimeEnvironment(BootstrapperContext bootstrapperContext) { RuntimeType = bootstrapperContext.RuntimeType; RuntimeArchitecture = bootstrapperContext.Architecture; OperatingSystem = bootstrapperContext.OperatingSystem; OperatingSystemVersion = bootstrapperContext.OsVersion; }
public static int Execute(string[] args, BootstrapperContext bootstrapperContext) { try { return(ExecuteAsync(args, bootstrapperContext).GetAwaiter().GetResult()); } catch (Exception ex) { PrintErrors(ex); return(1); } }
public static int Execute(string[] args, BootstrapperContext bootstrapperContext) { try { return ExecuteAsync(args, bootstrapperContext).GetAwaiter().GetResult(); } catch (Exception ex) { PrintErrors(ex); return 1; } }
public RuntimeEnvironment(BootstrapperContext bootstrapperContext) { // Use the DefaultRuntimeEnvironment to detect the OS details rather than bootstrapper context (temporary, this is probably going away anyway) var defaultEnv = new DefaultRuntimeEnvironment(); OperatingSystem = defaultEnv.OperatingSystem; OperatingSystemVersion = defaultEnv.OperatingSystemVersion; OperatingSystemPlatform = defaultEnv.OperatingSystemPlatform; RuntimeType = bootstrapperContext.RuntimeType; RuntimeArchitecture = bootstrapperContext.Architecture; RuntimePath = bootstrapperContext.RuntimeDirectory; }
public static Task <int> ExecuteAsync(string[] args, BootstrapperContext bootstrapperContext) { var app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = Constants.BootstrapperExeName; app.FullName = Constants.BootstrapperFullName; // These options were handled in the native code, but got passed through here. // We just need to capture them and clean them up. var optionProject = app.Option("--project|-p <PATH>", "Path to the project.json file or the application folder. Defaults to the current folder if not provided.", CommandOptionType.SingleValue); var optionAppbase = app.Option("--appbase <PATH>", "Application base directory path", CommandOptionType.SingleValue); var optionLib = app.Option("--lib <LIB_PATHS>", "Paths used for library look-up", CommandOptionType.MultipleValue); var optionDebug = app.Option("--debug", "Waits for the debugger to attach before beginning execution.", CommandOptionType.NoValue); if (bootstrapperContext.RuntimeType != "Mono") { app.Option("--bootstrapper-debug", "Waits for the debugger to attach before bootstrapping runtime.", CommandOptionType.NoValue); } #if DNX451 var optionFramework = app.Option("--framework <FRAMEWORK_ID>", "Set the framework version to use when running (i.e. dnx451, dnx452, dnx46, ...)", CommandOptionType.SingleValue); #endif var env = new RuntimeEnvironment(bootstrapperContext); app.HelpOption("-?|-h|--help"); app.VersionOption("--version", () => env.GetShortVersion(), () => env.GetFullVersion()); // Options below are only for help info display // They will be forwarded to Microsoft.Dnx.ApplicationHost var optionsToForward = new[] { app.Option("--watch", "Watch file changes", CommandOptionType.NoValue), app.Option("--packages <PACKAGE_DIR>", "Directory containing packages", CommandOptionType.SingleValue), app.Option("--configuration <CONFIGURATION>", "The configuration to run under", CommandOptionType.SingleValue), app.Option("--port <PORT>", "The port to the compilation server", CommandOptionType.SingleValue) }; app.Execute(args); // Help information was already shown because help option was specified if (app.IsShowingInformation) { return(Task.FromResult(0)); } // Show help information if no subcommand/option was specified if (!app.IsShowingInformation && app.RemainingArguments.Count == 0) { app.ShowHelp(); return(Task.FromResult(2)); } // Some options should be forwarded to Microsoft.Dnx.ApplicationHost var appHostName = "Microsoft.Dnx.ApplicationHost"; var appHostIndex = app.RemainingArguments.FindIndex(s => string.Equals(s, appHostName, StringComparison.OrdinalIgnoreCase)); foreach (var option in optionsToForward) { if (option.HasValue()) { if (appHostIndex < 0) { Console.WriteLine("The option '--{0}' can only be used with {1}", option.LongName, appHostName); return(Task.FromResult(1)); } if (option.OptionType == CommandOptionType.NoValue) { app.RemainingArguments.Insert(appHostIndex + 1, "--" + option.LongName); } else if (option.OptionType == CommandOptionType.SingleValue) { app.RemainingArguments.Insert(appHostIndex + 1, "--" + option.LongName); app.RemainingArguments.Insert(appHostIndex + 2, option.Value()); } else if (option.OptionType == CommandOptionType.MultipleValue) { foreach (var value in option.Values) { app.RemainingArguments.Insert(appHostIndex + 1, "--" + option.LongName); app.RemainingArguments.Insert(appHostIndex + 2, value); } } } } // Resolve the lib paths IEnumerable <string> searchPaths = ResolveSearchPaths(bootstrapperContext.RuntimeDirectory, optionLib.Values, app.RemainingArguments); var bootstrapper = new Bootstrapper(searchPaths); return(bootstrapper.RunAsync(app.RemainingArguments, env, bootstrapperContext.ApplicationBase, bootstrapperContext.TargetFramework)); }
public static int Main(string[] arguments) { // Check for the debug flag before doing anything else bool hasDebugWaitFlag = false; for (var i = 0; i < arguments.Length; ++i) { //anything without - or -- is appbase or non-dnx command if (arguments[i][0] != '-') { break; } if (arguments[i] == "--appbase") { //skip path argument ++i; continue; } if (arguments[i] == "--debug") { hasDebugWaitFlag = true; break; } } if (hasDebugWaitFlag) { if (!Debugger.IsAttached) { Process currentProc = Process.GetCurrentProcess(); Console.WriteLine("Process Id: {0}", currentProc.Id); Console.WriteLine("Waiting for the debugger to attach..."); while (!Debugger.IsAttached) { Thread.Sleep(250); } Console.WriteLine("Debugger attached."); } } arguments = ExpandCommandLineArguments(arguments); // Set application base dir var appbaseIndex = arguments.ToList().FindIndex(arg => string.Equals(arg, "--appbase", StringComparison.OrdinalIgnoreCase)); var appBase = appbaseIndex >= 0 && (appbaseIndex < arguments.Length - 1) ? arguments[appbaseIndex + 1] : Directory.GetCurrentDirectory(); string operatingSystem, osVersion, architecture; GetOsDetails(out operatingSystem, out osVersion, out architecture); var bootstrapperContext = new BootstrapperContext { OperatingSystem = operatingSystem, OsVersion = osVersion, Architecture = architecture, RuntimeDirectory = Path.GetDirectoryName(typeof(EntryPoint).Assembly.Location), ApplicationBase = appBase, // NOTE(anurse): Mono is always "dnx451" (for now). TargetFramework = new FrameworkName("DNX", new Version(4, 5, 1)), RuntimeType = "Mono" }; return RuntimeBootstrapper.Execute(arguments, bootstrapperContext); }
public static Task<int> ExecuteAsync(string[] args, BootstrapperContext bootstrapperContext) { var app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = Constants.BootstrapperExeName; app.FullName = Constants.BootstrapperFullName; // These options were handled in the native code, but got passed through here. // We just need to capture them and clean them up. var optionProject = app.Option("--project|-p <PATH>", "Path to the project.json file or the application folder. Defaults to the current folder if not provided.", CommandOptionType.SingleValue); var optionAppbase = app.Option("--appbase <PATH>", "Application base directory path", CommandOptionType.SingleValue); var optionLib = app.Option("--lib <LIB_PATHS>", "Paths used for library look-up", CommandOptionType.MultipleValue); var optionDebug = app.Option("--debug", "Waits for the debugger to attach before beginning execution.", CommandOptionType.NoValue); if (bootstrapperContext.RuntimeType != "Mono") { app.Option("--bootstrapper-debug", "Waits for the debugger to attach before bootstrapping runtime.", CommandOptionType.NoValue); } #if DNX451 var optionFramework = app.Option("--framework <FRAMEWORK_ID>", "Set the framework version to use when running (i.e. dnx451, dnx452, dnx46, ...)", CommandOptionType.SingleValue); #endif var env = new RuntimeEnvironment(bootstrapperContext); app.HelpOption("-?|-h|--help"); app.VersionOption("--version", () => env.GetShortVersion(), () => env.GetFullVersion()); // Options below are only for help info display // They will be forwarded to Microsoft.Dnx.ApplicationHost var optionsToForward = new[] { app.Option("--watch", "Watch file changes", CommandOptionType.NoValue), app.Option("--packages <PACKAGE_DIR>", "Directory containing packages", CommandOptionType.SingleValue), app.Option("--configuration <CONFIGURATION>", "The configuration to run under", CommandOptionType.SingleValue), app.Option("--port <PORT>", "The port to the compilation server", CommandOptionType.SingleValue) }; app.Execute(args); // Help information was already shown because help option was specified if (app.IsShowingInformation) { return Task.FromResult(0); } // Show help information if no subcommand/option was specified if (!app.IsShowingInformation && app.RemainingArguments.Count == 0) { app.ShowHelp(); return Task.FromResult(2); } // Some options should be forwarded to Microsoft.Dnx.ApplicationHost var appHostName = "Microsoft.Dnx.ApplicationHost"; var appHostIndex = app.RemainingArguments.FindIndex(s => string.Equals(s, appHostName, StringComparison.OrdinalIgnoreCase)); foreach (var option in optionsToForward) { if (option.HasValue()) { if (appHostIndex < 0) { Console.WriteLine("The option '--{0}' can only be used with {1}", option.LongName, appHostName); return Task.FromResult(1); } if (option.OptionType == CommandOptionType.NoValue) { app.RemainingArguments.Insert(appHostIndex + 1, "--" + option.LongName); } else if (option.OptionType == CommandOptionType.SingleValue) { app.RemainingArguments.Insert(appHostIndex + 1, "--" + option.LongName); app.RemainingArguments.Insert(appHostIndex + 2, option.Value()); } else if (option.OptionType == CommandOptionType.MultipleValue) { foreach (var value in option.Values) { app.RemainingArguments.Insert(appHostIndex + 1, "--" + option.LongName); app.RemainingArguments.Insert(appHostIndex + 2, value); } } } } // Resolve the lib paths IEnumerable<string> searchPaths = ResolveSearchPaths(bootstrapperContext.RuntimeDirectory, optionLib.Values, app.RemainingArguments); var bootstrapper = new Bootstrapper(searchPaths); return bootstrapper.RunAsync(app.RemainingArguments, env, bootstrapperContext.ApplicationBase, bootstrapperContext.TargetFramework); }