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

Merge dev branch #9

Merged
merged 11 commits into from
Jan 21, 2020
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
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --javacopt="--release 8"
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist: xenial
dist: bionic

addons:
apt:
Expand All @@ -13,7 +13,9 @@ script:
- cd examples
# build examples as a means of testing
- bazel build --jobs 2 //antlr2/Cpp/... //antlr2/Calc/... //antlr2/Python/... //antlr3/Cpp/... //antlr3/Java/... //antlr3/Python2/... //antlr3/Python3/... //antlr4/Cpp/... //antlr4/Go/... //antlr4/Java/... //antlr4/Python2/... //antlr4/Python3/...
- cd ..
- cd antlr4-opt
- bazel build --jobs 2 //...
- cd ../..
- bazel test --jobs 2 --test_output=errors //...
- bazel shutdown

Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@
# ANTLR Rules for Bazel

These build rules are used for processing [ANTLR](https://www.antlr.org)
grammars with [Bazel](https://bazel.build/). Currently C/C++, Go, Java and Python targets are supported.
grammars with [Bazel](https://bazel.build/).

* [Support Matrix](#matrix)
* [Workspace Setup](#setup)
+ [Details](docs/setup.md#setup)
* [Build Rules](#build-rules)
- [Java Example](#java-example)

<a name="matrix"></a>
## Support Matrix

| | antlr4 | antlr3 | antlr2
|---------|:-------------:|:-------------:|:----:|
| C | | Gen | Gen
| C++ | Gen + Runtime | Gen + Runtime | Gen + Runtime
| Go | Gen + Runtime | |
| Java | Gen + Runtime | Gen + Runtime | Gen + Runtime
| ObjC | | Gen |
| Python2 | Gen + Runtime | Gen + Runtime | Gen + Runtime
| Python3 | Gen + Runtime | Gen + Runtime |

Gen: Code Generation\
Runtime: Runtime Library bundled


<a name="setup"></a>
## Setup

Expand All @@ -25,13 +43,13 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_antlr",
sha256 = "f7c73e1fe3d3b1be3b65172da756a326d12100f6a8d1ef8327498705c0d52efc",
strip_prefix = "rules_antlr-0.4.0",
urls = ["https://github.com/marcohu/rules_antlr/archive/0.4.0.tar.gz"],
sha256 = "",
strip_prefix = "rules_antlr-0.5.0",
urls = ["https://github.com/marcohu/rules_antlr/archive/0.5.0.tar.gz"],
)

load("@rules_antlr//antlr:repositories.bzl", "rules_antlr_dependencies")
rules_antlr_dependencies("4.7.2")
rules_antlr_dependencies("4.8")
```

More detailed instructions can be found in the [Setup](docs/setup.md#setup) document.
Expand Down
23 changes: 13 additions & 10 deletions antlr/impl.bzl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""The common ANTLR rule implementation."""

load(":lang.bzl", "C", "CPP", "GO", "PYTHON", "PYTHON2", "PYTHON3")
load(":lang.bzl", "C", "CPP", "GO", "OBJC", "PYTHON", "PYTHON2", "PYTHON3")

AntlrInfo = provider(
fields = {
"sources": "The generated source files.",
"headers": "For C/C++ the generated header files.",
"data": "Additional ANTLR data files",
"headers": "The generated header files (for C/C++/ObjC).",
"data": "Additional ANTLR data files.",
},
doc = "A provider containing information about ANTLR code generation.",
)
Expand All @@ -31,7 +31,7 @@ def antlr(version, ctx, args):
data = []
sources = []
headers = []
cc = ctx.attr.language == CPP or ctx.attr.language == C
cc = ctx.attr.language == CPP or ctx.attr.language == C or ctx.attr.language == OBJC
output_type = "dir" if ctx.attr.language and ctx.attr.language != "Java" else "srcjar"

if output_type == "srcjar":
Expand Down Expand Up @@ -71,6 +71,7 @@ def antlr(version, ctx, args):
"OUTPUT_DIRECTORY": output_dir,
"PACKAGE_NAME": ctx.attr.package,
"SRC_JAR": srcjar.path if srcjar else "",
"TARGET": ctx.attr.name,
"TARGET_LANGUAGE": ctx.attr.language,
"TOOL_CLASSPATH": ",".join([f.path for f in tool_inputs]),
},
Expand All @@ -89,9 +90,6 @@ def antlr(version, ctx, args):
headers = headers,
data = [ctx.attr.name + ".antlr"],
),
platform_common.TemplateVariableInfo({
"INCLUDES": ctx.attr.name + ".inc/" + ctx.attr.package,
}),
CcInfo(compilation_context = compilation_context) if cc else _NullInfo(),
DefaultInfo(files = depset(outputs)),
]
Expand All @@ -106,10 +104,12 @@ def extension(language):
"""
if language == CPP or language == C:
return ".cc"
if language == PYTHON or language == PYTHON2 or language == PYTHON3:
return ".py"
if language == GO:
return ".go"
if language == OBJC:
return ".objc"
if language == PYTHON or language == PYTHON2 or language == PYTHON3:
return ".py"
return ""

def lib_dir(imports):
Expand All @@ -122,7 +122,10 @@ def lib_dir(imports):
"""
lib = {}
for resource in imports:
lib[resource.path.replace("/" + resource.basename, "")] = None
if resource.path.endswith(".srcjar"):
lib[resource.path] = None
else:
lib[resource.path.replace("/" + resource.basename, "")] = None
count = len(lib)

# the lib directory does not allow nested directories
Expand Down
3 changes: 2 additions & 1 deletion antlr/lang.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CSHARP = "CSharp"
GO = "Go"
JAVA = "Java"
JAVASCRIPT = "JavaScript"
OBJC = "ObjC"
PYTHON = "Python" # synonym for PYTHON3
PYTHON2 = "Python2"
PYTHON3 = "Python3"
Expand All @@ -16,4 +17,4 @@ def supported():
Returns:
the list of supported languages.
"""
return [C, CPP, GO, JAVA, PYTHON, PYTHON2, PYTHON3]
return [C, CPP, GO, JAVA, OBJC, PYTHON, PYTHON2, PYTHON3]
Loading