|
2 | 2 |
|
3 | 3 | [](https://circleci.com/gh/tschaffter/cxx-dev-tools) |
4 | 4 |
|
5 | | -Tools to support the development and CI of CXX projects. |
| 5 | +Tools for supporting the development of CXX projects |
6 | 6 |
|
7 | 7 | ## Overview |
8 | 8 |
|
9 | | -This repository provides tools and configurations that are meant to be unique |
10 | | -across many GitHub repositories. |
| 9 | +This repo provides a growing list of tools. |
11 | 10 |
|
12 | | -One of the tools provided by this repo is `cmake-format`, which is a CMake |
13 | | -linter and format validator for CMake files. Developers use this tool to |
14 | | -garantee that the content of all the CMake files in their project are formatted |
15 | | -in the same way. In the case of modular projects composed of multiple GitHub |
16 | | -repos, individual repos would typically import `cmake-format` independently of |
17 | | -each other with the risk that repos may use different version of `cmake-format`. |
18 | | -Moreover, `cmake-format` can take as input a confiration file that would be |
19 | | -typicallly copied to each repo, thus potentially leading to format discrepencies |
20 | | -across repositories. |
| 11 | +- CMake linter |
| 12 | +- CXX linter |
| 13 | +- Git hooks |
21 | 14 |
|
22 | | -To solve the above issues, this repo provides a wrapper that enables |
23 | | -`cmake-format` to be run from multiple repos while still using a single |
24 | | -configuration file. |
| 15 | +This tools aim to support best coding practices like linting files, comfiguring |
| 16 | +a Git pre-commit hook, etc. |
25 | 17 |
|
26 | | -## How to use this repository |
| 18 | +The main motivation for developing these tools is to address an issue that |
| 19 | +typically affects code bases that are organized into multiple repositories. In |
| 20 | +the example of a CMake linter: |
27 | 21 |
|
28 | | -If you want to use the default configurations of the tools, simply add this repo |
29 | | -as a git submodule to all your CXX projects that should have the same CXX and/or |
30 | | -CMake formating. |
| 22 | +1. each repository may host a copy of the configuration that the linter must use |
| 23 | +2. each repository may define a different version of the linter |
| 24 | + |
| 25 | +Both elements contribute to introduce discrepencies in the code formatting and |
| 26 | +make the maintenance of the code base across multiple repositories more |
| 27 | +difficult. |
| 28 | + |
| 29 | +The solution proposed is to define both tools and configurations in |
| 30 | +one repository. This reposiutory can then be added as a Git submodule to |
| 31 | +multiple repositories that will then benefit from the same tools and |
| 32 | +configurations. |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +If you want to use the tool versions and configurations defined in this |
| 37 | +repository, simply add it as a git submodule to your projects. |
| 38 | + |
| 39 | +```bash |
| 40 | +git submodule add -b master https://github.com/tschaffter/cxx-dev-tools.git cxx-dev-tools |
| 41 | +``` |
| 42 | + |
| 43 | +Run the following command to add the CXX dev tools to the PATH. |
31 | 44 |
|
32 | 45 | ```bash |
33 | | -git submodule add -b master https://github.com/tschaffter/cxx-dev-tools.git dev-cxx-tools |
| 46 | +cd dev-cxx-tools && . export.sh |
34 | 47 | ``` |
35 | 48 |
|
36 | | -Then, add the CXX dev tools to your PATH. |
| 49 | +If you want to customize the tool versions and configuration, then fork this |
| 50 | +repository before adding it as a submodule to your other projects. |
| 51 | + |
| 52 | +## Tools |
| 53 | + |
| 54 | +### cxxdt-cmake-lint |
| 55 | + |
| 56 | +Check if the format of the specified CXX files is compliant with the CXX style |
| 57 | +configuration defined in this repo. |
37 | 58 |
|
38 | 59 | ```bash |
39 | | -cd dev-cxx-tools/ |
40 | | -. export.sh |
| 60 | +$ cxxdt-cmake-lint test/cmake-lint/samples/invalid-format.cmake |
| 61 | +test/cmake-lint/samples/invalid-format.cmake |
| 62 | +============================================ |
| 63 | +test/cmake-lint/samples/invalid-format.cmake:10,04: [C0305] too many newlines between statements |
| 64 | + |
| 65 | +Summary |
| 66 | +======= |
| 67 | +files scanned: 1 |
| 68 | +found lint: |
| 69 | + Convention: 1 |
| 70 | + |
| 71 | +$ echo $? |
| 72 | +1 |
| 73 | + |
| 74 | +$ cxxdt-cmake-lint test/cmake-lint/samples/valid-format.cmake |
| 75 | +test/cmake-lint/samples/valid-format.cmake |
| 76 | +========================================== |
| 77 | + |
| 78 | +Summary |
| 79 | +======= |
| 80 | +files scanned: 1 |
| 81 | +found lint: |
| 82 | + |
| 83 | +$ echo $? |
| 84 | +0 |
| 85 | +``` |
| 86 | + |
| 87 | +The exit status returned is 0 if the format of the file is valid. |
| 88 | + |
| 89 | +If no CMake files are specified, `cxxdt-cmake-lint` tries to read a list CMake |
| 90 | +files from `./.cxxdt-cmake-lint` (one file/file expression per line). The |
| 91 | +following command is used in the CI configuration of this repo to check that the |
| 92 | +CMake module `BuildType.cmake` is correctly formatted. |
| 93 | + |
41 | 94 | ``` |
| 95 | +$ cxxdt-cmake-lint |
| 96 | +cmake/BuildType.cmake |
| 97 | +===================== |
| 98 | +
|
| 99 | +Summary |
| 100 | +======= |
| 101 | +files scanned: 1 |
| 102 | +found lint: |
| 103 | +
|
| 104 | +$ echo $? |
| 105 | +0 |
| 106 | +``` |
| 107 | + |
42 | 108 |
|
43 | | -You can now run `run-cmake-format.sh CMAKE_FILES` to easily format `CMAKE_FILES` |
44 | | -(e.g. `CMakeLists.txt`, `cmake/MyTool.cmake`, etc.) using the configuration file |
45 | | -located in `cmake/format/.cmake-format.json`. |
46 | 109 |
|
47 | | -In case you want to define your own CXX style, for example, fork this repo and |
48 | | -modify the CXX format configuration, then add your fork as a submodule to your |
49 | | -projects. |
50 | 110 |
|
51 | 111 | ## Continuous Integration |
52 | 112 |
|
|
0 commit comments