Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 1 | # Chromium OS Development Basics |
| 2 | |
| 3 | This document covers guidelines to keep in mind when working on the Chromium OS |
| 4 | project. |
| 5 | |
| 6 | [TOC] |
| 7 | |
| 8 | ## Documentation |
| 9 | |
| 10 | ### General guidelines |
| 11 | |
| 12 | Chromium OS follows the Chromium project's [documentation guidelines] and |
| 13 | [documentation best practices]. |
| 14 | |
| 15 | ### Design documents |
| 16 | |
| 17 | Design documents typically describe the problem that you're trying to solve, |
| 18 | different approaches that you considered, and the path that you're planning to |
| 19 | take. They're useful for soliciting opinions from others before you start on the |
| 20 | implementation, but they also help your code reviewers get their bearings and |
| 21 | can answer other developers' "why was this done like that?" questions after the |
| 22 | work is complete (even after you've forgotten the reasons why!). On top of all |
| 23 | that, a design doc often helps you solidify a design in your own mind and |
| 24 | convince yourself that you're not missing anything. |
| 25 | |
| 26 | Most non-trivial additions of new functionality, and particularly ones that |
| 27 | require adding new daemons or new interactions between different processes, |
| 28 | should have their own design docs. For smaller changes, documenting what you're |
| 29 | doing and why in the issue tracker is often enough. |
| 30 | |
| 31 | Share your design docs with your team mailing list, if not with the full |
| 32 | [chromium-os-dev] mailing list. See the existing [Chromium OS design docs] and |
| 33 | [Chromium design docs] for inspiration. |
| 34 | |
| 35 | ## Programming languages and style |
| 36 | |
| 37 | ### C++ |
| 38 | |
| 39 | Nearly all userspace code in the Chromium OS project, whether it's part of the |
| 40 | Chrome browser itself or a system daemon exposing new functionality, is written |
| 41 | in C++. Do not use another language unless there's a compelling reason why C++ |
| 42 | can't work for what you're doing. (Being more familiar with another language |
| 43 | than with C++ is not a compelling reason.) |
| 44 | |
| 45 | The Chromium project, and by extension the Chromium OS project, follow the |
| 46 | [Google C++ style guide], with the [Chromium C++ style guide] layered on top to |
| 47 | provide additional guidelines and clarify ambiguities. The [C++11 use in |
| 48 | Chromium] document lists which of the many new features introduced in the C++11 |
| 49 | standard are allowed. |
| 50 | |
| 51 | New C++ programs should go into new directories in the [platform2 repository], |
| 52 | which is checked out to `src/platform2`. |
| 53 | |
| 54 | ### C |
| 55 | |
| 56 | C should only be used for code that is part of the Linux kernel or Chrome OS |
| 57 | firmware. |
| 58 | |
| 59 | Both kernel and firmware code should follow the [Linux kernel coding style]. The |
Jesse Barnes | 163a39e | 2020-07-24 17:34:42 | [diff] [blame] | 60 | [Kernel Development] guide has more details about Chrome OS kernel development, and the |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 61 | [EC Development page] discusses firmware. |
| 62 | |
| 63 | ### Shell |
| 64 | |
| 65 | Sometimes shell scripting can be the best way to perform lightweight, |
Daniel Erat | e3b67cd | 2017-03-29 00:22:42 | [diff] [blame] | 66 | non-persistent tasks that need to run periodically on Chrome OS systems, but |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 67 | there are also big downsides: it's much more difficult to write tests for shell |
| 68 | scripts than for C++ code, and scripts have a tendency to grow to the point |
| 69 | where they become difficult to maintain. If you're planning to add a shell |
| 70 | script that is likely to grow in complexity, consider instead using C++ from the |
| 71 | start to save yourself the trouble of rewriting it down the road. |
| 72 | |
| 73 | Shell scripts are mainly used for a few categories of tasks in Chrome OS: |
| 74 | |
| 75 | * Upstart initialization scripts, as in [src/platform2/init]. See the |
| 76 | [init STYLE file] and [init README file] for guidelines. |
Daniel Erat | e3b67cd | 2017-03-29 00:22:42 | [diff] [blame] | 77 | * Portage `.ebuild` files, as in the [chromiumos-overlay repository]. We |
| 78 | follow the upstream guidelines; see the [Ebuild Writing] page and |
| 79 | specifically the [Ebuild File Format]. |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 80 | * Miscellaneous development-related tasks |
| 81 | |
| 82 | Read the [Google shell style guide] and [Chromium OS shell style guidelines] |
| 83 | before writing scripts, with the caveat that the Upstart or Portage guidelines |
Daniel Erat | e3b67cd | 2017-03-29 00:22:42 | [diff] [blame] | 84 | take precedence when writing those types of scripts. |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 85 | |
Mattias Nissler | 32b6aab | 2017-04-06 12:28:11 | [diff] [blame] | 86 | For shell scripts that ship with the OS image, be extra careful. The shell |
| 87 | provides powerful features, but the flip side is that security pitfalls are |
| 88 | tricky to avoid. Think twice whether your shell statements can have unintended |
| 89 | side effects, in particular if your script runs with full privileges (as is the |
| 90 | case with init scripts). As a guideline, keep things simple and move more |
| 91 | complex processing to a properly sandboxed environment in an C++ daemon. |
| 92 | |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 93 | ### Python |
| 94 | |
| 95 | The Python interpreter is not included in production Chrome OS system images, |
| 96 | but Python is used heavily for development and testing. |
| 97 | |
| 98 | We largely follow the [Google Python style guide], but see the |
| 99 | [Chromium OS Python style guidelines] for important differences, particularly |
Daniel Erat | e3b67cd | 2017-03-29 00:22:42 | [diff] [blame] | 100 | around indenting and naming. For tests, see the [autotest coding style]. |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 101 | |
| 102 | ## Testing |
| 103 | |
Daniel Erat | 03138d4 | 2017-03-29 15:08:01 | [diff] [blame] | 104 | The [Chromium OS testing site] is the main repository of information about |
| 105 | testing. |
| 106 | |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 107 | ### Unit tests |
| 108 | |
| 109 | Unit tests should be added alongside new code. It's important to design your |
| 110 | code with testability in mind, as adding tests after-the-fact often requires |
| 111 | heavy refactoring. |
| 112 | |
| 113 | Good unit tests are fast, lightweight, reliable, and easy to run within the |
| 114 | chroot as part of your development workflow. We use [Google Test] (which is |
Daniel Erat | e3b67cd | 2017-03-29 00:22:42 | [diff] [blame] | 115 | comprised of the GoogleTest unit testing framework and the GoogleMock mocking |
| 116 | framework) to test C++ code. [Why Google C++ Testing Framework?] and the |
| 117 | [Google Test FAQ] are good introductions, and the [unit testing document] has |
| 118 | more details about how unit tests get run. |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 119 | |
Daniel Erat | e522833 | 2017-08-30 00:17:07 | [diff] [blame] | 120 | See the [Best practices for writing Chrome OS unit tests] document for more |
| 121 | guidance on writing good unit tests. |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 122 | |
| 123 | ### Autotest |
| 124 | |
| 125 | [Autotest] is used to run tests on live Chrome OS systems. Autotests are useful |
| 126 | for performing integration testing (e.g. verifying that two processes are able |
| 127 | to communicate with each other over IPC), but they have heavy costs: |
| 128 | |
| 129 | * Autotests are harder to run than unit tests: you need either a dedicated |
| 130 | test device or a virtual machine. |
| 131 | * Autotests are much slower than unit tests: even a no-op test can take 30 |
| 132 | seconds or longer per run. |
| 133 | * Since autotests involve at least a controlling system and a test device, |
| 134 | they're susceptible to networking issues and hardware flakiness. |
| 135 | * Since autotests run on full, live systems, failures can be caused by issues |
| 136 | in components unrelated to the one that you're trying to test. |
| 137 | |
| 138 | Whenever you can get equivalent coverage from either unit tests or autotests, |
| 139 | use unit tests. Design your system with unit testing in mind. |
| 140 | |
| 141 | ## Code reviews |
| 142 | |
| 143 | The Chromium OS project follows the [Chromium code review policy]: all code and |
| 144 | data changes must be reviewed by another project member before being committed. |
| 145 | Note that Chromium OS's review process has some differences; see the |
| 146 | [Developer Guide's code review instructions]. |
| 147 | |
| 148 | OWNERS files are not (yet) enforced for non-browser parts of the Chromium OS |
| 149 | codebase, but please act as if they were. If there's an OWNERS file in the |
| 150 | directory that you're modifying or a parent directory, add at least one |
| 151 | developer that's listed in it to your code review and wait for their approval |
| 152 | before committing your change. |
| 153 | |
| 154 | Owners may want to consider setting up notifications for changes to their code. |
| 155 | To receive notifications of changes to `src/platform2/debugd`, open your |
| 156 | [Gerrit notification settings] and add a new entry for project |
| 157 | `chromiumos/platform2` and expression `file:"^debugd/.*"`. |
| 158 | |
| 159 | ## Issue trackers |
| 160 | |
| 161 | Public Chromium OS bugs and feature requests are tracked using the |
| 162 | [chromium issue tracker]. Note that this tracker is shared with the Chromium |
| 163 | project; most OS-specific issues are classified under an `OS>`-prefixed |
| 164 | component and have an `OS=Chrome` label. The `crbug.com` redirector makes it |
| 165 | easy to jump directly to an issue with a given ID; `https://crbug.com/123` will |
| 166 | redirect to issue #123, for instance. |
| 167 | |
| 168 | Keep discussion in the issue tracker instead of in email or over IM. Issues |
| 169 | remain permanently available and are viewable by people not present for the |
| 170 | original discussion; email and IM exchanges are harder to find after the fact |
| 171 | and may even be deleted automatically. `BUG=chromium:123` lines in commit |
| 172 | descriptions and `https://crbug.com/123` mentions in code comments also make it |
| 173 | easy to link back to the issue that describes the original motivation for a |
| 174 | change. |
| 175 | |
| 176 | Avoid discussing multiple problems in a single issue. It's not possible to split |
| 177 | an existing issue into multiple new issues, and it can take a long time to read |
| 178 | through an issue's full history to figure out what is currently being discussed. |
| 179 | |
| 180 | Similarly, do not reopen an old, closed issue in response to the reoccurrence of |
| 181 | a bug: the old issue probably contains now-irrelevant milestone and merge labels |
| 182 | and outdated information. Instead, create a new issue and refer to the prior |
| 183 | issue in its initial description. Text of the form `issue 123` will |
| 184 | automatically be turned into a link. |
| 185 | |
Daniel Erat | 03138d4 | 2017-03-29 15:08:01 | [diff] [blame] | 186 | There is much more information about filing bugs and using labels in the |
| 187 | [Chromium bug reporting guidelines]. |
| 188 | |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 189 | ## Mailing lists |
| 190 | |
Mike Frysinger | 9874841 | 2018-10-09 07:56:19 | [diff] [blame] | 191 | See the [contact] document for more details. |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 192 | |
| 193 | ## Developing in the open |
| 194 | |
| 195 | Chromium OS is an open-source project. Whenever possible (i.e. when not |
| 196 | discussing private, partner-related information), use the public issue tracker |
| 197 | and mailing lists rather than the internal versions. |
| 198 | |
Mike Frysinger | 9874841 | 2018-10-09 07:56:19 | [diff] [blame] | 199 | [contact]: contact.md |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 200 | [documentation guidelines]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/documentation_guidelines.md |
| 201 | [documentation best practices]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/documentation_best_practices.md |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 202 | [Chromium OS design docs]: https://www.chromium.org/chromium-os/chromiumos-design-docs |
| 203 | [Chromium design docs]: https://www.chromium.org/developers/design-documents |
| 204 | [Google C++ style guide]: https://google.github.io/styleguide/cppguide.html |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 205 | [Chromium C++ style guide]: https://chromium.googlesource.com/chromium/src/+/HEAD/styleguide/c++/c++.md |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 206 | [C++11 use in Chromium]: https://chromium-cpp.appspot.com/ |
Evan Benn | 4811c3a | 2019-10-31 00:18:42 | [diff] [blame] | 207 | [platform2 repository]: platform2_primer.md |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 208 | [Linux kernel coding style]: https://github.com/torvalds/linux/blob/HEAD/Documentation/process/coding-style.rst |
Jesse Barnes | 704211c | 2020-07-22 21:37:32 | [diff] [blame] | 209 | [Kernel Development]: kernel_development.md |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 210 | [EC Development page]: https://chromium.googlesource.com/chromiumos/platform/ec/+/HEAD/README.md |
| 211 | [src/platform2/init]: https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/init/ |
| 212 | [init STYLE file]: https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/init/STYLE |
| 213 | [init README file]: https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/init/README |
Mike Frysinger | 2db7b85 | 2020-09-10 08:37:44 | [diff] [blame^] | 214 | [chromiumos-overlay repository]: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 215 | [Ebuild Writing]: https://devmanual.gentoo.org/ebuild-writing/index.html |
| 216 | [Ebuild File Format]: https://devmanual.gentoo.org/ebuild-writing/file-format/index.html |
| 217 | [Google shell style guide]: https://google.github.io/styleguide/shell.xml |
Evan Benn | 4811c3a | 2019-10-31 00:18:42 | [diff] [blame] | 218 | [Chromium OS shell style guidelines]: styleguide/shell.md |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 219 | [Google Python style guide]: https://google.github.io/styleguide/pyguide.html |
Evan Benn | 4811c3a | 2019-10-31 00:18:42 | [diff] [blame] | 220 | [Chromium OS Python style guidelines]: styleguide/python.md |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 221 | [autotest coding style]: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/HEAD/docs/coding-style.md |
Daniel Erat | 03138d4 | 2017-03-29 15:08:01 | [diff] [blame] | 222 | [Chromium OS testing site]: https://www.chromium.org/chromium-os/testing |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 223 | [Google Test]: https://github.com/google/googletest |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 224 | [Why Google C++ Testing Framework?]: https://github.com/google/googletest/blob/HEAD/googletest/docs/primer.md |
| 225 | [Google Test FAQ]: https://github.com/google/googletest/blob/HEAD/googletest/docs/faq.md |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 226 | [unit testing document]: https://www.chromium.org/chromium-os/testing/adding-unit-tests-to-the-build |
Andrew McRae | 319c4f0 | 2019-10-03 01:59:43 | [diff] [blame] | 227 | [Best practices for writing Chrome OS unit tests]: testing/unit_tests.md |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 228 | [Autotest]: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/HEAD/docs/user-doc.md |
| 229 | [Chromium code review policy]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/code_reviews.md |
Evan Benn | 4811c3a | 2019-10-31 00:18:42 | [diff] [blame] | 230 | [Developer Guide's code review instructions]: developer_guide.md#Upload-your-changes-and-get-a-code-review |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 231 | [Gerrit notification settings]: https://chromium-review.googlesource.com/settings/#Notifications |
Mike Frysinger | 9fc0fc0 | 2020-09-05 05:18:57 | [diff] [blame] | 232 | [chromium issue tracker]: https://crbug.com/ |
Daniel Erat | 03138d4 | 2017-03-29 15:08:01 | [diff] [blame] | 233 | [Chromium bug reporting guidelines]: https://www.chromium.org/for-testers/bug-reporting-guidelines |
Daniel Erat | 0576ce7 | 2017-03-27 05:43:06 | [diff] [blame] | 234 | [chromium-os-dev]: https://groups.google.com/a/chromium.org/forum/#!forum/chromium-os-dev |