1 # Contributing to JsonCpp
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.
8 An example of a common Meson/Ninja environment is described next.
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.
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
28 meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE}
29 ninja -v -C build-${LIB_TYPE}
31 meson test --no-rebuild --print-errorlogs
34 ## Building and testing with other build systems
35 See https://github.com/open-source-parsers/jsoncpp/wiki/Building
37 ## Running the tests manually
39 You need to run tests manually only if you are troubleshooting an issue.
41 In the instructions below, replace `path/to/jsontest` with the path of the
42 `jsontest` executable that was compiled on your platform.
45 # This will run the Reader/Writer tests
46 python runjsontests.py path/to/jsontest
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
55 # This will run the unit tests (mostly Value)
56 python rununittests.py path/to/test_lib_json
58 # You can run the tests using valgrind:
59 python rununittests.py --valgrind path/to/test_lib_json
61 ## Building the documentation
63 Run the Python script `doxybuild.py` from the top directory:
65 python doxybuild.py --doxygen=$(which doxygen) --open --with-dot
67 See `doxybuild.py --help` for options.
69 ## Adding a reader/writer test
71 To add a test, you need to create two files in test/data:
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
77 The `TESTNAME.expected` file format is as follows:
79 * Each line represents a JSON element of the element tree represented by the
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`.
87 See the examples `test_complex_01.json` and `test_complex_01.expected` to better understand element paths.
89 ## Understanding reader/writer test output
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:
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.
108 Consumers of this library require a strict approach to incrementing versioning of the JsonCpp library. Currently, we follow the below set of rules:
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.
114 ## Preparing code for submission
116 Generally, JsonCpp's style guide has been pretty relaxed, with the following common themes:
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.
129 bool Reader::decodeNumber(Token& token) {
131 if (!decodeNumber(token, decoded))
133 currentValue().swapPayload(decoded);
134 currentValue().setOffsetStart(token.start_ - begin_);
135 currentValue().setOffsetLimit(token.end_ - begin_);
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:
143 ninja -v -C build-${LIB_TYPE}/ clang-format