blob: 5e374a0b21a8a99a008641e81331ea10876e3e14 [file] [log] [blame] [view]
btolschbaab5a12018-03-21 14:28:59 -07001# Open Screen Library
2
mark a. foltz616a1182021-07-14 16:20:03 -07003The Open Screen Library implements the Open Screen Protocol and the Chromecast
4protocols (discovery, application control, and media streaming).
mark a. foltz743b6202019-08-29 14:43:43 -07005
mark a. foltz616a1182021-07-14 16:20:03 -07006Information about the Open Screen Protocol and its specification can be found
7[on GitHub](https://w3c.github.io/openscreenprotocol/).
btolschbaab5a12018-03-21 14:28:59 -07008
mark a. foltz522f6b92019-10-21 17:49:59 -07009# Getting the code
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080010
mark a. foltz522f6b92019-10-21 17:49:59 -070011## Installing depot_tools
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080012
mark a. foltz616a1182021-07-14 16:20:03 -070013Library dependencies are managed using `gclient`, from the
mark a. foltz20103872019-03-15 15:46:03 -070014[depot_tools](https://www.chromium.org/developers/how-tos/depottools) repo.
15
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080016To get gclient, run the following command in your terminal:
17```bash
18 git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
19```
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080020
mark a. foltz20103872019-03-15 15:46:03 -070021Then add the `depot_tools` folder to your `PATH` environment variable.
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080022
mark a. foltz20103872019-03-15 15:46:03 -070023Note that openscreen does not use other features of `depot_tools` like `repo` or
Jordan Baylesc49eea62021-04-14 11:39:18 -070024`drover`. However, some `git-cl` functions *do* work, like `git cl try`,
25`git cl format`, `git cl lint`, and `git cl upload.`
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080026
mark a. foltz522f6b92019-10-21 17:49:59 -070027## Checking out code
mark a. foltz20103872019-03-15 15:46:03 -070028
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080029From the parent directory of where you want the openscreen checkout (e.g.,
30`~/my_project_dir`), configure `gclient` and check out openscreen with the
31following commands:
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080032
33```bash
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080034 cd ~/my_project_dir
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080035 gclient config https://chromium.googlesource.com/openscreen
36 gclient sync
37```
38
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080039The first `gclient` command will create a default .gclient file in
40`~/my_project_dir` that describes how to pull down the `openscreen` repository.
41The second command creates an `openscreen/` subdirectory, downloads the source
42code, all third-party dependencies, and the toolchain needed to build things;
43and at their appropriate revisions.
Jordan Baylesb5c9ece2019-02-22 15:16:44 -080044
mark a. foltz522f6b92019-10-21 17:49:59 -070045## Syncing your local checkout
mark a. foltz21f5c132018-10-08 12:18:22 -070046
Jordan Baylesc49eea62021-04-14 11:39:18 -070047To update your local checkout from the openscreen reference repository, just run
mark a. foltz21f5c132018-10-08 12:18:22 -070048
mark a. foltz20103872019-03-15 15:46:03 -070049```bash
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080050 cd ~/my_project_dir/openscreen
mark a. foltz20103872019-03-15 15:46:03 -070051 git pull
52 gclient sync
53```
mark a. foltz21f5c132018-10-08 12:18:22 -070054
mark a. foltz20103872019-03-15 15:46:03 -070055This will rebase any local commits on the remote top-of-tree, and update any
56dependencies that have changed.
mark a. foltzb0411512018-09-04 15:34:58 -070057
mark a. foltz522f6b92019-10-21 17:49:59 -070058# Build setup
mark a. foltzb0411512018-09-04 15:34:58 -070059
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080060The following are the main tools are required for development/builds:
btolschbaab5a12018-03-21 14:28:59 -070061
Yuri Wiitalab1072a32018-11-15 18:32:17 -080062 - Build file generator: `gn`
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080063 - Code formatter: `clang-format`
mark a. foltz20103872019-03-15 15:46:03 -070064 - Builder: `ninja` ([GitHub releases](https://github.com/ninja-build/ninja/releases))
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080065 - Compiler/Linker: `clang` (installed by default) or `gcc` (installed by you)
btolschbaab5a12018-03-21 14:28:59 -070066
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080067All of these--except `gcc` as noted above--are automatically downloaded/updated
68for the Linux and Mac environments via `gclient sync` as described above. The
69first two are installed into `buildtools/<platform>/`.
btolscha0f6adb2019-06-18 14:07:26 -070070
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080071Mac only: XCode must be installed on the system, to link against its frameworks.
mark a. foltz743b6202019-08-29 14:43:43 -070072
Yuri Wiitala50d8abc2020-01-09 18:36:09 -080073`clang-format` is used for maintaining consistent coding style, but it is not a
74complete replacement for adhering to Chromium/Google C++ style (that's on you!).
75The presubmit script will sanity-check that it has been run on all new/changed
76code.
Jordan Bayles0e8a6172019-01-23 14:54:41 -080077
mark a. foltz522f6b92019-10-21 17:49:59 -070078## Linux clang
Jordan Bayles0e8a6172019-01-23 14:54:41 -080079
mark a. foltz20103872019-03-15 15:46:03 -070080On Linux, the build will automatically download the Clang compiler from the
81Google storage cache, the same way that Chromium does it.
82
Max Yakimakha7e79fd92019-03-26 10:41:14 -070083Ensure that libstdc++ 8 is installed, as clang depends on the system
mark a. foltz20103872019-03-15 15:46:03 -070084instance of it. On Debian flavors, you can run:
85
86```bash
Jordan Bayles0e8a6172019-01-23 14:54:41 -080087 sudo apt-get install libstdc++-8-dev
mark a. foltz20103872019-03-15 15:46:03 -070088```
Jordan Bayles0e8a6172019-01-23 14:54:41 -080089
mark a. foltz522f6b92019-10-21 17:49:59 -070090## Linux gcc
mark a. foltz20103872019-03-15 15:46:03 -070091
92Setting the `gn` argument "is_gcc=true" on Linux enables building using gcc
mark a. foltz522f6b92019-10-21 17:49:59 -070093instead.
mark a. foltz20103872019-03-15 15:46:03 -070094
Max Yakimakha7e79fd92019-03-26 10:41:14 -070095```bash
mark a. foltz616a1182021-07-14 16:20:03 -070096 mkdir out/debug-gcc
97 gn gen out/debug-gcc --args="is_gcc=true"
Max Yakimakha7e79fd92019-03-26 10:41:14 -070098```
99
mark a. foltz522f6b92019-10-21 17:49:59 -0700100Note that g++ version 7 or newer must be installed. On Debian flavors you can
101run:
102
103```bash
104 sudo apt-get install gcc-7
105```
106
107## Mac clang
108
109On Mac OS X, the build will use the clang provided by
110[XCode](https://apps.apple.com/us/app/xcode/id497799835?mt=12), which must be
111installed.
112
113## Debug build
Max Yakimakha7e79fd92019-03-26 10:41:14 -0700114
115Setting the `gn` argument "is_debug=true" enables debug build.
116
117```bash
mark a. foltz616a1182021-07-14 16:20:03 -0700118 gn gen out/debug --args="is_debug=true"
Max Yakimakha7e79fd92019-03-26 10:41:14 -0700119```
120
121To install debug information for libstdc++ 8 on Debian flavors, you can run:
122
123```bash
124 sudo apt-get install libstdc++6-8-dbg
125```
126
mark a. foltz522f6b92019-10-21 17:49:59 -0700127## gn configuration
Max Yakimakha7e79fd92019-03-26 10:41:14 -0700128
129Running `gn args` opens an editor that allows to create a list of arguments
130passed to every invocation of `gn gen`.
131
132```bash
mark a. foltz616a1182021-07-14 16:20:03 -0700133 gn args out/debug
Max Yakimakha7e79fd92019-03-26 10:41:14 -0700134```
135
mark a. foltz522f6b92019-10-21 17:49:59 -0700136# Building targets
137
mark a. foltz616a1182021-07-14 16:20:03 -0700138## Cast Streaming sender and receiver
mark a. foltz20103872019-03-15 15:46:03 -0700139
mark a. foltz616a1182021-07-14 16:20:03 -0700140TODO(jophba): Fill in details
141
142## OSP demo
143
144The following commands will build the Open Screen Protocol demo and run it.
btolschbaab5a12018-03-21 14:28:59 -0700145
146``` bash
mark a. foltz616a1182021-07-14 16:20:03 -0700147 mkdir out/debug
148 gn gen out/debug # Creates the build directory and necessary ninja files
149 ninja -C out/debug osp_demo # Builds the executable with ninja
150 ./out/debug/osp_demo # Runs the executable
btolschbaab5a12018-03-21 14:28:59 -0700151```
152
153The `-C` argument to `ninja` works just like it does for GNU Make: it specifies
154the working directory for the build. So the same could be done as follows:
155
156``` bash
mark a. foltz616a1182021-07-14 16:20:03 -0700157 ./gn gen out/debug
158 cd out/debug
159 ninja osp_demo
160 ./osp_demo
btolschbaab5a12018-03-21 14:28:59 -0700161```
162
mark a. foltz20103872019-03-15 15:46:03 -0700163After editing a file, only `ninja` needs to be rerun, not `gn`. If you have
164edited a `BUILD.gn` file, `ninja` will re-run `gn` for you.
btolschbaab5a12018-03-21 14:28:59 -0700165
Yuri Wiitala50d8abc2020-01-09 18:36:09 -0800166Unless you like to wait longer than necessary for builds to complete, run
167`autoninja` instead of `ninja`, which takes the same command-line arguments.
168This will automatically parallelize the build for your system, depending on
169number of processor cores, RAM, etc.
170
mark a. foltz616a1182021-07-14 16:20:03 -0700171For details on running `osp_demo`, see its [README.md](osp/demo/README.md).
mark a. foltz20103872019-03-15 15:46:03 -0700172
mark a. foltz522f6b92019-10-21 17:49:59 -0700173## Building other targets
mark a. foltz20103872019-03-15 15:46:03 -0700174
mark a. foltz616a1182021-07-14 16:20:03 -0700175Running `ninja -C out/debug gn_all` will build all non-test targets in the
mark a. foltz20103872019-03-15 15:46:03 -0700176repository.
177
mark a. foltz616a1182021-07-14 16:20:03 -0700178`gn ls --type=executable out/debug` will list all of the executable targets
mark a. foltz20103872019-03-15 15:46:03 -0700179that can be built.
180
mark a. foltz616a1182021-07-14 16:20:03 -0700181If you want to customize the build further, you can run `gn args out/debug` to
182pull up an editor for build flags. `gn args --list out/debug` prints all of
mark a. foltz20103872019-03-15 15:46:03 -0700183the build flags available.
184
mark a. foltz522f6b92019-10-21 17:49:59 -0700185## Building and running unit tests
mark a. foltz20103872019-03-15 15:46:03 -0700186
187```bash
mark a. foltz616a1182021-07-14 16:20:03 -0700188 ninja -C out/debug openscreen_unittests
189 ./out/debug/openscreen_unittests
mark a. foltz20103872019-03-15 15:46:03 -0700190```
191
mark a. foltz616a1182021-07-14 16:20:03 -0700192# Contributing changes
mark a. foltz20103872019-03-15 15:46:03 -0700193
Jordan Baylesc49eea62021-04-14 11:39:18 -0700194Open Screen library code should follow the [Open Screen Library Style
mark a. foltz20103872019-03-15 15:46:03 -0700195Guide](docs/style_guide.md).
196
Jordan Baylesc49eea62021-04-14 11:39:18 -0700197This library uses [Chromium Gerrit](https://chromium-review.googlesource.com/) for
mark a. foltz616a1182021-07-14 16:20:03 -0700198patch management and code review (for better or worse). You will need to register
199for an account at `chromium-review.googlesource.com` to upload patches for review.
btolschbaab5a12018-03-21 14:28:59 -0700200
201The following sections contain some tips about dealing with Gerrit for code
mark a. foltz20103872019-03-15 15:46:03 -0700202reviews, specifically when pushing patches for review, getting patches reviewed,
203and committing patches.
btolschbaab5a12018-03-21 14:28:59 -0700204
mark a. foltz616a1182021-07-14 16:20:03 -0700205# Uploading a patch for review
btolschbaab5a12018-03-21 14:28:59 -0700206
mark a. foltz20103872019-03-15 15:46:03 -0700207The `git cl` tool handles details of interacting with Gerrit (the Chromium code
208review tool) and is recommended for pushing patches for review. Once you have
209committed changes locally, simply run:
mark a. foltzc689c462018-07-19 15:24:43 -0700210
211```bash
Yuri Wiitala50d8abc2020-01-09 18:36:09 -0800212 git cl format
mark a. foltz20103872019-03-15 15:46:03 -0700213 git cl upload
mark a. foltzc689c462018-07-19 15:24:43 -0700214```
215
Yuri Wiitala50d8abc2020-01-09 18:36:09 -0800216The first command will will auto-format the code changes. Then, the second
mark a. foltz616a1182021-07-14 16:20:03 -0700217command runs the `PRESUBMIT.py` script to check style and, if it passes, a
Yuri Wiitala50d8abc2020-01-09 18:36:09 -0800218newcode review will be posted on `chromium-review.googlesource.com`.
mark a. foltzc689c462018-07-19 15:24:43 -0700219
mark a. foltz20103872019-03-15 15:46:03 -0700220If you make additional commits to your local branch, then running `git cl
221upload` again in the same branch will merge those commits into the ongoing
222review as a new patchset.
btolschbaab5a12018-03-21 14:28:59 -0700223
mark a. foltz20103872019-03-15 15:46:03 -0700224It's simplest to create a local git branch for each patch you want reviewed
225separately. `git cl` keeps track of review status separately for each local
226branch.
btolschbaab5a12018-03-21 14:28:59 -0700227
mark a. foltz522f6b92019-10-21 17:49:59 -0700228## Addressing merge conflicts
mark a. foltzc689c462018-07-19 15:24:43 -0700229
mark a. foltz20103872019-03-15 15:46:03 -0700230If conflicting commits have been landed in the repository for a patch in review,
231Gerrit will flag the patch as having a merge conflict. In that case, use the
232instructions above to rebase your commits on top-of-tree and upload a new
233patchset with the merge conflicts resolved.
mark a. foltzc689c462018-07-19 15:24:43 -0700234
mark a. foltz522f6b92019-10-21 17:49:59 -0700235## Tryjobs
mark a. foltzc689c462018-07-19 15:24:43 -0700236
mark a. foltz20103872019-03-15 15:46:03 -0700237Clicking the `CQ DRY RUN` button (also, confusingly, labeled `COMMIT QUEUE +1`)
238will run the current patchset through all LUCI builders and report the results.
239It is always a good idea get a green tryjob on a patch before sending it for
240review to avoid extra back-and-forth.
mark a. foltzc689c462018-07-19 15:24:43 -0700241
mark a. foltz20103872019-03-15 15:46:03 -0700242You can also run `git cl try` from the commandline to submit a tryjob.
mark a. foltzc689c462018-07-19 15:24:43 -0700243
mark a. foltz522f6b92019-10-21 17:49:59 -0700244## Code reviews
mark a. foltzc689c462018-07-19 15:24:43 -0700245
mark a. foltz20103872019-03-15 15:46:03 -0700246Send your patch to one or more committers in the
247[COMMITTERS](https://chromium.googlesource.com/openscreen/+/refs/heads/master/COMMITTERS)
248file for code review. All patches must receive at least one LGTM by a committer
249before it can be submitted.
mark a. foltzc689c462018-07-19 15:24:43 -0700250
mark a. foltz616a1182021-07-14 16:20:03 -0700251## Submitting patches
mark a. foltzc689c462018-07-19 15:24:43 -0700252
mark a. foltz20103872019-03-15 15:46:03 -0700253After your patch has received one or more LGTM commit it by clicking the
254`SUBMIT` button (or, confusingly, `COMMIT QUEUE +2`) in Gerrit. This will run
255your patch through the builders again before committing to the main openscreen
256repository.
Jordan Baylesbc300c42020-01-22 16:59:12 -0800257
mark a. foltz616a1182021-07-14 16:20:03 -0700258# Additional resources
Jordan Baylesbc300c42020-01-22 16:59:12 -0800259
mark a. foltz616a1182021-07-14 16:20:03 -0700260* [Continuous builders](docs/continuous_build.md)
261* [Building and running fuzz tests](docs/fuzzing.md)
262* [Running on a Raspberry PI](docs/raspberry_pi.md)
263* [Unit test code coverage](docs/code_coverage.md)