Kristina Chodorow | 974b208 | 2015-03-31 14:49:30 +0000 | [diff] [blame] | 1 | --- |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 2 | layout: contribute |
| 3 | title: Contributing to Bazel |
Kristina Chodorow | 974b208 | 2015-03-31 14:49:30 +0000 | [diff] [blame] | 4 | --- |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 5 | |
| 6 | # Contributing to Bazel |
| 7 | |
| 8 | <p class="lead">We welcome contributions! This page covers setting up your |
| 9 | machine to develop Bazel and, when you've made a patch, how to submit it.</p> |
| 10 | |
| 11 | ## How can I contribute to Bazel? |
| 12 | |
| 13 | In general, we prefer contributions that fix bugs or add features (as opposed to |
| 14 | stylistic, refactoring, or "cleanup" changes). Please check with us on the |
| 15 | [dev list](https://groups.google.com/forum/#!forum/bazel-dev) before investing |
| 16 | a lot of time in a patch. |
| 17 | |
| 18 | ## Patch Acceptance Process |
| 19 | |
| 20 | <!-- Our markdown parser doesn't support nested lists. --> |
| 21 | <ol> |
| 22 | <li>Read the <a href="governance.html">Bazel governance plan</a>.</li> |
| 23 | <li>Discuss your plan and design, and get agreement on our <a href="https://groups.google.com/forum/#!forum/bazel-dev">mailing list</a>. |
| 24 | <li>Prepare a git commit that implements the feature. Don't forget to add tests. |
| 25 | <li>Create a new code review on <a href="https://bazel-review.googlesource.com">Gerrit</a> |
| 26 | by running: |
| 27 | <pre>$ git push https://bazel.googlesource.com/bazel HEAD:refs/for/master</pre> |
| 28 | Gerrit upload requires that you: |
| 29 | <ul> |
| 30 | <li>Have signed a |
| 31 | <a href="https://cla.developers.google.com">Contributor License Agreement</a>. |
| 32 | <li>Have an automatically generated "Change Id" line in your commit message. |
| 33 | If you haven't used Gerrit before, it will print a bash command to create |
| 34 | the git hook and then you will need to run `git commit --amend` to add the |
| 35 | line. |
| 36 | </ul> |
| 37 | The HTTP password required by Gerrit can be obtained from your |
| 38 | <a href="https://bazel-review.googlesource.com/#/settings/http-password">Gerrit settings page</a>. |
| 39 | See the |
| 40 | <a href="https://gerrit-review.googlesource.com/Documentation/user-upload.html">Gerrit documentation</a> |
| 41 | for more information about uploading changes. |
| 42 | <li>Complete a code review with a |
| 43 | <a href="governance.html#core-contributors">core contributor</a>. Amend your existing |
| 44 | commit and re-push to make changes to your patch. |
| 45 | <li>An engineer at Google applies the patch to our internal version control |
| 46 | system. |
| 47 | <li>The patch is exported as a Git commit, at which point the Gerrit code review |
| 48 | is closed. |
| 49 | </ol> |
| 50 | |
| 51 | ## Setting up your coding environment |
| 52 | |
Googler | 95c0ea1 | 2016-08-15 00:58:37 +0000 | [diff] [blame] | 53 | For now we have support for IntelliJ, and partial support for the Eclipse IDE |
| 54 | for Java. We don't have IDE support for other languages in Bazel right now. |
| 55 | |
| 56 | ### Creating an IntelliJ project |
| 57 | |
Googler | eb4deb1 | 2016-09-08 20:05:48 +0000 | [diff] [blame] | 58 | To work with IntelliJ, follow the instructions at |
Damien Martin-Guillerez | ba306ec | 2016-10-28 10:01:24 +0000 | [diff] [blame] | 59 | [ij.bazel.build](https://ij.bazel.build). |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 60 | |
| 61 | ### Creating an Eclipse project |
| 62 | |
| 63 | To work with Eclipse: |
| 64 | |
| 65 | * Install the [e4b](https://github.com/bazelbuild/e4b) plugin. |
| 66 | * Change the path to the Bazel binary in the plugin preferences. |
| 67 | * Import the Bazel workspace as a Bazel project (`File` > `New` > `Other` > |
| 68 | `Import Bazel Workspace`). |
| 69 | * Select `src > main > java` and `src > test > java` as directories and add |
| 70 | `//src/main/java/...` and `//src/test/java/...` as targets. |
| 71 | |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 72 | <a name="compile-bazel"></a> |
| 73 | ### Compiling Bazel |
| 74 | |
Klaus Aehlig | 8d10221 | 2016-11-11 14:42:42 +0000 | [diff] [blame] | 75 | To test out bazel, you need to compile it. To compile a development version of |
| 76 | Bazel, you need a working version of Bazel already, e.g., the latest release |
| 77 | version [compiled from source](/versions/master/docs/install.html#compiling-from-source). |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 78 | |
Klaus Aehlig | 8d10221 | 2016-11-11 14:42:42 +0000 | [diff] [blame] | 79 | `bazel build //src:bazel` builds the Bazel binary using `bazel` from your PATH |
| 80 | and the resulting binary can be found at `bazel-bin/src/bazel`. This is the |
| 81 | recommended way of rebuilding Bazel once you have bootstrapped it. |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 82 | |
| 83 | In addition to the Bazel binary, you might want to build the various tools Bazel |
| 84 | uses. They are located in `//src/java_tools/...`, `//src/objc_tools/...` and |
| 85 | `//src/tools/...` and their directories contain README files describing their |
| 86 | respective utility. |
| 87 | |
| 88 | When modifying Bazel, you want to make sure that the following still works: |
| 89 | |
Klaus Aehlig | 8d10221 | 2016-11-11 14:42:42 +0000 | [diff] [blame] | 90 | * Build a distribution archive with `bazel build //:bazel-distfile`. After |
| 91 | unzipping it in a new empty directory, run `bash compile.sh all` there. |
| 92 | It rebuilds Bazel with `./compile.sh`, Bazel with the |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 93 | `compile.sh` Bazel and Bazel with the Bazel-built binary. It compares if the |
| 94 | constructed Bazel builts are identical and then runs all bazel tests with |
| 95 | `bazel test //src/... //third_party/ijar/...`. This is what we use at Google |
| 96 | to ensure that we don't break Bazel when pushing new commits, too. |
| 97 | |
| 98 | ### Debugging Bazel |
| 99 | |
| 100 | Start creating a debug configuration for both C++ and Java in your `.bazelrc` |
| 101 | with the following: |
| 102 | |
| 103 | ``` |
| 104 | build:debug -c dbg |
| 105 | build:debug --javacopt="-g" |
| 106 | build:debug --copt="-g" |
| 107 | build:debug --strip="never" |
| 108 | ``` |
| 109 | |
| 110 | Then you can rebuild Bazel with `bazel build --config debug //src:bazel` and use |
| 111 | your favorite debugger to start debugging. |
| 112 | |
| 113 | For debugging the C++ client you can just run it from gdb or lldb as you normally would. |
| 114 | But if you want to debug the Java code, you must attach to the server using the following: |
| 115 | |
| 116 | * Run Bazel with debugging option `--host_jvm_debug` before the |
| 117 | command (e.g., `bazel --batch --host_jvm_debug build //src:bazel`). |
| 118 | * Attach a debugger to the port 5005. With `jdb` for instance, |
| 119 | run `jdb -attach localhost:5005`. From within Eclipse, use the |
| 120 | [remote Java application launch |
| 121 | configuration](http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-remotejava_launch_config.htm). |
Googler | 95c0ea1 | 2016-08-15 00:58:37 +0000 | [diff] [blame] | 122 | * Our IntelliJ plugin has built-in |
Damien Martin-Guillerez | ba306ec | 2016-10-28 10:01:24 +0000 | [diff] [blame] | 123 | [debugging support](https://ij.bazel.build/docs/run-configurations.html) |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 124 | |
| 125 | ## Bazel's code description |
| 126 | |
| 127 | Bazel is organized in several parts: |
| 128 | |
| 129 | * Client code in `src/main/cpp` provides the command-line interface. |
| 130 | * Protocol buffers in `src/main/protobuf`. |
| 131 | * Server code in `src/main/java` and `src/test/java`. |
Kush Chakraborty | 099059e | 2016-08-31 17:38:15 +0000 | [diff] [blame] | 132 | * Core code which is mostly composed of [SkyFrame](designs/skyframe.html) and some |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 133 | utilities. |
| 134 | * Rules written in Bazel's extension language |
| 135 | [Skylark](docs/skylark/index.html) are defined in `tools/build_rules`. If |
| 136 | you want to add rules, consider using [Skylark](docs/skylark/index.html) |
| 137 | first. |
| 138 | * Builtin rules in `com.google.devtools.build.lib.rules` and in |
Damien Martin-Guillerez | 9a9981e | 2016-08-05 09:41:13 +0000 | [diff] [blame] | 139 | `com.google.devtools.build.lib.bazel.rules`. You might want to read about |
Kush Chakraborty | f04849b | 2016-08-31 15:45:37 +0000 | [diff] [blame] | 140 | the [Challenges of Writing Rules](docs/rule-challenges.html) first. |
Damien Martin-Guillerez | 95a54b9 | 2016-07-28 12:47:11 +0000 | [diff] [blame] | 141 | * Java native interfaces in `src/main/native`. |
| 142 | * Various tooling for language support (see the list in the |
| 143 | [compiling Bazel](#compile-bazel) section). |