Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions clang/test/ClangScanDeps/include-tree-with-pch.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@

// RUN: %clang -x c-header %t/prefix.h -target x86_64-apple-macos12 -o %t/prefix.pch -fdepscan=inline -fdepscan-include-tree -Xclang -fcas-path -Xclang %t/cas
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree -cas-path %t/cas > %t/result.txt
// RUN: FileCheck %s -input-file %t/result.txt -DPREFIX=%/t
// RUN: cat %t/result.txt | %PathSanitizingFileCheck --sanitize PREFIX=%/t %s

// CHECK: {{.*}} - [[PREFIX]]/t.c
// CHECK: {{.*}} - PREFIX{{/|\\}}t.c
// CHECK-NEXT: (PCH)
// CHECK-NEXT: [[PREFIX]]/t.c
// CHECK-NEXT: PREFIX{{/|\\}}t.c
// CHECK-NEXT: 1:1 <built-in>
// CHECK-NEXT: [[PREFIX]]/t.h
// CHECK-NEXT: PREFIX{{/|\\}}t.h
// CHECK-NEXT: Files:
// CHECK-NEXT: [[PREFIX]]/t.c
// CHECK-NEXT: [[PREFIX]]/t.h
// CHECK-NEXT: [[PREFIX]]/prefix.h
// CHECK-NEXT: [[PREFIX]]/n1.h
// CHECK-NEXT: [[PREFIX]]/n2.h
// CHECK-NEXT: [[PREFIX]]/n3.h
// CHECK-NOT: [[PREFIX]]
// CHECK-NEXT: PREFIX{{/|\\}}t.c
// CHECK-NEXT: PREFIX{{/|\\}}t.h
// CHECK-NEXT: PREFIX{{/|\\}}prefix.h
// CHECK-NEXT: PREFIX{{/|\\}}n1.h
// CHECK-NEXT: PREFIX{{/|\\}}n2.h
// CHECK-NEXT: PREFIX{{/|\\}}n3.h
// CHECK-NOT: PREFIX

// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree-full -cas-path %t/cas > %t/deps.json

// RUN: cat %t/result.txt > %t/full.txt
// RUN: echo "FULL DEPS START" >> %t/full.txt
// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' >> %t/full.txt
// RUN: cat %t/deps.json >> %t/full.txt

// RUN: FileCheck %s -DPREFIX=%/t -DCLANG=%clang -check-prefix=FULL -input-file %t/full.txt
// RUN: cat %t/full.txt | %PathSanitizingFileCheck --sanitize PREFIX=%/t --sanitize CLANG=%/clang --enable-yaml-compatibility -check-prefix=FULL %s

// Capture the tree id from experimental-include-tree ; ensure that it matches
// the result from experimental-full.
// FULL: [[TREE_ID:llvmcas://[[:xdigit:]]+]] - [[PREFIX]]/t.c
// FULL: [[TREE_ID:llvmcas://[[:xdigit:]]+]] - PREFIX{{/|\\}}t.c
// FULL: FULL DEPS START

// FULL-NEXT: {
Expand All @@ -44,7 +44,7 @@
// FULL: "command-line": [
// FULL-NEXT: "-cc1"
// FULL: "-fcas-path"
// FULL-NEXT: "[[PREFIX]]/cas"
// FULL-NEXT: "PREFIX{{/|\\\\}}cas"
// FULL: "-disable-free"
// FULL: "-fcas-include-tree"
// FULL-NEXT: "[[TREE_ID]]"
Expand All @@ -57,13 +57,13 @@
// FULL-NEXT: "t.c"
// FULL-NOT: "t.c"
// FULL: ]
// FULL: "executable": "[[CLANG]]"
// FULL: "executable": "CLANG"
// FULL: "file-deps": [
// FULL-NEXT: "[[PREFIX]]/t.c"
// FULL-NEXT: "[[PREFIX]]/t.h"
// FULL-NEXT: "[[PREFIX]]/prefix.pch"
// FULL-NEXT: "PREFIX{{/|\\\\}}t.c"
// FULL-NEXT: "PREFIX{{/|\\\\}}t.h"
// FULL-NEXT: "PREFIX{{/|\\\\}}prefix.pch"
// FULL-NEXT: ]
// FULL: "input-file": "[[PREFIX]]/t.c"
// FULL: "input-file": "PREFIX{{/|\\\\}}t.c"
// FULL: }
// FULL: ]
// FULL: }
Expand Down
14 changes: 13 additions & 1 deletion clang/tools/driver/cc1depscan_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@
#if LLVM_ON_UNIX
#include <sys/file.h> // FIXME: Unix-only. Not portable.
#include <sys/signal.h> // FIXME: Unix-only. Not portable.
#endif // LLVM_ON_UNIX

#ifdef CLANG_HAVE_RLIMITS
#include <sys/resource.h>
#endif

using namespace clang;
using namespace llvm::opt;
#if LLVM_ON_UNIX
using cc1depscand::DepscanSharing;
#endif // LLVM_ON_UNIX
using llvm::Error;

#define DEBUG_TYPE "cc1depscand"
Expand Down Expand Up @@ -203,6 +206,7 @@ class SharedStream {
};
} // namespace

#ifdef LLVM_ON_UNIX
namespace {
/// FIXME: Move to LLVMSupport; probably llvm/Support/Process.h.
///
Expand Down Expand Up @@ -354,6 +358,7 @@ makeDepscanDaemonPath(StringRef Mode, const DepscanSharing &Sharing) {

return std::nullopt;
}
#endif // LLVM_ON_UNIX

static int
scanAndUpdateCC1Inline(const char *Exec, ArrayRef<const char *> InputArgs,
Expand All @@ -371,6 +376,7 @@ static Expected<llvm::cas::CASID> scanAndUpdateCC1InlineWithTool(
SmallVectorImpl<const char *> &OutputArgs, llvm::cas::ObjectStore &DB,
llvm::function_ref<const char *(const Twine &)> SaveArg);

#ifdef LLVM_ON_UNIX
static int scanAndUpdateCC1UsingDaemon(
const char *Exec, ArrayRef<const char *> OldArgs,
StringRef WorkingDirectory, SmallVectorImpl<const char *> &NewArgs,
Expand Down Expand Up @@ -432,6 +438,7 @@ static int scanAndUpdateCC1UsingDaemon(

return 0;
}
#endif // LLVM_ON_UNIX

// FIXME: This is a copy of Command::writeResponseFile. Command is too deeply
// tied with clang::Driver to use directly.
Expand Down Expand Up @@ -480,6 +487,7 @@ static int scanAndUpdateCC1(const char *Exec, ArrayRef<const char *> OldArgs,
}

// Collect these before returning to ensure they're claimed.
#ifdef LLVM_ON_UNIX
DepscanSharing Sharing;
if (Arg *A = Args.getLastArg(options::OPT_fdepscan_share_stop_EQ))
Sharing.Stop = A->getValue();
Expand Down Expand Up @@ -515,9 +523,11 @@ static int scanAndUpdateCC1(const char *Exec, ArrayRef<const char *> OldArgs,
}
}

#endif // LLVM_ON_UNIX
bool ProduceIncludeTree = Args.hasArg(options::OPT_fdepscan_include_tree);

auto SaveArg = [&Args](const Twine &T) { return Args.MakeArgString(T); };
#ifdef LLVM_ON_UNIX
CompilerInvocation::GenerateCASArgs(CASOpts, Sharing.CASArgs, SaveArg);
if (ProduceIncludeTree)
Sharing.CASArgs.push_back("-fdepscan-include-tree");
Expand All @@ -526,6 +536,7 @@ static int scanAndUpdateCC1(const char *Exec, ArrayRef<const char *> OldArgs,
return scanAndUpdateCC1UsingDaemon(Exec, OldArgs, WorkingDirectory, NewArgs,
*DaemonPath, Sharing, Diag, SaveArg,
CASOpts, RootID);
#endif // LLVM_ON_UNIX

return scanAndUpdateCC1Inline(Exec, OldArgs, WorkingDirectory, NewArgs,
ProduceIncludeTree, SaveArg, CASOpts, Diag,
Expand Down Expand Up @@ -626,6 +637,7 @@ int cc1depscan_main(ArrayRef<const char *> Argv, const char *Argv0,
return 0;
}

#ifdef LLVM_ON_UNIX
namespace {
struct ScanServer {
const char *Argv0 = nullptr;
Expand Down Expand Up @@ -1084,6 +1096,7 @@ int ScanServer::listen() {

return 0;
}
#endif // LLVM_ON_UNIX

static Expected<llvm::cas::CASID> scanAndUpdateCC1InlineWithTool(
tooling::dependencies::DependencyScanningTool &Tool,
Expand Down Expand Up @@ -1156,4 +1169,3 @@ scanAndUpdateCC1Inline(const char *Exec, ArrayRef<const char *> InputArgs,

return DiagsConsumer->getNumErrors() != 0;
}
#endif /* LLVM_ON_UNIX */
4 changes: 2 additions & 2 deletions clang/tools/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
#if LLVM_ON_UNIX
extern int cc1depscand_main(ArrayRef<const char *> Argv, const char *Argv0,
void *MainAddr);
#endif /* LLVM_ON_UNIX */
extern int cc1depscan_main(ArrayRef<const char *> Argv, const char *Argv0,
void *MainAddr);
#endif /* LLVM_ON_UNIX */
extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
void *MainAddr);
extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv,
Expand Down Expand Up @@ -252,10 +252,10 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
if (Tool == "-cc1depscand")
return cc1depscand_main(ArrayRef(ArgV).slice(2), ArgV[0],
GetExecutablePathVP);
#endif /* LLVM_ON_UNIX */
if (Tool == "-cc1depscan")
return cc1depscan_main(ArrayRef(ArgV).slice(2), ArgV[0],
GetExecutablePathVP);
#endif /* LLVM_ON_UNIX */
if (Tool == "-cc1as")
return cc1as_main(ArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);
if (Tool == "-cc1gen-reproducer")
Expand Down