developer.xml 5.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
               "docbook/dtd/xml/4.2/docbookx.dtd">
<book>
  <title>The Music Player Daemon - Developer's Manual</title>

  <chapter>
    <title>Introduction</title>

    <para>
      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
13
      contributions.  So far, more than 150 people have contributed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
      patches.
    </para>

    <para>
      This document is work in progress.  Most of it may be incomplete
      yet.  Please help!
    </para>
  </chapter>

  <chapter>
    <title>Code Style</title>

    <itemizedlist>
      <listitem>
        <para>
          indent with tabs (width 8)
        </para>
      </listitem>

      <listitem>
        <para>
35 36
          don't write CPP when you can write C++: use inline
          functions and constexpr instead of macros
37 38 39 40 41
        </para>
      </listitem>

      <listitem>
        <para>
42 43 44
          the code should be C++11 compliant, and must compile with
          <application>GCC</application> 4.6 and
          <application>clang</application> 3.2
45 46 47 48 49 50 51 52
        </para>
      </listitem>

      <listitem>
        <para>
          Some example code:
        </para>

53
        <programlisting lang="C">static inline int
54 55 56
foo(const char *abc, int xyz)
{
        if (abc == NULL) {
57
                LogWarning("Foo happened!");
58 59 60 61 62 63 64 65 66 67 68 69 70
                return -1;
        }

        return xyz;
}
        </programlisting>
      </listitem>
    </itemizedlist>
  </chapter>

  <chapter>
    <title>Hacking The Source</title>

71 72 73 74 75
    <para>
      MPD sources are managed in a git repository on <ulink
      url="http://git.musicpd.org/">git.musicpd.org</ulink>.
    </para>

76 77 78 79 80 81
    <para>
      Always write your code against the latest git:
    </para>

    <programlisting>git clone git://git.musicpd.org/master/mpd.git</programlisting>

82 83 84 85 86 87 88 89 90 91 92
    <para>
      If you already have a clone, update it:
    </para>

    <programlisting>git pull --rebase git://git.musicpd.org/master/mpd.git master</programlisting>

    <para>
      You can do without "--rebase", but we recommend that you rebase
      your repository on the "master" repository all the time.
    </para>

93 94 95 96 97 98 99 100 101
    <para>
      Configure with the options <option>--enable-debug
      --enable-werror</option>.  Enable as many plugins as possible,
      to be sure that you don't break any disabled code.
    </para>

    <para>
      Don't mix several changes in one single patch.  Create a
      separate patch for every change.  Tools like
102 103 104
      <application>stgit</application> help you with that.  This way,
      we can review your patches more easily, and we can pick the
      patches we like most first.
105
    </para>
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150


    <section>
      <title> Basic stgit usage</title>

      <para>
        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.
      </para>

      <para>
        stgit needs to be initialized on a git repository: stg init
      </para>

      <para>
        Before you edit the code, create a patch: stg new
        my-patch-name (stgit now asks you for the commit message).
      </para>

      <para>
        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: stg refresh
      </para>

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

      <para>
        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).
      </para>

      <para>
        When the whole patch series is finished, convert stgit patches
        to git commits: stg commit
      </para>
    </section>
151 152 153 154 155 156 157
  </chapter>

  <chapter>
    <title>Submitting Patches</title>

    <para>
      Send your patches to the mailing list:
158 159 160
      <email>mpd-devel@musicpd.org</email> (<ulink
      url="http://mailman.blarg.de/listinfo/mpd-devel">subscribe
      here</ulink>)
161
    </para>
162 163 164 165 166 167 168

    <para>
      <command>git pull</command> requests are preferred.  Regular
      contributors can get <ulink
      url="http://git.musicpd.org/account-policy.html">an account on
      git.musicpd.org</ulink>, but any public git repository will do.
    </para>
169
  </chapter>
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

  <chapter>
    <title>Development Tools</title>

    <section>
      <title>Clang Static Analyzer</title>

      <para>
        The <ulink url="http://clang-analyzer.llvm.org/">clang static
        analyzer</ulink> is a tool that helps find bugs.  To run it on
        the MPD code base, install LLVM and clang.  Configure MPD to
        use clang:
      </para>

      <programlisting>./configure --enable-debug CXX=clang++ CC=clang ...</programlisting>

      <para>
        It is recommended to use <option>--enable-debug</option>,
        because the analyzer takes advantage of
        <function>assert()</function> calls, which are only enabled in
        the debug build.
      </para>

      <para>
        Now run the analyzer:
      </para>

      <programlisting>scan-build --use-c++=clang++ --use-cc=clang make</programlisting>

      <para>
        The options <option>--use-c++</option> and
        <option>--use-cc</option> are necessary because it invokes
        <command>cc</command> for actually compiling the sources by
        default.  That breaks, because MPD requires a C99 compiler.
      </para>
    </section>
  </chapter>
207
</book>