<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - clang-scan-deps doesn't change directory to compilation database "directory" folder"
href="https://bugs.llvm.org/show_bug.cgi?id=47252">47252</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-scan-deps doesn't change directory to compilation database "directory" folder
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Tooling
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>romain.geissler@amadeus.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Hi,
I meet a problem when using a clang-scan-deps with a compilation database
generated with a given current working directory, but then later
clang-scan-deps is run with another different working directory.
Full example:
<span class="quote">> cat include/A.h</span >
#ifndef _A_h_
#define _A_h_
class A
{
public:
void f();
};
#endif
<span class="quote">> cat src/A.cpp</span >
#include "A.h"
void A::f() {}
<span class="quote">> cat Makefile</span >
all:src/A.o compile_commands.json run_scan_deps
src/%.o:src/%.cpp
clang -MJ $<.d.json -I include -o $@ -c $<
compile_commands.json:src/A.cpp.d.json src/A.o
sed -e '1i[' -e '$$s/,$$//' -e '$$a]' src/*.d.json > $@
run_scan_deps:compile_commands.json
cat $<
clang-scan-deps --compilation-database=$<
(cd src && clang-scan-deps --compilation-database=../$<)
clean:
${RM} src/*.o src/*.d.json compile_commands.json
.PHONY:all clean run_scan_deps
And if I run this:
<span class="quote">> make</span >
clang -MJ src/A.cpp.d.json -I include -o src/A.o -c src/A.cpp
sed -e '1i[' -e '$s/,$//' -e '$a]' src/*.d.json > compile_commands.json
cat compile_commands.json
[
{ "directory": "/remote/users/rgeissler/wk/tmp/clang-scan-deps", "file":
"src/A.cpp", "output": "src/A.o", "arguments":
["/remote/tools/Linux/2.6/1A/toolchain/x86_64-v21.0.4/bin/clang-12", "-xc++",
"src/A.cpp", "-I", "include", "-o", "src/A.o", "-c",
"--target=x86_64-1a-linux-gnu"]}
]
# First invocation of clang-scan-deps with the same current working directory
works:
clang-scan-deps --compilation-database=compile_commands.json
src/A.o: /remote/users/rgeissler/wk/tmp/clang-scan-deps/src/A.cpp \
/remote/users/rgeissler/wk/tmp/clang-scan-deps/include/A.h
# While if I change directory, it doesn't work anymore
(cd src && clang-scan-deps --compilation-database=../compile_commands.json)
Error while scanning dependencies for src/A.cpp:
error: no such file or directory: 'src/A.cpp'
error: no input files
error: unable to handle compilation, expected exactly one compiler job in ''
Makefile:12: recipe for target 'run_scan_deps' failed
make: *** [run_scan_deps] Error 1
I would have hoped that since in the compilation database is an absolute path
"/remote/users/rgeissler/wk/tmp/clang-scan-deps" then clang would change the
current directory to this folder (and do the same for each entry of the
database), before running the scan, but apparently it doesn't (or it doesn't
work as expected). It's a bit strange, since in the code, it looks like you try
to do that:
<a href="https://github.com/llvm/llvm-project/blob/master/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp#L208">https://github.com/llvm/llvm-project/blob/master/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp#L208</a>
llvm::Error DependencyScanningWorker::computeDependencies(
const std::string &Input, StringRef WorkingDirectory,
const CompilationDatabase &CDB, DependencyConsumer &Consumer) {
RealFS->setCurrentWorkingDirectory(WorkingDirectory);
...
where normally "WorkingDirectory" is the "directory" entry of the compilation
database.
Is it expected ?
Cheers,
Romain</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>