Home | History | Annotate | Download | only in source
      1 page.title=Submitting Patches
      2 @jd:body
      3 
      4 <!--
      5     Copyright 2010 The Android Open Source Project
      6 
      7     Licensed under the Apache License, Version 2.0 (the "License");
      8     you may not use this file except in compliance with the License.
      9     You may obtain a copy of the License at
     10 
     11         http://www.apache.org/licenses/LICENSE-2.0
     12 
     13     Unless required by applicable law or agreed to in writing, software
     14     distributed under the License is distributed on an "AS IS" BASIS,
     15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16     See the License for the specific language governing permissions and
     17     limitations under the License.
     18 -->
     19 <div id="qv-wrapper">
     20 
     21   <div id="qv">
     22     <h2>In this document</h2>
     23     <ol id="auto-toc">
     24     </ol>
     25   </div>
     26 </div>
     27 <p>This page describes the full process of submitting a patch to the AOSP, including
     28 reviewing and tracking changes with <a href="https://android-review.googlesource.com/">Gerrit</a>.</p>
     29 <h2 id="prerequisites">Prerequisites</h2>
     30 <ul>
     31 <li>
     32 <p>Before you follow the instructions on this page, you need to <a href="">initialize your
     33 build environment</a> and <a href="{@docRoot}source/downloading.html">download the source</a>.</p>
     34 </li>
     35 <li>
     36 <p>For details about Repo and Git, see the <a href="version-control.html">Developing</a> section.</p>
     37 </li>
     38 <li>
     39 <p>For information about the different roles you can play within the Android
     40 Open Source community, see <a href="/source/roles.html">Project roles</a>.</p>
     41 </li>
     42 <li>
     43 <p>If you plan to contribute code to the Android platform, be sure to read
     44 the <a href="/source/licenses.html">AOSP's licensing information</a>.</p>
     45 </li>
     46 <li>
     47 <p>Note that changes to some of the upstream projects used by Android should be
     48 made directly to that project, as described in <a href="#upstream-projects">Upstream Projects</a>.</p>
     49 </li>
     50 </ul>
     51 <h1 id="for-contributors">For contributors</h1>
     52 <h2 id="authenticate-with-the-server">Authenticate with the server</h2>
     53 <p>Before you can upload to Gerrit, you need to establish a password that
     54 will identify you with the server. You only need to do this once.</p>
     55 <ul>
     56 <li>
     57 <p>Sign in on the <a href="https://android-review.googlesource.com/">AOSP Gerrit Server</a>.</p>
     58 </li>
     59 <li>
     60 <p>Go to Settings -&gt; HTTP Password -&gt; Obtain Password</p>
     61 </li>
     62 <li>
     63 <p>Follow the instructions on the subsquent pages, and copy-paste your
     64 password in <code>~/.netrc</code>. If there are two password lines, copy both.</p>
     65 </li>
     66 </ul>
     67 <h2 id="start-a-repo-branch">Start a repo branch</h2>
     68 <p>For each change you intend to make, start a new branch within the relevant git repository:</p>
     69 <pre><code>$ repo start NAME .
     70 </code></pre>
     71 <p>You can start several independent branches at the same time in the same repository. The branch NAME is local to your workspace and will not be included on gerrit or the final source tree.</p>
     72 <h2 id="make-your-change">Make your change</h2>
     73 <p>Once you have modified the source files (and validated them, please) commit the changes to your local repository:</p>
     74 <pre><code>$ git add -A
     75 $ git commit -s
     76 </code></pre>
     77 <p>Provide a detailed description of the change in your commit message. This description will be pushed to the public AOSP repository, so please follow our guidelines for writing changelist descriptions: </p>
     78 <ul>
     79 <li>
     80 <p>Start with a one-line summary (60 characters max), followed by a blank line. This format is used by git and gerrit for various displays. </p>
     81 <pre><code>short description on first line
     82 
     83 more detailed description of your patch,
     84 which is likely to take up multiple lines.
     85 </code></pre>
     86 </li>
     87 <li>
     88 <p>The description should focus on what issue it solves, and how it solves it. The second part is somewhat optional when implementing new features, though desirable.</p>
     89 </li>
     90 <li>
     91 <p>Include a brief note of any assumptions or background information that may be important when another contributor works on this feature next year. </p>
     92 </li>
     93 </ul>
     94 <p>A unique change ID and your name and email as provided during <code>repo init</code> will be automatically added to your commit message. </p>
     95 <h2 id="upload-to-gerrit">Upload to gerrit</h2>
     96 <p>Once you have committed your change to your personal history, upload it to gerrit with</p>
     97 <pre><code>$ repo upload
     98 </code></pre>
     99 <p>If you have started multiple branches in the same repository, you will be prompted to select which one(s) to upload.</p>
    100 <p>After a successful upload, repo will provide you the URL of a new page on
    101 <a href="https://android-review.googlesource.com/">Gerrit</a>. Visit this link to view
    102 your patch on the review server, add comments, or request specific reviewers
    103 for your patch.</p>
    104 <h2 id="uploading-a-replacement-patch">Uploading a replacement patch</h2>
    105 <p>Suppose a reviewer has looked at your patch and requested a small modification. You can amend your commit within git, which will result in a new patch on gerrit with the same change ID as the original.</p>
    106 <p><em>Note that if you have made other commits since uploading this patch, you will need to manually move your git HEAD.</em></p>
    107 <pre><code>$ git add -A
    108 $ git commit --amend
    109 </code></pre>
    110 <p>When you upload the amended patch, it will replace the original on gerrit and in your local git history.</p>
    111 <h2 id="resolving-sync-conflicts">Resolving sync conflicts</h2>
    112 <p>If other patches are submitted to the source tree that conflict with yours, you will need to rebase your patch on top of the new HEAD of the source repository. The easy way to do this is to run</p>
    113 <pre><code>$ repo sync
    114 </code></pre>
    115 <p>This command first fetches the updates from the source server, then attempts to automatically rebase your HEAD onto the new remote HEAD.</p>
    116 <p>If the automatic rebase is unsuccessful, you will have to perform a manual rebase.</p>
    117 <pre><code>$ git rebase master
    118 </code></pre>
    119 <p>Using <code>git mergetool</code> may help you deal with the rebase conflict. Once you have successfully merged the conflicting files,</p>
    120 <pre><code>$ git rebase --continue
    121 </code></pre>
    122 <p>After either automatic or manual rebase is complete, run <code>repo upload</code> to submit your rebased patch.</p>
    123 <h2 id="after-a-submission-is-approved">After a submission is approved</h2>
    124 <p>After a submission makes it through the review and verification process, Gerrit automatically merges the change into the public repository. Other users will be able to run <code>repo sync</code> to pull the update into their local client.</p>
    125 <h1 id="for-reviewers-and-verifiers">For reviewers and verifiers</h1>
    126 <h2 id="reviewing-a-change">Reviewing a change</h2>
    127 <p>If you are assigned to be the Approver for a change, you need to determine the following:</p>
    128 <ul>
    129 <li>
    130 <p>Does this change fit within this project's stated purpose?</p>
    131 </li>
    132 <li>
    133 <p>Is this change valid within the project's existing architecture?</p>
    134 </li>
    135 <li>
    136 <p>Does this change introduce design flaws that will cause problems in the future?</p>
    137 </li>
    138 <li>
    139 <p>Does this change follow the best practices that have been established for this project?</p>
    140 </li>
    141 <li>
    142 <p>Is this change a good way to perform the described function?</p>
    143 </li>
    144 <li>
    145 <p>Does this change introduce any security or instability risks?</p>
    146 </li>
    147 </ul>
    148 <p>If you approve of the change, mark it with LGTM ("Looks Good to Me") within Gerrit.</p>
    149 <h2 id="verifying-a-change">Verifying a change</h2>
    150 <p>If you are assigned to be the Verifier for a change, you need to do the following:</p>
    151 <ul>
    152 <li>
    153 <p>Patch the change into your local client using one of the Download commands.</p>
    154 </li>
    155 <li>
    156 <p>Build and test the change.</p>
    157 </li>
    158 <li>
    159 <p>Within Gerrit use Publish Comments to mark the commit as "Verified" or "Fails," and add a message explaining what problems were identified.</p>
    160 </li>
    161 </ul>
    162 <h2 id="downloading-changes-from-gerrit">Downloading changes from Gerrit</h2>
    163 <p>A submission that has been verified and merged will be downloaded with the next <code>repo sync</code>. If you wish to download a specific change that has not yet been approved, run</p>
    164 <pre><code>$ repo download TARGET CHANGE
    165 </code></pre>
    166 <p>where TARGET is the local directory into which the change should be downloaded and CHANGE is the 
    167 change number as listed in <a href="https://android-review.googlesource.com/">Gerrit</a>. For more information,
    168 see the <a href="/source/using-repo.html">Repo reference</a>.</p>
    169 <h2 id="how-do-i-become-a-verifier-or-approver">How do I become a Verifier or Approver?</h2>
    170 <p>In short, contribute high-quality code to one or more of the Android projects.
    171 For details about the different roles in the Android Open Source community and
    172 who plays them, see <a href="/source/roles.html">Project Roles</a>.</p>
    173 <h2 id="diffs-and-comments">Diffs and comments</h2>
    174 <p>To open the details of the change within Gerrit, click on the "Id number" or "Subject" of a change. To compare the established code with the updated code, click the file name under "Side-by-side diffs."</p>
    175 <h2 id="adding-comments">Adding comments</h2>
    176 <p>Anyone in the community can use Gerrit to add inline comments to code submissions. A good comment will be relevant to the line or section of code to which it is attached in Gerrit. It might be a short and constructive suggestion about how a line of code could be improved, or it might be an explanation from the author about why the code makes sense the way it is.</p>
    177 <p>To add an inline comment, double-click the relevant line of the code and write your comment in the text box that opens. When you click Save, only you can see your comment.</p>
    178 <p>To publish your comments so that others using Gerrit will be able to see them, click the Publish Comments button. Your comments will be emailed to all relevant parties for this change, including the change owner, the patch set uploader (if different from the owner), and all current reviewers.</p>
    179 <p><a name="upstream-projects"></a></p>
    180 <h1 id="upstream-projects">Upstream Projects</h1>
    181 <p>Android makes use of a number of other open-source projects, such as the Linux kernel and WebKit, as described in
    182 <a href="/source/code-lines.html">Codelines, Branches, and Releases</a>. For most projects under <code>external/</code>, changes should be made upstream and then the Android maintainers informed of the new upstream release containing these changes. It may also be useful to upload patches that move us to track a new upstream release, though these can be difficult changes to make if the project is widely used within Android like most of the larger ones mentioned below, where we tend to upgrade with every release.</p>
    183 <p>One interesting special case is bionic. Much of the code there is from BSD, so unless the change is to code that's new to bionic, we'd much rather see an upstream fix and then pull a whole new file from the appropriate BSD. (Sadly we have quite a mix of different BSDs at the moment, but we hope to address that in future, and get into a position where we track upstream much more closely.)</p>
    184 <h2 id="icu4c">ICU4C</h2>
    185 <p>All changes to the ICU4C project at <code>external/icu4c</code> should be made upstream at
    186 <a href="http://site.icu-project.org/">icu-project.org/</a>.
    187 See <a href="http://site.icu-project.org/bugs">Submitting ICU Bugs and Feature Requests</a> for more.</p>
    188 
    189 <h2 id="llvmclangcompiler-rt">LLVM/Clang/Compiler-rt</h2>
    190 <p>All changes to LLVM-related projects (<code>external/clang</code>, <code>external/compiler-rt</code>,
    191 <code>external/llvm</code>) should be made upstream at
    192 <a href="http://llvm.org/">llvm.org/</a>.</p>
    193 
    194 <h2 id="mksh">
    195 <p>All changes to the MirBSD Korn Shell project at <code>external/mksh</code> should be made upstream
    196 either by sending an email to miros-mksh on the mirbsd.og domain (no subscription
    197 required to submit there) or (optionally) at <a href="https://launchpad.net/mksh">Launchpad</a>.
    198 </p>
    199 <h2 id="openssl">OpenSSL</h2>
    200 <p>All changes to the OpenSSL project at <code>external/openssl</code> should be made upstream at
    201 <a href="http://www.openssl.org">openssl.org</a>.</p>
    202 <h2 id="v8">V8</h2>
    203 <p>All changes to the V8 project at <code>external/v8</code> should be submitted upstream at
    204 <a href="https://code.google.com/p/v8">code.google.com/p/v8</a>. See <a href="https://code.google.com/p/v8/wiki/Contributing">Contributing to V8</a>
    205 for details.</p>
    206 <h2 id="webkit">WebKit</h2>
    207 <p>All changes to the WebKit project at <code>external/webkit</code> should be made
    208 upstream at <a href="http://www.webkit.org">webkit.org</a>. The process begins by filing a WebKit bug. 
    209 This bug should use <code>Android</code> for the <code>Platform</code> and <code>OS</code> 
    210 fields only if the bug is specific to Android. Bugs are far more likely to receive the reviewers'
    211 attention once a proposed fix is added and tests are included. See
    212 <a href="http://webkit.org/coding/contributing.html">Contributing Code to WebKit</a> for details.</p>
    213 <h2 id="zlib">zlib</h2>
    214 <p>All changes to the zlib project at <code>external/zlib</code> should be made upstream at
    215 <a href="http://zlib.net">zlib.net</a>.</p>
    216