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