yacd (Yet Another CompileDB) is a command-line tool for generating compile_commands.json files from make logs of makefile-based projects. This tool is specifically designed for C/C++ projects and is particularly useful for embedded development and cross-compilation environments.
Although it's called yacd, it's not yacc's younger brother! :)
This tool was heavily implemented with the participation of Qoder (https://qoder.com/).
- 🚀 Efficient Parsing: Fast parsing of logs generated by
make -Bnkw - 🎯 Precise Recognition: Smart identification of compilation commands, supporting multiple compilers (GCC, Clang, ARM toolchains, etc.)
- 📁 Path Handling: Support for both absolute and relative paths, with automatic working directory tracking
- 🔧 Flexible Input: Multiple input methods - file input, direct make command execution, and standard input pipes
- 🔄 Real-time Processing: Execute make commands directly and process output without intermediate files
- ✅ Standards Compliant: Generates JSON files compliant with Language Server Protocol standards
- 🧪 High Quality: Comprehensive unit test coverage ensuring code quality
Ensure you have Go 1.23 or higher installed.
git clone https://github.com/gerryqd/yacd.git
cd yacd
go build -o yacd .go install github.com/gerryqd/yacd@latestmake buildyacd supports three input methods:
- First, generate a make log:
make -Bnkw > build.log 2>&1- Use yacd to generate compile_commands.json:
yacd -i build.log -o compile_commands.json# Execute make command directly and process output
yacd -n "make clean all" -o compile_commands.json
yacd --dry-run "make" --verbose# Read from stdin using pipe
make -Bnkw | yacd -o compile_commands.json
yacd < build.log -o compile_commands.jsonyacd [flags]
Flags:
-i, --input string Input make log file path
-n, --dry-run string Execute make command with -Bnkw flags and process output directly
-o, --output string Output compile_commands.json file path (default "compile_commands.json")
-r, --relative Use relative paths instead of absolute paths
-b, --base-dir string Base directory path (used with --relative)
-v, --verbose Verbose output
-h, --help Show help information
# Generate make log and process with yacd
make -Bnkw > build.log 2>&1
yacd -i build.log -o compile_commands.json -v# Execute make command directly
yacd -n "make clean all" -o compile_commands.json --verbose
yacd --dry-run "make" -o compile_commands.json# Use pipe to process make output directly
make -Bnkw | yacd -o compile_commands.json --verbose
echo "sample make output" | yacd -o compile_commands.jsonyacd -i build.log -o compile_commands.json --relative --base-dir /project/root# For ARM projects using direct integration
yacd -n "make CROSS_COMPILE=arm-none-eabi-" -o compile_commands.json --verboseyacd supports automatic recognition of compilers using a simplified pattern matching approach. It can identify any compiler command containing the following patterns:
gcc(includes cross-compilers likearm-none-eabi-gcc,aarch64-linux-gnu-gcc)g++(includes cross-compilers likearm-none-eabi-g++)clangclang++cc
This simplified approach is more universal and automatically supports various cross-compilation toolchains without requiring specific prefix definitions.
The generated compile_commands.json file complies with the Clang compilation database standard:
[
{
"directory": "/home/user/project",
"command": "arm-none-eabi-gcc -c -mcpu=cortex-m0 -mthumb -DNDEBUG main.c -o main.o",
"file": "/home/user/project/main.c",
"output": "/home/user/project/main.o"
}
]yacd/
├── cmd/ # Command-line interface
├── generator/ # JSON generator
├── parser/ # Log parser
├── types/ # Type definitions
├── utils/ # Utility functions
│ ├── errorutil/ # Error handling utilities
│ └── pathutil/ # Path handling utilities
├── scripts/ # Helper scripts
├── .github/workflows/ # CI/CD configuration
├── Makefile # Build configuration
├── go.mod # Go module definition
├── go.sum # Go module checksums
├── main.go # Application entry point
├── README.md # Project documentation
└── LICENSE # License file
# Format code
make fmt
# Static analysis
make vet
# Run tests
make test
# Generate test coverage report
make test-coverage
# Build binary
make build
# Show sample usage examples
make run
# Show all available commands
make helpRun comprehensive code quality checks:
./scripts/quality-check.shThis script performs the following checks:
- Code formatting verification
- Static analysis
- Compilation checks
- Unit tests
- Test coverage
- Module dependency verification
- Race condition detection
The generated compile_commands.json can be directly used with VSCode's C/C++ extension and clangd:
- Place the generated file in the project root directory
- VSCode will automatically recognize it and provide intelligent code completion, navigation, and other features
While CMake can natively generate compilation databases, yacd is still useful for hybrid build systems:
# For CMake projects using make backend
cmake --build . -- -Bnkw > build.log 2>&1
yacd -i build.log -o compile_commands.jsonA: Parsing logs requires no modification to existing build systems, making it minimally invasive and particularly suitable for third-party projects or complex build environments that cannot be modified.
A: Yes, yacd is cross-platform and can run on Windows, Linux, and macOS. It supports three input methods: file input (-i), direct make command execution (-n), and standard input pipes.
A: yacd correctly handles working directory changes by tracking make's "Entering directory" and "Leaving directory" messages.
A: Absolute paths are used by default to ensure compatibility. Use the --relative option if you need relative paths.
A: Yes! Use the -n/--dry-run option to execute make commands directly, or use pipes to process make output in real-time: make -Bnkw | yacd -o compile_commands.json.
yacd has been optimized for performance:
- High memory efficiency, suitable for processing build logs from large projects
- Fast parsing speed, typically processing thousands of log lines per second
- Streaming processing support with stable memory usage
We welcome contributions of all kinds!
- Fork the project
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
- Ensure code passes all tests
- Add appropriate tests for new features
- Follow Go coding standards
- Update relevant documentation
This project is licensed under the MIT License. See the LICENSE file for details.
- Thanks to spf13/cobra for the excellent command-line framework
- Inspired by the design concepts from the bear project
- Thanks to compiledb-go for reference and inspiration
- Thanks to all contributors and users for their support
If you find this project useful, please give us a ⭐ star!
For any questions or suggestions, feel free to submit an issue.