Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVS-1668 Include header file language in the VCX command #5861

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,23 +314,21 @@ public void AddOptFromProperties(string input, string output, string cmd)
cmdBuilder.AddOptFromProperties(settingsMock.Object);

cmdBuilder.GetFullCmd().Should().Be(cmd);
cmdBuilder.HeaderFileLang.Should().Be("");
}

[TestMethod]
[DataRow("Default", "cpp")]
[DataRow("CompileAsC", "c")]
[DataRow("CompileAsCpp", "cpp")]
public void HeaderFileLang(string compileAs, string lang)
[DataRow("Default", "")]
[DataRow("CompileAsC", "/TC ")]
[DataRow("CompileAsCpp", "/TP ")]
public void HeaderFileLang(string compileAs, string cmd)
{
var cmdBuilder = new CmdBuilder(true);
var settingsMock = new Mock<IVCRulePropertyStorage>();
settingsMock.Setup(x => x.GetEvaluatedPropertyValue(It.IsAny<string>())).Returns<string>(s => s == "CompileAs" ? compileAs : "");

cmdBuilder.AddOptFromProperties(settingsMock.Object);

cmdBuilder.GetFullCmd().Should().Be("");
cmdBuilder.HeaderFileLang.Should().Be(lang);
cmdBuilder.GetFullCmd().Should().Be(cmd);
}

[TestMethod]
Expand Down Expand Up @@ -391,7 +389,6 @@ public void PCHUse()

cmdBuilder.AddOptFromProperties(settingsMock.Object);
cmdBuilder.GetFullCmd().Should().Be("/Yc\"C:\\pch.h\" ");
cmdBuilder.HeaderFileLang.Should().Be("");
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public void TryGet_Full_Cmd()
// Assert
request.Should().NotBeNull();
Assert.AreEqual("\"C:\\path\\cl.exe\" /permissive- /std:c++17 /EHsc /arch:AVX512 /MT /RTCu /Zp8 /TP /DA \"c:\\dummy\\file.cpp\"", request.CDCommand);
Assert.AreEqual("", request.HeaderFileLanguage);
Assert.AreEqual("C:\\path\\includeDir1;C:\\path\\includeDir2;C:\\path\\includeDir3;", request.EnvInclude);
Assert.AreEqual("c:\\dummy\\file.cpp", request.CDFile);
Assert.AreEqual("c:\\foo", request.CDDirectory);
Expand Down Expand Up @@ -175,7 +174,7 @@ public void TryGet_HeaderFileOptions_ReturnsValidConfig()
// Assert
request.Should().NotBeNull();
Assert.AreEqual("\"C:\\path\\cl.exe\" /Yu\"pch.h\" /FI\"pch.h\" /EHsc /RTCu \"c:\\dummy\\file.h\"", request.CDCommand);
Assert.AreEqual("cpp", request.HeaderFileLanguage);
Assert.AreEqual("c:\\dummy\\file.h", request.CDFile);

// Arrange
projectItemConfig.FileConfigProperties["CompileAs"] = "CompileAsC";
Expand All @@ -185,8 +184,18 @@ public void TryGet_HeaderFileOptions_ReturnsValidConfig()
request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.h");

// Assert
Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu \"c:\\dummy\\file.h\"", request.CDCommand);
Assert.AreEqual("c", request.HeaderFileLanguage);
Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu /TC \"c:\\dummy\\file.h\"", request.CDCommand);
Assert.AreEqual("c:\\dummy\\file.h", request.CDFile);

// Arrange
projectItemConfig.FileConfigProperties["CompileAs"] = "CompileAsCpp";

// Act
request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.h");

// Assert
Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu /TP \"c:\\dummy\\file.h\"", request.CDCommand);
Assert.AreEqual("c:\\dummy\\file.h", request.CDFile);
}

[TestMethod]
Expand Down
10 changes: 1 addition & 9 deletions src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ internal class CmdBuilder

StringBuilder Cmd { get; set; } = new StringBuilder();
bool IsHeader { get; set; }
public string HeaderFileLang { get; set; } = "";

public CmdBuilder(bool isHeader)
{
Expand Down Expand Up @@ -167,14 +166,7 @@ internal void AddOptFromProperties(IVCRulePropertyStorage properties)
AddCmdOpt(ConvertStructMemberAlignment(structMemberAlignment));

var compileAs = properties.GetEvaluatedPropertyValue("CompileAs");
if (IsHeader)
{
HeaderFileLang = (compileAs == "CompileAsC") ? "c" : "cpp";
}
else
{
AddCmdOpt(ConvertCompileAsAndGetLanguage(compileAs));
}
AddCmdOpt(ConvertCompileAsAndGetLanguage(compileAs));

// Additional options
var additionalOptions = properties.GetEvaluatedPropertyValue("AdditionalOptions");
Expand Down
4 changes: 2 additions & 2 deletions src/Integration.Vsix/CFamily/VcxProject/FileConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static FileConfig TryGet(ILogger logger, ProjectItem dteProjectItem, stri
// Not supported
return null;
}

CmdBuilder cmdBuilder = new CmdBuilder(vcFile.ItemType == "ClInclude");

var compilerPath = vcConfig.GetEvaluatedPropertyValue("ClCompilerPath");
Expand Down Expand Up @@ -76,7 +77,6 @@ public static FileConfig TryGet(ILogger logger, ProjectItem dteProjectItem, stri
CDCommand = cmdBuilder.GetFullCmd(),
CDFile = absoluteFilePath,
EnvInclude = envINCLUDE,
HeaderFileLanguage = cmdBuilder.HeaderFileLang,
};
}

Expand Down Expand Up @@ -134,7 +134,7 @@ private static IVCRulePropertyStorage GetVcFileSettings(ILogger logger, string a
public string CDCommand { get; set; }
public string CDFile { get; set; }
public string EnvInclude { get; set; }
public string HeaderFileLanguage { get; set; }

#endregion

}
Expand Down
1 change: 0 additions & 1 deletion src/Integration.Vsix/CFamily/VcxProject/IFileConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ internal interface IFileConfig
string CDCommand { get; }
string CDFile { get; }
string EnvInclude { get; }
string HeaderFileLanguage { get; }
}
}
Loading