Skip to content

Commit

Permalink
Add EmbedAllSources build task parameter (#23656)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat authored Jan 4, 2018
1 parent 7ad9a46 commit aa683ac
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/Compilers/Core/MSBuildTask/ManagedCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public ITaskItem[] EmbeddedFiles
get { return (ITaskItem[])_store[nameof(EmbeddedFiles)]; }
}

public bool EmbedAllSources
{
set { _store[nameof(EmbedAllSources)] = value; }
get { return _store.GetOrDefault(nameof(EmbedAllSources), false); }
}

public ITaskItem[] Analyzers
{
set { _store[nameof(Analyzers)] = value; }
Expand Down Expand Up @@ -845,6 +851,11 @@ private void AddAdditionalFilesToCommandLine(CommandLineBuilderExtension command
/// </summary>
private void AddEmbeddedFilesToCommandLine(CommandLineBuilderExtension commandLine)
{
if (EmbedAllSources)
{
commandLine.AppendSwitch("/embed");
}

if (EmbeddedFiles != null)
{
foreach (ITaskItem embeddedFile in EmbeddedFiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
DelaySign="$(DelaySign)"
DisabledWarnings="$(NoWarn)"
DocumentationFile="@(DocFileItem)"
EmbedAllSources="$(EmbedAllSources)"
EmbeddedFiles="@(EmbeddedFiles)"
EmitDebugInformation="$(DebugSymbols)"
EnvironmentVariables="$(CscEnvironment)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
DelaySign="$(DelaySign)"
DisabledWarnings="$(NoWarn)"
DocumentationFile="@(DocFileItem)"
EmbedAllSources="$(EmbedAllSources)"
EmbeddedFiles="@(EmbeddedFiles)"
EmitDebugInformation="$(DebugSymbols)"
EnvironmentVariables="$(VbcEnvironment)"
Expand Down
21 changes: 19 additions & 2 deletions src/Compilers/Core/MSBuildTaskTests/CscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,26 @@ public void Embed()

csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.DebugType = "portable";
csc.DebugType = "full";
csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems();
Assert.Equal(@"/debug:portable /out:test.exe test.cs", csc.GenerateResponseFileContents());
Assert.Equal(@"/debug:full /out:test.exe test.cs", csc.GenerateResponseFileContents());
}

[Fact]
public void EmbedAllSources()
{
var csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"test.cs", @"test.txt");
csc.EmbedAllSources = true;

Assert.Equal(@"/out:test.exe /embed /embed:test.cs /embed:test.txt test.cs", csc.GenerateResponseFileContents());

csc = new Csc();
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
csc.EmbedAllSources = true;

Assert.Equal(@"/out:test.exe /embed test.cs", csc.GenerateResponseFileContents());
}

[Fact]
Expand Down
21 changes: 19 additions & 2 deletions src/Compilers/Core/MSBuildTaskTests/VbcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,26 @@ public void Embed()

vbc = new Vbc();
vbc.Sources = MSBuildUtil.CreateTaskItems("test.vb");
vbc.DebugType = "portable";
vbc.DebugType = "full";
vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems();
Assert.Equal(@"/optionstrict:custom /debug:portable /out:test.exe test.vb", vbc.GenerateResponseFileContents());
Assert.Equal(@"/optionstrict:custom /debug:full /out:test.exe test.vb", vbc.GenerateResponseFileContents());
}

[Fact]
public void EmbedAllSources()
{
var vbc = new Vbc();
vbc.Sources = MSBuildUtil.CreateTaskItems("test.vb");
vbc.EmbeddedFiles = MSBuildUtil.CreateTaskItems(@"test.vb", @"test.txt");
vbc.EmbedAllSources = true;

Assert.Equal(@"/optionstrict:custom /out:test.exe /embed /embed:test.vb /embed:test.txt test.vb", vbc.GenerateResponseFileContents());

vbc = new Vbc();
vbc.Sources = MSBuildUtil.CreateTaskItems("test.vb");
vbc.EmbedAllSources = true;

Assert.Equal(@"/optionstrict:custom /out:test.exe /embed test.vb", vbc.GenerateResponseFileContents());
}

[Fact]
Expand Down

0 comments on commit aa683ac

Please sign in to comment.