项目作者: jflex-de

项目描述 :
Bazel rules to generate java files with JFlex
高级语言: Starlark
项目地址: git://github.com/jflex-de/bazel_rules.git
创建时间: 2018-10-09T08:03:12Z
项目社区:https://github.com/jflex-de/bazel_rules

开源协议:Apache License 2.0

下载


Bazel rules for JFlex & Cup

This repository offers two rules for projects using the Bazel build system:

  • Rule to generate java source files from a lexer specification, with JFlex

  • Rule to generate java source files from a parser specification, with CUP

Project health

Status of the master branch:

Build status

Disclaimer

This is not an officially supported Google product.

Prepare your Bazel workspace

Add a dependency on rules_jvm_external

See bazelbuild/rules_jvm_external.

Load the jflex rule

Load the bazel_rules in your WORKSPACE file
and add JFLEX_ARTIFACTS in your maven_install rule:

  1. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
  2. load("@rules_jvm_external//:defs.bzl", "maven_install")
  3. http_archive(
  4. name = "jflex_rules",
  5. sha256 = "c4d68bde12f47af86b6f80a34dd55c67e82cf77b7ff2317cb472c07b1d09a6da",
  6. strip_prefix = "bazel_rules-1.9.1",
  7. url = "https://github.com/jflex-de/bazel_rules/archive/v1.9.1.tar.gz",
  8. )
  9. load("@jflex_rules//jflex:deps.bzl", "JFLEX_ARTIFACTS")
  10. maven_install(
  11. name = "maven",
  12. artifacts = JFLEX_ARTIFACTS,
  13. maven_install_json = "//:maven_install.json",
  14. repositories = [
  15. "https://jcenter.bintray.com/",
  16. "https://maven.google.com",
  17. "https://repo1.maven.org/maven2",
  18. ],
  19. )

If this is the first time you use maven_install, you need to generate the maven_install.json with

  1. bazel run @maven//:pin

If you already used maven_install before, you need to update the pinned artifacts with:

  1. bazel run @unpinned_maven//:pin

Usage in BUILD files

  1. load("@jflex_rules//jflex:jflex.bzl", "jflex")
  2. load("@jflex_rules//cup:cup.bzl", "cup")
  3. jflex(
  4. name = "", # Choose a rule name
  5. srcs = [], # A list of flex specifications
  6. outputs = [], # List of expected generated files
  7. )
  8. cup(
  9. name = "", # Choose a rule name
  10. src = "", # Grammar specification
  11. )

As usual, these rules can be used as one of the srcs of another rules, such as a java_library.

For more details, see cup and jflex.

Directory layout

  1. ├── assets assets for the web site
  2. ├── cup contains the `cup.bzl` Skylark extension
  3. ├── java main Java source code
  4. └── jflex
  5. └── examples examples
  6. ├── calculator integration of JFlex and CUP
  7. └── helloworld simple lexer
  8. ├── javatests tests of the examples
  9. ├── jflex contains the `jflex.bzl` Skylark extension
  10. └── third_party Aliases for third-party libraries