Browse Source

Allow debugging specific projects (#163)

pull/175/head
Justin Kotalik 7 years ago
committed by GitHub
parent
commit
c33e37bf74
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      docs/commandline/tye-run.md
  2. 10
      src/Microsoft.Tye.Hosting/ProcessRunner.cs
  3. 8
      src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs
  4. 13
      src/Microsoft.Tye.Hosting/TyeHost.cs
  5. 7
      src/tye/Program.RunCommand.cs

6
docs/commandline/tye-run.md

@ -47,9 +47,9 @@ If a directory path is specified, `tye run` will default to using these files, i
Write distributed traces to the specified providers. Supported providers are zipkin. Write distributed traces to the specified providers. Supported providers are zipkin.
- `--debug` - `--debug <service>`
Waits for debugger attach in all services. Waits for debugger attach to service. Specify `*` to wait to attach to all services.
## Examples ## Examples
@ -68,5 +68,5 @@ If a directory path is specified, `tye run` will default to using these files, i
- Run an application and wait for all projects to debug attach: - Run an application and wait for all projects to debug attach:
```text ```text
tye run --debug tye run --debug *
``` ```

10
src/Microsoft.Tye.Hosting/ProcessRunner.cs

@ -18,14 +18,12 @@ namespace Microsoft.Tye.Hosting
public class ProcessRunner : IApplicationProcessor public class ProcessRunner : IApplicationProcessor
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly bool _debugMode; private readonly ProcessRunnerOptions _options;
private readonly bool _buildProjects;
public ProcessRunner(ILogger logger, ProcessRunnerOptions options) public ProcessRunner(ILogger logger, ProcessRunnerOptions options)
{ {
_logger = logger; _logger = logger;
_debugMode = options.DebugMode; _options = options;
_buildProjects = options.BuildProjects;
} }
public Task StartAsync(Tye.Hosting.Model.Application application) public Task StartAsync(Tye.Hosting.Model.Application application)
@ -103,7 +101,7 @@ namespace Microsoft.Tye.Hosting
if (service.Status.ProjectFilePath != null && if (service.Status.ProjectFilePath != null &&
service.Description.RunInfo is ProjectRunInfo project2 && service.Description.RunInfo is ProjectRunInfo project2 &&
project2.Build && project2.Build &&
_buildProjects) _options.BuildProjects)
{ {
// Sometimes building can fail because of file locking (like files being open in VS) // Sometimes building can fail because of file locking (like files being open in VS)
_logger.LogInformation("Building project {ProjectFile}", service.Status.ProjectFilePath); _logger.LogInformation("Building project {ProjectFile}", service.Status.ProjectFilePath);
@ -146,7 +144,7 @@ namespace Microsoft.Tye.Hosting
application.PopulateEnvironment(service, (k, v) => environment[k] = v); application.PopulateEnvironment(service, (k, v) => environment[k] = v);
if (_debugMode) if (_options.DebugMode && (_options.DebugAllServices || _options.ServicesToDebug.Contains(serviceName, StringComparer.OrdinalIgnoreCase)))
{ {
environment["DOTNET_STARTUP_HOOKS"] = typeof(Hosting.Runtime.HostingRuntimeHelpers).Assembly.Location; environment["DOTNET_STARTUP_HOOKS"] = typeof(Hosting.Runtime.HostingRuntimeHelpers).Assembly.Location;
} }

8
src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs

@ -11,13 +11,17 @@ namespace Microsoft.Tye.Hosting
{ {
public bool DebugMode { get; set; } public bool DebugMode { get; set; }
public bool BuildProjects { get; set; } public bool BuildProjects { get; set; }
public string[]? ServicesToDebug { get; set; }
public bool DebugAllServices { get; set; }
public static ProcessRunnerOptions FromArgs(string[] args) public static ProcessRunnerOptions FromArgs(string[] args, string[] servicesToDebug)
{ {
return new ProcessRunnerOptions return new ProcessRunnerOptions
{ {
BuildProjects = !args.Contains("--no-build"), BuildProjects = !args.Contains("--no-build"),
DebugMode = args.Contains("--debug") DebugMode = args.Contains("--debug"),
ServicesToDebug = servicesToDebug,
DebugAllServices = servicesToDebug.Contains("*", StringComparer.OrdinalIgnoreCase)
}; };
} }
} }

13
src/Microsoft.Tye.Hosting/TyeHost.cs

@ -34,11 +34,18 @@ namespace Microsoft.Tye.Hosting
private readonly Tye.Hosting.Model.Application _application; private readonly Tye.Hosting.Model.Application _application;
private readonly string[] _args; private readonly string[] _args;
private readonly string[] _servicesToDebug;
public TyeHost(Tye.Hosting.Model.Application application, string[] args) public TyeHost(Tye.Hosting.Model.Application application, string[] args)
: this(application, args, new string[0])
{
}
public TyeHost(Tye.Hosting.Model.Application application, string[] args, string[] servicesToDebug)
{ {
_application = application; _application = application;
_args = args; _args = args;
_servicesToDebug = servicesToDebug;
} }
public Tye.Hosting.Model.Application Application => _application; public Tye.Hosting.Model.Application Application => _application;
@ -73,7 +80,7 @@ namespace Microsoft.Tye.Hosting
var configuration = app.Configuration; var configuration = app.Configuration;
_processor = CreateApplicationProcessor(_args, _logger, configuration); _processor = CreateApplicationProcessor(_args, _servicesToDebug, _logger, configuration);
await app.StartAsync(); await app.StartAsync();
@ -238,7 +245,7 @@ namespace Microsoft.Tye.Hosting
return false; return false;
} }
private static AggregateApplicationProcessor CreateApplicationProcessor(string[] args, Microsoft.Extensions.Logging.ILogger logger, IConfiguration configuration) private static AggregateApplicationProcessor CreateApplicationProcessor(string[] args, string[] _servicesToDebug, Microsoft.Extensions.Logging.ILogger logger, IConfiguration configuration)
{ {
var diagnosticOptions = DiagnosticOptions.FromConfiguration(configuration); var diagnosticOptions = DiagnosticOptions.FromConfiguration(configuration);
var diagnosticsCollector = new DiagnosticsCollector(logger, diagnosticOptions); var diagnosticsCollector = new DiagnosticsCollector(logger, diagnosticOptions);
@ -251,7 +258,7 @@ namespace Microsoft.Tye.Hosting
new EventPipeDiagnosticsRunner(logger, diagnosticsCollector), new EventPipeDiagnosticsRunner(logger, diagnosticsCollector),
new ProxyService(logger), new ProxyService(logger),
new DockerRunner(logger), new DockerRunner(logger),
new ProcessRunner(logger, ProcessRunnerOptions.FromArgs(args)), new ProcessRunner(logger, ProcessRunnerOptions.FromArgs(args, _servicesToDebug)),
}; };
// If the docker command is specified then transform the ProjectRunInfo into DockerRunInfo // If the docker command is specified then transform the ProjectRunInfo into DockerRunInfo

7
src/tye/Program.RunCommand.cs

@ -51,7 +51,8 @@ namespace Microsoft.Tye
command.AddOption(new Option("--debug") command.AddOption(new Option("--debug")
{ {
Description = "Wait for debugger attach in all services.", Argument = new Argument<string[]>("service"),
Description = "Wait for debugger attach to specific service. Specify \"*\" to wait for all services.",
Required = false Required = false
}); });
@ -61,7 +62,7 @@ namespace Microsoft.Tye
Required = false Required = false
}); });
command.Handler = CommandHandler.Create<IConsole, FileInfo>(async (console, path) => command.Handler = CommandHandler.Create<IConsole, FileInfo, string[]>(async (console, path, debug) =>
{ {
// Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654 // Workaround for https://github.com/dotnet/command-line-api/issues/723#issuecomment-593062654
if (path is null) if (path is null)
@ -74,7 +75,7 @@ namespace Microsoft.Tye
InitializeThreadPoolSettings(serviceCount); InitializeThreadPoolSettings(serviceCount);
using var host = new TyeHost(application.ToHostingApplication(), args); using var host = new TyeHost(application.ToHostingApplication(), args, debug);
await host.RunAsync(); await host.RunAsync();
}); });

Loading…
Cancel
Save