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

Create jflex rule for bazel #401

Merged
merged 27 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
93db66f
Simplify .gitignore for examples
regisd Sep 30, 2018
99cb550
Kickstart Bazel
regisd Sep 30, 2018
d864166
Rename ant build direcorty to "formica".
regisd Sep 30, 2018
2c1e7ab
Fix BUILD rules for project "simple"
regisd Sep 30, 2018
7fd8b1a
Update README for simple Bazzel usage
regisd Sep 30, 2018
84a8d1c
Rename ant build directory to antbuild
regisd Sep 30, 2018
5cc8510
Merge branch 'master' into examples-bazel
regisd Oct 1, 2018
fb80c6e
Keep building JFlex in `build` dir
regisd Oct 1, 2018
6f5f060
Add BUILD for example "simple"
regisd Oct 1, 2018
aa34be4
Add simple/BUILD
regisd Oct 1, 2018
54f01e0
Remove old maven site
regisd Oct 1, 2018
7cea7f1
Update all titles in README
regisd Oct 1, 2018
de9826b
Very detailed README )merging all doc from site/apt)
regisd Oct 1, 2018
2eaa179
Fix BUILD
regisd Oct 1, 2018
d2f4a49
Add test deps
regisd Oct 1, 2018
a3d88a7
Use bazel migration tool to import all deps.
regisd Oct 1, 2018
5cb1817
Fix missing dep on guava
regisd Oct 1, 2018
0722ceb
Move test data in test/data
regisd Oct 1, 2018
96dbbb6
Hack to load src/test/data
regisd Oct 1, 2018
60ff120
Improve class structure
regisd Oct 1, 2018
6bcf05c
Disable test
regisd Oct 1, 2018
b6d0126
reformat BUILD files
regisd Oct 1, 2018
fec8337
Minor doc
regisd Oct 1, 2018
b355691
Cache the bazel output dir
regisd Oct 1, 2018
5cddb87
Shutdown the server in the script rather than in yml
regisd Oct 1, 2018
90b1270
Also cache the fetched repository items
regisd Oct 1, 2018
aba4a04
Fix syntax error in script
regisd Oct 1, 2018
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
**/target
dependency-reduced-pom.xml
bazel-*
# Generated by ant
jflex/build

# IntelliJ
*.iml
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ matrix:
- java -version
- sudo apt-get install ./tools/bazel-0.16.1.deb
sudo: true
after_success: blaze shutdown

# Empty the previously built artifacts
# They cannot be deleted in the before_cache phase,
Expand All @@ -75,6 +74,11 @@ cache:
timeout: 86400 # 24 hours
directories:
- $HOME/.m2
# All our Bazel build artifacts
- $HOME/__bazel_output_base__/
# Items fetched from repositories
- $HOME/__bazel_travis_root__/cache
# DO NOT cache __bazel_output_travis__/install
- jflex/lib
- tools

Expand Down
1 change: 1 addition & 0 deletions jflex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions jflex/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<property name="junit.jar.path" value="junit/junit/${junit.version}/junit-${junit.version}.jar" />

<!-- where build output goes, including the jflex jar -->
<!-- TODO(#304): Rename `build` directory to something else as Bazel uses `BUILD` files. -->
<property name="build.dir" value="build"/>
<property name="generated.sources.dir" value="${build.dir}/generated-sources"/>
<property name="compile.output.dir" value="${build.dir}/classes"/>
Expand Down
20 changes: 11 additions & 9 deletions jflex/examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
# So here is a test:

sh_test(
name = "hello_test",
size = "small",
srcs = [":hello_test_lib"],
name = "hello_test",
size = "small",
srcs = [":hello_test_lib"],
)

sh_library(
name = "hello_test_lib",
srcs = [":gen_hello_test_sh"],
name = "hello_test_lib",
srcs = [":gen_hello_test_sh"],
)

genrule(
name = "gen_hello_test_sh",
srcs = [],
outs = ["hello_test.sh"],
cmd = "echo 'echo \"Hello World\"' > $@",
name = "gen_hello_test_sh",
srcs = [],
outs = ["hello_test.sh"],
cmd = "echo 'echo \"Hello World\"' > $@",
)
26 changes: 22 additions & 4 deletions jflex/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Every example also provides its own `README.md` with more context.
All examples (try to) support multiple build systems:
- [Maven](https://maven.apache.org/).
- [ant](https://ant.apache.org/).
- [make](https://www.gnu.org/software/make). We place build artifacts in `out`.
- [bazel](https://bazel.build/).
- [make](https://www.gnu.org/software/make).

All examples follow the Maven layout, in particular:
- `src` contains the source files
Expand Down Expand Up @@ -56,7 +57,7 @@ In the end run the compiled lexer with:

When the example can be build with Maven, there is a `build.xml`.

We place build artifacts in the `build` directory.
We place build artifacts in the `antbuild` directory.

Also, we consistently use:
- `ant` _default action_ for **compile**
Expand All @@ -65,10 +66,27 @@ Also, we consistently use:
- `ant run` to run the lexer on a sample input
- `ant test` to run the lexer on the sample input and check it produces
the expected output.


### Bazel

When the example can be build with Bazel, there is a `BUILD` file.

Bazel places artifacts in `bazel-*` in the root `examples` directory
(because it is the workspace).

- `bazel build <targets>` generates the sources and compile for the given targets
- `bazel run <target>` runs the given target
- `bazel test <targets>` tests the given targets

You can build all examples from here with

bazel build //...

See also [third_party/de/jflex/README.md].

### GNU make

When the example can be build with Maven, there is a `Makefile`.
When the example can be build with make, there is a `Makefile`.

We place build artifacts in the `out` directory.

Expand Down
18 changes: 18 additions & 0 deletions jflex/examples/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# Workspace file for the Bazel build system
# https://bazel.build/

# JFlex doesn't use Bazel itself, but some examples do.
# This WORKSPACE is only to illustrate usage of Bazel on the examples.
# In a real usage, the WORKSPACE file is at the root of the workspace.
# https://docs.bazel.build/versions/master/build-ref.html#workspace

# TODO(#390) Add maven 1.7.0 when cup_runtime is published
# de.jflex:jflex-maven-plugin:maven-plugin:1.6.1
maven_jar(
name = "de_jflex_jflex_1_6_1",
artifact = "de.jflex:jflex:1.6.1",
repository = "https://jcenter.bintray.com/",
sha1 = "eb4d51e1a8ea7ee96068905ddeceb9b28737c7eb",
)

load("//third_party:generate_workspace.bzl", "generated_maven_jars")
generated_maven_jars()
4 changes: 3 additions & 1 deletion jflex/examples/byaccj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ JFlex with Yacc
This directory contains an interoperability example for [BYacc/J][byaccj] and JFlex.
This example implements a small calculator.

## Build with Make
## Build, run, test

### Build with Make

Use the Makefile to generate the lexer and parser.

Expand Down
8 changes: 5 additions & 3 deletions jflex/examples/cup-interpreter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ FJlex complex example (with CUP)
This directory contains an interpreter for a small functional
programming language (called "AS"). It uses JFlex and CUP.

## Build with maven
## Build, run, test

### Using Maven

../../../mvnw package

Expand All @@ -14,12 +16,12 @@ To run the interpreter on a sample input.

You can expect `src/test/data/output.good`.

## Build with ant
### Using ant

ant compile
ant run

## Build with make
### Using make

make test
java -cp java -cp ../../../cup/cup/java-cup-11b.jar:out src/test/data/example.as
Expand Down
12 changes: 6 additions & 6 deletions jflex/examples/cup-interpreter/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<java classname="Main">
<classpath>
<pathelement location="${java_cup}"/>
<pathelement path="build"/>
<pathelement path="antbuild"/>
</classpath>
<arg line="src/test/data/example.as"/> </java>
</target>
Expand All @@ -22,21 +22,21 @@
</target>

<target name="compile" depends="jflex,cup">
<javac destdir="build" classpath="${java_cup}">
<javac destdir="antbuild" classpath="${java_cup}">
<src path="src/main/java/" />
<src path="build/"/>
<src path="antbuild/"/>
</javac>
</target>

<target name="jflex">
<jflex file="src/main/jflex/scanner.flex" destdir="build" encoding="utf-8"/>
<jflex file="src/main/jflex/scanner.flex" destdir="antbuild" encoding="utf-8"/>
</target>

<target name="cup">
<cup srcfile="src/main/cup/parser.cup" interface="yes" destdir="build"/>
<cup srcfile="src/main/cup/parser.cup" interface="yes" destdir="antbuild"/>
</target>

<target name="clean">
<delete dir="build"/>
<delete dir="antbuild"/>
</target>
</project>
8 changes: 5 additions & 3 deletions jflex/examples/cup-java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ JFlex: Complex example (with CUP)

This directory contains a scanner and parser for the Java programming language (Java 1.2).

## Build with maven
## Build, run, test

### Using Maven

../../mvnw package

Expand All @@ -16,13 +18,13 @@ or more simply the uberjar version:
java -jar target/cup-java-full-1.0.jar <inputfile>


## Build with ant
### Using ant

ant compile
ant run
java -jar build:../../../cup/cup/java-cup-11b.jar JavaParser <inputfiles>

## Build with make
### Using make

Use the Makefile or Ant (via 'ant run') to generate the lexer and
parser, or type:
Expand Down
14 changes: 7 additions & 7 deletions jflex/examples/cup-java/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<target name="build" depends="clean,compile" />

<target name="run" depends="compile">
<java classname="JavaParser" classpath="build:${java_cup}">
<java classname="JavaParser" classpath="antbuild:${java_cup}">
<arg line="src/main/java/TestLexer.java"/>
</java>
</target>
Expand All @@ -19,25 +19,25 @@
</target>

<target name="compile" depends="cup,scanner,unicode">
<javac destdir="build" classpath="${java_cup}">
<javac destdir="antbuild" classpath="${java_cup}">
<src path="src/main/java/" />
<src path="build/"/>
<src path="antbuild/"/>
</javac>
</target>

<target name="cup">
<cup srcfile="src/main/cup/java12.cup" interface="yes" destdir="build"/>
<cup srcfile="src/main/cup/java12.cup" interface="yes" destdir="antbuild"/>
</target>

<target name="scanner">
<jflex file="src/main/jflex/java.flex" destdir="build"/>
<jflex file="src/main/jflex/java.flex" destdir="antbuild"/>
</target>

<target name="unicode">
<jflex file="src/main/jflex/unicode.flex" destdir="build"/>
<jflex file="src/main/jflex/unicode.flex" destdir="antbuild"/>
</target>

<target name="clean">
<delete dir="build"/>
<delete dir="antbuild"/>
</target>
</project>
9 changes: 5 additions & 4 deletions jflex/examples/cup-lcalc/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
JFlex with cup
==============
#JFlex with cup

This directory contains a small example of integration
between JFlex and [CUP][cup].
Expand All @@ -10,7 +9,9 @@ titled _Compiler Construction Tools_.

Small changes and updates to newest JFlex+Cup versions by Gerwin Klein.

## Build and run
## Build, run, test

### Using Maven

To compile:

Expand All @@ -28,7 +29,7 @@ mvn package
java -jar target/simple-maven-full-1.0.jar Main test.txt
```

## Files:
## Files

* `src/main/java/Main.java` demo of a main program
* `src/main/flex/lcalc.flex` the lexer spec
Expand Down
40 changes: 40 additions & 0 deletions jflex/examples/simple/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load("//third_party/de/jflex:build_rules.bzl", "jflex")

# The best practice is to define the rules in their respective directory in
# - src/main/java/org/example/foo/BUILD
# - src/main/jflex/BUILD
# - src/test/java/org/example/foo/BUILD
# - etc.
# However, this example is simple enough and we can define all rules here.

java_binary(
name = "simple_bin",
main_class = "Yylex",
runtime_deps = [":simple"],
)

java_library(
name = "simple",
# glob is not a best practice, but it's good enough for this example
srcs = glob(["src/main/java/**/*.java"]) + [":gen_lexer"],
)

jflex(
name = "gen_lexer",
srcs = ["src/main/jflex/simple.flex"],
outputs = ["Yylex.java"],
)

# Test disabled because Bazel uses JFlex 1.6.1
# And the dump has changed (i.e. the golden file is not coorect)
# TODO(#390) Use JFlex 1.7.0 and re-enabled the test when java_cup has been published on mvn repo
#java_test(
# name = "YylexTest",
# srcs = ["src/test/java/YylexTest.java"],
# data = glob(["src/test/data/**"]),
# deps = [
# ":simple",
# "//third_party/com/google/truth",
# "//third_party/com/google/guava"
# ],
#)
Loading