Bug 1904048 - Add prototype for ImageBitmap's BindingJSObjectMallocBytes. r=aosmond
[gecko.git] / docs / contributing / contribution_quickref.rst
blob9a9e5240e943fa4289cd9790a07da112d598ced3
1 Firefox Contributors' Quick Reference
2 =====================================
4 Some parts of this process, including cloning and compiling, can take a long time even on modern hardware.
5 If at any point you get stuck, please don't hesitate to ask at `https://chat.mozilla.org <https://chat.mozilla.org>`__
6 in the `#introduction <https://chat.mozilla.org/#/room/#introduction:mozilla.org>`__ channel.
8 Don’t hesitate to look at the :ref:`Getting Set Up To Work On The Firefox Codebase<Getting Set Up To Work On The Firefox Codebase>` for a more detailed tutorial.
10 Before you start
11 ----------------
12 Please register and create your account for
14 `Bugzilla <https://bugzilla.mozilla.org/>`__ : web-based general-purpose bug tracking system.
15 To register with Phabricator, make sure you enable Two-Factor Authentication (My Profile >> Edit Profile & Preferences >> Two-Factor Authentication) in Bugzilla.
17 `Phabricator <https://phabricator.services.mozilla.com/>`__: web-based software development collaboration tools, mainly for code review.
18 Please obtain an API Token (Settings >> Conduit API Tokens)
20 Windows dependencies
21 --------------------
23 #. You need a :ref:`supported version of Windows<tier_1_hosts>`.
24 #. Download the `MozillaBuild Package. <https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-Latest.exe>`__ Installation directory should be:
26     .. code-block:: shell
28         $ c:\mozilla-build\
30 #. Before moving on to the next steps, make sure to fulfill the :ref:`Windows prerequisites <Building Firefox On Windows>`
32 .. note::
34     All the commands of this tutorial must be run in the shell provided with the MozillaBuild Package (start-shell.bat)
36 :ref:`More information on building Firefox on Windows <Building Firefox On Windows>`
38 Bootstrap a copy of the Firefox source code
39 -------------------------------------------
41 You can download the source code and have Firefox automatically download and install the other dependencies it needs. The below command as per your Operating System, will download a lot of data (years of Firefox history!) then guide you through the interactive setup process.
43 Downloading can take from 40 minutes to two hours (depending on your connection) and the repository should be less than 5GB (~ 20GB after the build).
45 The **default options are recommended**.
46 If you're not planning to write C++ or Rust code, select :ref:`Artifact Mode <Understanding Artifact Builds>`
47 and follow the instructions at the end of the bootstrap for creating a mozconfig file.
49 To Setup Firefox On Windows
50 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
52 .. code-block:: shell
54     $ cd c:/
55     $ mkdir mozilla-source
56     $ cd mozilla-source
57     $ wget https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py
58     $ python3 bootstrap.py
60 More information on :ref:`building Firefox for Windows <Building Firefox On Windows>`.
62 To Setup Firefox On macOS and Linux
63 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65 .. code-block:: shell
67     $ curl https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py -O
68     $ python3 bootstrap.py
70 More information on :ref:`building Firefox for Linux <Building Firefox On Linux>` and :ref:`building Firefox for MacOS <Building Firefox On MacOS>`.
72 To Setup Firefox for Android
73 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75 .. code-block:: shell
77     $ curl https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py -O
78     $ python3 bootstrap.py
80 More information on :ref:`building Firefox for Android <Firefox for Android>`
82 To set up your editor
83 ---------------------
85 .. note::
87     Visual Studio Code is the recommended editor for Firefox development.
88     Not because it is better than the other editors but because we decided to
89     focus our energy on a single editor.
91 Setting up your editor is an important part of the contributing process. Having
92 linting and other features integrated, saves you time and will help with reducing
93 build and reviews cycles.
95 See our :ref:`editor page for more information about how to set up your favorite editor <Editor / IDE integration>`.
97 To build & run
98 --------------
100 Once the System is bootstrapped, run:
102 .. code-block:: shell
104     $ cd mozilla-unified
105     $ ./mach build
107 which will check for dependencies and start the build.
108 This will take a while; a few minutes to a few hours depending on your hardware.
110 .. note::
112     If you build Firefox often, add `ac_add_options \-\-with-ccache=sccache` to .mozconfig.
113     sccache will significantly speed up your builds by caching compilation results.
114     The Firefox build system will download sccache automatically.
116 .. note::
118     The default build is a compiled build with optimizations. Check out the
119     :ref:`mozconfig file documentation <Configuring Build Options>`
120     to see other build options. If you don't plan to change C++ or Rust code,
121     an :ref:`artifact build <Understanding Artifact Builds>` will be faster.
123 To run it:
125 .. code-block:: shell
127      $ ./mach run
129 This command will open your locally built Firefox in a new window.
131 :ref:`More information about building Firefox on Linux <Building Firefox On Linux>` / :ref:`More information about building Firefox on MacOS <Building Firefox On MacOS>`
133 If you encounter build errors, please reference the more detailed "Building Firefox" on your specific operating system document and specifically the "Troubleshooting" section.
135 .. _write_a_patch:
137 To write a patch
138 ----------------
140 Make the changes you need in the codebase. You can look up UI text in `Searchfox <https://searchfox.org>`__ to find the right file.
142 .. note::
143     If you are unsure of what changes you need to make, or need help from the mentor of the bug,
144     please don't hesitate to use the needinfo feature ("Request information from") on `Bugzilla <https://bugzilla.mozilla.org/home>`__ to get the attention of your mentor.
147 After making your changes, visualize your changes to ensure you're including all the necessary work:
149 .. code-block:: shell
151     # Mercurial
152     # For files changed/added/removed
153     $ hg status
155     # For detailed line changes
156     $ hg diff
158     # Git
159     # For files changed/added/removed
160     $ git status
162     # For detailed line changes
163     $ git diff
165 Then commit your changes:
167 .. code-block:: shell
169     # Mercurial
170     $ hg commit
172     # Git
173     $ git commit
175 .. _Commit message:
177 The commit message should look like:
179 .. code-block:: text
181     Bug xxxx - Short description of your change. r?reviewer
183     Optionally, a longer description of the change.
185 **Make sure you include the bug number and at least one reviewer (or reviewer group) in this format.**
187 For example, here is an example of a good commit message:
188 "Bug 123456 - Null-check presentation shell so we don't crash when a button removes itself
189 during its own onclick handler. r=person"
191 To :ref:`find a reviewer or a review group <Getting reviews>`, the easiest way is to run
192 ``hg log <modified-file>`` (or ``git log <modified-file>``, if
193 you're using git) on the relevant files, and look who usually is
194 reviewing the actual changes (ie not reformat, renaming of variables, etc).
197 To visualize your patch in the repository, run:
199 .. code-block:: shell
201     # Mercurial
202     $ hg wip
204     # Git
205     $ git show
207 :ref:`More information on how to work with stack of patches <Working with stack of patches Quick Reference>`
209 :ref:`More information on Mercurial <Mercurial Overview>`
211 To make sure the change follows the coding style
212 ------------------------------------------------
214 To detect coding style violations, use mach lint:
216 .. code-block:: shell
218     $ ./mach lint path/to/the/file/or/directory/you/changed
220     # To get the autofix, add --fix:
221     $ ./mach lint path/to/the/file/or/directory/you/changed --fix
223 :ref:`More information <Code quality>`
225 To test a change locally
226 ------------------------
228 To run the tests, use mach test with the path. However, it isn’t
229 always easy to parse the results.
231 .. code-block:: shell
233     $ ./mach test dom/serviceworkers
235 To run tests based on :ref:`GTest` (C/C++ based unit tests), run:
237 .. code-block:: shell
239     $ ./mach gtest 'QuotaManager.*'
241 To test a change remotely
242 -------------------------
244 Running all the tests for Firefox takes a very long time and requires multiple
245 operating systems with various configurations. To build Firefox and run its
246 tests on continuous integration servers (CI), multiple :ref:`options to select tasks <Selectors>`
247 are available.
249 To automatically select the tasks that are most likely to be affected by your changes, run:
251 .. code-block:: shell
253     $ ./mach try auto
255 To select tasks manually using a fuzzy search interface, run:
257 .. code-block:: shell
259     $ ./mach try fuzzy
261 To rerun the same tasks:
263 .. code-block:: shell
265     $ ./mach try again
267 From `Treeherder <https://treeherder.mozilla.org/>`__ (our continuous integration system), it is also possible to attach new jobs. As every review has
268 a try CI run associated, it makes this work easier. See :ref:`attach-job-review` for
269 more information.
271 .. note::
273     This requires `level 1 commit access <https://www.mozilla.org/about/governance/policies/commit/access-policy/>`__.
275     You can ask your reviewer to submit the patch for you if you don't have that
276     level of access.
278 :ref:`More information <Pushing to Try>`
281 To submit a patch
282 -----------------
284 To submit a patch for review, we use a tool called `moz-phab <https://pypi.org/project/MozPhab/>`__.
285 To install it, run:
287 .. code-block:: shell
289      $ ./mach install-moz-phab
291 Once you want to submit your patches (make sure you :ref:`use the right commit message <Commit message>`), run:
293 .. code-block:: shell
295      $ moz-phab
297 It will publish all the currently applied patches to Phabricator and inform the reviewer.
299 If you wrote several patches on top of each other:
301 .. code-block:: shell
303     $ moz-phab submit <first_revision>::<last_revision>
305 `More
306 information on how to use Phabricator and MozPhab <https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html>`__
308 To update the working directory
309 -------------------------------
311 If you're finished with a patch and would like to return to the tip to make a new patch:
313 .. code-block:: shell
315     $ hg pull central
316     $ hg up central
318 To update a submitted patch
319 ---------------------------
321 It is rare that a reviewer will accept the first version of patch. Moreover,
322 as the code review bot might suggest some improvements, changes to your patch
323 may be required.
325 If your patch is not loaded in your working directory, you first need to re-apply it:
327 .. code-block:: shell
329     $ moz-phab patch D<revision_id>
331     # Or you can use the URL of the revision on Phabricator
332     $ moz-phab patch https://phabricator.services.mozilla.com/D<revision_id>
334 Make your changes in the working folder and run:
336 .. code-block:: shell
338    # Or, if you need to pass arguments, e.g., changing the commit message:
339    $ hg commit --amend
341    # Git
342    $ git commit --amend
344 After amending the patch, you will need to submit it using moz-phab again.
346 .. warning::
348     Don't use ``hg commit --amend -m`` or ``git commit --amend -m``.
350     Phabricator tracks revision by editing the commit message when a
351     revision is created to add a special ``Differential Revision:
352     <url>`` line.
354     When ``--amend -m`` is used, that line will be lost, leading to
355     the creation of a new revision when re-submitted, which isn't
356     the desired outcome.
358 If you wrote many changes, you can squash or edit commits with the
359 command:
361 .. code-block:: shell
363    # Mercurial
364    $ hg histedit
366    # Git
367    $ git rebase -i
369 The submission step is the same as for the initial patch.
371 :ref:`More information on how to work with stack of patches <Working with stack of patches Quick Reference>`
373 Retrieve new changes from the repository
374 ----------------------------------------
376 To pull changes from the repository, run:
378 .. code-block:: shell
380    # Mercurial
381    $ hg pull --rebase
383    # Git
384    $ git pull --rebase
386 .. _push_a_change:
388 To push a change in the code base
389 ---------------------------------
391 Once the change has been accepted and you've fixed any remaining issues
392 the reviewer identified, the reviewer should land the patch.
394 If the patch has not landed on "autoland" (the integration branch) after a few days,
395 feel free to contact the reviewer and/or
396 @Aryx or @Sylvestre on the `#introduction <https://chat.mozilla.org/#/room/#introduction:mozilla.org>`__
397 channel.
399 The landing procedure will automatically close the review and the bug.
401 :ref:`More information <How to submit a patch>`
403 Contributing to GeckoView
404 -------------------------
406 Note that the GeckoView setup and contribution processes are different from those of Firefox;
407 GeckoView setup and contribution docs live in `geckoview.dev <https://geckoview.dev>`__.
409 More documentation about contribution
410 -------------------------------------
412 :ref:`How to Contribute Code to Firefox`
414 :ref:`Contributing to Mozilla projects`
416 https://mozilla-version-control-tools.readthedocs.io/en/latest/devguide/contributing.html
418 https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html
420 https://mikeconley.github.io/documents/How_mconley_uses_Mercurial_for_Mozilla_code