Convert compiler generated dependency files (usually ending in .d or .dep) to JSON.
Given the invocation
dep2j main.d file1.d
dep2j will take the input files
# main.d main.o: main.c file1.h file2.h
# file1.d file1.o: file1.c file1.h
and generate the following output (beautified for readability):
[
{
"target": "main.o",
"prerequisites": ["main.c", "file1.h", "file2.h"]
},
{
"target": "file1.o",
"prerequisites": ["file1.c", "file1.h"]
}
]
A typical use case within a project is to know about the dependencies between files. Compilers can emit that information in form of dependency (usually .d or .dep) files. However, these file adhere to a Makefile syntax and I am not aware of any good tools that are able to parse these files. Also, it seems like there are no other tools which can provide the dependency information in a suitable machine-readable format. The best I've found is clang-scan-deps, but up to at least version 14.0.6 its JSON output is experimental and likely to be changed in the future.
This project aims to solve this issue by outputting the parsed information from dependency files in JSON format. Using a well established format allows to easily build other tools and scripts around the generated output.
- Easy program distribution
- Low-latency
- No external dependencies
- Order of input is conserved in generated output
- Automatic merging of prerequisites
- Easy to use
- Minimalistic
To follow the instructions within this section, the user has to install the following tools:
Please note that users familiar with rust and cargo may wish the build and install the dep2j binary with cargo. If this is the case, it does not make sense to follow the instructions in the section below.
Execute the commands below to download the project and build the dep2j binary.
git clone https://github.com/stnuessl/dep2j
cd dep2j
make release
Install the resulting dep2j binary to the (default) /usr/local/bin directory with
make install
To uninstall dep2j, execute as root:
make uninstall
A generic invocation of dep2j is shown below:
dep2j [options] <file0> [... <fileN>]
Parse dependencies from file1.d and file2.d and format the generated output with python's json.tool module.
dep2j file1.d file2.d | python -m json.tool
Retrieve all dependency files from directory build/, write their content to dep2j's standard input, and store the resulting output in deps.json.
find build/ -name "*.d" | xargs cat | dep2j -o deps.json
Scan the source code with clang-scan-deps and pipe the information to dep2j to print the resulting JSON output to standard output.
clang-scan-deps --compilation-database=<file> | dep2j
Print help message.
dep2j --help
Print version information.
dep2j --version
- json_pp
- json_reformat (contained in yajl)
- json.tool