[llvm-bugs] [Bug 47252] New: clang-scan-deps doesn't change directory to compilation database "directory" folder
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Aug 20 06:33:12 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47252
Bug ID: 47252
Summary: clang-scan-deps doesn't change directory to
compilation database "directory" folder
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Tooling
Assignee: unassignedclangbugs at nondot.org
Reporter: romain.geissler at amadeus.com
CC: llvm-bugs at lists.llvm.org
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:
> cat include/A.h
#ifndef _A_h_
#define _A_h_
class A
{
public:
void f();
};
#endif
> cat src/A.cpp
#include "A.h"
void A::f() {}
> cat Makefile
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:
> make
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:
https://github.com/llvm/llvm-project/blob/master/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp#L208
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200820/8fbad80e/attachment.html>
More information about the llvm-bugs
mailing list