contributing.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. .. _contributing:
  2. ==============================================================================
  3. Contributing to libinput
  4. ==============================================================================
  5. So you want to contribute to libinput? Great! We'd love to help you be a part
  6. of our community. Here is some important information to help you.
  7. .. contents::
  8. :local:
  9. ------------------------------------------------------------------------------
  10. Code of Conduct
  11. ------------------------------------------------------------------------------
  12. As a freedesktop.org project, libinput follows the `freedesktop.org
  13. Contributor Covenant <https://www.freedesktop.org/wiki/CodeOfConduct>`_.
  14. Please conduct yourself in a respectful and civilised manner when
  15. interacting with community members on mailing lists, IRC, or bug trackers.
  16. The community represents the project as a whole, and abusive or bullying
  17. behaviour is not tolerated by the project.
  18. ------------------------------------------------------------------------------
  19. Contact
  20. ------------------------------------------------------------------------------
  21. Questions can be asked on ``#wayland`` on oftc or on the
  22. `wayland-devel@lists.freedesktop.org
  23. <https://lists.freedesktop.org/mailman/listinfo/wayland-devel>`_ mailing
  24. list.
  25. For IRC, ping user ``whot`` (Peter Hutterer, the libinput maintainer) though
  26. note that he lives on UTC+10 and thus the rest of the world is out of sync
  27. by default ;)
  28. For anything that appears to be device specific and/or related to a new
  29. feature, just file `an issue in our issue tracker
  30. <https://gitlab.freedesktop.org/libinput/libinput/issues>`_. It's usually the
  31. most efficient way to get answers.
  32. ------------------------------------------------------------------------------
  33. What to work on?
  34. ------------------------------------------------------------------------------
  35. If you don't already know what you want to improve or fix with libinput,
  36. then a good way of finding something is to search for the ``help needed``
  37. tag in our `issue tracker <https://gitlab.freedesktop.org/libinput/libinput/issues?label_name%5B%5D=help+needed>`_.
  38. These are issues that have been triaged to some degree and deemed to be a
  39. possible future feature to libinput.
  40. .. note:: Some of these issue may require specific hardware to reproduce.
  41. Another good place to help out with is the documentation. For anything you
  42. find in these pages that isn't clear enough please feel free to reword it
  43. and add what is missing.
  44. ------------------------------------------------------------------------------
  45. Getting the code
  46. ------------------------------------------------------------------------------
  47. The :ref:`building_libinput` have all the details but the short solution
  48. will be:
  49. ::
  50. $> git clone https://gitlab.freedesktop.org/libinput/libinput
  51. $> cd libinput
  52. $> meson setup --prefix=/usr builddir/
  53. $> ninja -C builddir/
  54. $> sudo ninja -C builddir/ install
  55. You can omit the last step if you only want to test locally.
  56. ------------------------------------------------------------------------------
  57. Working on the code
  58. ------------------------------------------------------------------------------
  59. If you are planning to send patches, it's a good idea to set up
  60. `pre-commit <https://pre-commit.com/>`_ with these commands::
  61. $> pre-commit install
  62. $> pre-commit install --hook-type pre-push
  63. This will check a few things before you commit and/or push to your repos to
  64. reduce the turnaround time for some common mistakes.
  65. libinput has a roughly three-parts architecture:
  66. - the front-end code which handles the ``libinput_some_function()`` API calls in ``libinput.c``
  67. - the generic evdev interface handling which maps those API calls to the
  68. backend calls (``evdev.c``).
  69. - there are device-specific backends which do most of the actual work -
  70. ``evdev-mt-touchpad.c`` is the one for touchpads for example.
  71. In general, things that only affect the internal workings of a device only
  72. get implemented in the device-specific backend. You only need to touch the
  73. API when you are adding configuration options. For more details, please read
  74. the :ref:`architecture` document. There's also a `blog post describing the
  75. building blocks
  76. <https://who-t.blogspot.com/2019/03/libinputs-internal-building-blocks.html>`_
  77. that may help to understand how it all fits together.
  78. Documentation is in ``/doc/api`` for the doxygen-generated API documentation.
  79. These are extracted from the libinput source code directly. The
  80. documentation you're reading right now is in ``/doc/user`` and generated with
  81. sphinx. Simply running ``ninja -C builddir`` will rebuild it and the final
  82. product ends up in ``builddir/Documentation``.
  83. ------------------------------------------------------------------------------
  84. Testing the code
  85. ------------------------------------------------------------------------------
  86. libinput provides a bunch of :ref:`tools` to debug any changes - without
  87. having to install libinput.
  88. The two most useful ones are :ref:`libinput debug-events
  89. <libinput-debug-events>` and :ref:`libinput debug-gui <libinput-debug-gui>`.
  90. Both tools can be run from the build directory directly and are great for
  91. quick test iterations::
  92. $> sudo ./builddir/libinput-debug-events --verbose
  93. $> sudo ./builddir/libinput-debug-gui --verbose
  94. The former provides purely textual output and is useful for verifying event
  95. streams from buttons, etc. The latter is particularly useful when you are
  96. trying to debug pointer movement or placement. ``libinput debug-gui`` will
  97. also visualize the raw data from the device so you can compare pointer
  98. behavior with what comes from the kernel.
  99. These tools create a new libinput context and will not affect your session's
  100. behavior. Only once you've installed libinput and restarted your session
  101. will your changes affect the X server/Wayland compositor.
  102. Once everything seems to be correct, it's time to run the
  103. :ref:`test-suite`::
  104. $> sudo ./builddir/libinput-test-suite
  105. This test suite can take test names etc. as arguments, have a look at
  106. :ref:`test-suite` for more info. There are a bunch of other tests that are
  107. run by the CI on merge requests, you can run those locally with ::
  108. $> sudo meson test -C builddir
  109. So it always pays to run that before submitting.
  110. .. _contributing_submitting_code:
  111. ------------------------------------------------------------------------------
  112. Submitting Code
  113. ------------------------------------------------------------------------------
  114. Any patches should be sent via a Merge Request (see the `GitLab docs
  115. <https://docs.gitlab.com/ce/gitlab-basics/add-merge-request.htm>`_)
  116. in the `libinput GitLab instance hosted by freedesktop.org
  117. <https://gitlab.freedesktop.org/libinput/libinput>`_.
  118. .. note:: freedesktop.org's GitLab instance has restrictions to prevent Spam
  119. and you cannot fork libinput until you have successfully
  120. `applied for fork permissions <https://gitlab.freedesktop.org/freedesktop/freedesktop/-/wikis/home>`_.
  121. Below are the steps required to submit a merge request. They do not
  122. replace `learning git <https://git-scm.com/doc>`__ but they should be
  123. sufficient to make some of the more confusing steps obvious.
  124. - `Register an account <https://gitlab.freedesktop.org/users/sign_in>`_ in
  125. the freedesktop.org GitLab instance and
  126. `apply for fork permissions <https://gitlab.freedesktop.org/freedesktop/freedesktop/-/wikis/home>`_.
  127. - `Fork libinput <https://gitlab.freedesktop.org/libinput/libinput/-/forks/new>`_
  128. into your username's namespace. Select public visibility.
  129. - Get libinput's main repository. git will call this repository ``origin``. ::
  130. git clone https://gitlab.freedesktop.org/libinput/libinput.git
  131. - Add the forked git repository to your remotes (replace ``USERNAME``
  132. with your username). git will call this repository ``gitlab``. ::
  133. cd /path/to/libinput.git
  134. git remote add gitlab git@ssh.gitlab.freedesktop.org:USERNAME/libinput.git
  135. git fetch gitlab
  136. - Create a new branch and commit your changes to that branch. ::
  137. git switch -C mynewbranch
  138. # edit files, make changes
  139. git add file1 file2
  140. git commit -s
  141. # edit commit message in the editor
  142. Replace ``mynewbranch`` (here and in the commands below) with a meaningful
  143. name. See :ref:`contributing_commit_messages` for details on the commit
  144. message format.
  145. - Push your changes to your fork and submit a merge request ::
  146. git push gitlab mynewbranch
  147. This command will print the URL to file a merge request, you then only
  148. have to click through. Alternatively you can go to:
  149. https://gitlab.freedesktop.org/USERNAME/libinput/merge_requests
  150. Select your branch name to merge and ``libinput/libinput`` ``main`` as target branch.
  151. - Verify that the CI completes successfully by visiting the merge request
  152. page. A successful pipeline shows only green ticks, failure is indicated
  153. by a red cross or a yellow exclamation mark (see
  154. the `GitLab Docs
  155. <https://docs.gitlab.com/ee/ci/pipelines/#pipeline-mini-graphs>`__). For
  156. details about the failures, click on the failed jobs in the pipelines
  157. and/or click the ``Expand`` button in the box for the test summaries.
  158. A merge request without a successful pipeline may never be looked at by a
  159. maintainer.
  160. - If changes are requested by the maintainers, please **amend** the
  161. commit(s) and **force-push** the updated branch. ::
  162. # edits in file foo.c
  163. git add foo.c
  164. git commit --amend
  165. git push -f gitlab mynewbranch
  166. A force-push will re-trigger the CI and notify the merge request that new
  167. changes are available.
  168. If the branch contains more than one commit, please look at
  169. `git interactive rebases
  170. <https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History>`__
  171. to learn how to change multiple commits, or squash new changes into older
  172. commits.
  173. ------------------------------------------------------------------------------
  174. Commit History
  175. ------------------------------------------------------------------------------
  176. libinput strives to have a
  177. `linear, 'recipe' style history <http://www.bitsnbites.eu/git-history-work-log-vs-recipe/>`_
  178. This means that every commit should be small, digestible, stand-alone, and
  179. functional. Rather than a purely chronological commit history like this: ::
  180. doc: final docs for view transforms
  181. fix tests when disabled, redo broken doc formatting
  182. better transformed-view iteration (thanks Hannah!)
  183. try to catch more cases in tests
  184. tests: add new spline test
  185. fix compilation on splines
  186. doc: notes on reticulating splines
  187. compositor: add spline reticulation for view transforms
  188. We aim to have a clean history which only reflects the final state, broken up
  189. into functional groupings: ::
  190. compositor: add spline reticulation for view transforms
  191. compositor: new iterator for view transforms
  192. tests: add view-transform correctness tests
  193. doc: fix Doxygen formatting for view transforms
  194. This ensures that the final patch series only contains the final state,
  195. without the changes and missteps taken along the development process.
  196. The first line of a commit message should contain a prefix indicating
  197. what part is affected by the patch followed by one sentence that
  198. describes the change. For example: ::
  199. touchpad: add software button behavior
  200. fallback: disable button debouncing on device foo
  201. If in doubt what prefix to use, look at other commits that change the
  202. same file(s) as the patch being sent.
  203. .. _contributing_commit_messages:
  204. ------------------------------------------------------------------------------
  205. Commit Messages
  206. ------------------------------------------------------------------------------
  207. When you re-send patches, revised or not, it would be very good to document the
  208. changes compared to the previous revision in the commit message and/or the
  209. merge request. If you have already received Reviewed-by or Acked-by tags, you
  210. should evaluate whether they still apply and include them in the respective
  211. commit messages. Otherwise the tags may be lost, reviewers miss the credit they
  212. deserve, and the patches may cause redundant review effort.
  213. If your commit solves a GitLab issue, add a ``Closes:`` tag followed by the
  214. issue number at the end of your commit message. For example: ::
  215. Closes: #974
  216. If your commit fixes an issue introduced by another commit, use a ``Fixes`` tag
  217. followed by the first 12 characters of the SHA-1 ID and the commit one line
  218. summary at the end of your commit message. For example: ::
  219. Fixes: 123456789012 ("The commit that caused the issue")
  220. For further reading, please see
  221. `'on commit messages' <http://who-t.blogspot.de/2009/12/on-commit-messages.html>`_
  222. as a general guideline on what commit messages should contain.
  223. ------------------------------------------------------------------------------
  224. Coding Style
  225. ------------------------------------------------------------------------------
  226. Please see the `CODING_STYLE.md
  227. <https://gitlab.freedesktop.org/libinput/libinput/blob/main/CODING_STYLE.md>`_
  228. document in the source tree.
  229. ------------------------------------------------------------------------------
  230. Tracking patches and follow-ups
  231. ------------------------------------------------------------------------------
  232. Once submitted to GitLab, your patches will be reviewed by the libinput
  233. development team on GitLab. Review may be entirely positive and result in your
  234. code landing instantly, in which case, great! You're done. However, we may ask
  235. you to make some revisions: fixing some bugs we've noticed, working to a
  236. slightly different design, or adding documentation and tests.
  237. If you do get asked to revise the patches, please bear in mind the notes above.
  238. You should use ``git rebase -i`` to make revisions, so that your patches
  239. follow the clear linear split documented above. Following that split makes
  240. it easier for reviewers to understand your work, and to verify that the code
  241. you're submitting is correct.
  242. A common request is to split single large patch into multiple patches. This can
  243. happen, for example, if when adding a new feature you notice a bug in
  244. libinput's core which you need to fix to progress. Separating these changes
  245. into separate commits will allow us to verify and land the bugfix quickly,
  246. pushing part of your work for the good of everyone, whilst revision and
  247. discussion continues on the larger feature part. It also allows us to direct
  248. you towards reviewers who best understand the different areas you are
  249. working on.
  250. When you have made any requested changes, please rebase the commits, verify
  251. that they still individually look good, then force-push your new branch to
  252. GitLab. This will update the merge request and notify everyone subscribed to
  253. your merge request, so they can review it again.
  254. There are also many GitLab CLI clients, if you prefer to avoid the web
  255. interface. It may be difficult to follow review comments without using the
  256. web interface though, so we do recommend using this to go through the review
  257. process, even if you use other clients to track the list of available
  258. patches.
  259. ------------------------------------------------------------------------------
  260. Failed pipeline errors
  261. ------------------------------------------------------------------------------
  262. After submitting your merge request to GitLab, you might receive an email
  263. informing you that your pipeline failed.
  264. Visit your merge request page and check the `pipeline mini graph
  265. <https://docs.gitlab.com/ee/ci/pipelines/#pipeline-mini-graphs>`_ to know which
  266. step failed.
  267. Follow the appropriate section to fix the errors.
  268. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  269. Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify
  270. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  271. When your merge request modifies the CI templates, you might see this error
  272. mainly due two reasons: the wrong file was modified and/or
  273. ``ci-fairy generate-template`` wasn't run.
  274. ``.gitlab-ci.yaml`` is auto generated, changes should be made in:
  275. - ``.gitlab-ci/ci.template``
  276. - ``.gitlab-ci/config.yaml``
  277. Once the changes are ready, run
  278. `ci-fairy <https://freedesktop.pages.freedesktop.org/ci-templates/ci-fairy.html#templating-gitlab-ci-yml>`_
  279. to update ``.gitlab-ci.yaml``: ::
  280. ci-fairy generate-template
  281. Finally, force-push you changes. See :ref:`contributing_submitting_code` for
  282. more details.
  283. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  284. Build errors
  285. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  286. Usually, checking the CI log is enough to catch this errors. However, your merge
  287. request is built using different configurations you might have not tested.
  288. In order to fix this kind of problems, you can compile libinput using the same
  289. flags used by the CI.
  290. For example, if an error is found in the ``build-no-libwacom`` step, open the
  291. log and search the build options: ::
  292. [...]
  293. + rm -rf 'build dir'
  294. + meson 'build dir' -Dlibwacom=false
  295. The Meson build system
  296. [...]
  297. Use the same flags to fix the issue and force-push you changes. See
  298. :ref:`contributing_submitting_code` for more details.
  299. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  300. Test errors
  301. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  302. The test suite is run for your merge request to check for bugs, regressions and
  303. memory leaks among other issues.
  304. Open the CI error log and search for a message similar to: ::
  305. :: Failure: ../test/test-touchpad.c:465: touchpad_2fg_scroll_slow_distance(synaptics-t440)
  306. See :ref:`test-suite` to learn how to run the failing tests.
  307. Once the tests are fixed, force-push you changes. See
  308. :ref:`contributing_submitting_code` for more details.