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

Discrepency between Windows and Linux on generated .ts file location #303

Open
BurtHarris opened this issue Mar 10, 2017 · 6 comments
Open

Comments

@BurtHarris
Copy link
Collaborator

BurtHarris commented Mar 10, 2017

When the Java part of the antlr4ts-cli tool gets invoked with a grammar file specification of benchmark/Java.g4, and -o benchmark/gen/std, the output goes to

  • benchmark/gen/std/./Java.ts on Windows
  • benchmark/gen/std/benchmark/Java.ts on Linux

This discrepancy currently causes later failures on Linux builds as reported in #252 & #283 during the tsc step, because tsc doesn't find the file in the expected location.

Workaround
The problem seems to be related to specifying relative path names on the antlr4ts command line. If your grammar files are in a subdirectory, it may work best to setup a script to run the tool in your package.json something like this:

    "antlr4ts": "cd src/grammar && antlr4ts -visitor Java.g4"

instead of

    "antlr4ts": "antlr4ts -visitor src/grammar/Java.g4"
@BurtHarris
Copy link
Collaborator Author

> antlr4ts -visitor benchmark/Java.g4 -DbaseImportPath=../../../src -o benchmark/gen/std

On Windows the output it looks like this:

Generating file 'C:\projects\antlr4ts\benchmark\gen\std\.\JavaLexer.ts' for grammar 'benchmark/Java.g4'
...

While on Linux:

Generating file '/home/travis/build/BurtHarris/antlr4ts/benchmark/gen/std/benchmark/JavaLexer.ts' for grammar 'benchmark/Java.g4'
...

Here's a link to show what the build output in this area should look like in context: https://ci.appveyor.com/project/sharwell/antlr4ts/build/1.0.473#L1187
vs
https://travis-ci.org/BurtHarris/antlr4ts#L1184

@BurtHarris
Copy link
Collaborator Author

BurtHarris commented Mar 10, 2017

This seems to be related outputDirectory in Tool.java, perhaps code in TypeScriptTool.java near line 82.

@sharwell
Copy link
Member

sharwell commented Apr 7, 2017

The ANTLR tool treats input paths differently if they contain a path separator - but for this check it only uses the default path separator for the current platform. For cases where you have one fixed build command that runs on both Windows and non-Windows systems, you must avoid specifying directory names in the set of input files passed to antlr4ts. See commit 27b9316 for the resolution as applied to this repository.

@BurtHarris
Copy link
Collaborator Author

BurtHarris commented May 14, 2017

I was confused by the title of #307. The fix in that PR is isn't very general, only fixes the problem in this one project. I'm now running into the same problem trying to build Mike's cool looking antlr4-c3. Sam, is it possible to fix the tool to be more platform-neutral? Perhaps Mike's antlr PR above can help.

@BurtHarris
Copy link
Collaborator Author

@sharwell it sounds like this new -Xexact-output-dir option is the key to addressing this issue.

I suspect taking advantage of it will be easy, but I've forgotten how to go about merging in and update from the antlr4/antlr4 repository. Any pointers to details?

@iwatakeshi
Copy link

Hi, I'm having a similar issue on MacOS when trying to build two .g4 files (one being the lexer and the other being the parser). The two files are located in a sub directory src/tom/grammar. When I run the build script antlr4ts -visitor *.g4, npm panics and displays the error:

error(160): TomParser.g4:4:17: cannot find tokens file './TomLexer.tokens'

It seems like antlr4 is looking at the current working directory (or root) instead of the location of the files. However, the workaround mentioned here resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants