blob: 9deed50330d68d9a34bac0aa3697efe8bf202126 [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= Gerrit Code Review - Building with Buck
David Pursehoused0525a72013-05-09 17:49:34 +01002
3
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08004== Installation
David Pursehoused0525a72013-05-09 17:49:34 +01005
David Ostrovsky3931c162014-06-15 00:33:40 +02006You need to use Java 8 and Node.js for building gerrit.
Deniz Türkoglud7559c02014-09-08 11:27:23 +02007
David Pursehoused0525a72013-05-09 17:49:34 +01008There is currently no binary distribution of Buck, so it has to be manually
Euler Jiangfa6549a2015-11-11 09:28:05 -08009built and installed. Apache Ant and gcc are required. Currently only Linux
10and Mac OS are supported.
David Pursehoused0525a72013-05-09 17:49:34 +010011
12Clone the git and build it:
13
14----
David Pursehouse3e028c92015-04-16 16:00:59 +090015 git clone https://github.com/facebook/buck
David Pursehoused0525a72013-05-09 17:49:34 +010016 cd buck
Shawn Pearce552c1b52014-11-27 11:48:28 -080017 git checkout $(cat ../gerrit/.buckversion)
David Pursehoused0525a72013-05-09 17:49:34 +010018 ant
19----
20
David Pursehousee9803ab2014-03-12 14:15:10 +090021If you don't have a `bin/` directory in your home directory, create one:
David Pursehoused0525a72013-05-09 17:49:34 +010022
23----
David Pursehouse64c16442013-05-14 10:49:03 +090024 mkdir ~/bin
David Pursehousee9803ab2014-03-12 14:15:10 +090025----
26
27Add the `~/bin` folder to the path:
28
29----
David Pursehouse64c16442013-05-14 10:49:03 +090030 PATH=~/bin:$PATH
David Pursehoused0525a72013-05-09 17:49:34 +010031----
32
David Pursehousee9803ab2014-03-12 14:15:10 +090033Note that the buck executable needs to be available in all shell sessions,
34so also make sure it is appended to the path globally.
35
David Pursehouse1d04f642014-09-10 11:09:02 +020036Add a symbolic link in `~/bin` to the buck and buckd executables:
David Pursehoused0525a72013-05-09 17:49:34 +010037
38----
David Pursehouse64c16442013-05-14 10:49:03 +090039 ln -s `pwd`/bin/buck ~/bin/
David Pursehouse1d04f642014-09-10 11:09:02 +020040 ln -s `pwd`/bin/buckd ~/bin/
David Pursehouse64c16442013-05-14 10:49:03 +090041----
42
David Pursehouse5c42b8c2013-05-17 13:25:47 +010043Verify that `buck` is accessible:
David Pursehouse64c16442013-05-14 10:49:03 +090044
45----
46 which buck
David Pursehoused0525a72013-05-09 17:49:34 +010047----
48
David Pursehousebe284992013-09-26 14:43:33 +090049To enable autocompletion of buck commands, install the autocompletion
Khai Do58964f12016-06-24 10:08:57 -070050script from `./scripts/buck-completion.bash` in the buck project. Refer
David Pursehousead4ed962014-09-10 11:09:26 +020051to the script's header comments for installation instructions.
David Pursehousebe284992013-09-26 14:43:33 +090052
David Ostrovsky69349b42015-04-20 06:56:30 +020053== Prerequisites
54
55Buck requires Python version 2.7 to be installed. The Maven download toolchain
56requires `curl` to be installed.
David Pursehoused0525a72013-05-09 17:49:34 +010057
David Pursehouse5861a9a2013-05-15 10:25:19 +090058[[eclipse]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080059== Eclipse Integration
David Pursehoused0525a72013-05-09 17:49:34 +010060
61
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080062=== Generating the Eclipse Project
David Pursehoused0525a72013-05-09 17:49:34 +010063
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070064Create the Eclipse project:
David Pursehoused0525a72013-05-09 17:49:34 +010065
66----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070067 tools/eclipse/project.py
David Pursehoused0525a72013-05-09 17:49:34 +010068----
69
David Pursehouse2b16f6a2015-08-28 09:38:50 +090070and then follow the link:dev-eclipse.html#setup[setup instructions].
David Pursehouseb46cf492013-05-14 09:41:30 +090071
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080072=== Refreshing the Classpath
David Pursehoused0525a72013-05-09 17:49:34 +010073
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070074If an updated classpath is needed, the Eclipse project can be
75refreshed and missing dependency JARs can be downloaded:
David Pursehoused0525a72013-05-09 17:49:34 +010076
77----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070078 tools/eclipse/project.py
David Pursehoused0525a72013-05-09 17:49:34 +010079----
80
81
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080082=== Attaching Sources
Shawn Pearce7b553262013-05-13 21:25:13 -070083
David Pursehousecb7f9142016-02-19 10:12:06 +090084Source JARs are downloaded by default. This allows Eclipse to show
85documentation or dive into the implementation of a library JAR.
86
87To save time and bandwidth, download of source JARs can be restricted
88to only those that are necessary to compile Java source into JavaScript
89using the GWT compiler:
Shawn Pearce7b553262013-05-13 21:25:13 -070090
91----
David Pursehousecb7f9142016-02-19 10:12:06 +090092 tools/eclipse/project.py --no-src
Shawn Pearce7b553262013-05-13 21:25:13 -070093----
94
95
David Pursehouse6de7ee22013-05-20 11:08:51 +090096[[build]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080097== Building on the Command Line
David Pursehoused0525a72013-05-09 17:49:34 +010098
99
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800100=== Gerrit Development WAR File
David Pursehoused0525a72013-05-09 17:49:34 +0100101
David Ostrovskyc43dd072015-12-01 08:06:51 +0100102To build the Gerrit web application that includes GWT UI and PolyGerrit UI:
David Pursehoused0525a72013-05-09 17:49:34 +0100103
104----
105 buck build gerrit
106----
107
Michael Ochmann8129ece2016-07-08 11:25:25 +0200108[NOTE]
109PolyGerrit UI may require additional tools (such as npm). Please read
Khai Do00545282016-04-16 08:27:23 -0700110the polygerrit-ui/README.md for more info.
111
David Pursehoused0525a72013-05-09 17:49:34 +0100112The output executable WAR will be placed in:
113
114----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900115 buck-out/gen/gerrit/gerrit.war
David Pursehoused0525a72013-05-09 17:49:34 +0100116----
117
David Ostrovskyc43dd072015-12-01 08:06:51 +0100118To build the Gerrit web application that includes only GWT UI:
119
120----
121 buck build gwtgerrit
122----
123
124The output executable WAR will be placed in:
125
126----
127 buck-out/gen/gwtgerrit/gwtgerrit.war
128----
129
David Pursehoused0525a72013-05-09 17:49:34 +0100130
David Ostrovsky7a295332015-02-27 19:19:45 +0100131=== Headless Mode
132
133To build Gerrit in headless mode, i.e. without the GWT Web UI:
134
135----
136 buck build headless
137----
138
139The output executable WAR will be placed in:
140
141----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900142 buck-out/gen/headless/headless.war
David Ostrovsky7a295332015-02-27 19:19:45 +0100143----
144
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800145=== Extension and Plugin API JAR Files
David Pursehoused0525a72013-05-09 17:49:34 +0100146
David Ostrovskye5487a02013-11-25 00:00:13 +0100147To build the extension, plugin and GWT API JAR files:
David Pursehoused0525a72013-05-09 17:49:34 +0100148
149----
150 buck build api
151----
152
David Ostrovskye5487a02013-11-25 00:00:13 +0100153Java binaries, Java sources and Java docs are generated into corresponding
David Pursehouse43dc7482013-12-13 14:54:42 +0900154project directories in `buck-out/gen`, here as example for plugin API:
David Pursehoused0525a72013-05-09 17:49:34 +0100155
156----
David Ostrovskye5487a02013-11-25 00:00:13 +0100157 buck-out/gen/gerrit-plugin-api/plugin-api.jar
David Ostrovskyf377aa92015-09-14 17:46:28 +0900158 buck-out/gen/gerrit-plugin-api/plugin-api-javadoc/plugin-api-javadoc.jar
David Ostrovskye5487a02013-11-25 00:00:13 +0100159 buck-out/gen/gerrit-plugin-api/plugin-api-src.jar
David Pursehoused0525a72013-05-09 17:49:34 +0100160----
161
David Ostrovsky358a4582014-05-13 23:55:04 +0200162Install {extension,plugin,gwt}-api to the local maven repository:
David Ostrovsky6e6a9672013-05-30 01:10:12 +0200163
164----
Luca Milanesio3301aff2016-06-10 09:54:24 +0100165 tools/maven/api.sh install
David Ostrovsky6e6a9672013-05-30 01:10:12 +0200166----
167
David Ostrovsky358a4582014-05-13 23:55:04 +0200168Install gerrit.war to the local maven repository:
169
170----
Luca Milanesio3301aff2016-06-10 09:54:24 +0100171 tools/maven/api.sh war_install
David Ostrovsky358a4582014-05-13 23:55:04 +0200172----
173
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800174=== Plugins
David Pursehouse0bc51db2013-05-14 12:46:49 +0900175
176To build all core plugins:
177
178----
179 buck build plugins:core
180----
181
182The output JAR files for individual plugins will be placed in:
183
184----
185 buck-out/gen/plugins/<name>/<name>.jar
186----
187
188The JAR files will also be packaged in:
189
190----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900191 buck-out/gen/plugins/core/core.zip
David Pursehouse0bc51db2013-05-14 12:46:49 +0900192----
193
194To build a specific plugin:
195
196----
Shawn Pearce6586c202013-11-09 08:54:48 -0800197 buck build plugins/<name>:<name>
David Pursehouse0bc51db2013-05-14 12:46:49 +0900198----
199
200The output JAR file will be be placed in:
201
202----
203 buck-out/gen/plugins/<name>/<name>.jar
204----
205
206Note that when building an individual plugin, the `core.zip` package
207is not regenerated.
208
Shawn Pearce6586c202013-11-09 08:54:48 -0800209Additional plugins with BUCK files can be added to the build
210environment by cloning the source repository into the plugins
211subdirectory:
212
213----
214 git clone https://gerrit.googlesource.com/plugins/<name> plugins/<name>
215 echo /plugins/<name> >>.git/info/exclude
216----
217
218Additional plugin sources will be automatically added to Eclipse the
219next time project.py is run:
220
221----
222 tools/eclipse/project.py
223----
224
David Pursehouse90a9c102013-09-06 18:42:10 +0900225
226[[documentation]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800227=== Documentation
David Pursehouse90a9c102013-09-06 18:42:10 +0900228
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700229To build only the documentation for testing or static hosting:
David Pursehouse90a9c102013-09-06 18:42:10 +0900230
231----
232 buck build docs
233----
234
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700235The generated html files will NOT come with the search box, and will be
236placed in:
David Pursehouse90a9c102013-09-06 18:42:10 +0900237
238----
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700239 buck-out/gen/Documentation/searchfree__tmp/Documentation
David Pursehouse90a9c102013-09-06 18:42:10 +0900240----
241
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700242The html files will also be bundled into `searchfree.zip` in this location:
David Pursehouse90a9c102013-09-06 18:42:10 +0900243
David Ostrovsky7cd233e2013-09-26 07:21:31 +0200244----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900245 buck-out/gen/Documentation/searchfree/searchfree.zip
David Ostrovsky7cd233e2013-09-26 07:21:31 +0200246----
David Pursehouse90a9c102013-09-06 18:42:10 +0900247
David Pursehousec08d03e2013-12-10 18:16:10 +0900248To build the executable WAR with the documentation included:
249
250----
251 buck build withdocs
252----
253
254The WAR file will be placed in:
255
256----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900257 buck-out/gen/withdocs/withdocs.war
David Pursehousec08d03e2013-12-10 18:16:10 +0900258----
259
Shawn Pearce16570462015-01-14 16:27:42 -0800260[[soyc]]
261=== GWT Compile Report
262
263The GWT compiler can output a compile report (or "story of your compile"),
264describing the size of the JavaScript and which source classes contributed
265to the overall download size.
266
267----
268 buck build soyc
269----
270
271The report will be written as an HTML page to the extras directory, and
272can be opened and viewed in any web browser:
273
274----
275 extras/gerrit_ui/soycReport/compile-report/index.html
276----
277
278Only the "Split Point Report" is created, "Compiler Metrics" are not output.
279
David Ostrovsky811e6032013-09-06 08:35:45 +0200280[[release]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800281=== Gerrit Release WAR File
David Ostrovsky811e6032013-09-06 08:35:45 +0200282
283To build the release of the Gerrit web application, including documentation and
284all core plugins:
285
286----
287 buck build release
288----
289
290The output release WAR will be placed in:
291
292----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900293 buck-out/gen/release/release.war
David Ostrovsky811e6032013-09-06 08:35:45 +0200294----
David Pursehouse0bc51db2013-05-14 12:46:49 +0900295
David Pursehouse5861a9a2013-05-15 10:25:19 +0900296[[tests]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800297== Running Unit Tests
David Pursehoused0525a72013-05-09 17:49:34 +0100298
Dave Borowitzafd7d392015-06-22 09:48:33 -0700299To run all tests including acceptance tests (but not flaky tests):
David Pursehoused0525a72013-05-09 17:49:34 +0100300
301----
Dave Borowitzafd7d392015-06-22 09:48:33 -0700302 buck test --exclude flaky
David Pursehoused0525a72013-05-09 17:49:34 +0100303----
304
Dave Borowitzafd7d392015-06-22 09:48:33 -0700305To exclude flaky and slow tests:
David Pursehoused0525a72013-05-09 17:49:34 +0100306
307----
Dave Borowitzafd7d392015-06-22 09:48:33 -0700308 buck test --exclude flaky slow
David Pursehoused0525a72013-05-09 17:49:34 +0100309----
310
Christian Aistleitner9fb58812015-06-21 19:46:11 +0200311To run only a specific group of acceptance tests:
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200312
313----
Christian Aistleitner9fb58812015-06-21 19:46:11 +0200314 buck test --include api
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200315----
316
317The following groups of tests are currently supported:
318
Christian Aistleitnerb03fc1a2015-06-21 19:49:12 +0200319* acceptance
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200320* api
David Ostrovsky4efb0f22014-12-18 08:55:13 +0100321* edit
Dave Borowitzafd7d392015-06-22 09:48:33 -0700322* flaky
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200323* git
324* pgm
325* rest
326* server
327* ssh
Christian Aistleitnerb03fc1a2015-06-21 19:49:12 +0200328* slow
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200329
David Ostrovskybb706152015-10-16 06:29:17 +0200330To run a specific test group, e.g. the rest-account test group:
Edwin Kempin674078a2013-08-20 11:37:14 +0200331
332----
David Ostrovskybb706152015-10-16 06:29:17 +0200333 buck test //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account:rest-account
Edwin Kempin674078a2013-08-20 11:37:14 +0200334----
335
David Ostrovskyfaec8052014-08-10 00:32:52 +0200336To create test coverage report:
337
338----
339 buck test --code-coverage --code-coverage-format html --no-results-cache
340----
341
342The HTML report is created in `buck-out/gen/jacoco/code-coverage/index.html`.
David Pursehoused0525a72013-05-09 17:49:34 +0100343
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800344== Dependencies
David Pursehoused0525a72013-05-09 17:49:34 +0100345
346Dependency JARs are normally downloaded automatically, but Buck can inspect
347its graph and download any missing JAR files. This is useful to enable
Shawn Pearcea7a3ee12013-09-20 10:42:37 -0700348subsequent builds to run without network access:
David Pursehoused0525a72013-05-09 17:49:34 +0100349
350----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -0700351 tools/download_all.py
David Pursehoused0525a72013-05-09 17:49:34 +0100352----
353
David Pursehouseb46cf492013-05-14 09:41:30 +0900354When downloading from behind a proxy (which is common in some corporate
355environments), it might be necessary to explicitly specify the proxy that
356is then used by `curl`:
357
358----
359 export http_proxy=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>
360----
361
Shawn Pearce1b89f852013-05-13 20:26:34 -0700362Redirection to local mirrors of Maven Central and the Gerrit storage
363bucket is supported by defining specific properties in
364`local.properties`, a file that is not tracked by Git:
365
366----
367 echo download.GERRIT = http://nexus.my-company.com/ >>local.properties
368 echo download.MAVEN_CENTRAL = http://nexus.my-company.com/ >>local.properties
369----
370
David Pursehouse6fb2c4d2013-05-16 16:51:46 +0900371The `local.properties` file may be placed in the root of the gerrit repository
372being built, or in `~/.gerritcodereview/`. The file in the root of the gerrit
373repository has precedence.
374
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800375== Building against unpublished Maven JARs
David Ostrovskyee9f9922013-08-15 00:21:04 +0200376
377To build against unpublished Maven JARs, like gwtorm or PrologCafe, the custom
David Pursehouseb99db5c2013-09-26 11:34:42 +0900378JARs must be installed in the local Maven repository (`mvn clean install`) and
379`maven_jar()` must be updated to point to the `MAVEN_LOCAL` Maven repository for
David Ostrovskyee9f9922013-08-15 00:21:04 +0200380that artifact:
381
David Pursehouseb99db5c2013-09-26 11:34:42 +0900382[source,python]
David Ostrovskyee9f9922013-08-15 00:21:04 +0200383----
384 maven_jar(
385 name = 'gwtorm',
386 id = 'gwtorm:gwtorm:42',
David Ostrovskyee9f9922013-08-15 00:21:04 +0200387 license = 'Apache2.0',
388 repository = MAVEN_LOCAL,
389 )
390----
391
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800392== Building against artifacts from custom Maven repositories
David Ostrovsky2536d062013-11-14 00:35:07 +0100393
394To build against custom Maven repositories, two modes of operations are
395supported: with rewrite in local.properties and without.
396
397Without rewrite the URL of custom Maven repository can be directly passed
398to the maven_jar() function:
399
400[source,python]
401----
402 GERRIT_FORGE = 'http://gerritforge.com/snapshot'
403
404 maven_jar(
405 name = 'gitblit',
406 id = 'com.gitblit:gitblit:1.4.0',
407 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
408 license = 'Apache2.0',
409 repository = GERRIT_FORGE,
410 )
411----
412
413When the custom URL has to be rewritten, then the same logic as with Gerrit
414known Maven repository is used: Repo name must be defined that matches an entry
415in local.properties file:
416
417----
418 download.GERRIT_FORGE = http://my.company.mirror/gerrit-forge
419----
420
421And corresponding BUCK excerpt:
422
423[source,python]
424----
425 GERRIT_FORGE = 'GERRIT_FORGE:'
426
427 maven_jar(
428 name = 'gitblit',
429 id = 'com.gitblit:gitblit:1.4.0',
430 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
431 license = 'Apache2.0',
432 repository = GERRIT_FORGE,
433 )
434----
435
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800436=== Caching Build Results
Shawn Pearce9e4e2432013-05-30 13:09:29 -0700437
438Build results can be locally cached, saving rebuild time when
439switching between Git branches. Buck's documentation covers
440caching in link:http://facebook.github.io/buck/concept/buckconfig.html[buckconfig].
441The trivial case using a local directory is:
442
443----
444 cat >.buckconfig.local <<EOF
445 [cache]
446 mode = dir
447 dir = buck-cache
448 EOF
449----
450
David Pursehouse6c3fd802014-10-24 13:50:44 +0900451[[clean-cache]]
452=== Cleaning The Buck Cache
453
454The cache for the Gerrit Code Review project is located in
Christian Aistleitner6f6de0d2015-03-26 14:25:03 +0100455`~/.gerritcodereview/buck-cache/locally-built-artifacts`.
David Pursehouse6c3fd802014-10-24 13:50:44 +0900456
457The Buck cache should never need to be manually deleted. If you find yourself
458deleting the Buck cache regularly, then it is likely that there is something
459wrong with your environment or your workflow.
460
461If you really do need to clean the cache manually, then:
462
463----
Christian Aistleitner6f6de0d2015-03-26 14:25:03 +0100464 rm -rf ~/.gerritcodereview/buck-cache/locally-built-artifacts
David Pursehouse6c3fd802014-10-24 13:50:44 +0900465----
466
Christian Aistleitner6f6de0d2015-03-26 14:25:03 +0100467Note that the root `buck-cache` folder should not be deleted as it also contains
468the `downloaded-artifacts` directory, which holds the artifacts that got
469downloaded (not built locally).
David Pursehouse6c3fd802014-10-24 13:50:44 +0900470
Edwin Kempin9a8b1dc2013-09-16 09:08:34 +0200471[[buck-daemon]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800472=== Using Buck daemon
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200473
David Pursehouseb99db5c2013-09-26 11:34:42 +0900474Buck ships with a daemon command `buckd`, which uses the
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200475link:https://github.com/martylamb/nailgun[Nailgun] protocol for running
476Java programs from the command line without incurring the JVM startup
David Pursehouseb99db5c2013-09-26 11:34:42 +0900477overhead.
478
479Using a Buck daemon can save significant amounts of time as it avoids the
480overhead of starting a Java virtual machine, loading the buck class files
481and parsing the build files for each command.
482
483It is safe to run several buck daemons started from different project
484directories and they will not interfere with each other. Buck's documentation
485covers daemon in http://facebook.github.io/buck/command/buckd.html[buckd].
486
David Ostrovsky26e3be62014-05-23 08:34:07 +0200487To use `buckd` the additional
488link:https://facebook.github.io/watchman[watchman] program must be installed.
489
David Ostrovsky37175422014-09-22 09:55:40 +0200490To disable `buckd`, the environment variable `NO_BUCKD` must be set. It's not
491recommended to put it in the shell config, as it can be forgotten about it and
492then assumed Buck was working as it should when it should be using buckd.
493Prepend the variable to Buck invocation instead:
494
495----
David Pursehouse8d4d3162014-10-24 13:57:06 +0900496 NO_BUCKD=1 buck build gerrit
David Ostrovsky37175422014-09-22 09:55:40 +0200497----
498
David Ostrovsky26e3be62014-05-23 08:34:07 +0200499[[watchman]]
500=== Installing watchman
501
502Watchman is used internally by Buck to monitor directory trees and is needed
503for buck daemon to work properly. Because buckd is activated by default in the
504latest version of Buck, it searches for the watchman executable in the
505path and issues a warning when it is not found and kills buckd.
506
507To prepare watchman installation on Linux:
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200508
509----
David Ostrovsky26e3be62014-05-23 08:34:07 +0200510 git clone https://github.com/facebook/watchman.git
511 cd watchman
512 ./autogen.sh
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200513----
514
David Ostrovsky26e3be62014-05-23 08:34:07 +0200515To install it in user home directory (without root privileges):
516
517----
518 ./configure --prefix $HOME/watchman
519 make install
520----
521
522To install it system wide:
523
524----
525 ./configure
526 make
527 sudo make install
528----
529
530Put $HOME/watchman/bin/watchman in path or link to $HOME/bin/watchman.
531
532To install watchman on OS X:
533
534----
535 brew install --HEAD watchman
536----
537
538See the original documentation for more information:
539link:https://facebook.github.io/watchman/docs/install.html[Watchman
540installation].
541
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800542=== Override Buck's settings
David Ostrovskyefaff302013-09-20 22:36:14 +0200543
Shawn Pearce4e1a8bc2013-11-28 18:38:30 -0800544Additional JVM args for Buck can be set in `.buckjavaargs` in the
545project root directory. For example to override Buck's default 1GB
546heap size:
David Ostrovskyefaff302013-09-20 22:36:14 +0200547
548----
Shawn Pearce4e1a8bc2013-11-28 18:38:30 -0800549 cat > .buckjavaargs <<EOF
David Ostrovsky3931c162014-06-15 00:33:40 +0200550 -Xms8000m -Xmx16000m
David Ostrovskyefaff302013-09-20 22:36:14 +0200551 EOF
552----
553
David Ostrovskyfe2934e2014-04-22 00:36:12 +0200554== Rerun unit tests
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700555
David Pursehouse56f60a42014-07-10 11:20:33 +0900556Test execution results are cached by Buck. If a test that was already run
557needs to be repeated, the unit test cache for that test must be removed first:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700558
559----
David Ostrovskybb706152015-10-16 06:29:17 +0200560 rm -rf buck-out/bin/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account/.rest-account/
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700561----
562
David Pursehouse56f60a42014-07-10 11:20:33 +0900563After clearing the cache, the test can be run again:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700564
565----
David Ostrovskybb706152015-10-16 06:29:17 +0200566 buck test //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account:rest-account
567 [-] TESTING...FINISHED 12,3s (12 PASS/0 FAIL)
568 RESULTS FOR //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account:rest-account
569 PASS 970ms 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.CapabilitiesIT
570 PASS 999ms 1 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.EditPreferencesIT
571 PASS 1,2s 1 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.GetAccountDetailIT
572 PASS 951ms 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.GetAccountIT
573 PASS 6,4s 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.GetDiffPreferencesIT
574 PASS 1,2s 4 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.PutUsernameIT
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700575 TESTS PASSED
576----
577
David Pursehouse56f60a42014-07-10 11:20:33 +0900578An alternative approach is to use Buck's `--filters` (`-f`) option:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700579
580----
David Ostrovsky7f660142015-10-16 17:24:17 +0200581 buck test -f 'com.google.gerrit.acceptance.rest.account.CapabilitiesIT'
582 Using buckd.
583 [-] PROCESSING BUCK FILES...FINISHED 1,0s [100%]
584 [-] BUILDING...FINISHED 2,8s [100%] (334/701 JOBS, 110 UPDATED, 5,1% CACHE MISS)
585 [-] TESTING...FINISHED 9,2s (6 PASS/0 FAIL)
David Ostrovskybb706152015-10-16 06:29:17 +0200586 RESULTS FOR SELECTED TESTS
David Ostrovsky7f660142015-10-16 17:24:17 +0200587 PASS 8,0s 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.CapabilitiesIT
David Ostrovskybb706152015-10-16 06:29:17 +0200588 PASS <100ms 4 Passed 0 Skipped 0 Failed //tools:util_test
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700589 TESTS PASSED
590----
591
David Pursehouse56f60a42014-07-10 11:20:33 +0900592When this option is used, the cache is disabled per design and doesn't need to
David Ostrovsky7f660142015-10-16 17:24:17 +0200593be explicitly deleted. Note, that this is a known issue, that python tests are
594always executed.
David Pursehouse56f60a42014-07-10 11:20:33 +0900595
596Note that when this option is used, the whole unit test cache is dropped, so
David Ostrovsky074859e2014-04-19 22:52:47 +0200597repeating the
598
599----
David Pursehouse56f60a42014-07-10 11:20:33 +0900600buck test
David Ostrovsky074859e2014-04-19 22:52:47 +0200601----
602
David Pursehouse56f60a42014-07-10 11:20:33 +0900603causes all tests to be executed again.
604
605To run tests without using cached results at all, use the `--no-results-cache`
606option:
607
608----
609buck test --no-results-cache
610----
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700611
David Ostrovsky4f430f32016-10-21 23:19:58 +0200612== Cross-compiling Java8 to Java7
613
614After switching to Java8, we should take care to not end up
615with Java8 code in stable branches. We assume that we don't
616really want to switch java versions locally every time we switch
617branches.
618
619Given that source level on 'stable-2.13' is 7, source level incompatibility
620will be already correctly detected, so that Java8 compiler would refuse
621to compile lambdas with -source 7 argument. However, unless bootclasspath
622is adjusted to point to Java7 runtime, it's possible to end up with broken
623code, that would compile with Java8 but will not run on Java7 runtime.
624
625To prevent this, add this line to your '.buckconfig.local' in the Gerrit
626source root directory when working on stable branches:
627
628----
629[java]
630 extra_arguments = -Xbootclasspath/p:/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/jre/lib/rt.jar
631----
632
633With this in place, methods that were added only in Java8 in runtime library,
634would be correctly refused to compile by Java8:
635
636----
637$ java -version
638openjdk version "1.8.0_101"
639
640$ buck build gerrit-server:server
641/home/davido/projects/gerrit/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectCacheImpl.java:218: error: cannot find symbol
642 return Collections.emptySortedSet();
643 ^
644 symbol: method emptySortedSet()
645 location: class java.util.Collections
646----
647
David Ostrovsky7674c522015-10-15 04:55:46 +0200648== Upgrading Buck
649
650The following tests should be executed, when Buck version is upgraded:
651
652* buck build release
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +0200653* tools/maven/api.sh install
David Ostrovsky7674c522015-10-15 04:55:46 +0200654* buck test
David Ostrovskye3721d12015-10-17 00:32:20 +0200655* buck build gerrit, change some sources in gerrit-server project,
656 repeat buck build gerrit and verify that gerrit.war was updated
David Ostrovsky7674c522015-10-15 04:55:46 +0200657* install and verify new gerrit site
658* upgrade and verify existing gerrit site
659* reindex existing gerrit site
660* verify that tools/eclipse/project.py produces sane Eclipse project
661* verify that tools/eclipse/project.py --src generates sources as well
662* verify that unit test execution from Eclipse works
663* verify that daemon started from Eclipse works
664* verify that GWT SDM debug session started from Eclipse works
665
David Ostrovsky44c7e612015-06-16 08:58:48 +0200666== Known issues and bugs
667
668=== Symbolic links and `watchman`
669
670`Buck` with activated `Watchman` has currently a
671[known bug](https://github.com/facebook/buck/issues/341) related to
672symbolic links. The symbolic links are used very often with external
673plugins, that are linked per symbolic link to the plugins directory.
David Pursehousea61ee502016-09-06 16:27:09 +0900674With this use case Buck is failing to rebuild the plugin artifact
David Ostrovsky44c7e612015-06-16 08:58:48 +0200675after it was built. All attempts to convince Buck to rebuild will fail.
676The only known way to recover is to weep out `buck-out` directory. The
677better workaround is to avoid using Watchman in this specific use case.
678Watchman can either be de-installed or disabled. See
679link:#buck-daemon[Using Buck daemon] section above how to temporarily
680disable `buckd`.
681
David Pursehouse226eaf32014-12-18 17:49:28 +0900682== Troubleshooting Buck
683
684In some cases problems with Buck itself need to be investigated. See for example
685link:https://gerrit-review.googlesource.com/62411[this attempt to upgrade Buck]
686and link:https://github.com/facebook/buck/pull/227[the fix that was needed] to
687make the update possible.
688
689To build Gerrit with a custom version of Buck, the following steps are necessary:
690
6911. In the Buck git apply any necessary changes from pull requests
6922. Compile Buck with `ant`
6933. In the root of the Gerrit project create a `.nobuckcheck` file to prevent Buck
694from updating itself
6954. Replace the sha1 in Gerrit's `.buckversion` file with the required version from
696the custom Buck build
6975. Build Gerrit as usual
698
David Pursehoused0525a72013-05-09 17:49:34 +0100699GERRIT
700------
701Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700702
703SEARCHBOX
704---------