| 1 |
# RUN: rm -rf %t.dir && mkdir -p %t.dir |
| 2 |
|
| 3 |
# The mock driver below is a shell script: |
| 4 |
# REQUIRES: shell |
| 5 |
|
| 6 |
# Create a bin directory to store the mock-driver and add it to the path |
| 7 |
# RUN: mkdir -p %t.dir/bin |
| 8 |
# RUN: export PATH=%t.dir/bin:$PATH |
| 9 |
# Generate a mock-driver that will print %temp_dir%/my/dir and |
| 10 |
# %temp_dir%/my/dir2 as include search paths. |
| 11 |
# RUN: echo '#!/bin/sh' >> %t.dir/bin/my_driver.sh |
| 12 |
# RUN: echo '[ "$0" = "%t.dir/bin/my_driver.sh" ] || exit' >> %t.dir/bin/my_driver.sh |
| 13 |
# RUN: echo 'args="$*"' >> %t.dir/bin/my_driver.sh |
| 14 |
# Check that clangd preserves certain flags like `-nostdinc` from |
| 15 |
# original invocation in compile_commands.json. |
| 16 |
# RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> %t.dir/bin/my_driver.sh |
| 17 |
# RUN: echo '[ -z "${args##*"-isysroot=/isysroot"*}" ] || exit' >> %t.dir/bin/my_driver.sh |
| 18 |
# RUN: echo '[ -z "${args##*"--sysroot /my/sysroot/path"*}" ] || exit' >> %t.dir/bin/my_driver.sh |
| 19 |
# RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh |
| 20 |
# RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> %t.dir/bin/my_driver.sh |
| 21 |
# RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> %t.dir/bin/my_driver.sh |
| 22 |
# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/bin/my_driver.sh |
| 23 |
# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/bin/my_driver.sh |
| 24 |
# RUN: echo 'printf "End of search list.\r\n" >&2' >> %t.dir/bin/my_driver.sh |
| 25 |
# RUN: chmod +x %t.dir/bin/my_driver.sh |
| 26 |
|
| 27 |
# Create header files my/dir/a.h and my/dir2/b.h |
| 28 |
# RUN: mkdir -p %t.dir/my/dir |
| 29 |
# RUN: touch %t.dir/my/dir/a.h |
| 30 |
# RUN: mkdir -p %t.dir/my/dir2 |
| 31 |
# RUN: touch %t.dir/my/dir2/b.h |
| 32 |
|
| 33 |
# Generate a compile_commands.json that will query the mock driver we've |
| 34 |
# created. Which should add a.h and b.h into include search path. |
| 35 |
# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json |
| 36 |
|
| 37 |
# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1 |
| 38 |
# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..." |
| 39 |
# (with the extra slash in the front), so we add it here. |
| 40 |
# RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %t.test.1 > %t.test |
| 41 |
|
| 42 |
# Bless the mock driver we've just created so that clangd can execute it. |
| 43 |
# Note: include clangd's stderr in the FileCheck input with "2>&1" so that we |
| 44 |
# can match output lines like "ASTWorker building file" |
| 45 |
# RUN: clangd -lit-test -query-driver="**.test,**.sh" < %t.test 2>&1 | FileCheck -strict-whitespace %t.test |
| 46 |
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}} |
| 47 |
--- |
| 48 |
{ |
| 49 |
"jsonrpc":"2.0", |
| 50 |
"method":"textDocument/didOpen", |
| 51 |
"params": { |
| 52 |
"textDocument": { |
| 53 |
"uri": "file://INPUT_DIR/the-file.cpp", |
| 54 |
"languageId":"cpp", |
| 55 |
"version":1, |
| 56 |
"text":"#include <a.h>\n#include <b.h>\n#if !defined(__ARM_ARCH) || !defined(__gnu_linux__)\n#error \"Invalid target\"\n#endif\n" |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
# Look for the "ASTWorker building file" line so that the subsequent diagnostics |
| 61 |
# that are matches are for the C++ source file and not a config file. |
| 62 |
# CHECK: ASTWorker building file |
| 63 |
# CHECK: "method": "textDocument/publishDiagnostics", |
| 64 |
# CHECK-NEXT: "params": { |
| 65 |
# CHECK-NEXT: "diagnostics": [], |
| 66 |
# CHECK-NEXT: "uri": "file://{{.*}}/the-file.cpp", |
| 67 |
--- |
| 68 |
{"jsonrpc":"2.0","id":10000,"method":"shutdown"} |
| 69 |
--- |
| 70 |
{"jsonrpc":"2.0","method":"exit"} |
| 71 |
|
| 72 |
# Generate a different compile_commands.json which does not point to the mock driver |
| 73 |
# RUN: echo '[{"directory": "%/t.dir", "command": "gcc the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json |
| 74 |
|
| 75 |
# Generate a clangd config file which points to the mock driver instead |
| 76 |
# RUN: echo 'CompileFlags:' > %t.dir/.clangd |
| 77 |
# RUN: echo ' Compiler: my_driver.sh' >> %t.dir/.clangd |
| 78 |
|
| 79 |
# Run clangd a second time, to make sure it picks up the driver name from the config file |
| 80 |
# Note, we need to pass -enable-config because -lit-test otherwise disables it |
| 81 |
# RUN: clangd -lit-test -enable-config -query-driver="**.test,**.sh" < %t.test 2>&1 | FileCheck -strict-whitespace %t.test |