Skip to content

Commit

Permalink
Add a wait option (#72852)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpar authored Apr 3, 2024
1 parent 8df8694 commit 8e7e236
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/Compilers/Shared/BuildServerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ internal static Task<BuildResponse> RunServerBuildRequestAsync(
buildRequest,
pipeName,
timeoutOverride: null,
tryCreateServerFunc: (pipeName, logger) => TryCreateServer(clientDirectory, pipeName, logger),
tryCreateServerFunc: (pipeName, logger) => TryCreateServer(clientDirectory, pipeName, logger, out int _),
logger,
cancellationToken);

Expand Down Expand Up @@ -446,8 +446,9 @@ internal static (string processFilePath, string commandLineArguments, string too
/// compiler server process was successful, it does not state whether the server successfully
/// started or not (it could crash on startup).
/// </summary>
internal static bool TryCreateServer(string clientDirectory, string pipeName, ICompilerServerLogger logger)
internal static bool TryCreateServer(string clientDirectory, string pipeName, ICompilerServerLogger logger, out int processId)
{
processId = 0;
var serverInfo = GetServerProcessInfo(clientDirectory, pipeName);

if (!File.Exists(serverInfo.toolFilePath))
Expand Down Expand Up @@ -492,6 +493,7 @@ internal static bool TryCreateServer(string clientDirectory, string pipeName, IC
logger.Log("Successfully created process with process id {0}", processInfo.dwProcessId);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
processId = processInfo.dwProcessId;
}
else
{
Expand All @@ -515,8 +517,15 @@ internal static bool TryCreateServer(string clientDirectory, string pipeName, IC
CreateNoWindow = true
};

Process.Start(startInfo);
return true;
if (Process.Start(startInfo) is { } process)
{
processId = process.Id;
return true;
}
else
{
return false;
}
}
catch
{
Expand Down
21 changes: 17 additions & 4 deletions src/Tools/Replay/Replay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ static ReplayOptions ParseOptions(string[] args)
string? outputDirectory = null;
string? binlogPath = null;
int maxParallel = 6;
bool wait = false;

var options = new Mono.Options.OptionSet()
{
{ "b|binlogPath=", "The binary log to relpay", v => binlogPath = v },
{ "o|outputDirectory=", "The directory to output the build results", v => outputDirectory = v },
{ "m|maxParallel=", "The maximum number of parallel builds", (int v) => maxParallel = v },
{ "w|wait", "Wait for a key press after starting the server", o => wait = o is object },
};

var rest = options.Parse(args);
Expand All @@ -44,7 +46,7 @@ static ReplayOptions ParseOptions(string[] args)
}
else if (rest.Count > 1)
{
throw new Exception("Too many arguments");
throw new Exception($"Too many arguments: {string.Join(" ", rest)}");
}

if (string.IsNullOrEmpty(binlogPath))
Expand All @@ -62,7 +64,8 @@ static ReplayOptions ParseOptions(string[] args)
clientDirectory: AppDomain.CurrentDomain.BaseDirectory!,
outputDirectory: outputDirectory,
binlogPath: binlogPath,
maxParallel: maxParallel);
maxParallel: maxParallel,
wait: wait);
}

static async Task<int> RunAsync(ReplayOptions options)
Expand All @@ -76,12 +79,20 @@ static async Task<int> RunAsync(ReplayOptions options)
Console.WriteLine("Starting server");

using var compilerServerLogger = new CompilerServerLogger("replay", Path.Combine(options.OutputDirectory, "server.log"));
if (!BuildServerConnection.TryCreateServer(options.ClientDirectory, options.PipeName, compilerServerLogger))
if (!BuildServerConnection.TryCreateServer(options.ClientDirectory, options.PipeName, compilerServerLogger, out int serverProcessId))
{
Console.WriteLine("Failed to start server");
return 1;
}

Console.WriteLine($"Process Id: {serverProcessId}");
if (options.Wait)
{
Console.WriteLine("Press any key to continue");
Console.ReadKey(intercept: true);
Console.WriteLine("Continuing");
}

try
{
var compilerCalls = ReadAllCompilerCalls(options.BinlogPath);
Expand Down Expand Up @@ -257,14 +268,16 @@ internal sealed class ReplayOptions(
string clientDirectory,
string outputDirectory,
string binlogPath,
int maxParallel)
int maxParallel,
bool wait)
{
internal string PipeName { get; } = pipeName;
internal string ClientDirectory { get; } = clientDirectory;
internal string OutputDirectory { get; } = outputDirectory;
internal string BinlogPath { get; } = binlogPath;
internal int MaxParallel { get; } = maxParallel;
internal string TempDirectory { get; } = Path.Combine(outputDirectory, "temp");
internal bool Wait { get; } = wait;
}

internal readonly struct BuildData(CompilerCall compilerCall, BuildResponse response)
Expand Down

0 comments on commit 8e7e236

Please sign in to comment.