HACKING 18.1 KB
Newer Older
1
2
3
4
Bootstraping from the GIT repository
====================================

(If you are building from a tarball, skip this section.)
5

6
7
8
9
10
11
12
13
Spot's gitlab page is at

  https://gitlab.lrde.epita.fr/spot/spot

The GIT repository can be cloned with

  git clone https://gitlab.lrde.epita.fr/spot/spot.git

14
15
Some files in SPOT's source tree are generated.  They are distributed
so that users do not need to tools to rebuild them, but we don't keep
16
all of them under GIT because it can generate lots of changes or
17
18
conflicts.

19
Here are the tools you need to bootstrap the GIT tree, or more
20
generally if you plan to regenerate some of the generated files.
21
22
(None of these tools are required by end users installing a tarball
since the generated files they produce are distributed.)
23

24
  GNU Autoconf >= 2.61
25
  GNU Automake >= 1.11
26
  GNU Libtool >= 2.4
27
  GNU Flex (the version seems to matters, we used 2.5.35)
28
  GNU Bison >= 3.0
29
  GNU Emacs (preferably >= 24 but it may work with older versions)
30
  Groff (a.k.a. GNU troff) >= 1.20
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
31
  SWIG >= 3.0 (for its better C++11 support)
32
  Doxygen >= 1.4.0
33
34
  Perl, with its Gettext module (it might be called something like
    liblocale-gettext-perl or p5-locale-gettext in your distribution)
35
36
  A complete LaTeX distribution, including latexmk and extra fonts
    like dsfont.sty.
Etienne Renault's avatar
Etienne Renault committed
37
  ImageMagick
38
  Python >= 3.3, IPython >= 2.3
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  GraphViz

The following additional tools are used if they are present, or
only for certain operations (like releases):

  pandoc    used during Debian packaging for the conversion of
            IPython notebooks to html
  optipng   used during "make dist" if present, to optimize
            distributed png images
  R         used by some example in the documentation (the
            documentation will still compile without R, but that
            example will appear broken)
  ltl2ba    used in the generated documentation and the test suite
  ltl2dstar likewise
  ltl3dra   likewise
  spin      likewise
  glucose >= 3.0  likewise
  lbtt >= 1.2.1a  used in the test suite (ltlcross is now more
            powerful, but additional tests do not hurt)

If you use Debian or a similar distribution, the Dockerfile at
https://github.com/adl/spot-docker/blob/master/debuild/Dockerfile
lists all the Debian packages that should be installed to build
Debian packages out of the GIT tree.  Additionally, the script
https://github.com/adl/spot-docker/blob/master/debuild/install.sh
installs the third-party tools that do not have Debian packages.

66

67
Bootstrap the GIT tree by running
68

69
  % autoreconf -vfi
70

71
and then go on with the usual
72

73
74
  % ./configure
  % make
75

76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Tricks
======

Avoiding Doxygen runs
---------------------

When there is no documentation built (e.g., after a fresh checkout
of the GIT tree), when the configure.ac file has changed, or when
the Doxygen configuration has changed, the doc will be rebuilt.

This can take quite some time, even though recent version of Doxygen
have started to parallelize things.  If you have no interest
in generating the documentation, just use the "magic touch":

  touch doc/stamp

Do that right before running make.  The timestamp of doc/stamp
is compared to configure.ac and Doxygen.in to decide if the
documentation is out-of-date.  The above command pretends the
documentation has just been built.


99
100
101
102
103
104
105
106
107
108
109
110
Avoiding org-mode runs
----------------------

The files in doc/org/ are org-mode files (a mode of Emacs that we use
to author documents that embed executable snippets), they are used to
generate the doc/userdoc/ HTML documentation.  If for some reason you
don't have emacs, or you simply want not to rebuild these files, use
another "magic touch":

  touch doc/org-stamp


111
112
113
Debugging Libtool executables
-----------------------------

114
The executables generated in the various testsuite directories of Spot
115
are not real binaries.  Because we use libtool to compile the spot
116
117
library in a portable manner, these executables are just scripts that
run the actual binary after setting some environment variables so that
118
119
the OS can find the library in the build tree.

120
121
A consequence is that tools like gdb or valgrind, that expect to work
on a binary, will be confused by the script.  Example:
122

123
  % cd bin
124
125
126
  % file ltl2tgba
  ltl2tgba: POSIX shell script text executable
  % gdb -q ltl2tgba
127
  "/home/adl/git/spot/bin/ltl2tgba/ltl2tgba": not in executable format: File format not recognized
128
129
  (gdb) quit

130
131
The proper way to run any command on these fake binaries is via
libtool:
132
133

  % ../../libtool --mode=execute file ltl2tgba
134
  /home/adl/git/spot/bin/.libs/lt-ltl2tgba: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
135
  % ../../libtool --mode=execute gdb -q ltl2tgba
136
  Reading symbols from /home/adl/git/spot/bin/.libs/lt-ltl2tgba...done.
137
138
  (gdb) quit

139
140
141
142
143
You can see that libtool turns ltl2tgba into .libs/lt-ltl2tgba, but it
also sets environment variables so that the dependent shared libraries
will be found.

If you are building Spot from the GIT repository, the libtool script
144
145
146
147
generated the root of the build tree should be the same as the libtool
script that is installed on your system.  So you can simply run
libtool instead of ../../libtool.

148
There is an undocumented feature of libtool that allows you to
149
shorthand "libtool --mode=execute" as "libtool execute" or even
150
151
152
153
154
155
156
157
"libtool e".  But you might also find convenient to define an alias, a
function, or a script to make that invocation even shorter.
For instance:

  alias le='libtool --mode=execute '

(The trailing space makes it possible to follow this command by
another aliased command.)
158
159


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
Profiling with callgrind
------------------------

Install valgrind and kcachegrind.

Then run the command you want to profile through valgrind's callgrind
tool.  For instance:

  % libtool e valgrind --tool=callgrind ltl2tgba -f 'GFa & GFb'

This will output a file called 'callgrind.PID' where PID is the
process ID printed during valgrind's run.  Load this file with
kcachegrind to get a graphical summary.

  % kcachegrind ./callgrind.PID


177
178
179
180
181
Running coverage tests
----------------------

First, compile (and link) Spot with coverage enabled.

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
182
  % ./configure CXX='g++ --coverage'
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  % make

Then run the test suite (or any program you want to study).

  % make check

Executing programs using Spot will generate a lot of *.gc* files
everywhere.  Collect these using lcov:

  % lcov --capture --directory src --output spot.info

Finally generate a coverage report in HTML:

  % genhtml --legend --demangle-cpp --output-directory html spot.info

This should create the directory html/.


201
202
203
Link-time optimizations
-----------------------

204
205
206
207
208
209
210
This is currently a bit tricky to setup, because the toolchain is not
mature enough.  However this is getting better and better.  The Debian
packages we built nightly are mostly built with link-time optimization
(the shared library uses link-time optimization, but the command-line
binary are built without because of some bug with exception
propagation).

211
212

You need:
213
  1. a version of GCC (>= 4.9) with gold and pluing linker enabled.
214
  2. a version of Libtool that knows how to deal with
215
     -flto flags (Libtool 2.4.2 will work)
216

217
218
Here are example options to pass to configure to build a static
version with link-time optimization:
219

220
  ./configure CC=gcc-4.9 CXX=g++-4.9 \
221
222
223
              --disable-devel --disable-debug \
              CFLAGS='-flto' CXXFLAGS='-flto' LDFLAGS='-fuse-linker-plugin' \
              --disable-shared --enable-static
224

225
226
If you want to build a shared library, see in debian/rules how it is
done.
227
228


229
230
231
232
233
234
235
236
237
238
239
240
Log driver for testsuite
------------------------

The PASS/FAIL status for each test of the testsuite is printed by
tools/test-driver.  This script can be changed to format the output
differently.  When we use Teamcity (for continuous integration) we
change the output format to something that Teamcity will understand
with:

  make check TEST_LOG_DRIVER=$PWD/tools/test-driver-teamcity


241
242
Coding conventions
==================
243

244
Here some of the conventions we follow in Spot, so that the code looks
245
246
247
248
249
250
homogeneous.  Please follow these strictly.  Since this is free
software, uniformity of the code matters a lot.  Most of these
conventions are derived from the GNU Coding Standards
(http://www.gnu.org/prep/standards.html) with the notable exception
that we do not put a space before the opening parenthesis in function
calls (this is hardly readable when chaining method calls).
251

252
253
254
Besides cosmetics, some of these conventions are also here
to prevent bugs and make it easier to devise safety checks.

255
The directory tests/sanity/ contains some scripts that are executed
256
257
258
259
260
261
262
263
264
during 'make check' or 'make installcheck' to check some of the
conventions discussed below.

For instance we have a check to ensure that any header can be included
twice, and we have another check to ensure that any header contains a
include guard that follow our naming convention.  This way we do not
forget guards, and we do not forget to rename them when a file is
copied into another one.

265

266
267
268
269
C++11
-----

  Spot uses some C++11 features, and therefore requires a C++11
270
271
272
273
274
275
  compiler.  The code relies on features that are not available in
  version of g++ older than 4.8, so this is our minimum requirement
  for now.  Avoid features that require 4.9.

  Reasonably recent versions of clang should work as well.  Our
  build farm has clang++ 3.5.
276

277
278
279
280
281
Encoding
--------

  * Use UTF-8 for non-ASCII characters.

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
282
283
284
  * Do not use tabs for indentation in C++ files.  Use only space to
    prevent issues with people assuming different tab widths.

285
286
  * If you edit files encoded in Latin-1 (the original default
    encoding for the project), feel free to convert them to UTF-8.
287
288
    In emacs the simplest way to convert the file is to add a comment
    with -*- coding: utf-8 -*- at the top or bottom of the file.
289

290
291
292
293
    There is some check in tests/sanity/ that will ensure that -*-
    coding: utf-8 -*- is used for all C++ files, but try to use it for
    all text files if they contain non-ascii characters.

294
295
296
297
298
299
300
301
302
303
Includes
--------

  * Use #include with angle-brackets to refer to public headers
    of Spot; i.e., those that will be installed, or system
    headers that are already installed.  E.g.,

    #include <spot/misc/version.hh>
    #include <iostream>

304
305
306
  * Use #include with double quotes to refer to private headers that
    are distributed with Spot.  Those can be from Spot itself, or from
    third-party libraries that we ship.  E.g.,
307
308
309
310
311
312
313

    #include "utf8/utf8.hh"
    #include "spot/priv/trim.hh"
    #include "config.h"

    This style of #include should never occur in public headers.

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
Exporting symbols
-----------------

  Since we are building a library, it is important to make a clear
  distinction between what is private and what is public.  In our
  setup, everything is private by default and has to be explicitely
  made public.

  * If a private symbol is needed only by one module, keep it inside
    the *.cc file, in an anonymous namespace.  Also mark it as static
    if it is a function or variable.  This is the best way to let the
    compiler and linker know that the symbol is not used elsewhere.

  * If a symbol could be used by several modules of the library but
    should still be private to the library, use a *.hh/*.cc pair of
    files, but list both files in the _SOURCES variable of that
    directory (see for instance weight.hh in tgbaalgos/Makefile.am).
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
331
332
    This will ensure that the header is not installed.
    Needless to say, no public header should include such a private
333
334
    header.

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
335
336
337
  * The directory src/priv/ can be used to store files that are
    globaly private the library, and that do not really belongs to
    other directories.
338
339
340

  * Functions and classes that are public should be marked with
    the SPOT_API macro.  This macro is defined in misc/common.hh,
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
341
    but you need not include it in a file that already includes
342
343
344
345
346
    another public header.

  * Do not make a symbol public just because you can.

  * Read http://www.akkadia.org/drepper/dsohowto.pdf for more
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
347
    information about how shared libraries work and why.
348

349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
Assertions
----------

  * There are different types of assertions.  Plain assert() is OK for
    invariants or post-conditions.  When asserting a pre-condition,
    carefully consider who the caller might be: if it can be in
    user-code (either in C++ or Python), throw an exception
    (std::runtime_error, std::invalid_argument, and spot::parse_error
    are the three exception types catched by the Python bindings).

  * Do not call assert() in public *.hh files: even if the installed
    libspot has been compiled with -DNDEBUG, the *.hh files will be
    recompiled by users, probably without -DNDEBUG.  So use
    SPOT_ASSERT() instead of assert(), this ensure asserts are only
    used inside libspot for debug builds.

365
366
367
Comments
--------

368
  * The language to use is American English.
369
370
371
372
373

  * When comments are sentences, they should start with a capital and
    end with a dot.  Dots that end sentences should be followed by two
    spaces (i.e., American typing convention), like in this paragraph.

374
375
376
  * Prefer C++-style comments (// foo) to C-style comments (/* foo */).
    Use /// for Doxygen comments.

377
378
379
Formating
---------

380
381
  * Braces around instruction blocks are always on their own line.
    Braces around initializers lists need not be on their own.
382
383
384
385
386

  * Text within braces is two-space indented.

    {
      f(12);
387

388
389
390
391
392
393
394
395
396
397
398
399
    }

  * Anything after a control statement is two-space indented.  This
    includes braces.

    if (test)
      {
        f(123);
	while (test2)
	  g(456);
      }

400
  * Braces from function/structure/enum/class/namespace definitions
401
402
403
404
405
406
407
408
409
410
411
    are not indented.

    class foo
    {
    public:
      Foo();
    protected:
      static int get_mumble();
    };

  * The above corresponds to the `gnu' indentation style under Emacs.
412
413

  * Put a space before the opening parenthesis in control statements
414
415
416
417
418
419
420
421
422
423
424
425

    if (test)
      {
        do
	  {
	    something();
	  }
	while (0);
      }

  * No space before parentheses in function calls.
    (`some()->foo()->bar()' is far more readable than
426
    `some ()->foo ()->bar ()')
427
428
429

  * No space after opening or before closing parentheses, however
    put a space after commas (as in english).
430

431
    func(arg1, arg2, arg3);
432

433
434
435
436
437
438
439
440
441
  * No useless parentheses in return statements.

    return 2;    (not `return (2);')

  * Spaces around infix binary or ternary operators:

    2 + 2;
    a = b;
    a <<= (3 + 5) * 3 + f(67 + (really ? 45 : 0));
442

Alexandre Duret-Lutz's avatar
typo    
Alexandre Duret-Lutz committed
443
444
  * No space after prefix unary operators, or before postfix unary
    operators:
445
446
447
448
449
450

    if (!test && y++ != 0)
      {
        ++x;
      }

451
452
453
  * When an expression spans over several lines, prefer splitting it
    before operators.  If it's inside a parenthesis, the following
    lines should be 1-indented w.r.t. the opening parenthesis.
454
455
456
457
458
459
460

    if (foo_this_is_long && bar > win(x, y, z)
        && !remaining_condition)
      {
        ...
      }

461
462
  * `else if' can be put as-is on a single line.

463
464
  * No line should be larger than 80 columns.
    If a line takes more than 80 columns, split it or rethink it.
465

466
467
468
469
470
471
472
473
474
    This makes it easier to print the code, allow people to work on
    small screens, makes it possible to display two files (or an
    editor and a terminal) side-by-side, ...

    This also puts some pressure on the programmer who writes code
    that has too much nested blocks: if you find yourself having to
    code between columns 60 and 80 because of identation, consider
    writing helper functions to simplify the structure of your code.

475
  * Labels or case statements are back-indented by two spaces,
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
476
    without space before the `:'.
477

Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
    if (something)
      {
      top:
        bar = foo();
        switch (something_else)
	  {
	  case first_case:
	    f();
	    break;
	  case second_case:
	    g();
	    break;
	  default:
	    goto top;
	  }
      }

495
496
497
498
499
500
501
502
503
504
505
506
507
  * Pointers and references are part of the type, and should be put
    near the type, not near the variable.

      int* p;        // not `int *p;'
      list& l;       // not `list &l;'
      void* magic(); // not `void *magic();'

  * Do not declare many variables on one line.
    Use
      int* p;
      int* q;
    instead of
      int *p, *q;
508
    The former declarations also allow you to comment each variable.
509
510
511
512

  * The include guard for src/somedir/foo.hh is
    SPOT_SOMEDIR_FOO_HH

513
Naming
514
------
515
516
517
518
519
520
521

  * Functions, methods, types, classes, etc. are named with lowercase
    letters, using an underscore to separate words.

      int compute_this_and_that();

      class this_is_a_class;
522

523
524
525
526
      typedef int int_array[];

    That is the style used in STL.

527
  * Private members end with an underscore.
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548

    class my_class
    {
    public:
      ...
      int get_val() const;
    private:
      int name_;
    };

  * Identifiers (even internal) starting with `_' are best avoided
    to limit clashes with system definitions.

  * Template arguments use capitalized name, with joined words.

    template <class T, int NumberOfThings>
    class foo
    {
      ...
    };

549
  * Enum members also use capitalized name, with joined words.
550
551
552

  * C Macros are all uppercase.

553
554
  * Use *.hxx for the implementation of templates that are private to
    Spot (i.e., not installed) and need to be included multiple times.
555

556
Other style recommandations
557
---------------------------
558

559
560
  * The original C++98 code used 0 for null pointers (and never NULL).
    Feel free to replace these by uses of C++11's nullptr instead.
561

562
563
564
  * Limit the scope of local variables by defining them as late as
    possible.  Do not reuse a local variables for two different things.

565
  * Do not systematically initialize local variables with 0 or other
566
    meaningless values.  This hides errors to valgrind.
567
568
569

  * Avoid <iostream>, <ostream>, etc. in headers whenever possible.
    Prefer <iosfwd> when predeclarations are sufficient, and then
570
    for instance use just <ostream> in the corresponding .cc file.
571
    (A plain <iostream> is needed when using std::cout, std::cerr, etc.)
572
573
574
575
576
577

  * Always declare helper functions and other local class definitions
    (used in a single .cc files) in anonymous namespaces.  (The risk
    otherwise is to declare two classes with the same name: the linker
    will ignore one of the two silently.  The resulting bugs are often
    difficult to understand.)
578
579
580

  * Always code as if the person who ends up maintaining your code is
    a violent psychopath who knows where you live.