blob: 70fb35be887181e008c9da5b1d51b1e7eeeaf585 [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
70In Eclipse, choose 'Import existing project' and select the `gerrit` project
Edwin Kempin0d687ff2013-06-14 09:41:07 +020071from the current working directory.
David Pursehoused0525a72013-05-09 17:49:34 +010072
73Expand the `gerrit` project, right-click on the `buck-out` folder, select
74'Properties', and then under 'Attributes' check 'Derived'.
75
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070076Note that if you make any changes in the project configuration
77that get saved to the `.project` file, for example adding Resource
78Filters on a folder, they will be overwritten the next time you run
79`tools/eclipse/project.py`.
David Pursehouse38ba8802013-05-17 13:42:03 +010080
David Pursehouseb46cf492013-05-14 09:41:30 +090081
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080082=== Refreshing the Classpath
David Pursehoused0525a72013-05-09 17:49:34 +010083
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070084If an updated classpath is needed, the Eclipse project can be
85refreshed and missing dependency JARs can be downloaded:
David Pursehoused0525a72013-05-09 17:49:34 +010086
87----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -070088 tools/eclipse/project.py
David Pursehoused0525a72013-05-09 17:49:34 +010089----
90
91
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080092=== Attaching Sources
Shawn Pearce7b553262013-05-13 21:25:13 -070093
94To save time and bandwidth source JARs are only downloaded by the buck
95build where necessary to compile Java source into JavaScript using the
96GWT compiler. Additional sources may be obtained, allowing Eclipse to
97show documentation or dive into the implementation of a library JAR:
98
99----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -0700100 tools/eclipse/project.py --src
Shawn Pearce7b553262013-05-13 21:25:13 -0700101----
102
103
David Pursehouse6de7ee22013-05-20 11:08:51 +0900104[[build]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800105== Building on the Command Line
David Pursehoused0525a72013-05-09 17:49:34 +0100106
107
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800108=== Gerrit Development WAR File
David Pursehoused0525a72013-05-09 17:49:34 +0100109
110To build the Gerrit web application:
111
112----
113 buck build gerrit
114----
115
116The output executable WAR will be placed in:
117
118----
119 buck-out/gen/gerrit.war
120----
121
122
David Ostrovsky7a295332015-02-27 19:19:45 +0100123=== Headless Mode
124
125To build Gerrit in headless mode, i.e. without the GWT Web UI:
126
127----
128 buck build headless
129----
130
131The output executable WAR will be placed in:
132
133----
134 buck-out/gen/headless.war
135----
136
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800137=== Extension and Plugin API JAR Files
David Pursehoused0525a72013-05-09 17:49:34 +0100138
David Ostrovskye5487a02013-11-25 00:00:13 +0100139To build the extension, plugin and GWT API JAR files:
David Pursehoused0525a72013-05-09 17:49:34 +0100140
141----
142 buck build api
143----
144
David Ostrovskye5487a02013-11-25 00:00:13 +0100145Java binaries, Java sources and Java docs are generated into corresponding
David Pursehouse43dc7482013-12-13 14:54:42 +0900146project directories in `buck-out/gen`, here as example for plugin API:
David Pursehoused0525a72013-05-09 17:49:34 +0100147
148----
David Ostrovskye5487a02013-11-25 00:00:13 +0100149 buck-out/gen/gerrit-plugin-api/plugin-api.jar
150 buck-out/gen/gerrit-plugin-api/plugin-api-src.jar
151 buck-out/gen/gerrit-plugin-api/plugin-api-javadoc.jar
David Pursehoused0525a72013-05-09 17:49:34 +0100152----
153
David Ostrovsky358a4582014-05-13 23:55:04 +0200154Install {extension,plugin,gwt}-api to the local maven repository:
David Ostrovsky6e6a9672013-05-30 01:10:12 +0200155
156----
157 buck build api_install
158----
159
David Ostrovsky358a4582014-05-13 23:55:04 +0200160Install gerrit.war to the local maven repository:
161
162----
163 buck build war_install
164----
165
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800166=== Plugins
David Pursehouse0bc51db2013-05-14 12:46:49 +0900167
168To build all core plugins:
169
170----
171 buck build plugins:core
172----
173
174The output JAR files for individual plugins will be placed in:
175
176----
177 buck-out/gen/plugins/<name>/<name>.jar
178----
179
180The JAR files will also be packaged in:
181
182----
183 buck-out/gen/plugins/core.zip
184----
185
186To build a specific plugin:
187
188----
Shawn Pearce6586c202013-11-09 08:54:48 -0800189 buck build plugins/<name>:<name>
David Pursehouse0bc51db2013-05-14 12:46:49 +0900190----
191
192The output JAR file will be be placed in:
193
194----
195 buck-out/gen/plugins/<name>/<name>.jar
196----
197
198Note that when building an individual plugin, the `core.zip` package
199is not regenerated.
200
Shawn Pearce6586c202013-11-09 08:54:48 -0800201Additional plugins with BUCK files can be added to the build
202environment by cloning the source repository into the plugins
203subdirectory:
204
205----
206 git clone https://gerrit.googlesource.com/plugins/<name> plugins/<name>
207 echo /plugins/<name> >>.git/info/exclude
208----
209
210Additional plugin sources will be automatically added to Eclipse the
211next time project.py is run:
212
213----
214 tools/eclipse/project.py
215----
216
David Pursehouse90a9c102013-09-06 18:42:10 +0900217
218[[documentation]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800219=== Documentation
David Pursehouse90a9c102013-09-06 18:42:10 +0900220
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700221To build only the documentation for testing or static hosting:
David Pursehouse90a9c102013-09-06 18:42:10 +0900222
223----
224 buck build docs
225----
226
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700227The generated html files will NOT come with the search box, and will be
228placed in:
David Pursehouse90a9c102013-09-06 18:42:10 +0900229
230----
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700231 buck-out/gen/Documentation/searchfree__tmp/Documentation
David Pursehouse90a9c102013-09-06 18:42:10 +0900232----
233
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700234The html files will also be bundled into `searchfree.zip` in this location:
David Pursehouse90a9c102013-09-06 18:42:10 +0900235
David Ostrovsky7cd233e2013-09-26 07:21:31 +0200236----
Yuxuan 'fishy' Wangf7803972014-09-03 12:23:21 -0700237 buck-out/gen/Documentation/searchfree.zip
David Ostrovsky7cd233e2013-09-26 07:21:31 +0200238----
David Pursehouse90a9c102013-09-06 18:42:10 +0900239
David Pursehousec08d03e2013-12-10 18:16:10 +0900240To build the executable WAR with the documentation included:
241
242----
243 buck build withdocs
244----
245
246The WAR file will be placed in:
247
248----
249 buck-out/gen/withdocs.war
250----
251
Shawn Pearce16570462015-01-14 16:27:42 -0800252[[soyc]]
253=== GWT Compile Report
254
255The GWT compiler can output a compile report (or "story of your compile"),
256describing the size of the JavaScript and which source classes contributed
257to the overall download size.
258
259----
260 buck build soyc
261----
262
263The report will be written as an HTML page to the extras directory, and
264can be opened and viewed in any web browser:
265
266----
267 extras/gerrit_ui/soycReport/compile-report/index.html
268----
269
270Only the "Split Point Report" is created, "Compiler Metrics" are not output.
271
David Ostrovsky811e6032013-09-06 08:35:45 +0200272[[release]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800273=== Gerrit Release WAR File
David Ostrovsky811e6032013-09-06 08:35:45 +0200274
275To build the release of the Gerrit web application, including documentation and
276all core plugins:
277
278----
279 buck build release
280----
281
282The output release WAR will be placed in:
283
284----
285 buck-out/gen/release.war
286----
David Pursehouse0bc51db2013-05-14 12:46:49 +0900287
David Ostrovskye64e30d2014-03-25 06:25:56 -0700288[[all]]
289=== Combined build target
290
291To build release and api targets, a combined build target is provided:
292
293----
294 buck build all
295----
296
David Pursehouse5861a9a2013-05-15 10:25:19 +0900297[[tests]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800298== Running Unit Tests
David Pursehoused0525a72013-05-09 17:49:34 +0100299
Dave Borowitzafd7d392015-06-22 09:48:33 -0700300To run all tests including acceptance tests (but not flaky tests):
David Pursehoused0525a72013-05-09 17:49:34 +0100301
302----
Dave Borowitzafd7d392015-06-22 09:48:33 -0700303 buck test --exclude flaky
David Pursehoused0525a72013-05-09 17:49:34 +0100304----
305
Dave Borowitzafd7d392015-06-22 09:48:33 -0700306To exclude flaky and slow tests:
David Pursehoused0525a72013-05-09 17:49:34 +0100307
308----
Dave Borowitzafd7d392015-06-22 09:48:33 -0700309 buck test --exclude flaky slow
David Pursehoused0525a72013-05-09 17:49:34 +0100310----
311
Christian Aistleitner9fb58812015-06-21 19:46:11 +0200312To run only a specific group of acceptance tests:
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200313
314----
Christian Aistleitner9fb58812015-06-21 19:46:11 +0200315 buck test --include api
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200316----
317
318The following groups of tests are currently supported:
319
Christian Aistleitnerb03fc1a2015-06-21 19:49:12 +0200320* acceptance
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200321* api
David Ostrovsky4efb0f22014-12-18 08:55:13 +0100322* edit
Dave Borowitzafd7d392015-06-22 09:48:33 -0700323* flaky
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200324* git
325* pgm
326* rest
327* server
328* ssh
Christian Aistleitnerb03fc1a2015-06-21 19:49:12 +0200329* slow
David Ostrovskyc4e0ac62014-04-21 18:25:18 +0200330
Edwin Kempin674078a2013-08-20 11:37:14 +0200331To run a specific test, e.g. the acceptance test
332`com.google.gerrit.acceptance.git.HttpPushForReviewIT`:
333
334----
335 buck test //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git:HttpPushForReviewIT
336----
337
David Ostrovskyfaec8052014-08-10 00:32:52 +0200338To create test coverage report:
339
340----
341 buck test --code-coverage --code-coverage-format html --no-results-cache
342----
343
344The HTML report is created in `buck-out/gen/jacoco/code-coverage/index.html`.
David Pursehoused0525a72013-05-09 17:49:34 +0100345
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800346== Dependencies
David Pursehoused0525a72013-05-09 17:49:34 +0100347
348Dependency JARs are normally downloaded automatically, but Buck can inspect
349its graph and download any missing JAR files. This is useful to enable
Shawn Pearcea7a3ee12013-09-20 10:42:37 -0700350subsequent builds to run without network access:
David Pursehoused0525a72013-05-09 17:49:34 +0100351
352----
Shawn Pearcea7a3ee12013-09-20 10:42:37 -0700353 tools/download_all.py
David Pursehoused0525a72013-05-09 17:49:34 +0100354----
355
David Pursehouseb46cf492013-05-14 09:41:30 +0900356When downloading from behind a proxy (which is common in some corporate
357environments), it might be necessary to explicitly specify the proxy that
358is then used by `curl`:
359
360----
361 export http_proxy=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port>
362----
363
Shawn Pearce1b89f852013-05-13 20:26:34 -0700364Redirection to local mirrors of Maven Central and the Gerrit storage
365bucket is supported by defining specific properties in
366`local.properties`, a file that is not tracked by Git:
367
368----
369 echo download.GERRIT = http://nexus.my-company.com/ >>local.properties
370 echo download.MAVEN_CENTRAL = http://nexus.my-company.com/ >>local.properties
371----
372
David Pursehouse6fb2c4d2013-05-16 16:51:46 +0900373The `local.properties` file may be placed in the root of the gerrit repository
374being built, or in `~/.gerritcodereview/`. The file in the root of the gerrit
375repository has precedence.
376
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800377== Building against unpublished Maven JARs
David Ostrovskyee9f9922013-08-15 00:21:04 +0200378
379To build against unpublished Maven JARs, like gwtorm or PrologCafe, the custom
David Pursehouseb99db5c2013-09-26 11:34:42 +0900380JARs must be installed in the local Maven repository (`mvn clean install`) and
381`maven_jar()` must be updated to point to the `MAVEN_LOCAL` Maven repository for
David Ostrovskyee9f9922013-08-15 00:21:04 +0200382that artifact:
383
David Pursehouseb99db5c2013-09-26 11:34:42 +0900384[source,python]
David Ostrovskyee9f9922013-08-15 00:21:04 +0200385----
386 maven_jar(
387 name = 'gwtorm',
388 id = 'gwtorm:gwtorm:42',
David Ostrovskyee9f9922013-08-15 00:21:04 +0200389 license = 'Apache2.0',
390 repository = MAVEN_LOCAL,
391 )
392----
393
David Ostrovsky07df9592014-02-01 23:47:22 +0100394== Building against unpublished JARs, that change frequently
395
396If a dependent Gerrit library is undergoing active development it must be
397recompiled and the change must be reflected in the Buck build process. For
398example testing Gerrit against changed JGit snapshot version. After building
399JGit library, the artifacts are created in local Maven build directory, e. g.:
400
401----
402 mvn package
403 /home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT.jar
404 /home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT-sources.jar
405----
406
407If as usual, installation of the build artifacts takes place in local maven
408repository, then the Buck build must fetch them from there with normal
409`download_file.py` process. Disadvantage of this approach is that Buck cache
410invalidation must occur to refresh the artifacts after next
411change-compile-install round trip.
412
413To shorten that workflow and take the installation of the artifacts to the
414local Maven repository and fetching it again from there out of the picture,
415`local_jar()` method is used instead of `maven_jar()`:
416
417[source,python]
418----
419 local_jar(
420 name = 'jgit',
421 jar = '/home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT.jar',
422 src = '/home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT-sources.jar',
423 deps = [':ewah']
424 )
425----
426
427This creates a symlink to the Buck targets direct against artifacts in
428another project's Maven target directory:
429
430----
431 buck-out/gen/lib/jgit/jgit.jar ->
432 /home/<user>/projects/jgit/org.eclipse.jgit/target/org.eclipse.jgit-3.3.0-SNAPSHOT.jar
433----
434
David Ostrovsky1a1b8b8a2014-10-23 22:37:58 +0200435After `buck clean` and `buck build lib/jgit:jgit` the symbolic link that was
436created the first time is lost due to Buck's caching mechanism. This means that
437when a new version of the local artifact is deployed (by running `mvn package`
438in the JGit project in the example above), Buck is not aware of it, because it
439still has a stale version of it in its cache.
440
441To solve this problem and re-create the symbolic link, you don't need to wipe out
442the entire Buck cache. Just rebuilding the target with the `--no-cache` option
443does the job:
444
445----
446 buck clean
447 buck build --no-cache lib/jgit:jgit
448----
449
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800450== Building against artifacts from custom Maven repositories
David Ostrovsky2536d062013-11-14 00:35:07 +0100451
452To build against custom Maven repositories, two modes of operations are
453supported: with rewrite in local.properties and without.
454
455Without rewrite the URL of custom Maven repository can be directly passed
456to the maven_jar() function:
457
458[source,python]
459----
460 GERRIT_FORGE = 'http://gerritforge.com/snapshot'
461
462 maven_jar(
463 name = 'gitblit',
464 id = 'com.gitblit:gitblit:1.4.0',
465 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
466 license = 'Apache2.0',
467 repository = GERRIT_FORGE,
468 )
469----
470
471When the custom URL has to be rewritten, then the same logic as with Gerrit
472known Maven repository is used: Repo name must be defined that matches an entry
473in local.properties file:
474
475----
476 download.GERRIT_FORGE = http://my.company.mirror/gerrit-forge
477----
478
479And corresponding BUCK excerpt:
480
481[source,python]
482----
483 GERRIT_FORGE = 'GERRIT_FORGE:'
484
485 maven_jar(
486 name = 'gitblit',
487 id = 'com.gitblit:gitblit:1.4.0',
488 sha1 = '1b130dbf5578ace37507430a4a523f6594bf34fa',
489 license = 'Apache2.0',
490 repository = GERRIT_FORGE,
491 )
492----
493
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800494=== Caching Build Results
Shawn Pearce9e4e2432013-05-30 13:09:29 -0700495
496Build results can be locally cached, saving rebuild time when
497switching between Git branches. Buck's documentation covers
498caching in link:http://facebook.github.io/buck/concept/buckconfig.html[buckconfig].
499The trivial case using a local directory is:
500
501----
502 cat >.buckconfig.local <<EOF
503 [cache]
504 mode = dir
505 dir = buck-cache
506 EOF
507----
508
David Pursehouse6c3fd802014-10-24 13:50:44 +0900509[[clean-cache]]
510=== Cleaning The Buck Cache
511
512The cache for the Gerrit Code Review project is located in
513`~/.gerritcodereview/buck-cache/cache`.
514
515The Buck cache should never need to be manually deleted. If you find yourself
516deleting the Buck cache regularly, then it is likely that there is something
517wrong with your environment or your workflow.
518
519If you really do need to clean the cache manually, then:
520
521----
522 rm -rf ~/.gerritcodereview/buck-cache/cache
523----
524
525Note that the root `buck-cache` folder should not be deleted as this is where
526downloaded artifacts are stored.
527
Edwin Kempin9a8b1dc2013-09-16 09:08:34 +0200528[[buck-daemon]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800529=== Using Buck daemon
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200530
David Pursehouseb99db5c2013-09-26 11:34:42 +0900531Buck ships with a daemon command `buckd`, which uses the
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200532link:https://github.com/martylamb/nailgun[Nailgun] protocol for running
533Java programs from the command line without incurring the JVM startup
David Pursehouseb99db5c2013-09-26 11:34:42 +0900534overhead.
535
536Using a Buck daemon can save significant amounts of time as it avoids the
537overhead of starting a Java virtual machine, loading the buck class files
538and parsing the build files for each command.
539
540It is safe to run several buck daemons started from different project
541directories and they will not interfere with each other. Buck's documentation
542covers daemon in http://facebook.github.io/buck/command/buckd.html[buckd].
543
David Ostrovsky26e3be62014-05-23 08:34:07 +0200544To use `buckd` the additional
545link:https://facebook.github.io/watchman[watchman] program must be installed.
546
David Ostrovsky37175422014-09-22 09:55:40 +0200547To disable `buckd`, the environment variable `NO_BUCKD` must be set. It's not
548recommended to put it in the shell config, as it can be forgotten about it and
549then assumed Buck was working as it should when it should be using buckd.
550Prepend the variable to Buck invocation instead:
551
552----
David Pursehouse8d4d3162014-10-24 13:57:06 +0900553 NO_BUCKD=1 buck build gerrit
David Ostrovsky37175422014-09-22 09:55:40 +0200554----
555
David Ostrovsky26e3be62014-05-23 08:34:07 +0200556[[watchman]]
557=== Installing watchman
558
559Watchman is used internally by Buck to monitor directory trees and is needed
560for buck daemon to work properly. Because buckd is activated by default in the
561latest version of Buck, it searches for the watchman executable in the
562path and issues a warning when it is not found and kills buckd.
563
564To prepare watchman installation on Linux:
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200565
566----
David Ostrovsky26e3be62014-05-23 08:34:07 +0200567 git clone https://github.com/facebook/watchman.git
568 cd watchman
569 ./autogen.sh
David Ostrovskyd5ae8d32013-09-15 20:10:17 +0200570----
571
David Ostrovsky26e3be62014-05-23 08:34:07 +0200572To install it in user home directory (without root privileges):
573
574----
575 ./configure --prefix $HOME/watchman
576 make install
577----
578
579To install it system wide:
580
581----
582 ./configure
583 make
584 sudo make install
585----
586
587Put $HOME/watchman/bin/watchman in path or link to $HOME/bin/watchman.
588
589To install watchman on OS X:
590
591----
592 brew install --HEAD watchman
593----
594
595See the original documentation for more information:
596link:https://facebook.github.io/watchman/docs/install.html[Watchman
597installation].
598
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800599=== Override Buck's settings
David Ostrovskyefaff302013-09-20 22:36:14 +0200600
Shawn Pearce4e1a8bc2013-11-28 18:38:30 -0800601Additional JVM args for Buck can be set in `.buckjavaargs` in the
602project root directory. For example to override Buck's default 1GB
603heap size:
David Ostrovskyefaff302013-09-20 22:36:14 +0200604
605----
Shawn Pearce4e1a8bc2013-11-28 18:38:30 -0800606 cat > .buckjavaargs <<EOF
607 -XX:MaxPermSize=512m -Xms8000m -Xmx16000m
David Ostrovskyefaff302013-09-20 22:36:14 +0200608 EOF
609----
610
David Ostrovskyfe2934e2014-04-22 00:36:12 +0200611== Rerun unit tests
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700612
David Pursehouse56f60a42014-07-10 11:20:33 +0900613Test execution results are cached by Buck. If a test that was already run
614needs to be repeated, the unit test cache for that test must be removed first:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700615
616----
Dave Borowitzb800a612015-04-11 14:27:11 -0400617 rm -rf buck-out/bin/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/group/.AddRemoveGroupMembersIT/
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700618----
619
David Pursehouse56f60a42014-07-10 11:20:33 +0900620After clearing the cache, the test can be run again:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700621
622----
Dave Borowitzb800a612015-04-11 14:27:11 -0400623 buck test //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/group:AddRemoveGroupMembersIT
624 TESTING //gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/group:AddRemoveGroupMembersIT
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700625 PASS 14,9s 8 Passed 0 Failed com.google.gerrit.acceptance.rest.group.AddRemoveGroupMembersIT
626 TESTS PASSED
627----
628
David Pursehouse56f60a42014-07-10 11:20:33 +0900629An alternative approach is to use Buck's `--filters` (`-f`) option:
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700630
631----
David Pursehouse56f60a42014-07-10 11:20:33 +0900632 buck test -f 'com.google.gerrit.acceptance.rest.change.SubmitByMergeAlwaysIT'
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700633 TESTING SELECTED TESTS
634 PASS 14,5s 6 Passed 0 Failed com.google.gerrit.acceptance.rest.change.SubmitByMergeAlwaysIT
635 TESTS PASSED
636----
637
David Pursehouse56f60a42014-07-10 11:20:33 +0900638When this option is used, the cache is disabled per design and doesn't need to
639be explicitly deleted.
640
641Note that when this option is used, the whole unit test cache is dropped, so
David Ostrovsky074859e2014-04-19 22:52:47 +0200642repeating the
643
644----
David Pursehouse56f60a42014-07-10 11:20:33 +0900645buck test
David Ostrovsky074859e2014-04-19 22:52:47 +0200646----
647
David Pursehouse56f60a42014-07-10 11:20:33 +0900648causes all tests to be executed again.
649
650To run tests without using cached results at all, use the `--no-results-cache`
651option:
652
653----
654buck test --no-results-cache
655----
David Ostrovskya4ea92e72014-03-25 06:42:33 -0700656
David Ostrovsky44c7e612015-06-16 08:58:48 +0200657== Known issues and bugs
658
659=== Symbolic links and `watchman`
660
661`Buck` with activated `Watchman` has currently a
662[known bug](https://github.com/facebook/buck/issues/341) related to
663symbolic links. The symbolic links are used very often with external
664plugins, that are linked per symbolic link to the plugins directory.
665With this use case Buck is failing to rebuild the plugin artefact
666after it was built. All attempts to convince Buck to rebuild will fail.
667The only known way to recover is to weep out `buck-out` directory. The
668better workaround is to avoid using Watchman in this specific use case.
669Watchman can either be de-installed or disabled. See
670link:#buck-daemon[Using Buck daemon] section above how to temporarily
671disable `buckd`.
672
David Pursehouse226eaf32014-12-18 17:49:28 +0900673== Troubleshooting Buck
674
675In some cases problems with Buck itself need to be investigated. See for example
676link:https://gerrit-review.googlesource.com/62411[this attempt to upgrade Buck]
677and link:https://github.com/facebook/buck/pull/227[the fix that was needed] to
678make the update possible.
679
680To build Gerrit with a custom version of Buck, the following steps are necessary:
681
6821. In the Buck git apply any necessary changes from pull requests
6832. Compile Buck with `ant`
6843. In the root of the Gerrit project create a `.nobuckcheck` file to prevent Buck
685from updating itself
6864. Replace the sha1 in Gerrit's `.buckversion` file with the required version from
687the custom Buck build
6885. Build Gerrit as usual
689
David Pursehoused0525a72013-05-09 17:49:34 +0100690GERRIT
691------
692Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700693
694SEARCHBOX
695---------