blob: 505d16fe5b5fc1abe2eb12bcd426b0bd2645daf4 [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
Deniz Türkoglud7559c02014-09-08 11:27:23 +02006Note that you need to use Java 7 for building gerrit.
7
David Pursehoused0525a72013-05-09 17:49:34 +01008There is currently no binary distribution of Buck, so it has to be manually
David Pursehouse64c16442013-05-14 10:49:03 +09009built and installed. Apache Ant is required. Currently only Linux and Mac
David Ostrovsky69349b42015-04-20 06:56:30 +020010OS 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
David Pursehousead4ed962014-09-10 11:09:26 +020050script from `./scripts/buck_completion.bash` in the buck project. Refer
51to 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
84To save time and bandwidth source JARs are only downloaded by the buck
85build where necessary to compile Java source into JavaScript using the
86GWT compiler. Additional sources may be obtained, allowing Eclipse to
87show documentation or dive into the implementation of a library JAR:
88
89----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070090 tools/eclipse/project.py --src
Shawn Pearce7b553262013-05-13 21:25:13 -070091----
92
93
David Pursehouse6de7ee22013-05-20 11:08:51 +090094[[build]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080095== Building on the Command Line
David Pursehoused0525a72013-05-09 17:49:34 +010096
97
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080098=== Gerrit Development WAR File
David Pursehoused0525a72013-05-09 17:49:34 +010099
100To build the Gerrit web application:
101
102----
103 buck build gerrit
104----
105
106The output executable WAR will be placed in:
107
108----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900109 buck-out/gen/gerrit/gerrit.war
David Pursehoused0525a72013-05-09 17:49:34 +0100110----
111
112
David Ostrovsky7a295332015-02-27 19:19:45 +0100113=== Headless Mode
114
115To build Gerrit in headless mode, i.e. without the GWT Web UI:
116
117----
118 buck build headless
119----
120
121The output executable WAR will be placed in:
122
123----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900124 buck-out/gen/headless/headless.war
David Ostrovsky7a295332015-02-27 19:19:45 +0100125----
126
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800127=== Extension and Plugin API JAR Files
David Pursehoused0525a72013-05-09 17:49:34 +0100128
David Ostrovskye5487a02013-11-25 00:00:13 +0100129To build the extension, plugin and GWT API JAR files:
David Pursehoused0525a72013-05-09 17:49:34 +0100130
131----
132 buck build api
133----
134
David Ostrovskye5487a02013-11-25 00:00:13 +0100135Java binaries, Java sources and Java docs are generated into corresponding
David Pursehouse43dc7482013-12-13 14:54:42 +0900136project directories in `buck-out/gen`, here as example for plugin API:
David Pursehoused0525a72013-05-09 17:49:34 +0100137
138----
David Ostrovskye5487a02013-11-25 00:00:13 +0100139 buck-out/gen/gerrit-plugin-api/plugin-api.jar
David Ostrovskyf377aa92015-09-14 17:46:28 +0900140 buck-out/gen/gerrit-plugin-api/plugin-api-javadoc/plugin-api-javadoc.jar
David Ostrovskye5487a02013-11-25 00:00:13 +0100141 buck-out/gen/gerrit-plugin-api/plugin-api-src.jar
David Pursehoused0525a72013-05-09 17:49:34 +0100142----
143
David Ostrovsky358a4582014-05-13 23:55:04 +0200144Install {extension,plugin,gwt}-api to the local maven repository:
David Ostrovsky6e6a9672013-05-30 01:10:12 +0200145
146----
147 buck build api_install
148----
149
David Ostrovsky358a4582014-05-13 23:55:04 +0200150Install gerrit.war to the local maven repository:
151
152----
153 buck build war_install
154----
155
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800156=== Plugins
David Pursehouse0bc51db2013-05-14 12:46:49 +0900157
158To build all core plugins:
159
160----
161 buck build plugins:core
162----
163
164The output JAR files for individual plugins will be placed in:
165
166----
167 buck-out/gen/plugins/<name>/<name>.jar
168----
169
170The JAR files will also be packaged in:
171
172----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900173 buck-out/gen/plugins/core/core.zip
David Pursehouse0bc51db2013-05-14 12:46:49 +0900174----
175
176To build a specific plugin:
177
178----
Shawn Pearce6586c202013-11-09 08:54:48 -0800179 buck build plugins/<name>:<name>
David Pursehouse0bc51db2013-05-14 12:46:49 +0900180----
181
182The output JAR file will be be placed in:
183
184----
185 buck-out/gen/plugins/<name>/<name>.jar
186----
187
188Note that when building an individual plugin, the `core.zip` package
189is not regenerated.
190
Shawn Pearce6586c202013-11-09 08:54:48 -0800191Additional plugins with BUCK files can be added to the build
192environment by cloning the source repository into the plugins
193subdirectory:
194
195----
196 git clone https://gerrit.googlesource.com/plugins/<name> plugins/<name>
197 echo /plugins/<name> >>.git/info/exclude
198----
199
200Additional plugin sources will be automatically added to Eclipse the
201next time project.py is run:
202
203----
204 tools/eclipse/project.py
205----
206
David Pursehouse90a9c102013-09-06 18:42:10 +0900207
208[[documentation]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800209=== Documentation
David Pursehouse90a9c102013-09-06 18:42:10 +0900210
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700211To build only the documentation for testing or static hosting:
David Pursehouse90a9c102013-09-06 18:42:10 +0900212
213----
214 buck build docs
215----
216
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700217The generated html files will NOT come with the search box, and will be
218placed in:
David Pursehouse90a9c102013-09-06 18:42:10 +0900219
220----
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700221 buck-out/gen/Documentation/searchfree__tmp/Documentation
David Pursehouse90a9c102013-09-06 18:42:10 +0900222----
223
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700224The html files will also be bundled into `searchfree.zip` in this location:
David Pursehouse90a9c102013-09-06 18:42:10 +0900225
David Ostrovsky7cd233e2013-09-26 07:21:31 +0200226----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900227 buck-out/gen/Documentation/searchfree/searchfree.zip
David Ostrovsky7cd233e2013-09-26 07:21:31 +0200228----
David Pursehouse90a9c102013-09-06 18:42:10 +0900229
David Pursehousec08d03e2013-12-10 18:16:10 +0900230To build the executable WAR with the documentation included:
231
232----
233 buck build withdocs
234----
235
236The WAR file will be placed in:
237
238----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900239 buck-out/gen/withdocs/withdocs.war
David Pursehousec08d03e2013-12-10 18:16:10 +0900240----
241
Shawn Pearce16570462015-01-14 16:27:42 -0800242[[soyc]]
243=== GWT Compile Report
244
245The GWT compiler can output a compile report (or "story of your compile"),
246describing the size of the JavaScript and which source classes contributed
247to the overall download size.
248
249----
250 buck build soyc
251----
252
253The report will be written as an HTML page to the extras directory, and
254can be opened and viewed in any web browser:
255
256----
257 extras/gerrit_ui/soycReport/compile-report/index.html
258----
259
260Only the "Split Point Report" is created, "Compiler Metrics" are not output.
261
David Ostrovsky811e6032013-09-06 08:35:45 +0200262[[release]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800263=== Gerrit Release WAR File
David Ostrovsky811e6032013-09-06 08:35:45 +0200264
265To build the release of the Gerrit web application, including documentation and
266all core plugins:
267
268----
269 buck build release
270----
271
272The output release WAR will be placed in:
273
274----
David Ostrovskyf377aa92015-09-14 17:46:28 +0900275 buck-out/gen/release/release.war
David Ostrovsky811e6032013-09-06 08:35:45 +0200276----
David Pursehouse0bc51db2013-05-14 12:46:49 +0900277
David Ostrovskye64e30d2014-03-25 06:25:56 -0700278[[all]]
279=== Combined build target
280
281To build release and api targets, a combined build target is provided:
282
283----
284 buck build all
285----
286
David Pursehouse5861a9a2013-05-15 10:25:19 +0900287[[tests]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800288== Running Unit Tests
David Pursehoused0525a72013-05-09 17:49:34 +0100289
Dave Borowitzafd7d392015-06-22 09:48:33 -0700290To run all tests including acceptance tests (but not flaky tests):
David Pursehoused0525a72013-05-09 17:49:34 +0100291
292----
Dave Borowitzafd7d392015-06-22 09:48:33 -0700293 buck test --exclude flaky
David Pursehoused0525a72013-05-09 17:49:34 +0100294----
295
Dave Borowitzafd7d392015-06-22 09:48:33 -0700296To exclude flaky and slow tests:
David Pursehoused0525a72013-05-09 17:49:34 +0100297
298----
Dave Borowitzafd7d392015-06-22 09:48:33 -0700299 buck test --exclude flaky slow
David Pursehoused0525a72013-05-09 17:49:34 +0100300----
301
Christian Aistleitner9fb58812015-06-21 19:46:11 +0200302To run only a specific group of acceptance tests:
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200303
304----
Christian Aistleitner9fb58812015-06-21 19:46:11 +0200305 buck test --include api
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200306----
307
308The following groups of tests are currently supported:
309
Christian Aistleitnerb03fc1a2015-06-21 19:49:12 +0200310* acceptance
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200311* api
David Ostrovsky4efb0f22014-12-18 08:55:13 +0100312* edit
Dave Borowitzafd7d392015-06-22 09:48:33 -0700313* flaky
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200314* git
315* pgm
316* rest
317* server
318* ssh
Christian Aistleitnerb03fc1a2015-06-21 19:49:12 +0200319* slow
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200320
David Ostrovskybb706152015-10-16 06:29:17 +0200321To run a specific test group, e.g. the rest-account test group:
Edwin Kempin674078a2013-08-20 11:37:14 +0200322
323----
David Ostrovskybb706152015-10-16 06:29:17 +0200324 buck test //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account:rest-account
Edwin Kempin674078a2013-08-20 11:37:14 +0200325----
326
David Ostrovskyfaec8052014-08-10 00:32:52 +0200327To create test coverage report:
328
329----
330 buck test --code-coverage --code-coverage-format html --no-results-cache
331----
332
333The HTML report is created in `buck-out/gen/jacoco/code-coverage/index.html`.
David Pursehoused0525a72013-05-09 17:49:34 +0100334
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800335== Dependencies
David Pursehoused0525a72013-05-09 17:49:34 +0100336
337Dependency JARs are normally downloaded automatically, but Buck can inspect
338its graph and download any missing JAR files. This is useful to enable
Shawn Pearcea7a3ee12013-09-20 10:42:37 -0700339subsequent builds to run without network access:
David Pursehoused0525a72013-05-09 17:49:34 +0100340
341----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -0700342 tools/download_all.py
David Pursehoused0525a72013-05-09 17:49:34 +0100343----
344
David Pursehouseb46cf492013-05-14 09:41:30 +0900345When downloading from behind a proxy (which is common in some corporate
346environments), it might be necessary to explicitly specify the proxy that
347is then used by `curl`:
348
349----
350 export http_proxy=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>
351----
352
Shawn Pearce1b89f852013-05-13 20:26:34 -0700353Redirection to local mirrors of Maven Central and the Gerrit storage
354bucket is supported by defining specific properties in
355`local.properties`, a file that is not tracked by Git:
356
357----
358 echo download.GERRIT = http://nexus.my-company.com/ >>local.properties
359 echo download.MAVEN_CENTRAL = http://nexus.my-company.com/ >>local.properties
360----
361
David Pursehouse6fb2c4d2013-05-16 16:51:46 +0900362The `local.properties` file may be placed in the root of the gerrit repository
363being built, or in `~/.gerritcodereview/`. The file in the root of the gerrit
364repository has precedence.
365
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800366== Building against unpublished Maven JARs
David Ostrovskyee9f9922013-08-15 00:21:04 +0200367
368To build against unpublished Maven JARs, like gwtorm or PrologCafe, the custom
David Pursehouseb99db5c2013-09-26 11:34:42 +0900369JARs must be installed in the local Maven repository (`mvn clean install`) and
370`maven_jar()` must be updated to point to the `MAVEN_LOCAL` Maven repository for
David Ostrovskyee9f9922013-08-15 00:21:04 +0200371that artifact:
372
David Pursehouseb99db5c2013-09-26 11:34:42 +0900373[source,python]
David Ostrovskyee9f9922013-08-15 00:21:04 +0200374----
375 maven_jar(
376 name = 'gwtorm',
377 id = 'gwtorm:gwtorm:42',
David Ostrovskyee9f9922013-08-15 00:21:04 +0200378 license = 'Apache2.0',
379 repository = MAVEN_LOCAL,
380 )
381----
382
David Ostrovsky07df9592014-02-01 23:47:22 +0100383== Building against unpublished JARs, that change frequently
384
385If a dependent Gerrit library is undergoing active development it must be
386recompiled and the change must be reflected in the Buck build process. For
387example testing Gerrit against changed JGit snapshot version. After building
388JGit library, the artifacts are created in local Maven build directory, e. g.:
389
390----
391 mvn package
392 /home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT.jar
393 /home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT-sources.jar
394----
395
396If as usual, installation of the build artifacts takes place in local maven
397repository, then the Buck build must fetch them from there with normal
398`download_file.py` process. Disadvantage of this approach is that Buck cache
399invalidation must occur to refresh the artifacts after next
400change-compile-install round trip.
401
402To shorten that workflow and take the installation of the artifacts to the
403local Maven repository and fetching it again from there out of the picture,
404`local_jar()` method is used instead of `maven_jar()`:
405
406[source,python]
407----
408 local_jar(
409 name = 'jgit',
410 jar = '/home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT.jar',
411 src = '/home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT-sources.jar',
412 deps = [':ewah']
413 )
414----
415
416This creates a symlink to the Buck targets direct against artifacts in
417another project's Maven target directory:
418
419----
420 buck-out/gen/lib/jgit/jgit.jar ->
421 /home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT.jar
422----
423
David Ostrovsky1a1b8b8a2014-10-23 22:37:58 +0200424After `buck clean` and `buck build lib/jgit:jgit` the symbolic link that was
425created the first time is lost due to Buck's caching mechanism. This means that
426when a new version of the local artifact is deployed (by running `mvn package`
427in the JGit project in the example above), Buck is not aware of it, because it
428still has a stale version of it in its cache.
429
430To solve this problem and re-create the symbolic link, you don't need to wipe out
431the entire Buck cache. Just rebuilding the target with the `--no-cache` option
432does the job:
433
434----
435 buck clean
436 buck build --no-cache lib/jgit:jgit
437----
438
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800439== Building against artifacts from custom Maven repositories
David Ostrovsky2536d062013-11-14 00:35:07 +0100440
441To build against custom Maven repositories, two modes of operations are
442supported: with rewrite in local.properties and without.
443
444Without rewrite the URL of custom Maven repository can be directly passed
445to the maven_jar() function:
446
447[source,python]
448----
449 GERRIT_FORGE = 'http://gerritforge.com/snapshot'
450
451 maven_jar(
452 name = 'gitblit',
453 id = 'com.gitblit:gitblit:1.4.0',
454 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
455 license = 'Apache2.0',
456 repository = GERRIT_FORGE,
457 )
458----
459
460When the custom URL has to be rewritten, then the same logic as with Gerrit
461known Maven repository is used: Repo name must be defined that matches an entry
462in local.properties file:
463
464----
465 download.GERRIT_FORGE = http://my.company.mirror/gerrit-forge
466----
467
468And corresponding BUCK excerpt:
469
470[source,python]
471----
472 GERRIT_FORGE = 'GERRIT_FORGE:'
473
474 maven_jar(
475 name = 'gitblit',
476 id = 'com.gitblit:gitblit:1.4.0',
477 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
478 license = 'Apache2.0',
479 repository = GERRIT_FORGE,
480 )
481----
482
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800483=== Caching Build Results
Shawn Pearce9e4e2432013-05-30 13:09:29 -0700484
485Build results can be locally cached, saving rebuild time when
486switching between Git branches. Buck's documentation covers
487caching in link:http://facebook.github.io/buck/concept/buckconfig.html[buckconfig].
488The trivial case using a local directory is:
489
490----
491 cat >.buckconfig.local <<EOF
492 [cache]
493 mode = dir
494 dir = buck-cache
495 EOF
496----
497
David Pursehouse6c3fd802014-10-24 13:50:44 +0900498[[clean-cache]]
499=== Cleaning The Buck Cache
500
501The cache for the Gerrit Code Review project is located in
Christian Aistleitner6f6de0d2015-03-26 14:25:03 +0100502`~/.gerritcodereview/buck-cache/locally-built-artifacts`.
David Pursehouse6c3fd802014-10-24 13:50:44 +0900503
504The Buck cache should never need to be manually deleted. If you find yourself
505deleting the Buck cache regularly, then it is likely that there is something
506wrong with your environment or your workflow.
507
508If you really do need to clean the cache manually, then:
509
510----
Christian Aistleitner6f6de0d2015-03-26 14:25:03 +0100511 rm -rf ~/.gerritcodereview/buck-cache/locally-built-artifacts
David Pursehouse6c3fd802014-10-24 13:50:44 +0900512----
513
Christian Aistleitner6f6de0d2015-03-26 14:25:03 +0100514Note that the root `buck-cache` folder should not be deleted as it also contains
515the `downloaded-artifacts` directory, which holds the artifacts that got
516downloaded (not built locally).
David Pursehouse6c3fd802014-10-24 13:50:44 +0900517
Edwin Kempin9a8b1dc2013-09-16 09:08:34 +0200518[[buck-daemon]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800519=== Using Buck daemon
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200520
David Pursehouseb99db5c2013-09-26 11:34:42 +0900521Buck ships with a daemon command `buckd`, which uses the
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200522link:https://github.com/martylamb/nailgun[Nailgun] protocol for running
523Java programs from the command line without incurring the JVM startup
David Pursehouseb99db5c2013-09-26 11:34:42 +0900524overhead.
525
526Using a Buck daemon can save significant amounts of time as it avoids the
527overhead of starting a Java virtual machine, loading the buck class files
528and parsing the build files for each command.
529
530It is safe to run several buck daemons started from different project
531directories and they will not interfere with each other. Buck's documentation
532covers daemon in http://facebook.github.io/buck/command/buckd.html[buckd].
533
David Ostrovsky26e3be62014-05-23 08:34:07 +0200534To use `buckd` the additional
535link:https://facebook.github.io/watchman[watchman] program must be installed.
536
David Ostrovsky37175422014-09-22 09:55:40 +0200537To disable `buckd`, the environment variable `NO_BUCKD` must be set. It's not
538recommended to put it in the shell config, as it can be forgotten about it and
539then assumed Buck was working as it should when it should be using buckd.
540Prepend the variable to Buck invocation instead:
541
542----
David Pursehouse8d4d3162014-10-24 13:57:06 +0900543 NO_BUCKD=1 buck build gerrit
David Ostrovsky37175422014-09-22 09:55:40 +0200544----
545
David Ostrovsky26e3be62014-05-23 08:34:07 +0200546[[watchman]]
547=== Installing watchman
548
549Watchman is used internally by Buck to monitor directory trees and is needed
550for buck daemon to work properly. Because buckd is activated by default in the
551latest version of Buck, it searches for the watchman executable in the
552path and issues a warning when it is not found and kills buckd.
553
554To prepare watchman installation on Linux:
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200555
556----
David Ostrovsky26e3be62014-05-23 08:34:07 +0200557 git clone https://github.com/facebook/watchman.git
558 cd watchman
559 ./autogen.sh
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200560----
561
David Ostrovsky26e3be62014-05-23 08:34:07 +0200562To install it in user home directory (without root privileges):
563
564----
565 ./configure --prefix $HOME/watchman
566 make install
567----
568
569To install it system wide:
570
571----
572 ./configure
573 make
574 sudo make install
575----
576
577Put $HOME/watchman/bin/watchman in path or link to $HOME/bin/watchman.
578
579To install watchman on OS X:
580
581----
582 brew install --HEAD watchman
583----
584
585See the original documentation for more information:
586link:https://facebook.github.io/watchman/docs/install.html[Watchman
587installation].
588
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800589=== Override Buck's settings
David Ostrovskyefaff302013-09-20 22:36:14 +0200590
Shawn Pearce4e1a8bc2013-11-28 18:38:30 -0800591Additional JVM args for Buck can be set in `.buckjavaargs` in the
592project root directory. For example to override Buck's default 1GB
593heap size:
David Ostrovskyefaff302013-09-20 22:36:14 +0200594
595----
Shawn Pearce4e1a8bc2013-11-28 18:38:30 -0800596 cat > .buckjavaargs <<EOF
597 -XX:MaxPermSize=512m -Xms8000m -Xmx16000m
David Ostrovskyefaff302013-09-20 22:36:14 +0200598 EOF
599----
600
David Ostrovskyfe2934e2014-04-22 00:36:12 +0200601== Rerun unit tests
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700602
David Pursehouse56f60a42014-07-10 11:20:33 +0900603Test execution results are cached by Buck. If a test that was already run
604needs to be repeated, the unit test cache for that test must be removed first:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700605
606----
David Ostrovskybb706152015-10-16 06:29:17 +0200607 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 -0700608----
609
David Pursehouse56f60a42014-07-10 11:20:33 +0900610After clearing the cache, the test can be run again:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700611
612----
David Ostrovskybb706152015-10-16 06:29:17 +0200613 buck test //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account:rest-account
614 [-] TESTING...FINISHED 12,3s (12 PASS/0 FAIL)
615 RESULTS FOR //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/account:rest-account
616 PASS 970ms 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.CapabilitiesIT
617 PASS 999ms 1 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.EditPreferencesIT
618 PASS 1,2s 1 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.GetAccountDetailIT
619 PASS 951ms 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.GetAccountIT
620 PASS 6,4s 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.GetDiffPreferencesIT
621 PASS 1,2s 4 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.PutUsernameIT
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700622 TESTS PASSED
623----
624
David Pursehouse56f60a42014-07-10 11:20:33 +0900625An alternative approach is to use Buck's `--filters` (`-f`) option:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700626
627----
David Ostrovsky7f660142015-10-16 17:24:17 +0200628 buck test -f 'com.google.gerrit.acceptance.rest.account.CapabilitiesIT'
629 Using buckd.
630 [-] PROCESSING BUCK FILES...FINISHED 1,0s [100%]
631 [-] BUILDING...FINISHED 2,8s [100%] (334/701 JOBS, 110 UPDATED, 5,1% CACHE MISS)
632 [-] TESTING...FINISHED 9,2s (6 PASS/0 FAIL)
David Ostrovskybb706152015-10-16 06:29:17 +0200633 RESULTS FOR SELECTED TESTS
David Ostrovsky7f660142015-10-16 17:24:17 +0200634 PASS 8,0s 2 Passed 0 Skipped 0 Failed com.google.gerrit.acceptance.rest.account.CapabilitiesIT
David Ostrovskybb706152015-10-16 06:29:17 +0200635 PASS <100ms 4 Passed 0 Skipped 0 Failed //tools:util_test
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700636 TESTS PASSED
637----
638
David Pursehouse56f60a42014-07-10 11:20:33 +0900639When this option is used, the cache is disabled per design and doesn't need to
David Ostrovsky7f660142015-10-16 17:24:17 +0200640be explicitly deleted. Note, that this is a known issue, that python tests are
641always executed.
David Pursehouse56f60a42014-07-10 11:20:33 +0900642
643Note that when this option is used, the whole unit test cache is dropped, so
David Ostrovsky074859e2014-04-19 22:52:47 +0200644repeating the
645
646----
David Pursehouse56f60a42014-07-10 11:20:33 +0900647buck test
David Ostrovsky074859e2014-04-19 22:52:47 +0200648----
649
David Pursehouse56f60a42014-07-10 11:20:33 +0900650causes all tests to be executed again.
651
652To run tests without using cached results at all, use the `--no-results-cache`
653option:
654
655----
656buck test --no-results-cache
657----
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700658
David Ostrovsky7674c522015-10-15 04:55:46 +0200659== Upgrading Buck
660
661The following tests should be executed, when Buck version is upgraded:
662
663* buck build release
664* buck build api_install
665* buck test
666* install and verify new gerrit site
667* upgrade and verify existing gerrit site
668* reindex existing gerrit site
669* verify that tools/eclipse/project.py produces sane Eclipse project
670* verify that tools/eclipse/project.py --src generates sources as well
671* verify that unit test execution from Eclipse works
672* verify that daemon started from Eclipse works
673* verify that GWT SDM debug session started from Eclipse works
674
David Ostrovsky44c7e612015-06-16 08:58:48 +0200675== Known issues and bugs
676
677=== Symbolic links and `watchman`
678
679`Buck` with activated `Watchman` has currently a
680[known bug](https://github.com/facebook/buck/issues/341) related to
681symbolic links. The symbolic links are used very often with external
682plugins, that are linked per symbolic link to the plugins directory.
683With this use case Buck is failing to rebuild the plugin artefact
684after it was built. All attempts to convince Buck to rebuild will fail.
685The only known way to recover is to weep out `buck-out` directory. The
686better workaround is to avoid using Watchman in this specific use case.
687Watchman can either be de-installed or disabled. See
688link:#buck-daemon[Using Buck daemon] section above how to temporarily
689disable `buckd`.
690
David Ostrovsky66f34292015-06-17 00:25:59 +0200691=== Re-triggering rule execution
692
693There is no way to re-trigger custom rules with side effects, like
694`api_{deploy|install}`. This is a `genrule()` that depends on Java sources
695and is deploying the Plugin API through custom Python script to the local or
696remote Maven repositories. When for some reasons the deployment was undone,
697there is no supported way to re-trigger the execution of `api_{deploy|install}`
698targets. That's because `--no-cache` option will ignore the `Buck` cache, but
699there is no way to ignore `buck-out` directory. To overcome this Buck's design
700limitation new `tools/maven/api.py` script was added, that always re-triggers
701installation or deployment of Plugin API to local or Central Maven repository.
702
703```
704 tools/maven/api.py {deploy|install}
705```
706
707Dry run mode is also supported:
708
709```
710 tools/maven/api.py -n {deploy|install}
711```
712
713With this script the deployment would re-trigger on every invocation.
714
David Pursehouse226eaf32014-12-18 17:49:28 +0900715== Troubleshooting Buck
716
717In some cases problems with Buck itself need to be investigated. See for example
718link:https://gerrit-review.googlesource.com/62411[this attempt to upgrade Buck]
719and link:https://github.com/facebook/buck/pull/227[the fix that was needed] to
720make the update possible.
721
722To build Gerrit with a custom version of Buck, the following steps are necessary:
723
7241. In the Buck git apply any necessary changes from pull requests
7252. Compile Buck with `ant`
7263. In the root of the Gerrit project create a `.nobuckcheck` file to prevent Buck
727from updating itself
7284. Replace the sha1 in Gerrit's `.buckversion` file with the required version from
729the custom Buck build
7305. Build Gerrit as usual
731
David Pursehoused0525a72013-05-09 17:49:34 +0100732GERRIT
733------
734Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700735
736SEARCHBOX
737---------