private string GetOutputPath(string filePath, BatchCompileConfiguration compileConfiguration) { foreach (var pathMap in compileConfiguration.Paths) { if (filePath.IndexOf(pathMap.SourcePath, StringComparison.OrdinalIgnoreCase) >= 0) { // If the configured sourcePath is a full file path we just assume the fileName is the relative name // Otherwise we calculate the relative path from the configured sourcePath to the current file var relativePath = pathMap.SourcePathIsFile ? Path.GetFileName(pathMap.SourcePath) : FileProbe.GetRelativePath(pathMap.SourcePath, filePath); string outputPath = pathMap.OutputPath; if (!pathMap.OutputPathIsFile) { // If output path is not a file we calculate the file path using the input filePath's relative location compared // to the output directory outputPath = Path.Combine(outputPath, relativePath); outputPath = Path.ChangeExtension(outputPath, ".js"); } return(outputPath); } } ChutzpahTracer.TraceError("Can't find location for generated path on {0}", filePath); return(null); }
private string GetOutputPath(string sourcePath, BatchCompileConfiguration compileConfiguration) { if (sourcePath.IndexOf(compileConfiguration.SourceDirectory, StringComparison.OrdinalIgnoreCase) >= 0) { var relativePath = FileProbe.GetRelativePath(compileConfiguration.SourceDirectory, sourcePath); var outputPath = Path.Combine(compileConfiguration.OutDirectory, relativePath); outputPath = Path.ChangeExtension(outputPath, ".js"); return(outputPath); } else { ChutzpahTracer.TraceWarning( "Can't find location for generated path on {0} since it is not inside of configured source dir {1}", sourcePath, compileConfiguration.SourceDirectory); } return(null); }
public BatchCompileResult RunBatchCompileProcess(BatchCompileConfiguration compileConfiguration) { ChutzpahTracer.TraceInformation("Started batch compile using {0} with args {1}", compileConfiguration.Executable, compileConfiguration.Arguments); var timeout = compileConfiguration.Timeout.Value; var p = new Process(); // Append path to where .net drop is so you can use things like msbuild p.StartInfo.EnvironmentVariables["Path"] += ";" + System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + ";"; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.UseShellExecute = false; p.StartInfo.FileName = compileConfiguration.Executable; p.StartInfo.Arguments = compileConfiguration.Arguments; p.StartInfo.WorkingDirectory = compileConfiguration.WorkingDirectory; p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; var output = new StringBuilder(); var error = new StringBuilder(); // Ensure we read both input/output fully and don't get into a deadlock using (var outputWaitHandle = new AutoResetEvent(false)) using (var errorWaitHandle = new AutoResetEvent(false)) { p.OutputDataReceived += (sender, e) => { if (e.Data == null) { outputWaitHandle.Set(); } else { output.AppendLine(e.Data); } }; p.ErrorDataReceived += (sender, e) => { if (e.Data == null) { errorWaitHandle.Set(); } else { error.AppendLine(e.Data); } }; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); if (p.WaitForExit(timeout) && outputWaitHandle.WaitOne(timeout) && errorWaitHandle.WaitOne(timeout)) { ChutzpahTracer.TraceInformation("Finished batch compile with exit code {0} using {1} with args {2}", p.ExitCode, compileConfiguration.Executable, compileConfiguration.Arguments); } else { ChutzpahTracer.TraceInformation("Finished batch compile on a timeout with exit code {0} using {1} with args {2}", p.ExitCode, compileConfiguration.Executable, compileConfiguration.Arguments); } return(new BatchCompileResult { StandardError = error.ToString(), StandardOutput = output.ToString(), ExitCode = p.ExitCode }); } }