developer.rst 4.15 KB
Newer Older
1 2 3 4 5
============================================
The Music Player Daemon - Developer's Manual
============================================

Introduction
Rasmus Steinke's avatar
Rasmus Steinke committed
6
============
7 8 9 10

This is a guide for those who wish to hack on the MPD source code.  MPD is an open project, and we are always happy about contributions.  So far, more than 150 people have contributed patches. This document is work in progress.  Most of it may be incomplete yet.  Please help!

Code Style
Rasmus Steinke's avatar
Rasmus Steinke committed
11
==========
12 13 14 15 16 17 18 19 20 21

* indent with tabs (width 8)
* don't write CPP when you can write C++: use inline functions and constexpr instead of macros
* comment your code, document your APIs
* the code should be C++14 compliant, and must compile with :program:`GCC` 6.0 and :program:`clang` 3.4
* report error conditions with C++ exceptions, preferable derived from :envvar:`std::runtime_error`
* all code must be exception-safe
* classes and functions names use CamelCase; variables are lower-case with words separated by underscore

Some example code:
Rasmus Steinke's avatar
Rasmus Steinke committed
22
~~~~~~~~~~~~~~~~~~
23 24 25 26 27 28 29 30 31 32 33 34 35 36

.. code-block:: c

    Foo(const char *abc, int xyz)
    {
        if (abc == nullptr) {
                LogWarning("Foo happened!");
                return -1;
        }

        return xyz;
    }

Hacking The Source
Rasmus Steinke's avatar
Rasmus Steinke committed
37 38
==================

39 40 41 42 43
MPD sources are managed in a git repository on
`Github <https://github.com/MusicPlayerDaemon/>`_.

Always write your code against the latest git:

44
.. code-block:: none
45 46 47 48 49

    git clone git://github.com/MusicPlayerDaemon/MPD

If you already have a clone, update it:

50
.. code-block:: none
51 52 53

    git pull --rebase git://github.com/MusicPlayerDaemon/MPD master

54
You can do without :option:`--rebase`, but we recommend that you rebase your repository on the "master" repository all the time.
55 56 57 58 59 60 61

Configure with the options :option:`--enable-debug --enable-werror`.  Enable as many plugins as possible, to be sure that you don't break any disabled code.

Don't mix several changes in one single patch.  Create a separate patch for every change. Tools like :program:`stgit` help you with that. This way, we can review your patches more easily, and we can pick the patches we like most first.

Basic stgit usage
-----------------
Rasmus Steinke's avatar
Rasmus Steinke committed
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
stgit allows you to create a set of patches and refine all of them: you can go back to any patch at any time, and re-edit it (both the code and the commit message). You can reorder patches and insert new patches at any position. It encourages creating separate patches for tiny changes.

stgit needs to be initialized on a git repository:

.. code-block:: sh

    stg init

Before you edit the code, create a patch:

.. code-block:: sh

    stg new my-patch-name

stgit now asks you for the commit message.

Now edit the code. Once you're finished, you have to "refresh" the patch, i.e. your edits are incorporated into the patch you have created:

.. code-block:: sh

    stg refresh

You may now continue editing the same patch, and refresh it as often as you like. Create more patches, edit and refresh them.

To view the list of patches, type stg series. To go back to a specific patch, type stg goto my-patch-name; now you can re-edit it (don't forget stg refresh when you're finished with that patch).

When the whole patch series is finished, convert stgit patches to git commits:

.. code-block:: sh

    stg commit

Submitting Patches
Rasmus Steinke's avatar
Rasmus Steinke committed
96
==================
97 98 99 100 101 102 103

Send your patches to the mailing list:
Email: `mpd-devel <mpd-devel@musicpd.org>`_

:program:`git pull` requests are preferred.

Development Tools
Rasmus Steinke's avatar
Rasmus Steinke committed
104
=================
105 106

Clang Static Analyzer
Rasmus Steinke's avatar
Rasmus Steinke committed
107
---------------------
108 109 110 111 112 113 114 115 116 117 118 119 120

 The `static analyzer <http://clang-analyzer.llvm.org/>`_ is a tool that helps find bugs. To run it on the MPD code base, install LLVM and clang. configure MPD to use clang:

.. code-block:: sh

    ./configure --enable-debug CXX=clang++ CC=clang ...

It is recommended to use :option:`--enable-debug`, because the analyzer takes advantage of :dfn:`assert()` calls, which are only enabled in the debug build. 

Now run the analyzer:

.. code-block:: sh

121
    scan-build --use-c++=clang++ --use-cc=clang make
122 123

The options :option:`--use-c++` and :option:`--use-cc` are necessary because it invokes :command:`cc` for actually compiling the sources by default. That breaks, because MPD requires a C99 compiler.