Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Building with Buck |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 2 | |
| 3 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 4 | == Installation |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 5 | |
Deniz Türkoglu | d7559c0 | 2014-09-08 11:27:23 +0200 | [diff] [blame] | 6 | Note that you need to use Java 7 for building gerrit. |
| 7 | |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 8 | There is currently no binary distribution of Buck, so it has to be manually |
David Pursehouse | 64c1644 | 2013-05-14 10:49:03 +0900 | [diff] [blame] | 9 | built and installed. Apache Ant is required. Currently only Linux and Mac |
David Ostrovsky | 69349b4 | 2015-04-20 06:56:30 +0200 | [diff] [blame] | 10 | OS are supported. |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 11 | |
| 12 | Clone the git and build it: |
| 13 | |
| 14 | ---- |
David Pursehouse | 3e028c9 | 2015-04-16 16:00:59 +0900 | [diff] [blame] | 15 | git clone https://github.com/facebook/buck |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 16 | cd buck |
Shawn Pearce | 552c1b5 | 2014-11-27 11:48:28 -0800 | [diff] [blame] | 17 | git checkout $(cat ../gerrit/.buckversion) |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 18 | ant |
| 19 | ---- |
| 20 | |
David Pursehouse | e9803ab | 2014-03-12 14:15:10 +0900 | [diff] [blame] | 21 | If you don't have a `bin/` directory in your home directory, create one: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 22 | |
| 23 | ---- |
David Pursehouse | 64c1644 | 2013-05-14 10:49:03 +0900 | [diff] [blame] | 24 | mkdir ~/bin |
David Pursehouse | e9803ab | 2014-03-12 14:15:10 +0900 | [diff] [blame] | 25 | ---- |
| 26 | |
| 27 | Add the `~/bin` folder to the path: |
| 28 | |
| 29 | ---- |
David Pursehouse | 64c1644 | 2013-05-14 10:49:03 +0900 | [diff] [blame] | 30 | PATH=~/bin:$PATH |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 31 | ---- |
| 32 | |
David Pursehouse | e9803ab | 2014-03-12 14:15:10 +0900 | [diff] [blame] | 33 | Note that the buck executable needs to be available in all shell sessions, |
| 34 | so also make sure it is appended to the path globally. |
| 35 | |
David Pursehouse | 1d04f64 | 2014-09-10 11:09:02 +0200 | [diff] [blame] | 36 | Add a symbolic link in `~/bin` to the buck and buckd executables: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 37 | |
| 38 | ---- |
David Pursehouse | 64c1644 | 2013-05-14 10:49:03 +0900 | [diff] [blame] | 39 | ln -s `pwd`/bin/buck ~/bin/ |
David Pursehouse | 1d04f64 | 2014-09-10 11:09:02 +0200 | [diff] [blame] | 40 | ln -s `pwd`/bin/buckd ~/bin/ |
David Pursehouse | 64c1644 | 2013-05-14 10:49:03 +0900 | [diff] [blame] | 41 | ---- |
| 42 | |
David Pursehouse | 5c42b8c | 2013-05-17 13:25:47 +0100 | [diff] [blame] | 43 | Verify that `buck` is accessible: |
David Pursehouse | 64c1644 | 2013-05-14 10:49:03 +0900 | [diff] [blame] | 44 | |
| 45 | ---- |
| 46 | which buck |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 47 | ---- |
| 48 | |
David Pursehouse | be28499 | 2013-09-26 14:43:33 +0900 | [diff] [blame] | 49 | To enable autocompletion of buck commands, install the autocompletion |
David Pursehouse | ad4ed96 | 2014-09-10 11:09:26 +0200 | [diff] [blame] | 50 | script from `./scripts/buck_completion.bash` in the buck project. Refer |
| 51 | to the script's header comments for installation instructions. |
David Pursehouse | be28499 | 2013-09-26 14:43:33 +0900 | [diff] [blame] | 52 | |
David Ostrovsky | 69349b4 | 2015-04-20 06:56:30 +0200 | [diff] [blame] | 53 | == Prerequisites |
| 54 | |
| 55 | Buck requires Python version 2.7 to be installed. The Maven download toolchain |
| 56 | requires `curl` to be installed. |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 57 | |
David Pursehouse | 5861a9a | 2013-05-15 10:25:19 +0900 | [diff] [blame] | 58 | [[eclipse]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 59 | == Eclipse Integration |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 60 | |
| 61 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 62 | === Generating the Eclipse Project |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 63 | |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 64 | Create the Eclipse project: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 65 | |
| 66 | ---- |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 67 | tools/eclipse/project.py |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 68 | ---- |
| 69 | |
| 70 | In Eclipse, choose 'Import existing project' and select the `gerrit` project |
Edwin Kempin | 0d687ff | 2013-06-14 09:41:07 +0200 | [diff] [blame] | 71 | from the current working directory. |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 72 | |
| 73 | Expand the `gerrit` project, right-click on the `buck-out` folder, select |
| 74 | 'Properties', and then under 'Attributes' check 'Derived'. |
| 75 | |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 76 | Note that if you make any changes in the project configuration |
| 77 | that get saved to the `.project` file, for example adding Resource |
| 78 | Filters on a folder, they will be overwritten the next time you run |
| 79 | `tools/eclipse/project.py`. |
David Pursehouse | 38ba880 | 2013-05-17 13:42:03 +0100 | [diff] [blame] | 80 | |
David Pursehouse | b46cf49 | 2013-05-14 09:41:30 +0900 | [diff] [blame] | 81 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 82 | === Refreshing the Classpath |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 83 | |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 84 | If an updated classpath is needed, the Eclipse project can be |
| 85 | refreshed and missing dependency JARs can be downloaded: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 86 | |
| 87 | ---- |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 88 | tools/eclipse/project.py |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 89 | ---- |
| 90 | |
| 91 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 92 | === Attaching Sources |
Shawn Pearce | 7b55326 | 2013-05-13 21:25:13 -0700 | [diff] [blame] | 93 | |
| 94 | To save time and bandwidth source JARs are only downloaded by the buck |
| 95 | build where necessary to compile Java source into JavaScript using the |
| 96 | GWT compiler. Additional sources may be obtained, allowing Eclipse to |
| 97 | show documentation or dive into the implementation of a library JAR: |
| 98 | |
| 99 | ---- |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 100 | tools/eclipse/project.py --src |
Shawn Pearce | 7b55326 | 2013-05-13 21:25:13 -0700 | [diff] [blame] | 101 | ---- |
| 102 | |
| 103 | |
David Pursehouse | 6de7ee2 | 2013-05-20 11:08:51 +0900 | [diff] [blame] | 104 | [[build]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 105 | == Building on the Command Line |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 106 | |
| 107 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 108 | === Gerrit Development WAR File |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 109 | |
| 110 | To build the Gerrit web application: |
| 111 | |
| 112 | ---- |
| 113 | buck build gerrit |
| 114 | ---- |
| 115 | |
| 116 | The output executable WAR will be placed in: |
| 117 | |
| 118 | ---- |
| 119 | buck-out/gen/gerrit.war |
| 120 | ---- |
| 121 | |
| 122 | |
David Ostrovsky | 7a29533 | 2015-02-27 19:19:45 +0100 | [diff] [blame] | 123 | === Headless Mode |
| 124 | |
| 125 | To build Gerrit in headless mode, i.e. without the GWT Web UI: |
| 126 | |
| 127 | ---- |
| 128 | buck build headless |
| 129 | ---- |
| 130 | |
| 131 | The output executable WAR will be placed in: |
| 132 | |
| 133 | ---- |
| 134 | buck-out/gen/headless.war |
| 135 | ---- |
| 136 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 137 | === Extension and Plugin API JAR Files |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 138 | |
David Ostrovsky | e5487a0 | 2013-11-25 00:00:13 +0100 | [diff] [blame] | 139 | To build the extension, plugin and GWT API JAR files: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 140 | |
| 141 | ---- |
| 142 | buck build api |
| 143 | ---- |
| 144 | |
David Ostrovsky | e5487a0 | 2013-11-25 00:00:13 +0100 | [diff] [blame] | 145 | Java binaries, Java sources and Java docs are generated into corresponding |
David Pursehouse | 43dc748 | 2013-12-13 14:54:42 +0900 | [diff] [blame] | 146 | project directories in `buck-out/gen`, here as example for plugin API: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 147 | |
| 148 | ---- |
David Ostrovsky | e5487a0 | 2013-11-25 00:00:13 +0100 | [diff] [blame] | 149 | 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 Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 152 | ---- |
| 153 | |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 154 | Install {extension,plugin,gwt}-api to the local maven repository: |
David Ostrovsky | 6e6a967 | 2013-05-30 01:10:12 +0200 | [diff] [blame] | 155 | |
| 156 | ---- |
| 157 | buck build api_install |
| 158 | ---- |
| 159 | |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 160 | Install gerrit.war to the local maven repository: |
| 161 | |
| 162 | ---- |
| 163 | buck build war_install |
| 164 | ---- |
| 165 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 166 | === Plugins |
David Pursehouse | 0bc51db | 2013-05-14 12:46:49 +0900 | [diff] [blame] | 167 | |
| 168 | To build all core plugins: |
| 169 | |
| 170 | ---- |
| 171 | buck build plugins:core |
| 172 | ---- |
| 173 | |
| 174 | The output JAR files for individual plugins will be placed in: |
| 175 | |
| 176 | ---- |
| 177 | buck-out/gen/plugins/<name>/<name>.jar |
| 178 | ---- |
| 179 | |
| 180 | The JAR files will also be packaged in: |
| 181 | |
| 182 | ---- |
| 183 | buck-out/gen/plugins/core.zip |
| 184 | ---- |
| 185 | |
| 186 | To build a specific plugin: |
| 187 | |
| 188 | ---- |
Shawn Pearce | 6586c20 | 2013-11-09 08:54:48 -0800 | [diff] [blame] | 189 | buck build plugins/<name>:<name> |
David Pursehouse | 0bc51db | 2013-05-14 12:46:49 +0900 | [diff] [blame] | 190 | ---- |
| 191 | |
| 192 | The output JAR file will be be placed in: |
| 193 | |
| 194 | ---- |
| 195 | buck-out/gen/plugins/<name>/<name>.jar |
| 196 | ---- |
| 197 | |
| 198 | Note that when building an individual plugin, the `core.zip` package |
| 199 | is not regenerated. |
| 200 | |
Shawn Pearce | 6586c20 | 2013-11-09 08:54:48 -0800 | [diff] [blame] | 201 | Additional plugins with BUCK files can be added to the build |
| 202 | environment by cloning the source repository into the plugins |
| 203 | subdirectory: |
| 204 | |
| 205 | ---- |
| 206 | git clone https://gerrit.googlesource.com/plugins/<name> plugins/<name> |
| 207 | echo /plugins/<name> >>.git/info/exclude |
| 208 | ---- |
| 209 | |
| 210 | Additional plugin sources will be automatically added to Eclipse the |
| 211 | next time project.py is run: |
| 212 | |
| 213 | ---- |
| 214 | tools/eclipse/project.py |
| 215 | ---- |
| 216 | |
David Pursehouse | 90a9c10 | 2013-09-06 18:42:10 +0900 | [diff] [blame] | 217 | |
| 218 | [[documentation]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 219 | === Documentation |
David Pursehouse | 90a9c10 | 2013-09-06 18:42:10 +0900 | [diff] [blame] | 220 | |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 221 | To build only the documentation for testing or static hosting: |
David Pursehouse | 90a9c10 | 2013-09-06 18:42:10 +0900 | [diff] [blame] | 222 | |
| 223 | ---- |
| 224 | buck build docs |
| 225 | ---- |
| 226 | |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 227 | The generated html files will NOT come with the search box, and will be |
| 228 | placed in: |
David Pursehouse | 90a9c10 | 2013-09-06 18:42:10 +0900 | [diff] [blame] | 229 | |
| 230 | ---- |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 231 | buck-out/gen/Documentation/searchfree__tmp/Documentation |
David Pursehouse | 90a9c10 | 2013-09-06 18:42:10 +0900 | [diff] [blame] | 232 | ---- |
| 233 | |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 234 | The html files will also be bundled into `searchfree.zip` in this location: |
David Pursehouse | 90a9c10 | 2013-09-06 18:42:10 +0900 | [diff] [blame] | 235 | |
David Ostrovsky | 7cd233e | 2013-09-26 07:21:31 +0200 | [diff] [blame] | 236 | ---- |
Yuxuan 'fishy' Wang | f780397 | 2014-09-03 12:23:21 -0700 | [diff] [blame] | 237 | buck-out/gen/Documentation/searchfree.zip |
David Ostrovsky | 7cd233e | 2013-09-26 07:21:31 +0200 | [diff] [blame] | 238 | ---- |
David Pursehouse | 90a9c10 | 2013-09-06 18:42:10 +0900 | [diff] [blame] | 239 | |
David Pursehouse | c08d03e | 2013-12-10 18:16:10 +0900 | [diff] [blame] | 240 | To build the executable WAR with the documentation included: |
| 241 | |
| 242 | ---- |
| 243 | buck build withdocs |
| 244 | ---- |
| 245 | |
| 246 | The WAR file will be placed in: |
| 247 | |
| 248 | ---- |
| 249 | buck-out/gen/withdocs.war |
| 250 | ---- |
| 251 | |
Shawn Pearce | 1657046 | 2015-01-14 16:27:42 -0800 | [diff] [blame] | 252 | [[soyc]] |
| 253 | === GWT Compile Report |
| 254 | |
| 255 | The GWT compiler can output a compile report (or "story of your compile"), |
| 256 | describing the size of the JavaScript and which source classes contributed |
| 257 | to the overall download size. |
| 258 | |
| 259 | ---- |
| 260 | buck build soyc |
| 261 | ---- |
| 262 | |
| 263 | The report will be written as an HTML page to the extras directory, and |
| 264 | can be opened and viewed in any web browser: |
| 265 | |
| 266 | ---- |
| 267 | extras/gerrit_ui/soycReport/compile-report/index.html |
| 268 | ---- |
| 269 | |
| 270 | Only the "Split Point Report" is created, "Compiler Metrics" are not output. |
| 271 | |
David Ostrovsky | 811e603 | 2013-09-06 08:35:45 +0200 | [diff] [blame] | 272 | [[release]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 273 | === Gerrit Release WAR File |
David Ostrovsky | 811e603 | 2013-09-06 08:35:45 +0200 | [diff] [blame] | 274 | |
| 275 | To build the release of the Gerrit web application, including documentation and |
| 276 | all core plugins: |
| 277 | |
| 278 | ---- |
| 279 | buck build release |
| 280 | ---- |
| 281 | |
| 282 | The output release WAR will be placed in: |
| 283 | |
| 284 | ---- |
| 285 | buck-out/gen/release.war |
| 286 | ---- |
David Pursehouse | 0bc51db | 2013-05-14 12:46:49 +0900 | [diff] [blame] | 287 | |
David Ostrovsky | e64e30d | 2014-03-25 06:25:56 -0700 | [diff] [blame] | 288 | [[all]] |
| 289 | === Combined build target |
| 290 | |
| 291 | To build release and api targets, a combined build target is provided: |
| 292 | |
| 293 | ---- |
| 294 | buck build all |
| 295 | ---- |
| 296 | |
David Pursehouse | 5861a9a | 2013-05-15 10:25:19 +0900 | [diff] [blame] | 297 | [[tests]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 298 | == Running Unit Tests |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 299 | |
Dave Borowitz | afd7d39 | 2015-06-22 09:48:33 -0700 | [diff] [blame^] | 300 | To run all tests including acceptance tests (but not flaky tests): |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 301 | |
| 302 | ---- |
Dave Borowitz | afd7d39 | 2015-06-22 09:48:33 -0700 | [diff] [blame^] | 303 | buck test --exclude flaky |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 304 | ---- |
| 305 | |
Dave Borowitz | afd7d39 | 2015-06-22 09:48:33 -0700 | [diff] [blame^] | 306 | To exclude flaky and slow tests: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 307 | |
| 308 | ---- |
Dave Borowitz | afd7d39 | 2015-06-22 09:48:33 -0700 | [diff] [blame^] | 309 | buck test --exclude flaky slow |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 310 | ---- |
| 311 | |
Christian Aistleitner | 9fb5881 | 2015-06-21 19:46:11 +0200 | [diff] [blame] | 312 | To run only a specific group of acceptance tests: |
David Ostrovsky | c4e0ac6 | 2014-04-21 18:25:18 +0200 | [diff] [blame] | 313 | |
| 314 | ---- |
Christian Aistleitner | 9fb5881 | 2015-06-21 19:46:11 +0200 | [diff] [blame] | 315 | buck test --include api |
David Ostrovsky | c4e0ac6 | 2014-04-21 18:25:18 +0200 | [diff] [blame] | 316 | ---- |
| 317 | |
| 318 | The following groups of tests are currently supported: |
| 319 | |
Christian Aistleitner | b03fc1a | 2015-06-21 19:49:12 +0200 | [diff] [blame] | 320 | * acceptance |
David Ostrovsky | c4e0ac6 | 2014-04-21 18:25:18 +0200 | [diff] [blame] | 321 | * api |
David Ostrovsky | 4efb0f2 | 2014-12-18 08:55:13 +0100 | [diff] [blame] | 322 | * edit |
Dave Borowitz | afd7d39 | 2015-06-22 09:48:33 -0700 | [diff] [blame^] | 323 | * flaky |
David Ostrovsky | c4e0ac6 | 2014-04-21 18:25:18 +0200 | [diff] [blame] | 324 | * git |
| 325 | * pgm |
| 326 | * rest |
| 327 | * server |
| 328 | * ssh |
Christian Aistleitner | b03fc1a | 2015-06-21 19:49:12 +0200 | [diff] [blame] | 329 | * slow |
David Ostrovsky | c4e0ac6 | 2014-04-21 18:25:18 +0200 | [diff] [blame] | 330 | |
Edwin Kempin | 674078a | 2013-08-20 11:37:14 +0200 | [diff] [blame] | 331 | To 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 Ostrovsky | faec805 | 2014-08-10 00:32:52 +0200 | [diff] [blame] | 338 | To create test coverage report: |
| 339 | |
| 340 | ---- |
| 341 | buck test --code-coverage --code-coverage-format html --no-results-cache |
| 342 | ---- |
| 343 | |
| 344 | The HTML report is created in `buck-out/gen/jacoco/code-coverage/index.html`. |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 345 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 346 | == Dependencies |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 347 | |
| 348 | Dependency JARs are normally downloaded automatically, but Buck can inspect |
| 349 | its graph and download any missing JAR files. This is useful to enable |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 350 | subsequent builds to run without network access: |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 351 | |
| 352 | ---- |
Shawn Pearce | a7a3ee1 | 2013-09-20 10:42:37 -0700 | [diff] [blame] | 353 | tools/download_all.py |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 354 | ---- |
| 355 | |
David Pursehouse | b46cf49 | 2013-05-14 09:41:30 +0900 | [diff] [blame] | 356 | When downloading from behind a proxy (which is common in some corporate |
| 357 | environments), it might be necessary to explicitly specify the proxy that |
| 358 | is then used by `curl`: |
| 359 | |
| 360 | ---- |
| 361 | export http_proxy=http://<proxy_user_id>:<proxy_password>@<proxy_server>:<proxy_port> |
| 362 | ---- |
| 363 | |
Shawn Pearce | 1b89f85 | 2013-05-13 20:26:34 -0700 | [diff] [blame] | 364 | Redirection to local mirrors of Maven Central and the Gerrit storage |
| 365 | bucket 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 Pursehouse | 6fb2c4d | 2013-05-16 16:51:46 +0900 | [diff] [blame] | 373 | The `local.properties` file may be placed in the root of the gerrit repository |
| 374 | being built, or in `~/.gerritcodereview/`. The file in the root of the gerrit |
| 375 | repository has precedence. |
| 376 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 377 | == Building against unpublished Maven JARs |
David Ostrovsky | ee9f992 | 2013-08-15 00:21:04 +0200 | [diff] [blame] | 378 | |
| 379 | To build against unpublished Maven JARs, like gwtorm or PrologCafe, the custom |
David Pursehouse | b99db5c | 2013-09-26 11:34:42 +0900 | [diff] [blame] | 380 | JARs 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 Ostrovsky | ee9f992 | 2013-08-15 00:21:04 +0200 | [diff] [blame] | 382 | that artifact: |
| 383 | |
David Pursehouse | b99db5c | 2013-09-26 11:34:42 +0900 | [diff] [blame] | 384 | [source,python] |
David Ostrovsky | ee9f992 | 2013-08-15 00:21:04 +0200 | [diff] [blame] | 385 | ---- |
| 386 | maven_jar( |
| 387 | name = 'gwtorm', |
| 388 | id = 'gwtorm:gwtorm:42', |
David Ostrovsky | ee9f992 | 2013-08-15 00:21:04 +0200 | [diff] [blame] | 389 | license = 'Apache2.0', |
| 390 | repository = MAVEN_LOCAL, |
| 391 | ) |
| 392 | ---- |
| 393 | |
David Ostrovsky | 07df959 | 2014-02-01 23:47:22 +0100 | [diff] [blame] | 394 | == Building against unpublished JARs, that change frequently |
| 395 | |
| 396 | If a dependent Gerrit library is undergoing active development it must be |
| 397 | recompiled and the change must be reflected in the Buck build process. For |
| 398 | example testing Gerrit against changed JGit snapshot version. After building |
| 399 | JGit 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 | |
| 407 | If as usual, installation of the build artifacts takes place in local maven |
| 408 | repository, then the Buck build must fetch them from there with normal |
| 409 | `download_file.py` process. Disadvantage of this approach is that Buck cache |
| 410 | invalidation must occur to refresh the artifacts after next |
| 411 | change-compile-install round trip. |
| 412 | |
| 413 | To shorten that workflow and take the installation of the artifacts to the |
| 414 | local 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 | |
| 427 | This creates a symlink to the Buck targets direct against artifacts in |
| 428 | another 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 Ostrovsky | 1a1b8b8a | 2014-10-23 22:37:58 +0200 | [diff] [blame] | 435 | After `buck clean` and `buck build lib/jgit:jgit` the symbolic link that was |
| 436 | created the first time is lost due to Buck's caching mechanism. This means that |
| 437 | when a new version of the local artifact is deployed (by running `mvn package` |
| 438 | in the JGit project in the example above), Buck is not aware of it, because it |
| 439 | still has a stale version of it in its cache. |
| 440 | |
| 441 | To solve this problem and re-create the symbolic link, you don't need to wipe out |
| 442 | the entire Buck cache. Just rebuilding the target with the `--no-cache` option |
| 443 | does the job: |
| 444 | |
| 445 | ---- |
| 446 | buck clean |
| 447 | buck build --no-cache lib/jgit:jgit |
| 448 | ---- |
| 449 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 450 | == Building against artifacts from custom Maven repositories |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 451 | |
| 452 | To build against custom Maven repositories, two modes of operations are |
| 453 | supported: with rewrite in local.properties and without. |
| 454 | |
| 455 | Without rewrite the URL of custom Maven repository can be directly passed |
| 456 | to 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 | |
| 471 | When the custom URL has to be rewritten, then the same logic as with Gerrit |
| 472 | known Maven repository is used: Repo name must be defined that matches an entry |
| 473 | in local.properties file: |
| 474 | |
| 475 | ---- |
| 476 | download.GERRIT_FORGE = http://my.company.mirror/gerrit-forge |
| 477 | ---- |
| 478 | |
| 479 | And 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' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 494 | === Caching Build Results |
Shawn Pearce | 9e4e243 | 2013-05-30 13:09:29 -0700 | [diff] [blame] | 495 | |
| 496 | Build results can be locally cached, saving rebuild time when |
| 497 | switching between Git branches. Buck's documentation covers |
| 498 | caching in link:http://facebook.github.io/buck/concept/buckconfig.html[buckconfig]. |
| 499 | The 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 Pursehouse | 6c3fd80 | 2014-10-24 13:50:44 +0900 | [diff] [blame] | 509 | [[clean-cache]] |
| 510 | === Cleaning The Buck Cache |
| 511 | |
| 512 | The cache for the Gerrit Code Review project is located in |
| 513 | `~/.gerritcodereview/buck-cache/cache`. |
| 514 | |
| 515 | The Buck cache should never need to be manually deleted. If you find yourself |
| 516 | deleting the Buck cache regularly, then it is likely that there is something |
| 517 | wrong with your environment or your workflow. |
| 518 | |
| 519 | If you really do need to clean the cache manually, then: |
| 520 | |
| 521 | ---- |
| 522 | rm -rf ~/.gerritcodereview/buck-cache/cache |
| 523 | ---- |
| 524 | |
| 525 | Note that the root `buck-cache` folder should not be deleted as this is where |
| 526 | downloaded artifacts are stored. |
| 527 | |
Edwin Kempin | 9a8b1dc | 2013-09-16 09:08:34 +0200 | [diff] [blame] | 528 | [[buck-daemon]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 529 | === Using Buck daemon |
David Ostrovsky | d5ae8d3 | 2013-09-15 20:10:17 +0200 | [diff] [blame] | 530 | |
David Pursehouse | b99db5c | 2013-09-26 11:34:42 +0900 | [diff] [blame] | 531 | Buck ships with a daemon command `buckd`, which uses the |
David Ostrovsky | d5ae8d3 | 2013-09-15 20:10:17 +0200 | [diff] [blame] | 532 | link:https://github.com/martylamb/nailgun[Nailgun] protocol for running |
| 533 | Java programs from the command line without incurring the JVM startup |
David Pursehouse | b99db5c | 2013-09-26 11:34:42 +0900 | [diff] [blame] | 534 | overhead. |
| 535 | |
| 536 | Using a Buck daemon can save significant amounts of time as it avoids the |
| 537 | overhead of starting a Java virtual machine, loading the buck class files |
| 538 | and parsing the build files for each command. |
| 539 | |
| 540 | It is safe to run several buck daemons started from different project |
| 541 | directories and they will not interfere with each other. Buck's documentation |
| 542 | covers daemon in http://facebook.github.io/buck/command/buckd.html[buckd]. |
| 543 | |
David Ostrovsky | 26e3be6 | 2014-05-23 08:34:07 +0200 | [diff] [blame] | 544 | To use `buckd` the additional |
| 545 | link:https://facebook.github.io/watchman[watchman] program must be installed. |
| 546 | |
David Ostrovsky | 3717542 | 2014-09-22 09:55:40 +0200 | [diff] [blame] | 547 | To disable `buckd`, the environment variable `NO_BUCKD` must be set. It's not |
| 548 | recommended to put it in the shell config, as it can be forgotten about it and |
| 549 | then assumed Buck was working as it should when it should be using buckd. |
| 550 | Prepend the variable to Buck invocation instead: |
| 551 | |
| 552 | ---- |
David Pursehouse | 8d4d316 | 2014-10-24 13:57:06 +0900 | [diff] [blame] | 553 | NO_BUCKD=1 buck build gerrit |
David Ostrovsky | 3717542 | 2014-09-22 09:55:40 +0200 | [diff] [blame] | 554 | ---- |
| 555 | |
David Ostrovsky | 26e3be6 | 2014-05-23 08:34:07 +0200 | [diff] [blame] | 556 | [[watchman]] |
| 557 | === Installing watchman |
| 558 | |
| 559 | Watchman is used internally by Buck to monitor directory trees and is needed |
| 560 | for buck daemon to work properly. Because buckd is activated by default in the |
| 561 | latest version of Buck, it searches for the watchman executable in the |
| 562 | path and issues a warning when it is not found and kills buckd. |
| 563 | |
| 564 | To prepare watchman installation on Linux: |
David Ostrovsky | d5ae8d3 | 2013-09-15 20:10:17 +0200 | [diff] [blame] | 565 | |
| 566 | ---- |
David Ostrovsky | 26e3be6 | 2014-05-23 08:34:07 +0200 | [diff] [blame] | 567 | git clone https://github.com/facebook/watchman.git |
| 568 | cd watchman |
| 569 | ./autogen.sh |
David Ostrovsky | d5ae8d3 | 2013-09-15 20:10:17 +0200 | [diff] [blame] | 570 | ---- |
| 571 | |
David Ostrovsky | 26e3be6 | 2014-05-23 08:34:07 +0200 | [diff] [blame] | 572 | To install it in user home directory (without root privileges): |
| 573 | |
| 574 | ---- |
| 575 | ./configure --prefix $HOME/watchman |
| 576 | make install |
| 577 | ---- |
| 578 | |
| 579 | To install it system wide: |
| 580 | |
| 581 | ---- |
| 582 | ./configure |
| 583 | make |
| 584 | sudo make install |
| 585 | ---- |
| 586 | |
| 587 | Put $HOME/watchman/bin/watchman in path or link to $HOME/bin/watchman. |
| 588 | |
| 589 | To install watchman on OS X: |
| 590 | |
| 591 | ---- |
| 592 | brew install --HEAD watchman |
| 593 | ---- |
| 594 | |
| 595 | See the original documentation for more information: |
| 596 | link:https://facebook.github.io/watchman/docs/install.html[Watchman |
| 597 | installation]. |
| 598 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 599 | === Override Buck's settings |
David Ostrovsky | efaff30 | 2013-09-20 22:36:14 +0200 | [diff] [blame] | 600 | |
Shawn Pearce | 4e1a8bc | 2013-11-28 18:38:30 -0800 | [diff] [blame] | 601 | Additional JVM args for Buck can be set in `.buckjavaargs` in the |
| 602 | project root directory. For example to override Buck's default 1GB |
| 603 | heap size: |
David Ostrovsky | efaff30 | 2013-09-20 22:36:14 +0200 | [diff] [blame] | 604 | |
| 605 | ---- |
Shawn Pearce | 4e1a8bc | 2013-11-28 18:38:30 -0800 | [diff] [blame] | 606 | cat > .buckjavaargs <<EOF |
| 607 | -XX:MaxPermSize=512m -Xms8000m -Xmx16000m |
David Ostrovsky | efaff30 | 2013-09-20 22:36:14 +0200 | [diff] [blame] | 608 | EOF |
| 609 | ---- |
| 610 | |
David Ostrovsky | fe2934e | 2014-04-22 00:36:12 +0200 | [diff] [blame] | 611 | == Rerun unit tests |
David Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 612 | |
David Pursehouse | 56f60a4 | 2014-07-10 11:20:33 +0900 | [diff] [blame] | 613 | Test execution results are cached by Buck. If a test that was already run |
| 614 | needs to be repeated, the unit test cache for that test must be removed first: |
David Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 615 | |
| 616 | ---- |
Dave Borowitz | b800a61 | 2015-04-11 14:27:11 -0400 | [diff] [blame] | 617 | rm -rf buck-out/bin/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/group/.AddRemoveGroupMembersIT/ |
David Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 618 | ---- |
| 619 | |
David Pursehouse | 56f60a4 | 2014-07-10 11:20:33 +0900 | [diff] [blame] | 620 | After clearing the cache, the test can be run again: |
David Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 621 | |
| 622 | ---- |
Dave Borowitz | b800a61 | 2015-04-11 14:27:11 -0400 | [diff] [blame] | 623 | 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 Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 625 | PASS 14,9s 8 Passed 0 Failed com.google.gerrit.acceptance.rest.group.AddRemoveGroupMembersIT |
| 626 | TESTS PASSED |
| 627 | ---- |
| 628 | |
David Pursehouse | 56f60a4 | 2014-07-10 11:20:33 +0900 | [diff] [blame] | 629 | An alternative approach is to use Buck's `--filters` (`-f`) option: |
David Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 630 | |
| 631 | ---- |
David Pursehouse | 56f60a4 | 2014-07-10 11:20:33 +0900 | [diff] [blame] | 632 | buck test -f 'com.google.gerrit.acceptance.rest.change.SubmitByMergeAlwaysIT' |
David Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 633 | TESTING SELECTED TESTS |
| 634 | PASS 14,5s 6 Passed 0 Failed com.google.gerrit.acceptance.rest.change.SubmitByMergeAlwaysIT |
| 635 | TESTS PASSED |
| 636 | ---- |
| 637 | |
David Pursehouse | 56f60a4 | 2014-07-10 11:20:33 +0900 | [diff] [blame] | 638 | When this option is used, the cache is disabled per design and doesn't need to |
| 639 | be explicitly deleted. |
| 640 | |
| 641 | Note that when this option is used, the whole unit test cache is dropped, so |
David Ostrovsky | 074859e | 2014-04-19 22:52:47 +0200 | [diff] [blame] | 642 | repeating the |
| 643 | |
| 644 | ---- |
David Pursehouse | 56f60a4 | 2014-07-10 11:20:33 +0900 | [diff] [blame] | 645 | buck test |
David Ostrovsky | 074859e | 2014-04-19 22:52:47 +0200 | [diff] [blame] | 646 | ---- |
| 647 | |
David Pursehouse | 56f60a4 | 2014-07-10 11:20:33 +0900 | [diff] [blame] | 648 | causes all tests to be executed again. |
| 649 | |
| 650 | To run tests without using cached results at all, use the `--no-results-cache` |
| 651 | option: |
| 652 | |
| 653 | ---- |
| 654 | buck test --no-results-cache |
| 655 | ---- |
David Ostrovsky | a4ea92e7 | 2014-03-25 06:42:33 -0700 | [diff] [blame] | 656 | |
David Ostrovsky | 44c7e61 | 2015-06-16 08:58:48 +0200 | [diff] [blame] | 657 | == 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 |
| 663 | symbolic links. The symbolic links are used very often with external |
| 664 | plugins, that are linked per symbolic link to the plugins directory. |
| 665 | With this use case Buck is failing to rebuild the plugin artefact |
| 666 | after it was built. All attempts to convince Buck to rebuild will fail. |
| 667 | The only known way to recover is to weep out `buck-out` directory. The |
| 668 | better workaround is to avoid using Watchman in this specific use case. |
| 669 | Watchman can either be de-installed or disabled. See |
| 670 | link:#buck-daemon[Using Buck daemon] section above how to temporarily |
| 671 | disable `buckd`. |
| 672 | |
David Pursehouse | 226eaf3 | 2014-12-18 17:49:28 +0900 | [diff] [blame] | 673 | == Troubleshooting Buck |
| 674 | |
| 675 | In some cases problems with Buck itself need to be investigated. See for example |
| 676 | link:https://gerrit-review.googlesource.com/62411[this attempt to upgrade Buck] |
| 677 | and link:https://github.com/facebook/buck/pull/227[the fix that was needed] to |
| 678 | make the update possible. |
| 679 | |
| 680 | To build Gerrit with a custom version of Buck, the following steps are necessary: |
| 681 | |
| 682 | 1. In the Buck git apply any necessary changes from pull requests |
| 683 | 2. Compile Buck with `ant` |
| 684 | 3. In the root of the Gerrit project create a `.nobuckcheck` file to prevent Buck |
| 685 | from updating itself |
| 686 | 4. Replace the sha1 in Gerrit's `.buckversion` file with the required version from |
| 687 | the custom Buck build |
| 688 | 5. Build Gerrit as usual |
| 689 | |
David Pursehouse | d0525a7 | 2013-05-09 17:49:34 +0100 | [diff] [blame] | 690 | GERRIT |
| 691 | ------ |
| 692 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 693 | |
| 694 | SEARCHBOX |
| 695 | --------- |