private void ProcessHeaderInclude(string value) { // Count depth int depth = 0; while (value[depth] == '.') { depth++; } var filename = value.Substring(depth + 1).Replace("\\\\", "/"); if (!Path.IsPathRooted(filename)) { filename = filename.Substring(9); // HACK TODO : Get correct path } var include = new HeaderInclude() { Filename = filename, }; // Move to matching depth while (_currentIncludes.Count > depth) { _currentIncludes.Pop(); } // Ensure there is a current node if (depth == 0) { throw new InvalidOperationException("Missing root include node."); } // Skip precompiled module files var extension = Path.GetExtension(filename); if (extension != $".{ModuleFileExtension}") { // Add to current _currentIncludes.Peek().Includes.Add(include); } // Set the new include as the current depth _currentIncludes.Push(include); }
private Task <HeaderInclude> CompileAsync(string file, CompileArguments args) { // Set the working directory to the output directory var workingDirectory = Path.Combine(args.RootDirectory, args.OutputDirectory); string compiler = Path.Combine(_toolsPath, @"bin/clang++.exe"); var commandArgs = BuildCompilerArguments(file, args, workingDirectory); Log.Info($"{file}"); Log.Verbose($"PWD={workingDirectory}"); Log.Verbose($"{compiler} {commandArgs}"); // Add a single root element if includes requested if (args.GenerateIncludeTree) { _currentIncludes.Push(new HeaderInclude() { Filename = file, }); } _inWarningMessage = false; _inErrorMessage = false; using (Process process = new Process()) { process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.FileName = compiler; process.StartInfo.WorkingDirectory = workingDirectory; process.StartInfo.Arguments = commandArgs; process.OutputDataReceived += ProcessOutputDataReceived; process.ErrorDataReceived += ProcessErrorDataReceived; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); if (process.ExitCode != 0) { throw new InvalidOperationException(); } HeaderInclude result = null; // Check if requested include headers if (args.GenerateIncludeTree) { // Move up to the root node while (_currentIncludes.Count > 1) { _currentIncludes.Pop(); } if (_currentIncludes.Count != 1) { throw new InvalidOperationException("Expected one root includes node."); } result = _currentIncludes.Pop(); } return(Task.FromResult(result)); } }