Skip to content

Commit

Permalink
Upd
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Dec 13, 2024
1 parent dcbc939 commit 12acac9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/CFamily/CMake/CompilationDatabaseEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public class CompilationDatabaseEntry
[JsonProperty("file")]
public string File { get; set; }

[JsonProperty("arguments")]
public string Arguments { get; set; }

[JsonProperty("environment")]
public IList<string> Environment { get; set; }
}
13 changes: 3 additions & 10 deletions src/CFamily/CompilationDatabase/CompilationDatabaseRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CompilationDatabaseRequest(CompilationDatabaseEntry databaseEntry, Reques
{
}

internal CompilationDatabaseRequest(CompilationDatabaseEntry databaseEntry,
internal CompilationDatabaseRequest(CompilationDatabaseEntry databaseEntry,
RequestContext context, IReadOnlyDictionary<string, string> environmentVariables,
IRulesConfigProtocolFormatter rulesConfigProtocolFormatter)
{
Expand All @@ -52,7 +52,7 @@ internal CompilationDatabaseRequest(CompilationDatabaseEntry databaseEntry,
Context = context ?? throw new ArgumentNullException(nameof(context));

// Must have a Command or Arguments but not both
var hasArgs = !string.IsNullOrEmpty(databaseEntry.Arguments);
var hasArgs = false;
var hasCmd = !string.IsNullOrEmpty(databaseEntry.Command);

if (!hasArgs && !hasCmd || (hasArgs && hasCmd))
Expand All @@ -75,14 +75,7 @@ public void WriteRequest(BinaryWriter writer)
WriteSetting(writer, "File", Context.File);
WriteSetting(writer, "Directory", databaseEntry.Directory);

if(databaseEntry.Arguments == null)
{
WriteSetting(writer, "Command", databaseEntry.Command);
}
else
{
WriteSetting(writer, "Arguments", databaseEntry.Arguments);
}
WriteSetting(writer, "Command", databaseEntry.Command);

WriteRulesConfig(writer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void VerifyDatabaseContents()
var serializedCompilationDatabase = fileSystemService.File.ReceivedCalls().Single().GetArguments()[1] as string;
var compilationDatabaseEntries = JsonConvert.DeserializeObject<CompilationDatabaseEntry[]>(serializedCompilationDatabase);
var compilationDatabaseEntry = compilationDatabaseEntries.Single();
compilationDatabaseEntry.Should().BeEquivalentTo(new CompilationDatabaseEntry { Directory = SourceDirectory, File = SourceFilePath, Command = CompileCommand, Arguments = null, Environment = default}, options => options.Excluding(x => x.Environment));
compilationDatabaseEntry.Should().BeEquivalentTo(new CompilationDatabaseEntry { Directory = SourceDirectory, File = SourceFilePath, Command = CompileCommand, Environment = default}, options => options.Excluding(x => x.Environment));
compilationDatabaseEntry.Environment.Should().Contain([$"{CustomVariableName}={CustomVariableValue}", $"INCLUDE={EnvIncludeValue}"]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ internal interface IVCXCompilationDatabaseStorage : IDisposable
[PartCreationPolicy(CreationPolicy.Shared)]
internal sealed class VCXCompilationDatabaseStorage : IVCXCompilationDatabaseStorage
{
private bool disposed;
private const string IncludeEntryName = "INCLUDE";
private readonly string compilationDatabaseDirectoryPath = PathHelper.GetTempDirForTask(true, "VCXCD");

private readonly ImmutableList<string> environmentVariablePairs;
private readonly ImmutableList<string> staticEnvironmentVariableEntries;
private readonly IFileSystemService fileSystemService;
private readonly IThreadHandling threadHandling;
private readonly ILogger logger;
private bool disposed;

[ImportingConstructor]
public VCXCompilationDatabaseStorage(IFileSystemService fileSystemService, IEnvironmentVariableProvider environmentVariableProvider, IThreadHandling threadHandling, ILogger logger)
{
this.fileSystemService = fileSystemService;
this.threadHandling = threadHandling;
this.logger = logger;
environmentVariablePairs = ImmutableList.CreateRange(environmentVariableProvider.GetAll().Select(x => GetEnvVarPair(x.name, x.value)));
staticEnvironmentVariableEntries = ImmutableList.CreateRange(environmentVariableProvider.GetAll().Select(x => GetFormattedEnvironmentEntry(x.name, x.value)));
}

private static string GetEnvVarPair(string name, string value) => $"{name}={value}";
private static string GetFormattedEnvironmentEntry(string name, string value) => $"{name}={value}";

public ICompilationDatabaseHandle CreateDatabase(IFileConfig fileConfig)
{
Expand All @@ -69,7 +69,7 @@ public ICompilationDatabaseHandle CreateDatabase(IFileConfig fileConfig)
Directory = fileConfig.CDDirectory,
Command = fileConfig.CDCommand,
File = fileConfig.CDFile,
Environment = environmentVariablePairs.Add(GetEnvVarPair("INCLUDE", fileConfig.EnvInclude))
Environment = staticEnvironmentVariableEntries.Insert(0, GetFormattedEnvironmentEntry(IncludeEntryName, fileConfig.EnvInclude))
};
var compilationDatabase = new[] { compilationDatabaseEntry };

Expand Down

0 comments on commit 12acac9

Please sign in to comment.