Warning, /sdk/codevis/doc/command_line_codebase_generation.md is written in an unsupported language. File is not indexed.

0001 # Command line interface
0002 
0003 There are two ways to run the codebase parse: The GUI and the command line
0004 interface. In this document we will discuss the command line interface.
0005 
0006 The `codevis_create_codebase_db` tool takes a `compile_commands.json` file as input and
0007 outputs an SQLite code database (.db file). Multiple `compile_commands.json` can be
0008 specified to generate a database spanning multiple projects.
0009 
0010 Run `codevis_create_codebase_db --help` to see all available parameters. Some parameters are summarized here:
0011 
0012 - `-j` option can be used to use multiple threads to parse the codebase. This
0013 is similar to the `-j` option to `make` and is strongly advised.
0014 
0015 - `--update` allows the updating of an existing database. This is done
0016 incrementally so only files which have been updated since that database was
0017 generated are re-parsed.
0018 
0019 - `--physical-only` can be used to skip parsing for logical relationships. The
0020 physical parse is considerably faster than the logical parse so this is a good
0021 idea for situations where no logical relationships or classes are needed in the
0022 diagram.
0023 
0024 - `--ignore` option takes a glob describing file paths to skip. For example
0025 using `--ignore *.t.cpp` will skip all unit tests. It is strongly recommended to
0026 specify at least `--ignore *.t.cpp --ignore *.m.cpp --ignore *standalone*` so
0027 that multiple definitions of the main() (or other things) in each file cannot
0028 cause inconsistencies in the database. In general, the database relies on the
0029 one-definition-rule (as does the C++ linker). If two translation units are not
0030 intended to be linked into the same binary, they should not be included
0031 in the same code database.
0032 
0033 - `--compile-command` Ingests a *single* entry of the compile commands file in 
0034 the form of a JSON object with `file`, `directory`, `command`, `output` keys, and 
0035 produces a database file with *just* the contents of this translation unit (plus used headers).
0036 if you used the `--compile-commands` flag, you will need to merge the 
0037 resulting databases into a single one later on (just like you need to run a linter on multiple
0038 object files to produce a binary). for that we have the tool `codevis_merge_databases`
0039 
0040 # Example 1
0041 
0042 For this example, you need to have `CMake` installed.
0043 
0044 Download the [bjg example project](../project_tests/bjg_wrong_cmake/) in this repository and unpack it somewhere.
0045 Create a `build` folder and run `CMake` to generate the `compile_commands.json` file, required by Codevis:
0046 
0047 ```
0048 cd bjg_wrong_cmake/ && mkdir build/ && cd build
0049 cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
0050 ```
0051 
0052 Run codevis to parse the code and build the database file:
0053 
0054 ```
0055 codevis_create_codebase_db --compile-commands-json compile_commands.json --source-path .. -j6 -o bjg.db --replace
0056 ```
0057 
0058 After the parsing is done, you can turn the database file into a project file that can be visualized with Codevis:
0059 
0060 ```
0061 codevis_create_prj_from_db bjg.db bjg.lks
0062 ```
0063 
0064 The following image is the resulting project, visualized on Codevis GUI:
0065 
0066 ![example-4](images/codevis-4.png)
0067 
0068 
0069 # Example 2
0070 
0071 For this example, Bloomberg's Open Source BDE code will be used as a target. BDE uses a meta-build system (bde-tools) to configure arguments and the
0072 environment for cmake. Information about configuring and building BDE can be found at
0073 
0074 https://bloomberg.github.io/bde/library_information/build.html
0075 
0076 A full BDE build is not required to generate the database. We only need to
0077 configure and run cmake.
0078 
0079 1. Checkout the bde-tools repo
0080 
0081         $ git clone https://github.com/bloomberg/bde-tools.git
0082 
0083 2. Add the bde-tools/bin directory to your $PATH to allow easier access to the helper scripts.
0084 
0085 3. Checkout the bde repo
0086 
0087         $ git clone https://github.com/bloomberg/bde.git
0088 
0089 This command sets environment variables that define effective ufid/uplid, compiler and build
0090 directory for subsequent commands. Where possible, it is a good idea to configure the BDE
0091 build to use  clang (as we parse the codebase using clang). Configurations for other
0092 compilers have been tested and work currently, but may not in the future if some non-clang
0093 compiler extensions are used.
0094 
0095 3. 1 (Optional) To see which compilers are available on your platform:
0096 
0097         $ bde_build_env.py list
0098 
0099 Output should look something like
0100 
0101 ```
0102 Available compilers:
0103  0: gcc-11.2.0 (default)
0104      CXX: /usr/lib/ccache/g++
0105      CC : /usr/lib/ccache/gcc
0106      Toolchain: gcc-default
0107  1: gcc-11.2.0 
0108      CXX: /usr/lib/ccache/g++-11
0109      CC : /usr/lib/ccache/gcc-11
0110      Toolchain: gcc-default
0111  2: clang-13.0.0 
0112      CXX: /usr/lib/ccache/clang++
0113      CC : /usr/lib/ccache/clang
0114      Toolchain: clang-default
0115 ```
0116 
0117         $ eval `bde_build_env.py --build-type=Release -c clang-13.0.0`
0118 
0119 4. Configure bde (a fully build is not needed)
0120 
0121         $ cmake_build.py configure
0122 
0123 You should now have the `compile_commands.json` file in the bde build directory
0124 for your target/compiler configuration.
0125 
0126 5. Run the tool against the BDE source to generate a database:
0127 
0128         $ create_codebase_db --compile-commands-json /path/to/bde/build --source-path /path/to/bde -j4
0129 
0130 The tool will then output a raw database file, which can be converted to a project file using the `codevis_create_prj_from_db` CLI tool.
0131 
0132 
0133 ## Troubleshooting
0134 
0135 Whilst the parser is running you may see messages about missing header files;
0136 ```
0137 /usr/include/wchar.h:35:10: fatal error: 'stddef.h' file not found
0138 #include <stddef.h>
0139          ^~~~~~~~~~
0140 ```
0141 
0142 This occurs when clang can't find its own standard library headers. Try the GUI
0143 via one of the application bundles (e.g. appimage), as these should distribute
0144 the headers with the application.