tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

contribution_quickref.rst (12872B)


      1 Firefox Contributors' Quick Reference
      2 =====================================
      3 
      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.
      7 
      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.
      9 
     10 Before you start
     11 ----------------
     12 Please register and create your account for
     13 
     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.
     16 
     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)
     19 
     20 Windows dependencies
     21 --------------------
     22 
     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:
     25 
     26    .. code-block:: shell
     27 
     28        $ c:\mozilla-build\
     29 
     30 #. Before moving on to the next steps, make sure to fulfill the :ref:`Windows prerequisites <Building Firefox On Windows>`
     31 
     32 .. note::
     33 
     34    All the commands of this tutorial must be run in the shell provided with the MozillaBuild Package (start-shell.bat)
     35 
     36 :ref:`More information on building Firefox on Windows <Building Firefox On Windows>`
     37 
     38 Bootstrap a copy of the Firefox source code
     39 -------------------------------------------
     40 
     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.
     42 
     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).
     44 
     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.
     48 
     49 To Setup Firefox On Windows
     50 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     51 
     52 .. code-block:: shell
     53 
     54    $ cd c:/
     55    $ mkdir mozilla-source
     56    $ cd mozilla-source
     57    $ wget https://raw.githubusercontent.com/mozilla-firefox/firefox/refs/heads/main/python/mozboot/bin/bootstrap.py
     58 
     59    $ python3 bootstrap.py
     60 
     61 More information on :ref:`building Firefox for Windows <Building Firefox On Windows>`.
     62 
     63 To Setup Firefox On macOS and Linux
     64 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     65 
     66 .. code-block:: shell
     67 
     68    $ curl -L https://raw.githubusercontent.com/mozilla-firefox/firefox/refs/heads/main/python/mozboot/bin/bootstrap.py -O
     69 
     70    $ python3 bootstrap.py
     71 
     72 More information on :ref:`building Firefox for Linux <Building Firefox On Linux>` and :ref:`building Firefox for MacOS <Building Firefox On MacOS>`.
     73 
     74 To Setup Firefox for Android
     75 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     76 
     77 .. code-block:: shell
     78 
     79    $ curl -L https://raw.githubusercontent.com/mozilla-firefox/firefox/refs/heads/main/python/mozboot/bin/bootstrap.py -O
     80 
     81    $ python3 bootstrap.py
     82 
     83 More information on :ref:`building Firefox for Android <Firefox for Android>`
     84 
     85 To set up your editor
     86 ---------------------
     87 
     88 .. note::
     89 
     90    Visual Studio Code is the recommended editor for Firefox development.
     91    Not because it is better than the other editors but because we decided to
     92    focus our energy on a single editor.
     93 
     94 Setting up your editor is an important part of the contributing process. Having
     95 linting and other features integrated, saves you time and will help with reducing
     96 build and reviews cycles.
     97 
     98 See our :ref:`editor page for more information about how to set up your favorite editor <Editor / IDE integration>`.
     99 
    100 More advanced git configuration
    101 -------------------------------
    102 
    103 See the :ref:`Git tips and tricks page <Git Tricks>` to use a personal fork, and for other useful git configurations.
    104 
    105 To build & run
    106 --------------
    107 
    108 Once the System is bootstrapped, run:
    109 
    110 .. code-block:: shell
    111 
    112    $ cd firefox
    113    $ ./mach build
    114 
    115 which will check for dependencies and start the build.
    116 This will take a while; a few minutes to a few hours depending on your hardware.
    117 
    118 .. note::
    119 
    120    If you build Firefox often, add `ac_add_options \-\-with-ccache=sccache` to .mozconfig.
    121    sccache will significantly speed up your builds by caching compilation results.
    122    The Firefox build system will download sccache automatically.
    123 
    124 .. note::
    125 
    126    The default build is a compiled build with optimizations. Check out the
    127    :ref:`mozconfig file documentation <Configuring Build Options>`
    128    to see other build options. If you don't plan to change C++ or Rust code,
    129    an :ref:`artifact build <Understanding Artifact Builds>` will be faster.
    130 
    131 To run it:
    132 
    133 .. code-block:: shell
    134 
    135     $ ./mach run
    136 
    137 This command will open your locally built Firefox in a new window.
    138 
    139 :ref:`More information about building Firefox on Linux <Building Firefox On Linux>` / :ref:`More information about building Firefox on MacOS <Building Firefox On MacOS>`
    140 
    141 If you encounter build errors, please reference the more detailed "Building Firefox" on your specific operating system document and specifically the "Troubleshooting" section.
    142 
    143 .. _write_a_patch:
    144 
    145 To write a patch
    146 ----------------
    147 
    148 Make the changes you need in the codebase. You can look up UI text in `Searchfox <https://searchfox.org>`__ to find the right file.
    149 
    150 .. note::
    151    If you are unsure of what changes you need to make, or need help from the mentor of the bug,
    152    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.
    153 
    154 
    155 After making your changes, visualize your changes to ensure you're including all the necessary work:
    156 
    157 .. code-block:: shell
    158 
    159    # For files changed/added/removed
    160    $ git status
    161 
    162    # For detailed line changes
    163    $ git diff
    164 
    165 Then commit your changes:
    166 
    167 .. code-block:: shell
    168 
    169    # Git
    170    $ git commit
    171 
    172 .. _Commit message:
    173 
    174 The commit message should look like:
    175 
    176 .. code-block:: text
    177 
    178    Bug xxxx - Short description of your change. r?reviewer
    179 
    180    Optionally, a longer description of the change.
    181 
    182 **Make sure you include the bug number and at least one reviewer (or reviewer group) in this format.**
    183 
    184 For example, here is an example of a good commit message:
    185 "Bug 123456 - Null-check presentation shell so we don't crash when a button removes itself
    186 during its own onclick handler. r=person"
    187 
    188 To :ref:`find a reviewer or a review group <Getting reviews>`, the easiest way is to run
    189 `git log <modified-file>`` on the relevant files, and look who usually is
    190 reviewing the actual changes (ie not reformat, renaming of variables, etc).
    191 
    192 
    193 To visualize your patch in the repository, run:
    194 
    195 .. code-block:: shell
    196 
    197    # Git
    198    $ git show
    199 
    200 :ref:`More information on how to work with stack of patches <Working with stack of patches Quick Reference>`
    201 
    202 To make sure the change follows the coding style
    203 ------------------------------------------------
    204 
    205 To detect coding style violations, use mach lint:
    206 
    207 .. code-block:: shell
    208 
    209    $ ./mach lint path/to/the/file/or/directory/you/changed
    210 
    211    # To get the autofix, add --fix:
    212    $ ./mach lint path/to/the/file/or/directory/you/changed --fix
    213 
    214 :ref:`More information <Code quality>`
    215 
    216 To test a change locally
    217 ------------------------
    218 
    219 To run the tests, use mach test with the path. However, it isn’t
    220 always easy to parse the results.
    221 
    222 .. code-block:: shell
    223 
    224    $ ./mach test dom/serviceworkers
    225 
    226 To run tests based on :ref:`GTest` (C/C++ based unit tests), run:
    227 
    228 .. code-block:: shell
    229 
    230    $ ./mach gtest 'QuotaManager.*'
    231 
    232 To test a change remotely
    233 -------------------------
    234 
    235 Running all the tests for Firefox takes a very long time and requires multiple
    236 operating systems with various configurations. To build Firefox and run its
    237 tests on continuous integration servers (CI), multiple :ref:`options to select tasks <Selectors>`
    238 are available.
    239 
    240 To automatically select the tasks that are most likely to be affected by your changes, run:
    241 
    242 .. code-block:: shell
    243 
    244    $ ./mach try auto
    245 
    246 To select tasks manually using a fuzzy search interface, run:
    247 
    248 .. code-block:: shell
    249 
    250    $ ./mach try fuzzy
    251 
    252 To rerun the same tasks:
    253 
    254 .. code-block:: shell
    255 
    256    $ ./mach try again
    257 
    258 From `Treeherder <https://treeherder.mozilla.org/>`__ (our continuous integration system), it is also possible to attach new jobs. As every review has
    259 a try CI run associated, it makes this work easier. See :ref:`attach-job-review` for
    260 more information.
    261 
    262 .. note::
    263 
    264    This requires `level 1 commit access <https://www.mozilla.org/about/governance/policies/commit/access-policy/>`__.
    265 
    266    You can ask your reviewer to submit the patch for you if you don't have that
    267    level of access.
    268 
    269 :ref:`More information <Pushing to Try>`
    270 
    271 
    272 To submit a patch
    273 -----------------
    274 
    275 To submit a patch for review, we use a tool called `moz-phab <https://pypi.org/project/MozPhab/>`__.
    276 To install it, run:
    277 
    278 .. code-block:: shell
    279 
    280     $ ./mach install-moz-phab
    281 
    282 Once you want to submit your patches (make sure you :ref:`use the right commit message <Commit message>`), run:
    283 
    284 .. code-block:: shell
    285 
    286     $ moz-phab
    287 
    288 It will publish all the currently applied patches to Phabricator and inform the reviewer.
    289 
    290 If you wrote several patches on top of each other:
    291 
    292 .. code-block:: shell
    293 
    294    $ moz-phab submit <first_revision>::<last_revision>
    295 
    296 `More
    297 information on how to use Phabricator and MozPhab <https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html>`__
    298 
    299 To update the working directory
    300 -------------------------------
    301 
    302 If you're finished with a patch and would like to return to the tip to make a new patch:
    303 
    304 .. code-block:: shell
    305 
    306    $ git pull --rebase
    307 
    308 To update a submitted patch
    309 ---------------------------
    310 
    311 It is rare that a reviewer will accept the first version of patch. Moreover,
    312 as the code review bot might suggest some improvements, changes to your patch
    313 may be required.
    314 
    315 If your patch is not loaded in your working directory, you first need to re-apply it:
    316 
    317 .. code-block:: shell
    318 
    319    $ moz-phab patch D<revision_id>
    320 
    321    # Or you can use the URL of the revision on Phabricator
    322    $ moz-phab patch https://phabricator.services.mozilla.com/D<revision_id>
    323 
    324 Make your changes in the working folder and run:
    325 
    326 .. code-block:: shell
    327 
    328   # Git
    329   $ git commit --amend
    330 
    331 After amending the patch, you will need to submit it using moz-phab again.
    332 
    333 .. warning::
    334 
    335    Don't use ``git commit --amend -m``.
    336 
    337    Phabricator tracks revision by editing the commit message when a
    338    revision is created to add a special ``Differential Revision:
    339    <url>`` line.
    340 
    341    When ``--amend -m`` is used, that line will be lost, leading to
    342    the creation of a new revision when re-submitted, which isn't
    343    the desired outcome.
    344 
    345 If you wrote many changes, you can squash or edit commits with the
    346 command:
    347 
    348 .. code-block:: shell
    349 
    350   # Git
    351   $ git rebase -i
    352 
    353 The submission step is the same as for the initial patch.
    354 
    355 :ref:`More information on how to work with stack of patches <Working with stack of patches Quick Reference>`
    356 
    357 Retrieve new changes from the repository
    358 ----------------------------------------
    359 
    360 To pull changes from the repository, run:
    361 
    362 .. code-block:: shell
    363 
    364   # Git
    365   $ git pull --rebase
    366 
    367 .. _push_a_change:
    368 
    369 To push a change in the code base
    370 ---------------------------------
    371 
    372 Once the change has been accepted and you've fixed any remaining issues
    373 the reviewer identified, the reviewer should land the patch.
    374 
    375 If the patch has not landed on "autoland" (the integration branch) after a few days,
    376 feel free to contact the reviewer and/or
    377 @Aryx or @Sylvestre on the `#introduction <https://chat.mozilla.org/#/room/#introduction:mozilla.org>`__
    378 channel.
    379 
    380 The landing procedure will automatically close the review and the bug.
    381 
    382 :ref:`More information <How to submit a patch>`
    383 
    384 Contributing to GeckoView
    385 -------------------------
    386 
    387 Note that the GeckoView setup and contribution processes are different from those of Firefox;
    388 GeckoView setup and contribution docs live in `geckoview.dev <https://geckoview.dev>`__.
    389 
    390 More documentation about contribution
    391 -------------------------------------
    392 
    393 :ref:`How to Contribute Code to Firefox`
    394 
    395 :ref:`Contributing to Mozilla projects`
    396 
    397 https://mozilla-version-control-tools.readthedocs.io/en/latest/devguide/contributing.html
    398 
    399 https://moz-conduit.readthedocs.io/en/latest/phabricator-user.html