46 lines
1.2 KiB
Batchfile
46 lines
1.2 KiB
Batchfile
@echo off
|
|
REM Merge multiple compilation command files generated by clang -MJ and dump it
|
|
REM to standard output as a JSON array.
|
|
REM
|
|
REM An entry generated by clang -MJ, looks like this:
|
|
REM
|
|
REM {
|
|
REM "directory": "/home/user/dev/llvm/build",
|
|
REM "file": "/tmp/foo.cpp",
|
|
REM "output": "foo.o",
|
|
REM "arguments": ["/usr/bin/clang-5.0", "-xc++", "/tmp/foo.cpp", "--driver-mode=g++", "-Wall", "-I", "/home/user/dev/libcpp/libcpp/include", "-c", "--target=x86_64-unknown-linux-gnu"]
|
|
REM }
|
|
REM
|
|
REM See: https://sarcasm.github.io/notes/dev/compilation-database.html#clang
|
|
|
|
setlocal EnableDelayedExpansion
|
|
if [%1]==[] (
|
|
echo Usage: %0 [compilation command files...]
|
|
exit /b -1
|
|
)
|
|
|
|
REM Count the number of arguments we received
|
|
set arg_count=0
|
|
for %%x in (%*) do ( set /A arg_count+=1 )
|
|
|
|
REM Open a JSON array to splat the JSON compile commands objects into
|
|
echo [
|
|
|
|
REM Append the compile commands in
|
|
set arg_next_index=0
|
|
for %%x in (%*) do (
|
|
set /A arg_next_index+=1
|
|
set /P contents=<%%x
|
|
|
|
REM On the last compile command to append to the array, remove the trailing
|
|
REM comma on the JSON object
|
|
if !arg_next_index! == !arg_count! (
|
|
set contents=!contents:~0,-1!
|
|
)
|
|
|
|
echo !contents!
|
|
)
|
|
|
|
REM Close the JSON array
|
|
echo ]
|