CONTRIBUTING.md 14.7 KB
Newer Older
1 2
Contributing to the Flutter engine
==================================
A
Adam Barth 已提交
3

4
[![Build Status](https://travis-ci.org/flutter/engine.svg)](https://travis-ci.org/flutter/engine)
A
Adam Barth 已提交
5

6 7 8 9 10 11 12 13 14 15 16
I built it before. Remind me, how do I do it again?
--------------------

If you have previously built the engine (i.e. your environment is already setup) and just want a refresher, then feel free to skip to one of the following sections:

- [Build for Android](#android-cross-compiling-from-mac-or-linux)
- [Build for iOS](#ios-cross-compiling-from-mac)
- [Build flutter_tester](#desktop-mac-and-linux-for-tests)

Otherwise, begin from the next section, which will help you prepare your environment.

I
Ian Hickson 已提交
17 18 19
Things you will need
--------------------

20 21 22
 * Linux, Mac OS X, or Windows
     * Windows doesn't support cross-compiling artifacts for Android or iOS
     * Linux doesn't support cross-compiling artifacts for iOS
I
Ian Hickson 已提交
23
 * git (used for source version control).
24
 * An IDE. We recommend [IntelliJ with the Flutter plugin](https://flutter.io/intellij-ide/) or Xcode.
I
Ian Hickson 已提交
25
 * An ssh client (used to authenticate with GitHub).
I
Ian Hickson 已提交
26
 * Chromium's [depot_tools](http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up) (make sure it's in your path). We use the `gclient` tool from depot_tools.
I
Ian Hickson 已提交
27
 * Python (used by many of our tools, including 'gclient').
28 29
 * On Mac OS X and Linux: curl and unzip (used by `gclient sync`).
 * On Windows: Visual Studio (required for non-Googlers only).
30
 * Recommended for Googlers: Goma for distributed builds.
I
Ian Hickson 已提交
31

32
You do not need [Dart](https://www.dartlang.org/downloads/linux.html) installed, as a Dart tool chain is automatically downloaded as part of the "getting the code" step. Similarly for the Android SDK, it's downloaded by the `gclient sync` step below.
I
Ian Hickson 已提交
33

I
Ian Hickson 已提交
34 35
Getting the code and configuring your environment
-------------------------------------------------
A
Adam Barth 已提交
36

I
Ian Hickson 已提交
37
 * Ensure all the dependencies described in the previous section, in particular git, ssh, depot_tools, python, and curl, are installed.
I
Ian Hickson 已提交
38
 * Fork `https://github.com/flutter/engine` into your own GitHub account. If you already have a fork, and are now installing a development environment on a new machine, make sure you've updated your fork so that you don't use stale configuration options from long ago.
I
Ian Hickson 已提交
39
 * If you haven't configured your machine with an SSH key that's known to github then
H
updated  
Hans Muller 已提交
40
   follow the directions here: https://help.github.com/articles/generating-ssh-keys/.
I
Ian Hickson 已提交
41
 * Create an empty directory for your copy of the repository. For best results, call it `engine`: some of the tools assume this name when working across repositories. (They can be configured to use other names too, so this isn't a strict requirement.)
42
 * Create a `.gclient` file in the `engine` directory with the following contents, replacing
A
Adam Barth 已提交
43
   `<your_name_here>` with your GitHub account name:
A
Adam Barth 已提交
44 45 46 47 48

```
solutions = [
  {
    "managed": False,
49
    "name": "src/flutter",
50
    "url": "git@github.com:<your_name_here>/engine.git",
A
Adam Barth 已提交
51 52 53 54 55 56
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]
```
57 58

 * `cd engine` (Change to the directory in which you put the `.gclient` file.)
I
Ian Hickson 已提交
59
 * `gclient sync` This will fetch all the source code that Flutter depends on. Avoid interrupting this script, it can leave your repository in an inconsistent state that is tedious to clean up.
I
Ian Hickson 已提交
60 61 62
 * `cd src/flutter` (Change to the `flutter` directory of the `src` directory that `gclient sync` created in your `engine` directory.)
 * `git remote add upstream git@github.com:flutter/engine.git` (So that you fetch from the master `flutter/engine` repository, not your clone, when running `git fetch` et al.)
 * `cd ..` (Return to the `src` directory that `gclient sync` created in your `engine` directory.)
63 64
 * If you're on Linux, run `sudo ./build/install-build-deps-android.sh`
 * If you're on Linux, run `sudo ./build/install-build-deps.sh`
I
Ian Hickson 已提交
65
 * If you're on Mac, install Oracle's Java JDK, version 1.7 or later.
66
 * If you're on Mac, install `ant`: `brew install ant`
67
 * If you're on Windows, install Visual Studio (non-Google developers only)
68
 * If you're planning on working on the [buildroot](https://github.com/flutter/buildroot) repository as well, and have a local checkout of that repository, run the following commands in the `src` directory to update your git remotes accordingly:
69

70 71 72 73
 ```bash
 git remote rename origin upstream
 git remote add origin git@github.com:<your_name_here>/buildroot.git
  ```
A
Adam Barth 已提交
74

75 76
Building and running the code
-----------------------------
A
Adam Barth 已提交
77

78 79 80 81 82 83 84 85 86 87 88 89
### General

Most developers will use the `flutter` tool in [the main Flutter repository](https://github.com/flutter/flutter) for interacting with their built flutter/engine.  To do so, the `flutter` tool accepts two global parameters `local-engine-src-path` and `local-engine`, a typical invocation would be: `--local-engine-src-path /path/to/engine/src --local-engine=android_debug_unopt`.

Additionally if you've modified dart sources in `flutter/engine`, you'll need to add a `dependency_overrides` section to point to your modified `package:sky_engine` and `package:sky_services` to the `pubspec.yaml` for the flutter app you're using the custom engine with.  A typical example would be:
```
dependency_overrides:
  sky_engine:
    path: /path/to/flutter/engine/out/host_debug/gen/dart-pkg/sky_engine
  sky_services:
    path: /path/to/flutter/engine/out/host_debug/gen/dart-pkg/sky_services
```
90
Depending on the platform you choose below, you will need to replace `host_debug` with the appropriate directory.
91

92 93
### Android (cross-compiling from Mac or Linux)

94
Run the following steps, from the `src` directory created in the steps above:
95

96 97
* `git pull upstream master` in `src/flutter` to update the Flutter Engine repo.
* `gclient sync` to update your dependencies.
98 99
* `./flutter/tools/gn --android --unoptimized` to prepare your build files for device-side executables (or `--android --android-cpu [x86|x64] --unoptimized` for x86/x64 emulators) .
* `./flutter/tools/gn --unoptimized` to prepare the build files for host-side executables.
100
* `ninja -C out/android_debug_unopt && ninja -C out/host_debug_unopt` to build all executables (use `out/android_debug_unopt_x64` for x86/x64 emulators).
X
xster 已提交
101
    * For Googlers, consider also using the option `-j 1000` to parallelize the build using Goma.
102 103 104

This builds a debug-enabled ("unoptimized") binary configured to run Dart in
checked mode ("debug"). There are other versions, [discussed on the wiki](https://github.com/flutter/flutter/wiki/Flutter's-modes).
105

106 107
To run an example with your locally built binary, you'll also need to clone
[the main Flutter repository](https://github.com/flutter/flutter). See
A
Adam Barth 已提交
108
[the instructions for contributing](https://github.com/flutter/flutter/blob/master/CONTRIBUTING.md)
109 110
to the main Flutter repository for detailed instructions. For your convenience,
the `engine` and `flutter` directories should be in the same parent directory.
A
Adam Barth 已提交
111

112 113
Once you've got everything set up, you can run an example using your locally
built engine by switching to that example's directory, running `pub get` to make
114
sure its dependencies have been downloaded, and using `flutter run` with an
115 116
explicit `--local-engine-src-path` pointing at the `engine/src` directory. Make
sure you have a device connected over USB and debugging enabled on that device:
A
Adam Barth 已提交
117

118
 * `cd /path/to/flutter/examples/hello_world`
119
 * `../../bin/flutter run --local-engine-src-path /path/to/engine/src --local-engine=android_debug_unopt` or `--local-engine=android_debug_unopt_x64`
A
Adam Barth 已提交
120

121 122 123
If you put the `engine` and `flutter` directories side-by-side, you can skip the
tedious `--local-engine-src-path` option and the `flutter` tool will
automatically determine the path.
124

125 126 127 128
You can also specify a particular Dart file to run if you want to run an example
that doesn't have a `lib/main.dart` file using the `-t` command-line option. For
example, to run the `tabs.dart` example in the `examples/widgets` directory on a
connected Android device, from that directory you would run:
129

130
 * `flutter run --local-engine=android_debug_unopt -t tabs.dart`
131

132 133 134 135 136
If you're going to be debugging crashes in the engine, make sure you add
`android:debuggable="true"` to the `<application>` element in the
`android/AndroidManifest.xml` file for the Flutter app you are using
to test the engine.

137 138
### iOS (cross-compiling from Mac)

139
* Make sure you have Xcode 9.0+ installed.
140
* `git pull upstream master` in `src/flutter` to update the Flutter Engine repo.
141
* `gclient sync` to update dependencies.
142
* `./flutter/tools/gn --ios --unoptimized` to prepare build files for device-side executables (or `--ios --simulator --unoptimized` for simulator).
143
  * For a discussion on the various flags and modes, [read this discussion](https://github.com/flutter/flutter/wiki/Flutter's-modes).
144
  * This also produces an Xcode project for working with the engine source code at `out/ios_debug_unopt`
145
* `./flutter/tools/gn --unoptimized` to prepare the build files for host-side executables.
146
* `ninja -C out/ios_debug_unopt && ninja -C out/host_debug_unopt` to build all artifacts (use `out/ios_debug_sim_unopt` for Simulator).
X
xster 已提交
147
    * For Googlers, consider also using the option `-j 1000` to parallelize the build using Goma.
148 149 150

Once the artifacts are built, you can start using them in your application by following these steps:
* `cd /path/to/flutter/examples/hello_world`
151
* `../../bin/flutter run --local-engine-src-path /path/to/engine/src --local-engine=ios_debug_unopt` or `--local-engine=ios_debug_sim_unopt` for simulator
152
  * If you are debugging crashes in the engine, you can connect the `LLDB` debugger from `Xcode` by opening `ios/Runner.xcworkspace` and starting the application by clicking the Run button (CMD + R).
X
xster 已提交
153
  * To debug non crashing code, open Xcode with `ios/Runner.xcworkspace`, expand Flutter->Runner->Supporting Files->main.m in the Runner project. Put a breakpoint in main() then set your desired breakpoint in the engine in [lldb](https://lldb.llvm.org/tutorial.html) via `breakpoint set -...`.
154 155


156 157
### Desktop (Mac and Linux), for tests

158 159 160 161 162
To run the tests, you should first clone [the main Flutter repository](https://github.com/flutter/flutter).
See [the instructions for contributing](https://github.com/flutter/flutter/blob/master/CONTRIBUTING.md)
to the main Flutter repository for detailed instructions. By default, Flutter will use the bundled version
of the engine. Follow the next steps to run tests using the locally-built engine:

163 164 165 166
* `git pull upstream master` in `src/flutter` to update the Flutter Engine repo.
* `gclient sync` to update your dependencies.
* `./flutter/tools/gn --unoptimized` to prepare your build files.
* `ninja -C out/host_debug_unopt` to build a desktop unoptimized binary.
X
xster 已提交
167
    * For Googlers, consider also using the option `-j 1000` to parallelize the build using Goma.
168
* `--unoptimized` disables C++ compiler optimizations and does not strip debug symbols. You may skip the flag and invoke `ninja -C out/host_debug` if you would rather have the native components optimized.
169
* `flutter test --local-engine=host_debug_unopt` will run tests using the locally-built `flutter_tester`.
170

171 172 173 174 175 176 177 178 179 180
### Desktop (gen_snapshot for Windows)

You can only build selected binaries on Windows (mainly `gen_snapshot`).

* Make sure you have Visual Studio installed (non-Googlers only).
* `git pull upstream master` in `src/flutter` to update the Flutter Engine repo.
* `gclient sync` to update your dependencies.
* `python .\flutter\tools\gn [--unoptimized] --runtime-mode=[debug|profile|release] [--android]` to prepare your build files.
* `ninja -C .\out\<dir created by previous step> gen_snapshot` to build.

181 182
### Building all the builds that matter on Linux and Android

183
The following script will update all the builds that matter if you're developing on Linux and testing on Android and created the `.gclient` file in `~/dev/engine`:
184 185 186 187

```bash
set -ex

188
cd ~/dev/engine/src/flutter
189 190 191
git fetch upstream
git rebase upstream/master
gclient sync
192
cd ..
193

194 195 196 197 198 199 200
flutter/tools/gn --unoptimized --runtime-mode=debug
flutter/tools/gn --android --unoptimized --runtime-mode=debug
flutter/tools/gn --android --unoptimized --runtime-mode=profile
flutter/tools/gn --android --unoptimized --runtime-mode=release
flutter/tools/gn --android --runtime-mode=debug
flutter/tools/gn --android --runtime-mode=profile
flutter/tools/gn --android --runtime-mode=release
201 202

cd out
I
Ian Hickson 已提交
203
find . -mindepth 1 -maxdepth 1 -type d | xargs -n 1 sh -c 'ninja -C $0 || exit 255'
204 205 206
```


A
Adam Barth 已提交
207 208 209
Contributing code
-----------------

I
Ian Hickson 已提交
210 211
We gladly accept contributions via GitHub pull requests. See [the wiki](https://github.com/flutter/engine/wiki) for
information about the engine's architecture.
212 213

To start working on a patch:
214

I
Ian Hickson 已提交
215
 * Make sure you are in the `engine/src/flutter` directory.
216 217
 * `git fetch upstream`
 * `git checkout upstream/master -b name_of_your_branch`
218 219 220 221 222 223 224
 * Hack away.
   * Please peruse our [style guides](https://flutter.io/style-guide/) and
     [design principles](https://flutter.io/design-principles/) before
     working on anything non-trivial. These guidelines are intended to
     keep the code consistent and avoid common pitfalls.
   * C, C++, and Objective-C code should be formatted with `clang-format` before
     submission (use `buildtools/<OS>/clang/bin/clang-format --style=file -i`).
225
 * `git commit -a -m "<your brief but informative commit message>"`
226
 * `git push origin name_of_your_branch`
227 228 229

To send us a pull request:

230 231
 * `git pull-request` (if you are using [Hub](http://github.com/github/hub/)) or
   go to `https://github.com/flutter/engine` and click the
232
   "Compare & pull request" button
C
Collin Jackson 已提交
233

Y
yjbanov 已提交
234 235
Once you've gotten an LGTM from a project maintainer, submit your changes to the
`master` branch using one of the following methods:
236 237 238 239 240 241

* Wait for one of the project maintainers to submit it for you
* Click the green "Merge pull request" button on the GitHub UI of your pull
  request (requires commit access)
* `git push upstream name_of_your_branch:master` (requires commit access)

I
Ian Hickson 已提交
242 243 244 245 246
Then, make sure it doesn't make our tree catch fire by watching [the waterfall](https://build.chromium.org/p/client.flutter/waterfall). The waterfall runs
slightly different tests than Travis, so it's possible for the tree to go red even if
Travis did not. If that happens, please immediately revert your change. Do not check
anything in while the tree is red unless you are trying to resolve the problem.

I
Ian Hickson 已提交
247 248 249 250 251
Please make sure all your checkins have detailed commit messages explaining the patch.
If you made multiple commits for a single pull request, either make sure each one has a detailed
message explaining that specific commit, or squash your commits into one single checkin with a
detailed message before sending the pull request.

C
Collin Jackson 已提交
252 253 254 255
You must complete the
[Contributor License Agreement](https://cla.developers.google.com/clas).
You can do this online, and it only takes a minute.
If you've never submitted code before, you must add your (or your
C
Collin Jackson 已提交
256
organization's) name and contact info to the [AUTHORS](AUTHORS) file.