Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 1 | # Workflows |
| 2 | |
| 3 | ## Checkouts |
| 4 | |
| 5 | In order to make changes to DevTools frontend, build, run, test, and submit changes, several workflows exist. Having [depot_tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up) set up is a common prerequisite. |
| 6 | |
| 7 | ### Standalone checkout |
| 8 | |
| 9 | As a standalone project, Chrome DevTools frontend can be checked out and built independently from Chromium. The main advantage is not having to check out and build Chromium. |
| 10 | |
| 11 | However, to run layout tests, you need to use the [integrated checkout](#Integrated-checkout). |
| 12 | |
| 13 | #### Checking out source |
| 14 | |
| 15 | To check out the source for DevTools frontend only, follow these steps: |
| 16 | |
| 17 | ```bash |
| 18 | mkdir devtools |
| 19 | cd devtools |
| 20 | fetch devtools-frontend |
| 21 | ``` |
| 22 | |
| 23 | #### Build |
| 24 | |
| 25 | To build, follow these steps: |
| 26 | |
| 27 | ```bash |
| 28 | cd devtools-frontend |
| 29 | gn gen out/Default |
| 30 | autoninja -C out/Default |
| 31 | ``` |
| 32 | |
Tim van der Lippe | f407ef2 | 2021-02-04 13:56:38 | [diff] [blame] | 33 | The resulting build artifacts can be found in `out/Default/gen/front_end`. |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 34 | |
| 35 | #### Update to latest |
| 36 | |
| 37 | To update to latest tip of tree version: |
| 38 | |
| 39 | ```bash |
| 40 | git fetch origin |
| 41 | git checkout origin/master |
| 42 | gclient sync |
| 43 | ``` |
| 44 | |
| 45 | #### Run in a pre-built Chromium |
| 46 | |
| 47 | You can run a [build](#Build) of DevTools frontend in a pre-built Chromium in order to avoid the expensive Chromium build. For example, you can use the latest version of Chrome Canary, or the downloaded binary in `third_party/chrome`. |
| 48 | |
| 49 | ##### Running from file system |
| 50 | |
| 51 | This works with Chromium 79 or later. |
| 52 | **(Requires `brew install coreutils` on Mac.)** |
| 53 | |
| 54 | ```bash |
Tim van der Lippe | f407ef2 | 2021-02-04 13:56:38 | [diff] [blame] | 55 | <path-to-chrome>/chrome --custom-devtools-frontend=file://$(realpath out/Default/gen/front_end) |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 56 | ``` |
| 57 | |
Tim van der Lippe | f407ef2 | 2021-02-04 13:56:38 | [diff] [blame] | 58 | Note that `$(realpath out/Default/gen/front_end)` expands to the absolute path to build artifacts for DevTools frontend. |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 59 | |
| 60 | Open DevTools via F12 on Windows/Linux or Cmd+Option+I on Mac. |
| 61 | |
Jan Scheffler | 698810c | 2020-10-28 10:17:16 | [diff] [blame] | 62 | If you get errors along the line of `Uncaught TypeError: Cannot read property 'setInspectedTabId'` you probably specified an incorrect path - the path has to be absolute. On Mac and Linux, the file url will start with __three__ slashes: `file:///Users/...`. |
| 63 | |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 64 | Tip: You can inspect DevTools with DevTools by undocking DevTools and then opening a second instance of DevTools (F12 on Windows/Linux, Cmd+Option+I on Mac). |
| 65 | |
| 66 | ##### Running from remote URL |
| 67 | |
| 68 | This works with Chromium 85 or later. |
| 69 | |
Tim van der Lippe | f407ef2 | 2021-02-04 13:56:38 | [diff] [blame] | 70 | Serve the content of `out/Default/gen/front_end` on a web server, e.g. via `python -m http.server`. |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 71 | |
| 72 | Then point to that web server when starting Chromium, for example: |
| 73 | |
| 74 | ```bash |
| 75 | <path-to-chrome>/chrome --custom-devtools-frontend=http://localhost:8000/ |
| 76 | ``` |
| 77 | |
| 78 | Open DevTools via F12 on Windows/Linux or Cmd+Option+I on Mac. |
| 79 | |
| 80 | ##### Running in hosted mode |
| 81 | |
Tim van der Lippe | f407ef2 | 2021-02-04 13:56:38 | [diff] [blame] | 82 | Serve the content of `out/Default/gen/front_end` on a web server, e.g. via `python -m http.server`. |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 83 | |
| 84 | Then point to that web server when starting Chromium, for example: |
| 85 | |
| 86 | ```bash |
| 87 | <path-to-chrome>/chrome --custom-devtools-frontend=http://localhost:8000/ --remote-debugging-port=9222 |
| 88 | ``` |
| 89 | |
| 90 | In a regular Chrome tab, go to the URL `http://localhost:9222#custom=true`. It lists URLs that can be copied to new Chrome tabs to inspect individual debug targets. |
| 91 | |
| 92 | ### Integrated checkout |
| 93 | |
| 94 | The integrated workflow offers the best of both worlds, and allows for working on both Chromium and DevTools frontend side-by-side. This is strongly recommended for folks working primarily on DevTools. |
| 95 | |
| 96 | This workflow will ensure that your local setup is equivalent to how Chromium infrastructure tests your change. It comes in two flavors. |
| 97 | |
| 98 | A full [Chromium checkout](#Chromium-checkout) is a pre-requisite for the following steps. |
| 99 | |
| 100 | #### Remove existing devtools-frontend sub-repository |
| 101 | |
| 102 | First, you need to remove the existing devtools-frontend sub-repo from the Chromium checkout in `chromium/src/`. |
| 103 | |
| 104 | In `chromium/src`, run `gclient sync` to make sure you have installed all required submodules. |
| 105 | |
| 106 | ```bash |
| 107 | gclient sync |
| 108 | ``` |
| 109 | |
| 110 | Then, disable `gclient sync` for DevTools frontend inside of Chromium by editing `.gclient` config. From `chromium/src/`, run |
| 111 | |
| 112 | ```bash |
| 113 | vim $(gclient root)/.gclient |
| 114 | ``` |
| 115 | |
| 116 | In the `custom_deps` section, insert this line: |
| 117 | |
| 118 | ```python |
| 119 | "src/third_party/devtools-frontend/src": None, |
| 120 | ``` |
| 121 | |
| 122 | Then run |
| 123 | |
| 124 | ```bash |
| 125 | gclient sync -D |
| 126 | ``` |
| 127 | |
| 128 | This removes the DevTools frontend dependency. We now create a symlink to refer to the standalone checkout (execute in `chromium/src` and make sure that `third_party/devtools-frontend` exists): |
| 129 | |
| 130 | **(Note that the folder names do NOT include the trailing slash)** |
| 131 | |
| 132 | Following this step, there are two approaches to integrating the standalone devtools. |
| 133 | |
| 134 | #### Flavor 1: separate gclient projects |
| 135 | |
| 136 | The first approach is to have separate gclient projects, one for each repository, and manually |
| 137 | create a symlink. First, get a checkout of [DevTools frontend](#Standalone-checkout). |
| 138 | |
| 139 | To then create the symlink: |
| 140 | |
| 141 | ```bash |
| 142 | ln -s path/to/standalone/devtools-frontend third_party/devtools-frontend/src |
| 143 | ``` |
| 144 | |
| 145 | Running `gclient sync` in `chromium/src/` will update dependencies for the Chromium checkout. |
| 146 | Running `gclient sync` in `chromium/src/third_party/devtools-frontend/src` will update dependencies for the standalone checkout. |
| 147 | |
| 148 | #### Flavor 2: a single gclient project |
| 149 | |
| 150 | The second approach is to have a single gclient project that automatically gclient sync's all dependencies for both repositories |
| 151 | |
| 152 | After removing your devtools dependency, modify the .gclient file for `chromium/src` |
| 153 | to add the devtools project and a hook to automatically symlink (comments are optional): |
| 154 | |
| 155 | ```python |
| 156 | solutions = [ |
| 157 | { |
| 158 | # Chromium src project |
| 159 | "url": "https://chromium.googlesource.com/chromium/src.git", |
| 160 | "managed": False, |
| 161 | "name": "src", |
| 162 | "custom_deps": { |
| 163 | "src/third_party/devtools-frontend/src": None, |
| 164 | }, |
| 165 | "custom_vars": {}, |
| 166 | }, |
| 167 | { |
| 168 | # devtools-frontend project |
| 169 | "name": "devtools-frontend", |
| 170 | "url": "https://chromium.googlesource.com/devtools/devtools-frontend", |
| 171 | "custom_deps": {} |
| 172 | } |
| 173 | ] |
| 174 | ``` |
| 175 | |
| 176 | Run `gclient sync` once in `chromium/src/` to get the new devtools frontend checkout. |
| 177 | |
| 178 | To automatically symlink between `devtools-frontend` and `chromium/src`, you can add the following |
| 179 | hook to your `.gclient` file to manage your `chromium/src` repository after your list of solutions. |
| 180 | |
| 181 | ```python |
| 182 | hooks = [ |
| 183 | { |
| 184 | # Ensure devtools is symlinked in the correct location on every gclient sync |
| 185 | 'name': 'Symlink Depot Tools', |
| 186 | 'pattern': '.', |
| 187 | 'action': [ |
| 188 | 'python', |
| 189 | '<path>/<to>/devtools-frontend/scripts/deps/ensure_symlink.py', |
| 190 | '<path>/<to>/chromium/src', |
| 191 | '<path>/<to>/devtools-frontend' |
| 192 | ], |
| 193 | } |
| 194 | ] |
| 195 | ``` |
| 196 | |
| 197 | Running `gclient sync` anywhere within `chromium/src/` or `chromium/src/third_party/devtools-frontend/src` will update dependencies for both checkouts. Running `gclient sync -D` will not remove your symlink. |
| 198 | |
| 199 | ### Chromium checkout |
| 200 | |
| 201 | DevTools frontend can also be developed as part of the full Chromium checkout. |
| 202 | This workflow can be used to make small patches to DevTools as a Chromium engineer. |
| 203 | However, it is different to our infrastructure setup and how to execute general maintenance work, and therefore discouraged. |
| 204 | |
| 205 | #### Checking out source |
| 206 | |
| 207 | Follow [instructions](https://www.chromium.org/developers/how-tos/get-the-code) to check out Chromium. DevTools frontend can be found under `third_party/devtools-frontend/src/`. |
| 208 | |
| 209 | #### Build |
| 210 | |
Tim van der Lippe | f407ef2 | 2021-02-04 13:56:38 | [diff] [blame] | 211 | Refer to [instructions](https://www.chromium.org/developers/how-tos/get-the-code) to build Chromium. |
| 212 | To only build DevTools frontend, use `devtools_frontend_resources` as build target. |
| 213 | The resulting build artifacts for DevTools frontend can be found in `out/Default/gen/third_party/devtools-frontend/src/front_end`. |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 214 | |
| 215 | #### Run |
| 216 | |
| 217 | Run Chrome with bundled DevTools frontend: |
| 218 | |
| 219 | ```bash |
| 220 | out/Default/chrome |
| 221 | ``` |
| 222 | |
| 223 | ## Test |
| 224 | |
| 225 | ### DevTools frontend |
| 226 | |
| 227 | Test are available by running scripts in `scripts/test/`. Please refer to the [overview document](https://docs.google.com/document/d/1c2KLKoFMqLB2A9sNAHIhYb70XFyfBUBs5BZSYfQAT-Y/edit). The current test status can be seen at the [test waterfall](https://ci.chromium.org/p/devtools-frontend/g/main/console). |
| 228 | |
| 229 | ### Layout tests |
| 230 | |
| 231 | After building content shell as part of Chromium, we can also run layout tests that are relevant for DevTools frontend: |
| 232 | |
| 233 | ```bash |
| 234 | autoninja -C out/Default content_shell |
Alfonso Castaño | ae3dc89 | 2020-10-16 10:54:47 | [diff] [blame] | 235 | third_party/blink/tools/run_web_tests.py -t Default http/tests/devtools |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 236 | ``` |
| 237 | |
| 238 | ## Creating a change |
| 239 | |
| 240 | Usual [steps](https://chromium.googlesource.com/chromium/src/+/master/docs/contributing.md#creating-a-change) for creating a change work out of the box, when executed in the DevTools frontend repository. |
| 241 | |
| 242 | ## Managing dependencies |
| 243 | |
| 244 | - To sync dependencies from Chromium to DevTools frontend, use `scripts/deps/roll_deps.py && npm run generate-protocol-resources`. |
| 245 | |
| 246 | The following scripts run as AutoRollers, but can be manually invoked if desired: |
| 247 | |
| 248 | - To roll the HEAD commit of DevTools frontend into Chromium, use `scripts/deps/roll_to_chromium.py`. |
| 249 | - To update DevTools frontend's DEPS, use `roll-dep`. |
| 250 | |
Mathias Bynens | 5a8fc1f | 2020-08-24 07:40:12 | [diff] [blame] | 251 | ## Merges and cherry-picks |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 252 | |
Mathias Bynens | 5a8fc1f | 2020-08-24 07:40:12 | [diff] [blame] | 253 | _Merge request/approval is handled by Chromium Release Managers. DevTools follows [The Zen of Merge Requests](https://www.chromium.org/developers/the-zen-of-merge-requests). In exceptional cases please get in touch with [email protected]._ |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 254 | |
| 255 | Step-by-step guide on how to merge: |
| 256 | |
Mathias Bynens | a8c8707 | 2020-08-31 14:32:17 | [diff] [blame] | 257 | 1. Request approval to merge by adding the `Merge-Request-XX` label to the relevant crbug. A bot will come by and either ask for more info ([example](https://bugs.chromium.org/p/chromium/issues/detail?id=1123307#c1)) or approve the request. |
Mathias Bynens | 5a8fc1f | 2020-08-24 07:40:12 | [diff] [blame] | 258 | 1. Backmerges are done to the `chromium/xxxx` (e.g. `chromium/3979`) branch on the DevTools frontend repo. |
| 259 | Use <https://chromiumdash.appspot.com/branches> or [Omahaproxy](https://omahaproxy.appspot.com/) |
| 260 | to find out what branch a major Chromium version has (column `true_branch`). |
| 261 | 1. Open the to-be-merged commit in Gerrit |
| 262 | ([example](https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1928912)). |
| 263 | 1. Click the hamburger menu on the top right and select “Cherry pick”. |
| 264 | 1. Select the branch to merge to e.g. `chromium/3968`. |
| 265 | 1. The cherry-pick CL is created |
| 266 | ([example](https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1928913)). |
| 267 | 1. Get it reviewed if necessary. |
Mathias Bynens | a8c8707 | 2020-08-31 14:32:17 | [diff] [blame] | 268 | 1. Once merge request approval is granted (see step 1), click the hamburger menu on the cherry-pick CL and select “Submit”. (Setting the Commit-Queue bit (+2) has no effect because these branches don’t have a commit queue.) |
Mathias Bynens | 5a8fc1f | 2020-08-24 07:40:12 | [diff] [blame] | 269 | 1. Done. |
Yang Guo | 03e780e | 2020-06-17 10:18:09 | [diff] [blame] | 270 | |
| 271 | ## Useful Commands |
| 272 | |
| 273 | ### `git cl format --js` |
| 274 | |
| 275 | Formats all code using clang-format. |
| 276 | |
| 277 | ### `npm run check` |
| 278 | |
| 279 | Runs all static analysis checks on DevTools code. |