Fix jsoncpp.pc file
[platform/upstream/jsoncpp.git] / CONTRIBUTING.md
1 # Contributing to JsonCpp
2
3 ## Building
4
5 Both CMake and Meson tools are capable of generating a variety of build environments for you preferred development environment.
6 Using cmake or meson you can generate an XCode, Visual Studio, Unix Makefile, Ninja, or other environment that fits your needs.
7
8 An example of a common Meson/Ninja environment is described next.
9
10 ## Building and testing with Meson/Ninja
11 Thanks to David Seifert (@SoapGentoo), we (the maintainers) now use
12 [meson](http://mesonbuild.com/) and [ninja](https://ninja-build.org/) to build
13 for debugging, as well as for continuous integration (see
14 [`./.travis_scripts/meson_builder.sh`](./.travis_scripts/meson_builder.sh) ). Other systems may work, but minor
15 things like version strings might break.
16
17 First, install both meson (which requires Python3) and ninja.
18 If you wish to install to a directory other than /usr/local, set an environment variable called DESTDIR with the desired path:
19     DESTDIR=/path/to/install/dir
20
21 Then,
22
23     cd jsoncpp/
24     BUILD_TYPE=debug
25     #BUILD_TYPE=release
26     LIB_TYPE=shared
27     #LIB_TYPE=static
28     meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
29     ninja -v -C build-${LIB_TYPE}
30     cd build-${LIB_TYPE}
31     meson test --no-rebuild --print-errorlogs
32     sudo ninja install
33
34 ## Building and testing with other build systems
35 See https://github.com/open-source-parsers/jsoncpp/wiki/Building
36
37 ## Running the tests manually
38
39 You need to run tests manually only if you are troubleshooting an issue.
40
41 In the instructions below, replace `path/to/jsontest` with the path of the
42 `jsontest` executable that was compiled on your platform.
43
44     cd test
45     # This will run the Reader/Writer tests
46     python runjsontests.py path/to/jsontest
47
48     # This will run the Reader/Writer tests, using JSONChecker test suite
49     # (http://www.json.org/JSON_checker/).
50     # Notes: not all tests pass: JsonCpp is too lenient (for example,
51     # it allows an integer to start with '0'). The goal is to improve
52     # strict mode parsing to get all tests to pass.
53     python runjsontests.py --with-json-checker path/to/jsontest
54
55     # This will run the unit tests (mostly Value)
56     python rununittests.py path/to/test_lib_json
57
58     # You can run the tests using valgrind:
59     python rununittests.py --valgrind path/to/test_lib_json
60
61 ## Building the documentation
62
63 Run the Python script `doxybuild.py` from the top directory:
64
65     python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
66
67 See `doxybuild.py --help` for options.
68
69 ## Adding a reader/writer test
70
71 To add a test, you need to create two files in test/data:
72
73 * a `TESTNAME.json` file, that contains the input document in JSON format.
74 * a `TESTNAME.expected` file, that contains a flatened representation of the
75   input document.
76
77 The `TESTNAME.expected` file format is as follows:
78
79 * Each line represents a JSON element of the element tree represented by the
80   input document.
81 * Each line has two parts: the path to access the element separated from the
82   element value by `=`. Array and object values are always empty (i.e.
83   represented by either `[]` or `{}`).
84 * Element path `.` represents the root element, and is used to separate object
85   members. `[N]` is used to specify the value of an array element at index `N`.
86
87 See the examples `test_complex_01.json` and `test_complex_01.expected` to better understand element paths.
88
89 ## Understanding reader/writer test output
90
91 When a test is run, output files are generated beside the input test files. Below is a short description of the content of each file:
92
93 * `test_complex_01.json`: input JSON document.
94 * `test_complex_01.expected`: flattened JSON element tree used to check if
95   parsing was corrected.
96 * `test_complex_01.actual`: flattened JSON element tree produced by `jsontest`
97   from reading `test_complex_01.json`.
98 * `test_complex_01.rewrite`: JSON document written by `jsontest` using the
99   `Json::Value` parsed from `test_complex_01.json` and serialized using
100   `Json::StyledWritter`.
101 * `test_complex_01.actual-rewrite`: flattened JSON element tree produced by
102   `jsontest` from reading `test_complex_01.rewrite`.
103 * `test_complex_01.process-output`: `jsontest` output, typically useful for
104   understanding parsing errors.
105
106 ## Versioning rules
107
108 Consumers of this library require a strict approach to incrementing versioning of the JsonCpp library. Currently, we follow the below set of rules:
109
110 * Any new public symbols require a minor version bump.
111 * Any alteration or removal of public symbols requires a major version bump, including changing the size of a class. This is necessary for
112 consumers to do dependency injection properly.
113
114 ## Preparing code for submission
115
116 Generally, JsonCpp's style guide has been pretty relaxed, with the following common themes:
117
118 * Variables and function names use lower camel case (E.g. parseValue or collectComments).
119 * Class use camel case (e.g. OurReader)
120 * Member variables have a trailing underscore
121 * Prefer `nullptr` over `NULL`.
122 * Passing by non-const reference is allowed.
123 * Single statement if blocks may omit brackets.
124 * Generally prefer less space over more space.
125
126 For an example:
127
128 ```c++
129 bool Reader::decodeNumber(Token& token) {
130   Value decoded;
131   if (!decodeNumber(token, decoded))
132     return false;
133   currentValue().swapPayload(decoded);
134   currentValue().setOffsetStart(token.start_ - begin_);
135   currentValue().setOffsetLimit(token.end_ - begin_);
136   return true;
137 }
138 ```
139
140 Before submitting your code, ensure that you meet the versioning requirements above, follow the style guide of the file you are modifying (or the above rules for new files), and run clang format. Meson exposes clang format with the following command:
141
142 ```
143 ninja -v -C build-${LIB_TYPE}/ clang-format
144 ```