1Firefox Contributors' Quick Reference
2=====================================
3
4Some parts of this process, including cloning and compiling, can take a long time even on modern hardware.
5If at any point you get stuck, please don't hesitate to ask at `https://chat.mozilla.org <https://chat.mozilla.org>`__
6in the `#introduction <https://chat.mozilla.org/#/room/#introduction:mozilla.org>`__ channel.
7
8Before you start
9----------------
10Please register and create your account for
11
12`Bugzilla <https://bugzilla.mozilla.org/>`__ : web-based general-purpose bug tracking system.
13To register with Phabricator, make sure you enable Two-Factor Authentication (My Profile >> Edit Profile & Preferences >> Two-Factor Authentication) in Bugzilla.
14
15`Phabricator <https://phabricator.services.mozilla.com/>`__: web-based software development collaboration tools, mainly for code review.
16Please obtain an API Token (Settings >> Conduit API Tokens)
17
18Clone the sources
19-----------------
20
21You can use either mercurial or git. `Mercurial <https://www.mercurial-scm.org/downloads>`__ is the canonical version control system.
22
23.. code-block:: shell
24
25    $ hg clone https://hg.mozilla.org/mozilla-central/
26
27For git, see the `git cinnabar documentation <https://github.com/glandium/git-cinnabar/wiki/Mozilla:-A-git-workflow-for-Gecko-development>`__
28
29The clone can take from 40 minutes to two hours (depending on your connection) and
30the repository should be less than 5GB (~ 20GB after the build).
31
32If you have any network connection issues and cannot clone with command, try :ref:`Mercurial bundles <Mercurial bundles>`.
33
34:ref:`More information <Mercurial Overview>`
35
36Install dependencies (non-Windows)
37----------------------------------
38
39Firefox provides a mechanism to install all dependencies; in the source tree:
40
41.. code-block:: shell
42
43     $ ./mach bootstrap
44
45The default options are recommended.
46If you're not planning to write C++ or Rust code, select :ref:`Artifact Mode <Understanding Artifact Builds>`
47and follow the instructions at the end of the bootstrap for creating a mozconfig file.
48
49More information :ref:`for Linux <Building Firefox On Linux>` and :ref:`for MacOS <Building Firefox On MacOS>`
50
51Windows dependencies
52--------------------
53
54#. You need 64-bit version of Windows 7 or later.
55#. Download and install `Visual Studio Community Edition. <https://visualstudio.microsoft.com/downloads/>`__
56#. Finally download the `MozillaBuild Package. <https://ftp.mozilla.org/pub/mozilla.org/mozilla/libraries/win32/MozillaBuildSetup-Latest.exe>`__ Installation directory should be:
57
58    .. code-block:: shell
59
60        $ c:\mozilla-build\
61
62#. Before moving on to the next steps, make sure to fulfill the :ref:`Windows prerequisites <Building Firefox On Windows>`
63
64.. note::
65
66    All the commands of this tutorial must be run in the shell provided with the MozillaBuild Package (start-shell.bat)
67
68:ref:`More information <Building Firefox On Windows>`
69
70To build & run
71--------------
72
73Once all the dependencies have been installed, run:
74
75.. code-block:: shell
76
77     $ ./mach build
78
79which will check for dependencies and start the build.
80This will take a while; a few minutes to a few hours depending on your hardware.
81
82.. note::
83
84    The default build is a compiled build with optimizations. Check out the
85    :ref:`mozconfig file documentation <Configuring Build Options>`
86    to see other build options. If you don't plan to change C++ or Rust code,
87    an :ref:`artifact build <Understanding Artifact Builds>` will be faster.
88
89To run it:
90
91.. code-block:: shell
92
93     $ ./mach run
94
95:ref:`More information about Linux <Building Firefox On Linux>` / :ref:`More information about MacOS <Building Firefox On MacOS>`
96
97.. _write_a_patch:
98
99To write a patch
100----------------
101
102Make the changes you need in the codebase. You can look up UI text in `Searchfox <https://searchfox.org>`__ to find the right file.
103
104Then:
105
106.. code-block:: shell
107
108    # Mercurial
109    $ hg commit
110
111    # Git
112    $ git commit
113
114.. _Commit message:
115
116The commit message should look like:
117
118.. code-block:: text
119
120    Bug xxxx - Short description of your change. r?reviewer
121
122    Optionally, a longer description of the change.
123
124**Make sure you include the bug number and at least one reviewer (or reviewer group) in this format.**
125
126To :ref:`find a reviewer or a review group <Getting reviews>`, the easiest way is to run
127``hg log <modified-file>`` (or ``git log <modified-file>``, if
128you're using git) on the relevant files, and look who usually is
129reviewing the actual changes (ie not reformat, renaming of variables, etc).
130
131
132To visualize your patch in the repository, run:
133
134.. code-block:: shell
135
136    # Mercurial
137    $ hg wip
138
139    # Git
140    $ git show
141
142:ref:`More information on how to work with stack of patches <Working with stack of patches Quick Reference>`
143
144:ref:`More information <Mercurial Overview>`
145
146To make sure the change follows the coding style
147------------------------------------------------
148
149To detect coding style violations, use mach lint:
150
151.. code-block:: shell
152
153    $ ./mach lint path/to/the/file/or/directory/you/changed
154
155    # To get the autofix, add --fix:
156    $ ./mach lint path/to/the/file/or/directory/you/changed --fix
157
158:ref:`More information <Code quality>`
159
160To test a change locally
161------------------------
162
163To run the tests, use mach test with the path. However, it isn’t
164always easy to parse the results.
165
166.. code-block:: shell
167
168    $ ./mach test dom/serviceworkers
169
170`More information <https://developer.mozilla.org/docs/Mozilla/QA/Automated_testing>`__
171
172To test a change remotely
173-------------------------
174
175Running all the tests for Firefox takes a very long time and requires multiple
176operating systems with various configurations. To build Firefox and run its
177tests on continuous integration servers (CI), two commands are available:
178
179.. code-block:: shell
180
181    $ ./mach try chooser
182
183To select jobs running a fuzzy search:
184
185.. code-block:: shell
186
187    $ ./mach try fuzzy
188
189From `Treeherder <https://treeherder.mozilla.org/>`__ (our continuous integration system), it is also possible to attach new jobs. As every review has
190a try CI run associated, it makes this work easier. See :ref:`attach-job-review` for
191more information.
192
193.. note::
194
195    This requires `level 1 commit access <https://www.mozilla.org/about/governance/policies/commit/access-policy/>`__.
196
197    You can ask your reviewer to submit the patch for you if you don't have that
198    level of access.
199
200:ref:`More information <Pushing to Try>`
201
202
203To submit a patch
204-----------------
205
206To submit a patch for review, we use a tool called `moz-phab <https://pypi.org/project/MozPhab/>`__.
207To install it, run:
208
209.. code-block:: shell
210
211     $ ./mach install-moz-phab
212
213Once you want to submit your patches (make sure you :ref:`use the right commit message <Commit message>`), run:
214
215.. code-block:: shell
216
217     $ moz-phab
218
219It will publish all the currently applied patches to Phabricator and inform the reviewer.
220
221If you wrote several patches on top of each other:
222
223.. code-block:: shell
224
225    $ moz-phab submit <first_revision>::<last_revision>
226
227`More
228information <https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html>`__
229
230To update a submitted patch
231---------------------------
232
233It is rare that a reviewer will accept the first version of patch. Moreover,
234as the code review bot might suggest some improvements, changes to your patch
235may be required.
236
237Run:
238
239.. code-block:: shell
240
241   # Mercurial
242   $ hg commit --amend
243
244   # Git
245   $ git commit --amend
246
247After amending the patch, you will need to submit it using moz-phab again.
248
249.. warning::
250
251    Don't use ``hg commit --amend -m`` or ``git commit --amend -m``.
252
253    Phabricator tracks revision by editing the commit message when a
254    revision is created to add a special ``Differential Revision:
255    <url>`` line.
256
257    When ``--amend -m`` is used, that line will be lost, leading to
258    the creation of a new revision when re-submitted, which isn't
259    the desired outcome.
260
261If you wrote many changes, you can squash or edit commits with the
262command:
263
264.. code-block:: shell
265
266   # Mercurial
267   $ hg histedit
268
269   # Git
270   $ git rebase -i
271
272The submission step is the same as for the initial patch.
273
274:ref:`More information on how to work with stack of patches <Working with stack of patches Quick Reference>`
275
276Retrieve new changes from the repository
277----------------------------------------
278
279To pull changes from the repository, run:
280
281.. code-block:: shell
282
283   # Mercurial
284   $ hg pull --rebase
285
286   # Git
287   $ git pull --rebase
288
289.. _push_a_change:
290
291To push a change in the code base
292---------------------------------
293
294Once the change has been accepted and you've fixed any remaining issues
295the reviewer identified, the reviewer should land the patch.
296
297If the patch has not landed on "autoland" (the integration branch) after a few days,
298feel free to contact the reviewer and/or
299@Aryx or @Sylvestre on the `#introduction <https://chat.mozilla.org/#/room/#introduction:mozilla.org>`__
300channel.
301
302The landing procedure will automatically close the review and the bug.
303
304:ref:`More information <How to submit a patch>`
305
306Contributing to GeckoView
307-------------------------
308
309Note that the GeckoView setup and contribution processes are different from those of Firefox;
310GeckoView setup and contribution docs live in `geckoview.dev <https://geckoview.dev>`__.
311
312More documentation about contribution
313-------------------------------------
314
315https://developer.mozilla.org/docs/Mozilla/Developer_guide/Introduction
316
317https://mozilla-version-control-tools.readthedocs.io/en/latest/devguide/contributing.html
318
319https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html
320