Skip to content

Commit

Permalink
Support for TreatWarningsAsErrors, SuperClass, ContextSuperClass opti…
Browse files Browse the repository at this point in the history
…ons in build task, fixes tunnelvisionlabs#278
  • Loading branch information
KvanTTT committed May 13, 2019
1 parent 4874e01 commit 20141d5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
10 changes: 8 additions & 2 deletions runtime/CSharp/Antlr4BuildTasks/Antlr4.CodeGenerator.targets
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<Visitor>true</Visitor>
<Abstract>false</Abstract>
<ForceAtn>false</ForceAtn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<SuperClass></SuperClass>
<ContextSuperClass></ContextSuperClass>
</Antlr4>
</ItemDefinitionGroup>

Expand Down Expand Up @@ -149,7 +152,10 @@
GenerateVisitor="%(Antlr4.Visitor)"
ForceAtn="%(Antlr4.ForceAtn)"
AbstractGrammar="%(Antlr4.Abstract)"
UseCSharpGenerator="$(Antlr4UseCSharpGenerator)">
UseCSharpGenerator="$(Antlr4UseCSharpGenerator)"
TreatWarningsAsErrors="%(Antlr4.TreatWarningsAsErrors)"
SuperClass="%(Antlr4.SuperClass)"
ContextSuperClass="%(Antlr4.ContextSuperClass)">

<Output ItemName="Antlr4GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />
</Antlr4ClassGenerationTask>
Expand Down Expand Up @@ -196,7 +202,7 @@
</Choose>

<Import Condition="'$(Antlr4IsSdkProject)' == 'True'" Project="Antlr4.CodeGenerator.DefaultItems.targets" />

<!-- Support for NCrunch -->
<ItemGroup Condition="'$(NCrunch)' == '1'">
<!-- NCrunch tries to copy the fewest possible files to its build directory, those it misses are declared here. -->
Expand Down
21 changes: 21 additions & 0 deletions runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ public bool UseCSharpGenerator
set;
}

public bool TreatWarningsAsErrors
{
get;
set;
}

public string SuperClass
{
get;
set;
}

public string ContextSuperClass
{
get;
set;
}

[Output]
public ITaskItem[] GeneratedCodeFiles
{
Expand Down Expand Up @@ -306,6 +324,9 @@ private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper()
wrapper.JavaInstallation = JavaInstallation;
wrapper.JavaExecutable = JavaExecutable;
wrapper.UseCSharpGenerator = UseCSharpGenerator;
wrapper.TreatWarningsAsErrors = TreatWarningsAsErrors;
wrapper.SuperClass = SuperClass;
wrapper.ContextSuperClass = ContextSuperClass;
return wrapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ public bool UseCSharpGenerator
set;
}

public bool TreatWarningsAsErrors
{
get;
set;
}

public string SuperClass
{
get;
set;
}

public string ContextSuperClass
{
get;
set;
}

public IList<string> SourceCodeFiles
{
get
Expand Down Expand Up @@ -282,6 +300,21 @@ public bool Execute()
arguments.Add(TargetNamespace);
}

if (TreatWarningsAsErrors)
arguments.Add("-Werror");

if (!string.IsNullOrEmpty(SuperClass))
{
arguments.Add("-DsuperClass");
arguments.Add(SuperClass);
}

if (!string.IsNullOrEmpty(ContextSuperClass))
{
arguments.Add("-DcontextSuperClass");
arguments.Add(ContextSuperClass);
}

arguments.AddRange(SourceCodeFiles);

#if NETSTANDARD
Expand Down

0 comments on commit 20141d5

Please sign in to comment.