blob: 82fe917c8d1c521014bfcb772393d5831a3d8b27 [file] [log] [blame] [view]
Kristina Chodorow974b2082015-03-31 14:49:30 +00001---
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +00002layout: contribute
3title: Contributing to Bazel
Kristina Chodorow974b2082015-03-31 14:49:30 +00004---
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +00005
6# Contributing to Bazel
7
8<p class="lead">We welcome contributions! This page covers setting up your
9machine to develop Bazel and, when you've made a patch, how to submit it.</p>
10
11## How can I contribute to Bazel?
12
13In general, we prefer contributions that fix bugs or add features (as opposed to
14stylistic, refactoring, or "cleanup" changes). Please check with us on the
15[dev list](https://groups.google.com/forum/#!forum/bazel-dev) before investing
16a 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
Googler95c0ea12016-08-15 00:58:37 +000053For now we have support for IntelliJ, and partial support for the Eclipse IDE
54for Java. We don't have IDE support for other languages in Bazel right now.
55
56### Creating an IntelliJ project
57
Googlereb4deb12016-09-08 20:05:48 +000058To work with IntelliJ, follow the instructions at
Damien Martin-Guillerezba306ec2016-10-28 10:01:24 +000059[ij.bazel.build](https://ij.bazel.build).
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +000060
61### Creating an Eclipse project
62
63To 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-Guillerez95a54b92016-07-28 12:47:11 +000072<a name="compile-bazel"></a>
73### Compiling Bazel
74
Klaus Aehlig8d102212016-11-11 14:42:42 +000075To test out bazel, you need to compile it. To compile a development version of
76Bazel, you need a working version of Bazel already, e.g., the latest release
77version [compiled from source](/versions/master/docs/install.html#compiling-from-source).
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +000078
Klaus Aehlig8d102212016-11-11 14:42:42 +000079`bazel build //src:bazel` builds the Bazel binary using `bazel` from your PATH
80and the resulting binary can be found at `bazel-bin/src/bazel`. This is the
81recommended way of rebuilding Bazel once you have bootstrapped it.
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +000082
83In addition to the Bazel binary, you might want to build the various tools Bazel
84uses. They are located in `//src/java_tools/...`, `//src/objc_tools/...` and
85`//src/tools/...` and their directories contain README files describing their
86respective utility.
87
88When modifying Bazel, you want to make sure that the following still works:
89
Klaus Aehlig8d102212016-11-11 14:42:42 +000090* 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-Guillerez95a54b92016-07-28 12:47:11 +000093 `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
100Start creating a debug configuration for both C++ and Java in your `.bazelrc`
101with the following:
102
103```
104build:debug -c dbg
105build:debug --javacopt="-g"
106build:debug --copt="-g"
107build:debug --strip="never"
108```
109
110Then you can rebuild Bazel with `bazel build --config debug //src:bazel` and use
111your favorite debugger to start debugging.
112
113For debugging the C++ client you can just run it from gdb or lldb as you normally would.
114But 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).
Googler95c0ea12016-08-15 00:58:37 +0000122* Our IntelliJ plugin has built-in
Damien Martin-Guillerezba306ec2016-10-28 10:01:24 +0000123 [debugging support](https://ij.bazel.build/docs/run-configurations.html)
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000124
125## Bazel's code description
126
127Bazel 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 Chakraborty099059e2016-08-31 17:38:15 +0000132 * Core code which is mostly composed of [SkyFrame](designs/skyframe.html) and some
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000133 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-Guillerez9a9981e2016-08-05 09:41:13 +0000139 `com.google.devtools.build.lib.bazel.rules`. You might want to read about
Kush Chakrabortyf04849b2016-08-31 15:45:37 +0000140 the [Challenges of Writing Rules](docs/rule-challenges.html) first.
Damien Martin-Guillerez95a54b92016-07-28 12:47:11 +0000141* Java native interfaces in `src/main/native`.
142* Various tooling for language support (see the list in the
143 [compiling Bazel](#compile-bazel) section).