Skip to content

Add EmbedAllSources build task parameter #23656

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

Merged
merged 1 commit into from
Jan 4, 2018
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
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)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense doing it this way? For the MSBuild experience, I assume you'd just write:

<ItemGroup>
   <EmbeddedFiles Include="@(Compile)" />
</ItemGroup>

or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler already has /embed command line option. That's much more efficient since we avoid copying all Compile items.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should say EmbedAllSource or EmbedAllSourceFiles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, EmbedAllSourceFiles would be probably somewhat better but F# already uses EmbedAllSources and it's good to be consistent across the board.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(F# could introduce an alternative property, but then that would just add complexity that's not worth it).

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