blob: 14bd6c49f89d742370d33e9e38154eb6f32be5c4 [file] [log] [blame] [view]
andybons22afb312015-08-31 02:24:511# Cr
andybons3322f762015-08-24 21:37:092
andybons22afb312015-08-31 02:24:513Cr is the new unified interface to the myriad tools we use while working within
4a chromium checkout. Its main additional feature is that it allows you to build
5many configurations and run targets within a single checkout (by not relying on
6a directory called 'out'). This is especially important when you want to
7cross-compile (for instance, building android from linux or building arm from
8intel), but it extends to any build variation.
9
10[TOC]
andybons3322f762015-08-24 21:37:0911
12## A quick example
13
andybons22afb312015-08-31 02:24:5114The following is all you need to prepare an output directory, and then build and
15run the release build of chrome for the host platform:
16
17```shell
18cr init
19cr run
andybons3322f762015-08-24 21:37:0920```
21
andybons22afb312015-08-31 02:24:5122## How do I get it?
andybons3322f762015-08-24 21:37:0923
24You already have it, it lives in `src/tools/cr`
25
andybons22afb312015-08-31 02:24:5126You can run the cr.py file by hand, but if you are using bash it is much easier
27to source the bash helpers. This will add a cr function to your bash shell that
28runs with pyc generation turned off, and also installs the bash tab completion
29handler (which is very primitive at the moment, it only completes the command
30not the options) It also adds a function you can use in your prompt to tell you
31your selected build (`_cr_ps1`), and an helper to return you to the root of your
32active tree (`crcd`). I recommend you add the following lines to the end of your
33`~/.bashrc` (with a more correct path):
34
35```shell
36CR_CLIENT_PATH="/path/to/chromium"
37source ${CR_CLIENT_PATH}/src/tools/cr/cr-bash-helpers.sh
andybons3322f762015-08-24 21:37:0938```
andybons22afb312015-08-31 02:24:5139
andybons3322f762015-08-24 21:37:0940At that point the cr command is available to you.
41
andybons22afb312015-08-31 02:24:5142## How do I use it?
andybons3322f762015-08-24 21:37:0943
44It should be mostly self documenting
andybons22afb312015-08-31 02:24:5145
46 cr --help
47
andybons3322f762015-08-24 21:37:0948will list all the commands installed
andybons22afb312015-08-31 02:24:5149
50 cr --help command
51
andybons3322f762015-08-24 21:37:0952will give you more detailed help for a specific command.
53
andybons22afb312015-08-31 02:24:5154_**A note to existing android developers:**_
andybons3322f762015-08-24 21:37:0955
andybons22afb312015-08-31 02:24:5156* Do not source envsetup! ever!
57* If you use cr in a shell that has had envsetup sourced, miscellaneous things
58 will be broken. The cr tool does all the work that envsetup used to do in a
59 way that does not pollute your current shell.
60* If you really need a shell that has had the environment modified like
61 envsetup used to do, see the cr shell command, also probably file a bug for
62 a missing cr feature!
andybons3322f762015-08-24 21:37:0963
andybons22afb312015-08-31 02:24:5164## The commands
andybons3322f762015-08-24 21:37:0965
andybons22afb312015-08-31 02:24:5166Below are some common workflows, but first there is a quick overview of the
67commands currently in the system.
andybons3322f762015-08-24 21:37:0968
andybons22afb312015-08-31 02:24:5169### Output directory commands
andybons3322f762015-08-24 21:37:0970
andybons22afb312015-08-31 02:24:5171 init
andybons3322f762015-08-24 21:37:0972
andybons22afb312015-08-31 02:24:5173Create and configure an output directory. Also runs select to make it the
74default.
andybons3322f762015-08-24 21:37:0975
andybons22afb312015-08-31 02:24:5176 select
andybons3322f762015-08-24 21:37:0977
andybons22afb312015-08-31 02:24:5178Select an output directory. This makes it the default output for all commands,
79so you can omit the --out option if you want to.
andybons3322f762015-08-24 21:37:0980
andybons22afb312015-08-31 02:24:5181 prepare
82
83Prepares an output directory. This runs any preparation steps needed for an
84output directory to be viable, which at the moment means run gyp.
85
86### Build commands
87
88 build
89
90Build a target.
91
92 install
93
94Install a binary. Does build first unless `--builder==skip`. This does nothing
95on linux, and installs the apk onto the device for android builds.
96
97 run
98
99Invoke a target. Does an install first, unless `--installer=skip`.
100
101 debug
102
103Debug a target. Does a run first, unless `--runner=skip`. Uses the debugger
104specified by `--debugger`.
105
106### Other commands
107
108 sync
109
110Sync the source tree. Uses gclient sync to do the real work.
111
112 shell
113
114Run an exernal command in a cr environment. This is an escape hatch, if passed
115a command it runs it in the correct environment for the current output
116directory, otherwise it starts a sub shell with that environment. This allows
117you to run any commands that don't have shims, or are too specialized to get
118one. This is especially important on android where the environment is heavily
119modified.
120
121## Preparing to build
andybons3322f762015-08-24 21:37:09122
123The first thing you need to do is prepare an output directory to build into.
124You do this with:
andybons3322f762015-08-24 21:37:09125
andybons22afb312015-08-31 02:24:51126 cr init
andybons3322f762015-08-24 21:37:09127
andybons22afb312015-08-31 02:24:51128By default on linux this will prepare a linux x86 release build output
129directory, called `out_linux/Release`, if you want an android debug one, you can
130use:
andybons3322f762015-08-24 21:37:09131
andybons22afb312015-08-31 02:24:51132 cr init --out=out_android/Debug
andybons3322f762015-08-24 21:37:09133
andybons22afb312015-08-31 02:24:51134The output directory can be called anything you like, but if you pick a non
135standard name cr might not be able to infer the platform, in which case you need
136to specify it. The second part **must** be either Release or Debug. All options
137can be shortened to the shortest non ambiguous prefix, so the short command line
138to prepare an android debug output directory in out is:
139
140 cr init --o=out/Debug --p=android
141
142It is totally safe to do this in an existing output directory, and is an easy
143way to migrate an existing output directory to use in cr if you don't want to
144start from scratch.
145
146Most commands in cr take a --out parameter to tell them which output directory
147you want to operate on, but it will default to the last value passed to init or
148select. This enables you to omit it from most commands.
149
150Both init and select do additional work to prepare the output directory, which
151include things like running gyp. You can do that work on it's own with the
152prepare command if you want, something you need to do when changing between
153branches where you have modified the build files.
154
155If you want to set custom GYP defines for your build you can do this by adding
156adding the `-s GYP_DEFINES` argument, for example:
157
158 cr init --o=out/Debug -s GYP_DEFINES=component=shared_library
159
160## Running chrome
andybons3322f762015-08-24 21:37:09161
162If you just want to do a basic build and run, then you do
andybons3322f762015-08-24 21:37:09163
andybons22afb312015-08-31 02:24:51164 cr run
andybons3322f762015-08-24 21:37:09165
andybons22afb312015-08-31 02:24:51166which will build, install if necessary, and run chrome, with some default args
167to open on https://www.google.com/. The same command line will work for any
168supported platform and mode. If you want to just run it again, you can turn off
169the build and install steps,
170
171 cr run --installer=skip
172
173note that turning off install automatically turns off build (which you could do
174with `--builder=skip`) as there is no point building if you are not going to
175install.
176
177## Debugging chrome
andybons3322f762015-08-24 21:37:09178
179To start chrome under a debugger you use
andybons3322f762015-08-24 21:37:09180
andybons22afb312015-08-31 02:24:51181 cr debug
182
183which will build, install, and run chrome, and attach a debugger to it. This
184works on any supported platform, and if multiple debuggers are available, you
185can select which one you want with `--debugger=my_debugger`
186
187## Help, it went wrong!
andybons3322f762015-08-24 21:37:09188
189There are a few things to do, and you should probably do all of them.
andybons22afb312015-08-31 02:24:51190Run your commands with dry-run and/or verbose turned on to see what the tool is
191really doing, for instance
andybons3322f762015-08-24 21:37:09192
andybons22afb312015-08-31 02:24:51193 cr --d -vvvv init
andybons3322f762015-08-24 21:37:09194
andybons22afb312015-08-31 02:24:51195The number of v's matter, it's the verbosity level, you can also just specify
196the value with -v=4 if you would rather.
andybons3322f762015-08-24 21:37:09197
andybons22afb312015-08-31 02:24:51198[Report a bug], even if it is just something that confused or annoyed rather
199than broke, we want this tool to be very low friction for developers.
andybons3322f762015-08-24 21:37:09200
andybons22afb312015-08-31 02:24:51201## Known issues
202
203You can see the full list of issues with
204[this](https://code.google.com/p/chromium/issues/list?can=2&q=label%3Atool-cr)
205query, but here are the high level issues:
206
207* **Only supports gtest** : You run tests using the run command, which tries
208 to infer from the target whether it is a runnable binary or a test. The
209 inference could be improved, and it needs to handle the other test types as
210 well.
211* **No support for windows or mac** : allowed for in the design, but need
212 people with expertise on those platforms to help out
213* **Bash completion** : The hooks for it are there, but at the moment it only
214 ever completes the command, not any of the arguments
215
216[Report a bug]:
217https://code.google.com/p/chromium/issues/entry?comment=%3CDont%20forget%20to%20attach%20the%20command%20lines%20used%20with%20-v=4%20if%20possible%3E&pri=2&labels=OS-Android,tool-cr,Build-Tools,Type-Bug&[email protected]&status=Assigned