GithubHelp home page GithubHelp logo

isabella232 / build_file_generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bazelbuild/build_file_generator

0.0 0.0 0.0 156 KB

Generate BUILD files for your Java files

License: Apache License 2.0

Python 6.67% Java 90.04% Shell 2.22% Scala 1.07%

build_file_generator's Introduction

Build status

NOTE: This project is deprecated and no longer maintained.

BUILD File Generator

BUILD File Generator generates Bazel BUILD files for Java code.

  1. It reads all .java files, and extracts the class dependency graph.
  2. Computes the strongly connected components of the graph.
  3. For each component, creates a java_library rule.

Why is it useful?

Having all sources in a single BUILD rule doesn't allow Bazel to parallelize and cache builds. In order to fully benefit from Bazel, one must write multiple BUILD rules and connect them.

This project automates writing granular BUILD rules that allow Bazel to parallelize and cache builds.

It's useful to quickly try out Bazel on your project as well as to periodically optimize your build graph.

BFG is composed of two general components

  1. Language specific parsers
  2. The BFG binary

The parsers read your source code and generate a class dependency graph in the form of a protobuf. To generate your BUILD files, you pass the generated protobuf into the BFG binary.

Step 1: Using parsers to generate dependency graphs

Suppose your project's Java code is in core/src/main/java/ and core/src/test/java/.

bazel run //lang/java/src/main/java/com/google/devtools/build/bfg:JavaSourceFileParserCli -- --roots=core/src/main/java,core/src/test/java $(find core/src/main/java/ core/src/test/java/ -name \*.java) > bfg.bin

The output is a serialized [ParserOutput] (https://github.com/bazelbuild/BUILD_file_generator/blob/672c5572499e96f6a89bfaa5d7baaf92184c6d7c/src/main/java/com/google/devtools/build/bfg/bfg.proto#L9) proto

Step 2: Generating BUILD files using BFG binary

TODO(bazel-devel): add explanation and valid example arguments.

bazel run //src/main/java/com/google/devtools/build/bfg -- --buildozer=$BUILDOZER --whitelist=$YOUR_JAVA_PACKAGE < bfg.bin

Supported Languages

We currently support Java projects. The next language on our roadmap is Scala.

Development

Third-party Maven dependencies

We use a bazel-deps to manage Maven jar dependencies. All of our dependencies are listed in maven_deps.yaml. bazel-deps provides tools to manage dependencies in that file and generates the Bazel build files for them in thirdparty/jvm/.

To use bazel-deps, use the wrapper scripts in dev-scripts/dependencies/. Don't edit the files under thirdparty/jvm/ by hand.

To add or update a dependency, run ./dev-scripts/dependencies/add-dep.sh MAVEN_COORD, where MAVEN_COORD is the Maven coordinate of the dependency, such as com.google.guava:guava:23.0. Add the --scala option if it is a Scala dependency.

After running this, you'll see changes to maven_deps.yaml and one or more files under thirdparty/jvm. Add and commit all of those changes. Similarly, if you run add-dep.sh with a new version of an existing dependency, it will be updated in maven_deps.yaml and any changed indirect dependencies will be reflected in the generated files.

You can also edit maven_deps.yaml manually. You will need to do this to remove a dependency, or to add exclusions to a dependency's dependencies. After making changes, run ./dev-scripts/dependencies/generate.sh to rebuild the generated files, and commit the changes to the generated files.

build_file_generator's People

Contributors

cgrushko avatar greggdonovan avatar petroseskinder avatar philwo avatar dslomov avatar meteorcloudy avatar buchgr avatar laurentlb avatar cushon avatar renovate-bot avatar davidstanke avatar katre avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.