OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright 2015 The Crashpad Authors. All rights reserved. |
| 3 |
| 4 Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 you may not use this file except in compliance with the License. |
| 6 You may obtain a copy of the License at |
| 7 |
| 8 http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
| 10 Unless required by applicable law or agreed to in writing, software |
| 11 distributed under the License is distributed on an "AS IS" BASIS, |
| 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 See the License for the specific language governing permissions and |
| 14 limitations under the License. |
| 15 --> |
| 16 |
| 17 # Developing Crashpad |
| 18 |
| 19 ## Status |
| 20 |
| 21 [Project status](status.md) information has moved to its own page. |
| 22 |
| 23 ## Introduction |
| 24 |
| 25 Crashpad is a [Chromium project](https://dev.chromium.org/Home). Most of its |
| 26 development practices follow Chromium’s. In order to function on its own in |
| 27 other projects, Crashpad uses |
| 28 [mini_chromium](https://chromium.googlesource.com/chromium/mini_chromium/), a |
| 29 small, self-contained library that provides many of Chromium’s useful low-level |
| 30 base routines. [mini_chromium’s |
| 31 README](https://chromium.googlesource.com/chromium/mini_chromium/+/master/README
.md) |
| 32 provides more detail. |
| 33 |
| 34 ## Prerequisites |
| 35 |
| 36 To develop Crashpad, the following tools are necessary, and must be present in |
| 37 the `$PATH` environment variable: |
| 38 |
| 39 * Appropriate development tools. For macOS, this is |
| 40 [Xcode](https://developer.apple.com/xcode/) and for Windows, it’s [Visual |
| 41 Studio](https://www.visualstudio.com/). |
| 42 * Chromium’s |
| 43 [depot_tools](https://dev.chromium.org/developers/how-tos/depottools). |
| 44 * [Git](https://git-scm.com/). This is provided by Xcode on macOS and by |
| 45 depot_tools on Windows. |
| 46 * [Python](https://www.python.org/). This is provided by the operating system |
| 47 on macOS, and by depot_tools on Windows. |
| 48 |
| 49 ## Getting the Source Code |
| 50 |
| 51 The main source code repository is a Git repository hosted at |
| 52 https://chromium.googlesource.com/crashpad/crashpad. Although it is possible to |
| 53 check out this repository directly with `git clone`, Crashpad’s dependencies are |
| 54 managed by |
| 55 [`gclient`](https://dev.chromium.org/developers/how-tos/depottools#TOC-gclient) |
| 56 instead of Git submodules, so to work on Crashpad, it is best to use `fetch` to |
| 57 get the source code. |
| 58 |
| 59 `fetch` and `gclient` are part of the |
| 60 [depot_tools](https://dev.chromium.org/developers/how-tos/depottools). There’s |
| 61 no need to install them separately. |
| 62 |
| 63 ### Initial Checkout |
| 64 |
| 65 ``` |
| 66 $ mkdir ~/crashpad |
| 67 $ cd ~/crashpad |
| 68 $ fetch crashpad |
| 69 ``` |
| 70 |
| 71 `fetch crashpad` performs the initial `git clone` and `gclient sync`, |
| 72 establishing a fully-functional local checkout. |
| 73 |
| 74 ### Subsequent Checkouts |
| 75 |
| 76 ``` |
| 77 $ cd ~/crashpad/crashpad |
| 78 $ git pull -r |
| 79 $ gclient sync |
| 80 ``` |
| 81 |
| 82 ## Building |
| 83 |
| 84 Crashpad uses [GYP](https://gyp.gsrc.io/) to generate |
| 85 [Ninja](https://ninja-build.org/) build files. The build is described by `.gyp` |
| 86 files throughout the Crashpad source code tree. The |
| 87 [`build/gyp_crashpad.py`](https://chromium.googlesource.com/crashpad/crashpad/+/
master/build/gyp_crashpad.py) |
| 88 script runs GYP properly for Crashpad, and is also called when you run `fetch |
| 89 crashpad`, `gclient sync`, or `gclient runhooks`. |
| 90 |
| 91 The Ninja build files and build output are in the `out` directory. Both debug- |
| 92 and release-mode configurations are available. The examples below show the debug |
| 93 configuration. To build and test the release configuration, substitute `Release` |
| 94 for `Debug`. |
| 95 |
| 96 ``` |
| 97 $ cd ~/crashpad/crashpad |
| 98 $ ninja -C out/Debug |
| 99 ``` |
| 100 |
| 101 Ninja is part of the |
| 102 [depot_tools](https://dev.chromium.org/developers/how-tos/depottools). There’s |
| 103 no need to install it separately. |
| 104 |
| 105 ### Android |
| 106 |
| 107 Crashpad’s Android port is in its early stages. This build relies on |
| 108 cross-compilation. It’s possible to develop Crashpad for Android on any platform |
| 109 that the [Android NDK (Native Development |
| 110 Kit)](https://developer.android.com/ndk/) runs on. |
| 111 |
| 112 If it’s not already present on your system, [download the NDK package for your |
| 113 system](https://developer.android.com/ndk/downloads/) and expand it to a |
| 114 suitable location. These instructions assume that it’s been expanded to |
| 115 `~/android-ndk-r13`. |
| 116 |
| 117 To build Crashpad, portions of the NDK must be reassembled into a [standalone |
| 118 toolchain](https://developer.android.com/ndk/guides/standalone_toolchain.html). |
| 119 This is a repackaged subset of the NDK suitable for cross-compiling for a single |
| 120 Android architecture (such as `arm`, `arm64`, `x86`, and `x86_64`) targeting a |
| 121 specific [Android API |
| 122 level](https://source.android.com/source/build-numbers.html). The standalone |
| 123 toolchain only needs to be built from the NDK one time for each set of options |
| 124 desired. To build a standalone toolchain targeting 64-bit ARM and API level 21 |
| 125 (Android 5.0 “Lollipop”), run: |
| 126 |
| 127 ``` |
| 128 $ cd ~ |
| 129 $ python android-ndk-r13/build/tools/make_standalone_toolchain.py \ |
| 130 --arch=arm64 --api=21 --install-dir=android-ndk-r13_arm64_api21 |
| 131 ``` |
| 132 |
| 133 Note that Chrome uses Android API level 21 for 64-bit platforms and 16 for |
| 134 32-bit platforms. See Chrome’s |
| 135 [`build/config/android/config.gni`](https://chromium.googlesource.com/chromium/s
rc/+/master/build/config/android/config.gni) |
| 136 which sets `_android_api_level` and `_android64_api_level`. |
| 137 |
| 138 To configure a Crashpad build for Android using this standalone toolchain, set |
| 139 several environment variables directing the build to the standalone toolchain, |
| 140 along with GYP options to identify an Android build. This must be done after any |
| 141 `gclient sync`, or instead of any `gclient runhooks` operation. The environment |
| 142 variables only need to be set for this `gyp_crashpad.py` invocation, and need |
| 143 not be permanent. |
| 144 |
| 145 ``` |
| 146 $ cd ~/crashpad/crashpad |
| 147 $ CC_target=~/android-ndk-r13_arm64_api21/bin/clang \ |
| 148 CXX_target=~/android-ndk-r13_arm64_api21/bin/clang++ \ |
| 149 AR_target=~/android-ndk-r13_arm64_api21/bin/aarch64-linux-android-ar \ |
| 150 NM_target=~/android-ndk-r13_arm64_api21/bin/aarch64-linux-android-nm \ |
| 151 READELF_target=~/android-ndk-r13_arm64_api21/bin/aarch64-linux-android-readelf
\ |
| 152 python build/gyp_crashpad.py \ |
| 153 -DOS=android -Dtarget_arch=arm64 -Dclang=1 \ |
| 154 --generator-output=out_android_arm64_api21 -f ninja-android |
| 155 ``` |
| 156 |
| 157 It is also possible to use GCC instead of Clang by making the appropriate |
| 158 substitutions: `aarch64-linux-android-gcc` for `CC_target`; |
| 159 `aarch64-linux-android-g++` for `CXX_target`; and `-Dclang=0` as an argument to |
| 160 `gyp_crashpad.py`. |
| 161 |
| 162 Target “triplets” to use for `ar`, `nm`, `readelf`, `gcc`, and `g++` are: |
| 163 |
| 164 | Architecture | Target “triplet” | |
| 165 |:-------------|:------------------------| |
| 166 | `arm` | `arm-linux-androideabi` | |
| 167 | `arm64` | `aarch64-linux-android` | |
| 168 | `x86` | `i686-linux-android` | |
| 169 | `x86_64` | `x86_64-linux-android` | |
| 170 |
| 171 The port is incomplete, but targets known to be working include `crashpad_util`, |
| 172 `crashpad_test`, and `crashpad_test_test`. This list will grow over time. To |
| 173 build, direct `ninja` to the specific `out` directory chosen by |
| 174 `--generator-output` above. |
| 175 |
| 176 ``` |
| 177 $ ninja -C out_android_arm64_api21/out/Debug crashpad_test_test |
| 178 ``` |
| 179 |
| 180 ## Testing |
| 181 |
| 182 Crashpad uses [Google Test](https://github.com/google/googletest/) as its |
| 183 unit-testing framework, and some tests use [Google |
| 184 Mock](https://github.com/google/googletest/tree/master/googlemock/) as well. Its |
| 185 tests are currently split up into several test executables, each dedicated to |
| 186 testing a different component. This may change in the future. After a successful |
| 187 build, the test executables will be found at `out/Debug/crashpad_*_test`. |
| 188 |
| 189 ``` |
| 190 $ cd ~/crashpad/crashpad |
| 191 $ out/Debug/crashpad_minidump_test |
| 192 $ out/Debug/crashpad_util_test |
| 193 ``` |
| 194 |
| 195 A script is provided to run all of Crashpad’s tests. It accepts a single |
| 196 argument that tells it which configuration to test. |
| 197 |
| 198 ``` |
| 199 $ cd ~/crashpad/crashpad |
| 200 $ python build/run_tests.py Debug |
| 201 ``` |
| 202 |
| 203 ### Android |
| 204 |
| 205 To test on Android, use [ADB (Android Debug |
| 206 Bridge)](https://developer.android.com/studio/command-line/adb.html) to `adb |
| 207 push` test executables and test data to a device or emulator, then use `adb |
| 208 shell` to get a shell to run the test executables from. ADB is part of the |
| 209 [Android SDK](https://developer.android.com/sdk/). Note that it is sufficient to |
| 210 install just the command-line tools. The entire Android Studio IDE is not |
| 211 necessary to obtain ADB. |
| 212 |
| 213 This example runs `crashpad_test_test` on a device. This test executable has a |
| 214 run-time dependency on a second executable and a test data file, which are also |
| 215 transferred to the device prior to running the test. |
| 216 |
| 217 ``` |
| 218 $ cd ~/crashpad/crashpad |
| 219 $ adb push out_android_arm64_api21/out/Debug/crashpad_test_test /data/local/tmp/ |
| 220 [100%] /data/local/tmp/crashpad_test_test |
| 221 $ adb push \ |
| 222 out_android_arm64_api21/out/Debug/crashpad_test_test_multiprocess_exec_tes
t_child \ |
| 223 /data/local/tmp/ |
| 224 [100%] /data/local/tmp/crashpad_test_test_multiprocess_exec_test_child |
| 225 $ adb shell mkdir -p /data/local/tmp/crashpad_test_data_root/test |
| 226 $ adb push test/paths_test_data_root.txt \ |
| 227 /data/local/tmp/crashpad_test_data_root/test/ |
| 228 [100%] /data/local/tmp/crashpad_test_data_root/test/paths_test_data_root.txt |
| 229 $ adb shell |
| 230 device:/ $ cd /data/local/tmp |
| 231 device:/data/local/tmp $ CRASHPAD_TEST_DATA_ROOT=crashpad_test_data_root \ |
| 232 ./crashpad_test_test |
| 233 ``` |
| 234 |
| 235 ## Contributing |
| 236 |
| 237 Crashpad’s contribution process is very similar to [Chromium’s contribution |
| 238 process](https://dev.chromium.org/developers/contributing-code). |
| 239 |
| 240 ### Code Review |
| 241 |
| 242 A code review must be conducted for every change to Crashpad’s source code. Code |
| 243 review is conducted on [Chromium’s |
| 244 Gerrit](https://chromium-review.googlesource.com/) system, and all code reviews |
| 245 must be sent to an appropriate reviewer, with a Cc sent to |
| 246 [crashpad-dev](https://groups.google.com/a/chromium.org/group/crashpad-dev). The |
| 247 [`codereview.settings`](https://chromium.googlesource.com/crashpad/crashpad/+/ma
ster/codereview.settings) |
| 248 file specifies this environment to `git-cl`. |
| 249 |
| 250 `git-cl` is part of the |
| 251 [depot_tools](https://dev.chromium.org/developers/how-tos/depottools). There’s |
| 252 no need to install it separately. |
| 253 |
| 254 ``` |
| 255 $ cd ~/crashpad/crashpad |
| 256 $ git checkout -b work_branch origin/master |
| 257 …do some work… |
| 258 $ git add … |
| 259 $ git commit |
| 260 $ git cl upload |
| 261 ``` |
| 262 |
| 263 The [PolyGerrit interface](https://polygerrit.appspot.com/) to Gerrit, |
| 264 undergoing active development, is recommended. To switch from the classic |
| 265 GWT-based Gerrit UI to PolyGerrit, click the PolyGerrit link in a Gerrit review |
| 266 page’s footer. |
| 267 |
| 268 Uploading a patch to Gerrit does not automatically request a review. You must |
| 269 select a reviewer on the Gerrit review page after running `git cl upload`. This |
| 270 action notifies your reviewer of the code review request. If you have lost track |
| 271 of the review page, `git cl issue` will remind you of its URL. Alternatively, |
| 272 you can request review when uploading to Gerrit by using `git cl upload |
| 273 --send-mail`. |
| 274 |
| 275 Git branches maintain their association with Gerrit reviews, so if you need to |
| 276 make changes based on review feedback, you can do so on the correct Git branch, |
| 277 committing your changes locally with `git commit`. You can then upload a new |
| 278 patch set with `git cl upload` and let your reviewer know you’ve addressed the |
| 279 feedback. |
| 280 |
| 281 ### Landing Changes |
| 282 |
| 283 After code review is complete and “Code-Review: +1” has been received from all |
| 284 reviewers, project members can commit the patch themselves: |
| 285 |
| 286 ``` |
| 287 $ cd ~/crashpad/crashpad |
| 288 $ git checkout work_branch |
| 289 $ git cl land |
| 290 ``` |
| 291 |
| 292 Alternatively, patches can be committed by clicking the “Submit” button in the |
| 293 Gerrit UI. |
| 294 |
| 295 Crashpad does not currently have a [commit |
| 296 queue](https://dev.chromium.org/developers/testing/commit-queue), so |
| 297 contributors who are not project members will have to ask a project member to |
| 298 commit the patch for them. Project members can commit changes on behalf of |
| 299 external contributors by clicking the “Submit” button in the Gerrit UI. |
| 300 |
| 301 ### External Contributions |
| 302 |
| 303 Copyright holders must complete the [Individual Contributor License |
| 304 Agreement](https://developers.google.com/open-source/cla/individual) or |
| 305 [Corporate Contributor License |
| 306 Agreement](https://developers.google.com/open-source/cla/corporate) as |
| 307 appropriate before any submission can be accepted, and must be listed in the |
| 308 [`AUTHORS`](https://chromium.googlesource.com/crashpad/crashpad/+/master/AUTHORS
) |
| 309 file. Contributors may be listed in the |
| 310 [`CONTRIBUTORS`](https://chromium.googlesource.com/crashpad/crashpad/+/master/CO
NTRIBUTORS) |
| 311 file. |
| 312 |
| 313 ## Buildbot |
| 314 |
| 315 The [Crashpad Buildbot](https://build.chromium.org/p/client.crashpad/) performs |
| 316 automated builds and tests of Crashpad. Before checking out or updating the |
| 317 Crashpad source code, and after checking in a new change, it is prudent to check |
| 318 the Buildbot to ensure that “the tree is green.” |
OLD | NEW |