|
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.IO; |
5 | 5 | using System.Linq; |
| 6 | +using System.Text; |
6 | 7 | using System.Threading.Tasks; |
7 | 8 | using System.Windows; |
8 | 9 | using System.Windows.Media; |
| 10 | +using Newtonsoft.Json; |
9 | 11 |
|
10 | 12 | namespace StructLayout |
11 | 13 | { |
@@ -562,17 +564,42 @@ public async Task<ParseResult> ParseClangAsync(ProjectProperties projProperties, |
562 | 564 |
|
563 | 565 | string clangCmd = language + archStr + standard + flags + defines + includes + forceInc + workDir + extra; |
564 | 566 |
|
565 | | - string outputPath = OutputDirectory + @"tempResult.slbin"; |
566 | | - string contextCmd = AdjustPath(location.Filename) + " -r=" + location.Line + " -c=" + location.Column + " -o=" + AdjustPath(outputPath); |
| 567 | + string outputPath = Path.Combine(OutputDirectory, "tempResult.slbin"); |
| 568 | + |
| 569 | + string compileCommandsDir = Path.Combine(OutputDirectory, "compile_commands"); |
| 570 | + errorStr = CreateDirectory(compileCommandsDir); |
| 571 | + if (errorStr != null) |
| 572 | + { |
| 573 | + return new ParseResult { Status = ParseResult.StatusCode.InvalidOutputDir, ParserLog = errorStr }; |
| 574 | + } |
| 575 | + |
| 576 | + string compileCommandsFilePath = Path.Combine(compileCommandsDir, "compile_commands.json"); |
| 577 | + using (StreamWriter compileCommandsFile = File.CreateText(compileCommandsFilePath)) |
| 578 | + using (JsonTextWriter writer = new JsonTextWriter(compileCommandsFile)) |
| 579 | + { |
| 580 | + writer.Formatting = Formatting.Indented; |
| 581 | + writer.WriteStartArray(); |
| 582 | + writer.WriteStartObject(); |
| 583 | + if (projProperties.WorkingDirectory != null) |
| 584 | + { |
| 585 | + writer.WritePropertyName("directory"); |
| 586 | + writer.WriteValue(projProperties.WorkingDirectory); |
| 587 | + } |
| 588 | + writer.WritePropertyName("command"); |
| 589 | + writer.WriteValue($"clang {clangCmd} {AdjustPath(location.Filename)}"); |
| 590 | + writer.WritePropertyName("file"); |
| 591 | + writer.WriteValue(location.Filename); |
| 592 | + } |
567 | 593 |
|
568 | | - string toolCmd = contextCmd + " --" + clangCmd; |
| 594 | + string toolCmd = $"-r={location.Line} -c={location.Column} -o={AdjustPath(outputPath)} -p {AdjustPath(compileCommandsDir)} {AdjustPath(location.Filename)}"; |
569 | 595 |
|
570 | 596 | OutputLog.Focus(); |
571 | 597 | OutputLog.Log("Looking for structures at " + location.Filename + ":" + location.Line + ":" + location.Column+"..."); |
572 | 598 |
|
573 | 599 | if (PrintCommandLine) |
574 | 600 | { |
575 | | - OutputLog.Log("CLANG ARGUMENTS: " + clangCmd); |
| 601 | + OutputLog.Log($"TOOL ARGUMENTS: {toolCmd}"); |
| 602 | + OutputLog.Log($"CLANG ARGUMENTS: {clangCmd}"); |
576 | 603 | //OutputLog.Log("GENERATED FILE: " + outputPath); |
577 | 604 | } |
578 | 605 |
|
|
0 commit comments