Skip to content

Commit 98b5125

Browse files
authored
Merge pull request #233 from sharwell/fix-codegen-test
Fix the testing of the Antlr4UseCSharpGenerator property
2 parents 3fd4fe8 + b19d8c0 commit 98b5125

19 files changed

+123
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ obj/
2424
reference/.metadata/
2525
reference/reference.net/
2626
/runtime/CSharp/packages/
27+
/build/DotnetValidation*/packages/
2728

2829
# ignore Java (Maven) build directory
2930
tool/target/

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ init:
55
- git config --global core.autocrlf true
66
build_script:
77
- cd build
8-
- powershell -Command .\build.ps1 -VisualStudioVersion "15.0" -Verbosity minimal -GenerateTests -MavenRepo C:\MavenRepo -Logger "${env:ProgramFiles}\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" -Java6Home "${env:ProgramFiles}\Java\jdk1.7.0\jre" -Validate
8+
- powershell -Command .\build.ps1 -VisualStudioVersion "15.0" -GenerateTests -MavenRepo C:\MavenRepo -Logger "${env:ProgramFiles}\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" -Java6Home "${env:ProgramFiles}\Java\jdk1.7.0\jre"
99
- cd ..
1010
test_script:
1111
- vstest.console /logger:Appveyor /TestCaseFilter:"TestCategory=runtime-suite" "C:\projects\antlr4cs\runtime\CSharp\Antlr4.Runtime.Test\bin\%CONFIGURATION%\net45\Antlr4.Runtime.Test.dll"

build/DotnetValidation/DotnetValidation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net20;net30;net35;net35-cf;net40;net45;netcoreapp1.1;portable40-net40+sl5+win8+wp8+wpa81</TargetFrameworks>
66
<EnableDefaultNoneItems>False</EnableDefaultNoneItems>
7-
<UseCSharpGenerator>True</UseCSharpGenerator>
7+
<Antlr4UseCSharpGenerator>True</Antlr4UseCSharpGenerator>
88
</PropertyGroup>
99

1010
<Choose>

build/DotnetValidation/NuGet.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3+
<config>
4+
<add key="globalPackagesFolder" value="packages" />
5+
</config>
36
<packageSources>
47
<add key="Local Build" value="..\nuget" />
58
</packageSources>

build/DotnetValidationOld/DotnetValidation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net20;net30;net35;net35-cf;net40;net45;netcoreapp1.1;portable40-net40+sl5+win8+wp8+wpa81</TargetFrameworks>
66
<EnableDefaultNoneItems>False</EnableDefaultNoneItems>
7-
<UseCSharpGenerator>False</UseCSharpGenerator>
7+
<Antlr4UseCSharpGenerator>False</Antlr4UseCSharpGenerator>
88
</PropertyGroup>
99

1010
<Choose>

build/DotnetValidationOld/NuGet.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3+
<config>
4+
<add key="globalPackagesFolder" value="packages" />
5+
</config>
36
<packageSources>
47
<add key="Local Build" value="..\nuget" />
58
</packageSources>

build/build.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ param (
22
[switch]$Debug,
33
[string]$VisualStudioVersion = "15.0",
44
[switch]$NoClean,
5-
[string]$Verbosity = "normal",
5+
[string]$Verbosity = "minimal",
66
[string]$Logger,
77
[string]$Java6Home,
88
[string]$MavenHome,
99
[string]$MavenRepo,
1010
[switch]$SkipMaven,
1111
[switch]$SkipKeyCheck,
1212
[switch]$GenerateTests,
13-
[switch]$Validate
13+
[switch]$NoValidate
1414
)
1515

1616
# build the solutions
@@ -183,7 +183,7 @@ ForEach ($package in $packages) {
183183
}
184184

185185
# Validate code generation using the Java code generator
186-
If ($Validate) {
186+
If (-not $NoValidate) {
187187
git 'clean' '-dxf' 'DotnetValidationOld'
188188
dotnet 'run' '--project' '.\DotnetValidationOld\DotnetValidation.csproj' '--framework' 'netcoreapp1.1'
189189
if (-not $?) {
@@ -192,7 +192,7 @@ If ($Validate) {
192192
}
193193

194194
git 'clean' '-dxf' 'DotnetValidationOld'
195-
nuget 'restore' 'DotnetValidationOld'
195+
&$nuget 'restore' 'DotnetValidationOld'
196196
&$msbuild '/nologo' '/m' '/nr:false' '/t:Rebuild' $LoggerArgument "/verbosity:$Verbosity" "/p:Configuration=$BuildConfig" '.\DotnetValidationOld\DotnetValidation.sln'
197197
if (-not $?) {
198198
$host.ui.WriteErrorLine('Build failed, aborting!')
@@ -237,7 +237,7 @@ If ($Validate) {
237237
}
238238

239239
# Validate code generation using the C# code generator
240-
If ($Validate) {
240+
If (-not $NoValidate) {
241241
git 'clean' '-dxf' 'DotnetValidation'
242242
dotnet 'run' '--project' '.\DotnetValidation\DotnetValidation.csproj' '--framework' 'netcoreapp1.1'
243243
if (-not $?) {
@@ -246,7 +246,7 @@ If ($Validate) {
246246
}
247247

248248
git 'clean' '-dxf' 'DotnetValidation'
249-
nuget 'restore' 'DotnetValidation'
249+
&$nuget 'restore' 'DotnetValidation'
250250
&$msbuild '/nologo' '/m' '/nr:false' '/t:Rebuild' $LoggerArgument "/verbosity:$Verbosity" "/p:Configuration=$BuildConfig" '.\DotnetValidation\DotnetValidation.sln'
251251
if (-not $?) {
252252
$host.ui.WriteErrorLine('Build failed, aborting!')

runtime/CSharp/Antlr4.Tool/Analysis/LeftRecursiveRuleAnalyzer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Antlr4.Analysis
2323
using NotNullAttribute = Antlr4.Runtime.Misc.NotNullAttribute;
2424
using Path = System.IO.Path;
2525
using Tuple = System.Tuple;
26+
using Uri = System.Uri;
2627

2728
/** Using a tree walker on the rules, determine if a rule is directly left-recursive and if it follows
2829
* our pattern.
@@ -76,11 +77,11 @@ public LeftRecursiveRuleAnalyzer(GrammarAST ruleAST,
7677

7778
public virtual void LoadPrecRuleTemplates()
7879
{
80+
string codeBaseLocation = new Uri(typeof(AntlrTool).GetTypeInfo().Assembly.CodeBase).LocalPath;
81+
string baseDirectory = Path.GetDirectoryName(codeBaseLocation);
7982
string templateGroupFile = Path.Combine("Tool", "Templates", "LeftRecursiveRules.stg");
8083
recRuleTemplates = new TemplateGroupFile(
81-
Path.Combine(
82-
Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
83-
templateGroupFile),
84+
Path.Combine(baseDirectory, templateGroupFile),
8485
Encoding.UTF8);
8586
if (!recRuleTemplates.IsDefined("recRule"))
8687
{

runtime/CSharp/Antlr4.Tool/AntlrTool.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Antlr4
1717
using Antlr4.Tool.Ast;
1818
using ANTLRStringStream = Antlr.Runtime.ANTLRStringStream;
1919
using CommonTokenStream = Antlr.Runtime.CommonTokenStream;
20+
using Console = System.Console;
2021
using StreamWriter = System.IO.StreamWriter;
2122
using Directory = System.IO.Directory;
2223
using Exception = System.Exception;
@@ -853,6 +854,7 @@ public virtual TextWriter GetOutputFileWriter(Grammar g, string fileName)
853854
// for subdir/T.g4, you get subdir here. Well, depends on -o etc...
854855
string outputDir = GetOutputDirectory(g.fileName);
855856
string outputFile = Path.Combine(outputDir, fileName);
857+
Console.WriteLine($"Generating file '{Path.GetFullPath(outputFile)}' for grammar '{g.fileName}'");
856858

857859
Directory.CreateDirectory(outputDir);
858860

runtime/CSharp/Antlr4.Tool/Codegen/Target.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Antlr4.Codegen
1616
using Path = System.IO.Path;
1717
using TemplateMessage = Antlr4.StringTemplate.Misc.TemplateMessage;
1818
using TokenConstants = Antlr4.Runtime.TokenConstants;
19+
using Uri = System.Uri;
1920

2021
/** */
2122
public abstract class AbstractTarget
@@ -397,9 +398,11 @@ public virtual bool GrammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode)
397398
[return: NotNull]
398399
protected virtual TemplateGroup LoadTemplates()
399400
{
401+
string codeBaseLocation = new Uri(typeof(AntlrTool).GetTypeInfo().Assembly.CodeBase).LocalPath;
402+
string baseDirectory = Path.GetDirectoryName(codeBaseLocation);
400403
TemplateGroup result = new TemplateGroupFile(
401404
Path.Combine(
402-
Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
405+
baseDirectory,
403406
Path.Combine(CodeGenerator.TEMPLATE_ROOT, GetLanguage(), GetLanguage() + TemplateGroup.GroupFileExtension)),
404407
Encoding.UTF8);
405408
result.RegisterRenderer(typeof(int), new NumberRenderer());

0 commit comments

Comments
 (0)