blob: 3c791b3a37630c458e2445296d05c881bfbd5100 [file] [log] [blame] [view]
Adam Barth576795d2015-11-08 21:33:00 -08001Contributing to Flutter
2=======================
3
4[![Build Status](https://travis-ci.org/flutter/flutter.svg)](https://travis-ci.org/flutter/flutter)
5
Ian Hicksoncffe4812016-12-10 21:46:57 -08006_See also: [Flutter's code of conduct](https://flutter.io/design-principles/#code-of-conduct)_
7
Adam Barth576795d2015-11-08 21:33:00 -08008Things you will need
9--------------------
10
Michael Goderbauer13edb322017-06-26 09:47:05 -070011 * Linux, Mac OS X, or Windows
Adam Barth576795d2015-11-08 21:33:00 -080012 * git (used for source version control).
Adam Barthf68343e2017-02-08 20:50:29 -080013 * An IDE. We recommend [IntelliJ with the Flutter plugin](https://flutter.io/intellij-ide/).
Adam Barth576795d2015-11-08 21:33:00 -080014 * An ssh client (used to authenticate with GitHub).
15 * Python (used by some of our tools).
Adam Barth576795d2015-11-08 21:33:00 -080016 * The Android platform tools (see [Issue #55](https://github.com/flutter/flutter/issues/55)
Adam Barthf4c62a82015-11-08 22:18:16 -080017 about downloading the Android platform tools automatically).
Ian Hickson82686642016-02-08 13:39:24 -080018 _If you're also working on the Flutter engine, you can use the
Adam Barthf4c62a82015-11-08 22:18:16 -080019 copy of the Android platform tools in
Ian Hickson82686642016-02-08 13:39:24 -080020 `.../engine/src/third_party/android_tools/sdk/platform-tools`._
Adam Barth576795d2015-11-08 21:33:00 -080021 - Mac: `brew install android-platform-tools`
22 - Linux: `sudo apt-get install android-tools-adb`
23
24Getting the code and configuring your environment
25-------------------------------------------------
26
27 * Ensure all the dependencies described in the previous section, in particular
Ian Hicksone23d7602016-02-15 10:46:24 -080028 git, ssh, and python are installed. Ensure that `adb`
29 (from the Android platform tools) is in your path (e.g.,
30 that `which adb` prints sensible output).
Adam Barth576795d2015-11-08 21:33:00 -080031 * Fork `https://github.com/flutter/flutter` into your own GitHub account. If
32 you already have a fork, and are now installing a development environment on
33 a new machine, make sure you've updated your fork so that you don't use stale
34 configuration options from long ago.
35 * If you haven't configured your machine with an SSH key that's known to github then
36 follow the directions here: https://help.github.com/articles/generating-ssh-keys/.
37 * `git clone git@github.com:<your_name_here>/flutter.git`
38 * `cd flutter`
39 * `git remote add upstream git@github.com:flutter/flutter.git` (So that you
40 fetch from the master repository, not your clone, when running `git fetch`
41 et al.)
Adam Barth576795d2015-11-08 21:33:00 -080042 * Add this repository's `bin` directory to your path. That will let you use the
Ian Hicksone23d7602016-02-15 10:46:24 -080043 `flutter` command in this directory more easily.
Lex Berezhny778742e2016-02-27 12:35:05 -050044 * Run `flutter update-packages` This will fetch all the Dart packages that
45 Flutter depends on. You can replicate what this script does by running
46 `pub get` in each directory that contains a `pubspec.yaml` file.
Adam Barth576795d2015-11-08 21:33:00 -080047
48Running the examples
49--------------------
50
51To run an example with a prebuilt binary from the cloud, switch to that
52example's directory, run `pub get` to make sure its dependencies have been
Devon Carew04eee822016-02-17 07:34:59 -080053downloaded, and use `flutter run`. Make sure you have a device connected over
Adam Barth576795d2015-11-08 21:33:00 -080054USB and debugging enabled on that device.
55
Ali Ghassemi53c86e02016-05-20 13:06:03 -070056 * `cd examples/hello_world`
57 * `flutter run`
Adam Barth576795d2015-11-08 21:33:00 -080058
59You can also specify a particular Dart file to run if you want to run an example
60that doesn't have a `lib/main.dart` file using the `-t` command-line option. For
Ali Ghassemi705b5d12016-05-20 13:53:18 -070061example, to run the `widgets/spinning_square.dart` example in the [examples/layers](examples/layers)
Adam Barth576795d2015-11-08 21:33:00 -080062directory on a connected Android device, from that directory you would run:
Ali Ghassemi53c86e02016-05-20 13:06:03 -070063`flutter run -t widgets/spinning_square.dart`
Adam Barth576795d2015-11-08 21:33:00 -080064
65When running code from the examples directory, any changes you make to the
66example code, as well as any changes to Dart code in the
67[packages/flutter](packages/flutter) directory and subdirectories, will
68automatically be picked when you relaunch the app. You can do the same for your
69own code by mimicking the `pubspec.yaml` files in the `examples` subdirectories.
70
Ian Hickson895aaa92016-12-15 15:59:57 -080071Running the analyzer
72--------------------
73
74When editing Flutter code, it's important to check the code with the analyzer. There are two
75main ways to run it. In either case you will want to run `flutter update-packages --upgrade`
76first, or you will get version conflict issues or bogus error messages about core clases like
77Offset from `dart:ui`.
78
79For a one-off, use `flutter analyze --flutter-repo`. This uses the `.analysis_options_repo` file
80at the root of the repository for its configuration.
81
82For continuous analysis, use `flutter analyze --flutter-repo --watch`. This uses normal
83`.analysis_options` files, and they can differ from package to package.
84
85If you want to see how many members are missing dartdocs, you should use the first option,
86providing the additional command `--dartdocs`.
87
88If you omit the `--flutter-repo` option you may end up in a confusing state because that will
89assume you want to check a single package and the flutter repository has several packages.
90
91
Adam Barth576795d2015-11-08 21:33:00 -080092Running the tests
93-----------------
94
Michael Goderbauer13edb322017-06-26 09:47:05 -070095_The `flutter test` command is not available on Windows (See [#8516](https://github.com/flutter/flutter/issues/8516))._
96
Ian Hickson7151fdd2015-12-15 22:32:45 -080097To automatically find all files named `_test.dart` inside a package's `test/` subdirectory, and run them inside the flutter shell as a test, use the `flutter test` command, e.g:
Adam Barth576795d2015-11-08 21:33:00 -080098
Eric Seidel723e5f72015-12-08 14:09:47 -080099 * `cd examples/stocks`
Eric Seidel724388d2015-12-08 13:51:05 -0800100 * `flutter test`
Adam Barth576795d2015-11-08 21:33:00 -0800101
Eric Seidel723e5f72015-12-08 14:09:47 -0800102Individual tests can also be run directly, e.g. `flutter test lib/my_app_test.dart`
103
Eric Seidel724388d2015-12-08 13:51:05 -0800104Flutter tests use [package:flutter_test](https://github.com/flutter/flutter/tree/master/packages/flutter_test) which provides flutter-specific extensions on top of [package:test](https://pub.dartlang.org/packages/test).
Adam Barth576795d2015-11-08 21:33:00 -0800105
xster9610ff62017-02-17 11:17:05 -0800106`flutter test` runs tests inside the flutter shell. To debug tests in Observatory, use the `--start-paused` option to start the test in a paused state and wait for connection from a debugger. This option lets you set breakpoints before the test runs.
Eric Seidel723e5f72015-12-08 14:09:47 -0800107
Michael Goderbauer32271e92017-02-08 13:00:44 -0800108To run all the tests for the entire Flutter repository, the same way that Travis runs them, run `dart dev/bots/test.dart`.
Eric Seidel723e5f72015-12-08 14:09:47 -0800109
Adam Barthb4002502016-05-31 10:28:25 -0700110If you've built [your own flutter engine](#working-on-the-engine-and-the-framework-at-the-same-time), you can pass `--local-engine` to change what flutter shell `flutter test` uses. For example,
111if you built an engine in the `out/host_debug_unopt` directory, you can pass
112`--local-engine=host_debug_unopt` to run the tests in that engine.
Adam Barth576795d2015-11-08 21:33:00 -0800113
Ian Hickson895aaa92016-12-15 15:59:57 -0800114Flutter tests are headless, you won't see any UI. You can use
Ian Hickson34190682015-11-09 00:30:45 -0800115`print` to generate console output or you can interact with the DartVM
116via observatory at [http://localhost:8181/](http://localhost:8181/).
Adam Barth576795d2015-11-08 21:33:00 -0800117
118Adding a test
119-------------
120
Ian Hickson895aaa92016-12-15 15:59:57 -0800121To add a test to the Flutter package, create a file whose name
Ian Hickson7151fdd2015-12-15 22:32:45 -0800122ends with `_test.dart` in the `packages/flutter/test` directory. The
123test should have a `main` function and use the `test` package.
Adam Barth576795d2015-11-08 21:33:00 -0800124
xster606ee362017-01-25 19:00:06 -0800125Working with flutter tools
126--------------------------
127
128The flutter tools itself is built when you run `flutter` for the first time and each time
129you run `flutter upgrade`. If you want to alter and re-test the tool's behavior itself,
130locally commit your tool changes in git and the tool will be rebuilt from Dart sources
131in `packages/flutter_tools` the next time you run `flutter`.
132
Michael Goderbauer7532a992017-08-10 08:46:56 -0700133Alternatively, delete the `bin/cache/flutter_tools.snapshot` file. Doing so will
134force a rebuild of the tool from your local sources the next time you run `flutter`.
135
xster606ee362017-01-25 19:00:06 -0800136flutter_tools' tests run inside the Dart command line VM rather than in the
137flutter shell. To run the test:
138
139* `cd packages/flutter_tools`
Jason Simmons38606a72017-07-13 17:38:11 -0700140* `pub run test -j1`
xster606ee362017-01-25 19:00:06 -0800141
142The pre-built flutter tool runs in release mode with the observatory off by default.
143To enable debugging mode and the observatory on the `flutter` tool, uncomment the
144`FLUTTER_TOOL_ARGS` line in the `bin/flutter` shell script.
145
Adam Barth576795d2015-11-08 21:33:00 -0800146Contributing code
147-----------------
148
149We gladly accept contributions via GitHub pull requests.
150
Ian Hickson895aaa92016-12-15 15:59:57 -0800151Please peruse our
152[style guides](https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo) and
153[design principles](https://flutter.io/design-principles/) before
154working on anything non-trivial. These guidelines are intended to
155keep the code consistent and avoid common pitfalls.
156
Adam Barth576795d2015-11-08 21:33:00 -0800157To start working on a patch:
158
159 * `git fetch upstream`
160 * `git checkout upstream/master -b name_of_your_branch`
Ian Hickson895aaa92016-12-15 15:59:57 -0800161 * Hack away.
Ian Hickson34190682015-11-09 00:30:45 -0800162 * `git commit -a -m "<your informative commit message>"`
Adam Barth576795d2015-11-08 21:33:00 -0800163 * `git push origin name_of_your_branch`
164
165To send us a pull request:
166
167* `git pull-request` (if you are using [Hub](http://github.com/github/hub/)) or
168 go to `https://github.com/flutter/flutter` and click the
169 "Compare & pull request" button
170
171Please make sure all your checkins have detailed commit messages explaining the patch.
Adam Barth576795d2015-11-08 21:33:00 -0800172
Ian Hicksonbe9dd4b2017-07-13 10:23:29 -0700173Once you've gotten an LGTM from a project maintainer and once your PR has received
174the green light from all our automated testing (Travis, Appveyor, etc), and once
175the tree is green (see the [design principles](https://flutter.io/design-principles/)
176document for more details), submit your changes to the `master` branch using one of
177the following methods:
yjbanov15e7bdb2016-02-02 11:17:16 -0800178
Ali Ghassemi53c86e02016-05-20 13:06:03 -0700179* Wait for one of the project maintainers to submit it for you.
yjbanov15e7bdb2016-02-02 11:17:16 -0800180* Click the green "Merge pull request" button on the GitHub UI of your pull
181 request (requires commit access)
yjbanov15e7bdb2016-02-02 11:17:16 -0800182
Adam Barth576795d2015-11-08 21:33:00 -0800183You must complete the
184[Contributor License Agreement](https://cla.developers.google.com/clas).
185You can do this online, and it only takes a minute.
186If you've never submitted code before, you must add your (or your
187organization's) name and contact info to the [AUTHORS](AUTHORS) file.
188
Ian Hicksoncffe4812016-12-10 21:46:57 -0800189We grant commit access to people who have gained our trust and demonstrated
190a commitment to Flutter.
191
Adam Barth56039c02016-06-23 13:43:42 -0700192Tools for tracking an improving test coverage
193---------------------------------------------
194
195We strive for a high degree of test coverage for the Flutter framework. We use
196Coveralls to [track our test coverage](https://coveralls.io/github/flutter/flutter?branch=master).
197You can download our current coverage data from cloud storage and visualize it
198in Atom as follows:
199
Adam Barth428023c2017-02-08 10:56:03 -0800200 * Install [Atom](https://atom.io/).
Adam Barth56039c02016-06-23 13:43:42 -0700201 * Install the [lcov-info](https://atom.io/packages/lcov-info) package for Atom.
Adam Barth10931af2016-06-23 16:31:25 -0700202 * Open the `packages/flutter` folder in Atom.
203 * Open a Dart file in the `lib` directory an type `Ctrl+Alt+C` to bring up the
204 coverage data.
205
206If you don't see any coverage data, check that you have an `lcov.info` file in
207the `packages/flutter/coverage` directory. It should have been downloaded by the
208`flutter update-packages` command you ran previously.
Adam Barth56039c02016-06-23 13:43:42 -0700209
Adam Barth46da9e82016-06-23 18:02:55 -0700210If you want to iterate quickly on improving test coverage, consider using this
211workflow:
212
213 * Open a file and observe that some line is untested.
214 * Write a test that exercises that line.
215 * Run `flutter test --merge-coverage path/to/your/test_test.dart`.
216 * After the test passes, observe that the line is now tested.
217
218This workflow merges the coverage data from this test run with the base coverage
219data downloaded by `flutter update-packages`.
220
Adam Barth56039c02016-06-23 13:43:42 -0700221See [issue 4719](https://github.com/flutter/flutter/issues/4719) for ideas about
222how to improve this workflow.
223
Adam Barth576795d2015-11-08 21:33:00 -0800224Working on the engine and the framework at the same time
225--------------------------------------------------------
226
227You can work both with this repository (flutter.git) and the Flutter
228[engine repository](https://github.com/flutter/engine) at the same time using
229the following steps.
230
2311. Follow the instructions above for creating a working copy of this repository.
232
2332. Follow the [contributing instructions](https://github.com/flutter/engine/blob/master/CONTRIBUTING.md)
234 for the engine repository to create a working copy of the engine. When you
235 create the `.gclient` file for the engine, be sure to create it in a
236 directory named `engine` that is a sibling of the directory in which you
237 cloned this repository. For example, if you cloned this repository into the
238 `/foo/bar/flutter` directory, you should create the `.gclient` file in the
239 `/foo/bar/engine` directory. The actual code from the engine repository will
240 end up in `/foo/bar/engine/src` because `gclient` creates a `src` directory
241 underneath the directory that contains the `.gclient` file.
242
2433. To run tests on your host machine, build one of the host configurations
Adam Barthb4002502016-05-31 10:28:25 -0700244 (e.g., `out/host_debug_unopt`). To run examples on Android, build one of the
245 Android configurations (e.g., `out/android_debug_unopt`).
Adam Barth576795d2015-11-08 21:33:00 -0800246
Ian Hickson34190682015-11-09 00:30:45 -0800247You should now be able to run the tests against your locally built
Adam Barthb4002502016-05-31 10:28:25 -0700248engine using the `flutter test --local-engine=host_debug_unopt` command. To run
249one of the examples on your device using your locally built engine, use the
250`--local-engine=android_debug_unopt` option to the `flutter` tool:
Adam Barth576795d2015-11-08 21:33:00 -0800251
Adam Barthb4002502016-05-31 10:28:25 -0700252 * `flutter run --local-engine=android_debug_unopt`
Adam Barth576795d2015-11-08 21:33:00 -0800253
254Making a breaking change to the engine
255--------------------------------------
256
krisgiesing3dfdf4b2016-03-15 13:16:48 -0700257If you make a breaking change to the engine, you'll need to land your change in a
Adam Barth576795d2015-11-08 21:33:00 -0800258few steps:
259
2601. Land your change in the engine repository.
261
2622. Publish a new version of the engine that contains your change. See the
263 engine's [release process](https://github.com/flutter/engine/wiki/Release-process)
264 for instructions about how to publish a new version of the engine. Publishing
265 a new version is important in order to not break folks using prebuilt
266 binaries in their workflow (e.g., our customers).
267
2683. Land a change that update our dependency on the `sky_engine` and
269 `sky_services` packages to point to the new version of the engine that you
270 just published. These dependencies are defined by [packages/flutter/pubspec.yaml](packages/flutter/pubspec.yaml).
271 After changing the `pubspec.yaml` file, you'll need to run
Jason Simmons587a6e82015-11-10 16:06:09 -0800272 `./dev/update_packages.dart` to update all the packages in this repository to
Adam Barth576795d2015-11-08 21:33:00 -0800273 see the new dependency. As part of landing this change, you should make
274 whatever other changes are needed in this repository to account for your
275 breaking change.