|
2 | 2 | using ConsoleAppFramework; |
3 | 3 | using Devlooped; |
4 | 4 |
|
| 5 | +if (Environment.GetEnvironmentVariable("GO_DEBUG") == "1") |
| 6 | + System.Diagnostics.Debugger.Launch(); |
| 7 | + |
5 | 8 | var app = ConsoleApp.Create(); |
6 | 9 | app.Add("", RunAsync); |
7 | 10 | app.Add("dev", DevAsync); |
|
13 | 16 | /// <param name="input">Path to an existing .cs file or remote ref (owner/repo[@ref][:path]).</param> |
14 | 17 | /// <param name="r2r">Publish with ReadyToRun instead of native AOT; supports more dynamic .NET features while keeping most publish optimizations. </param> |
15 | 18 | /// <param name="gdbg">Launch debugger before executing.</param> |
16 | | -static async Task<int> RunAsync([Argument] string input, bool r2r = false, [Hidden] bool gdbg = false) |
| 19 | +/// <param name="args">Arguments to pass to the app, or to dotnet publish and the app, separated by --.</param> |
| 20 | +static async Task<int> RunAsync([Argument] string input, bool r2r = false, [Hidden] bool gdbg = false, [Argument] params string[] args) |
17 | 21 | { |
18 | 22 | if (gdbg) |
19 | 23 | System.Diagnostics.Debugger.Launch(); |
@@ -48,6 +52,36 @@ state.App is not null && |
48 | 52 | return await ExecuteAppAsync(publishDir, () => ProcessRunner.RunAsync(state.App, appArgs)); |
49 | 53 | } |
50 | 54 |
|
| 55 | +/// <summary>Runs a file-based .NET app from a .cs entrypoint using dotnet run for fast iteration.</summary> |
| 56 | +/// <param name="input">Path to an existing .cs file or remote ref (owner/repo[@ref][:path]).</param> |
| 57 | +/// <param name="r2r">Accepted for consistency (ignored for dev which uses dotnet run).</param> |
| 58 | +/// <param name="gdbg">Launch debugger before executing.</param> |
| 59 | +/// <param name="args">Arguments to pass to the app, or to dotnet run and the app, separated by --.</param> |
| 60 | +static async Task<int> DevAsync([Argument] string input, [Hidden] bool r2r = false, [Hidden] bool gdbg = false, [Argument] params string[] args) |
| 61 | +{ |
| 62 | + if (gdbg) |
| 63 | + System.Diagnostics.Debugger.Launch(); |
| 64 | + |
| 65 | + var source = await GetEffectiveSourceAsync(input); |
| 66 | + if (source is null) |
| 67 | + return 1; |
| 68 | + |
| 69 | + var context = Prepare(source, GoArgs.ForwardArgs); |
| 70 | + if (context is null) |
| 71 | + return 1; |
| 72 | + |
| 73 | + var (dotnet, cs, publishDir, stamp, targets, _, dotnetArgs, appArgs) = context.Value; |
| 74 | + |
| 75 | + if (BuildState.TryRead(stamp, out var state) && |
| 76 | + state.Bin is not null && |
| 77 | + BuildManager.IsUpToDate(state, state.Bin)) |
| 78 | + return await ExecuteAppAsync(publishDir, () => ProcessRunner.DotnetExecAsync(dotnet, state.Bin, appArgs)); |
| 79 | + |
| 80 | + File.WriteAllText(stamp, string.Empty, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); |
| 81 | + |
| 82 | + return await ExecuteAppAsync(publishDir, () => ProcessRunner.DotnetRunAsync(dotnet, cs, stamp, targets, dotnetArgs, appArgs)); |
| 83 | +} |
| 84 | + |
51 | 85 | /// <summary>Deletes cached publish artifacts for a file-based .NET app, or for a remote ref.</summary> |
52 | 86 | /// <param name="input">Path to an existing .cs file or remote ref (owner/repo[@ref][:path]).</param> |
53 | 87 | /// <param name="all">Delete cached artifacts for all apps instead.</param> |
@@ -138,35 +172,6 @@ static int CleanAsync([Argument] string? input = null, bool all = false, [Hidden |
138 | 172 | return AppCleaner.Clean(pdir, stmp, cs); |
139 | 173 | } |
140 | 174 |
|
141 | | -/// <summary>Runs a file-based .NET app from a .cs entrypoint using dotnet run for fast iteration.</summary> |
142 | | -/// <param name="input">Path to an existing .cs file or remote ref (owner/repo[@ref][:path]).</param> |
143 | | -/// <param name="r2r">Accepted for consistency (ignored for dev which uses dotnet run).</param> |
144 | | -/// <param name="gdbg">Launch debugger before executing.</param> |
145 | | -static async Task<int> DevAsync([Argument] string input, [Hidden] bool r2r = false, [Hidden] bool gdbg = false) |
146 | | -{ |
147 | | - if (gdbg) |
148 | | - System.Diagnostics.Debugger.Launch(); |
149 | | - |
150 | | - var source = await GetEffectiveSourceAsync(input); |
151 | | - if (source is null) |
152 | | - return 1; |
153 | | - |
154 | | - var context = Prepare(source, GoArgs.ForwardArgs); |
155 | | - if (context is null) |
156 | | - return 1; |
157 | | - |
158 | | - var (dotnet, cs, publishDir, stamp, targets, _, dotnetArgs, appArgs) = context.Value; |
159 | | - |
160 | | - if (BuildState.TryRead(stamp, out var state) && |
161 | | - state.Bin is not null && |
162 | | - BuildManager.IsUpToDate(state, state.Bin)) |
163 | | - return await ExecuteAppAsync(publishDir, () => ProcessRunner.DotnetExecAsync(dotnet, state.Bin, appArgs)); |
164 | | - |
165 | | - File.WriteAllText(stamp, string.Empty, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); |
166 | | - |
167 | | - return await ExecuteAppAsync(publishDir, () => ProcessRunner.DotnetRunAsync(dotnet, cs, stamp, targets, dotnetArgs, appArgs)); |
168 | | -} |
169 | | - |
170 | 175 | static async Task<int> ExecuteAppAsync(string publishDir, Func<Task<int>> execute) |
171 | 176 | { |
172 | 177 | Directory.Touch(publishDir); |
|
0 commit comments