Hi klimek,

It isn't appropriate for a tool to be stomping over the dependency files,
especially if the actual build uses a compiler other than Clang or the tool
cannot find all the headers for some reason (which would cause the existing
dependency file to be deleted).

If a tool actually needs to care about dependency files we can think about
adding a mechanism for getting to this information.

http://llvm-reviews.chandlerc.com/D2912

Files:
  lib/Tooling/Tooling.cpp
  unittests/Tooling/ToolingTest.cpp

Index: lib/Tooling/Tooling.cpp
===================================================================
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -99,6 +99,7 @@
       *Diagnostics);
   Invocation->getFrontendOpts().DisableFree = false;
   Invocation->getCodeGenOpts().DisableFree = false;
+  Invocation->getDependencyOutputOpts() = DependencyOutputOptions();
   return Invocation;
 }
 
Index: unittests/Tooling/ToolingTest.cpp
===================================================================
--- unittests/Tooling/ToolingTest.cpp
+++ unittests/Tooling/ToolingTest.cpp
@@ -236,6 +236,17 @@
                              "int skipMeNot() { an_error_here }"));
 }
 
+TEST(runToolOnCodeWithArgs, TestNoDepFile) {
+  llvm::SmallString<32> DepFilePath;
+  ASSERT_FALSE(
+      llvm::sys::fs::createTemporaryFile("depfile", "d", DepFilePath));
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+      new SkipBodyAction, "",
+      { "-MMD", "-MT", DepFilePath.str(), "-MF", DepFilePath.str() }));
+  EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str()));
+  EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str()));
+}
+
 struct CheckSyntaxOnlyAdjuster: public ArgumentsAdjuster {
   bool &Found;
   bool &Ran;
Index: lib/Tooling/Tooling.cpp
===================================================================
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -99,6 +99,7 @@
       *Diagnostics);
   Invocation->getFrontendOpts().DisableFree = false;
   Invocation->getCodeGenOpts().DisableFree = false;
+  Invocation->getDependencyOutputOpts() = DependencyOutputOptions();
   return Invocation;
 }
 
Index: unittests/Tooling/ToolingTest.cpp
===================================================================
--- unittests/Tooling/ToolingTest.cpp
+++ unittests/Tooling/ToolingTest.cpp
@@ -236,6 +236,17 @@
                              "int skipMeNot() { an_error_here }"));
 }
 
+TEST(runToolOnCodeWithArgs, TestNoDepFile) {
+  llvm::SmallString<32> DepFilePath;
+  ASSERT_FALSE(
+      llvm::sys::fs::createTemporaryFile("depfile", "d", DepFilePath));
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+      new SkipBodyAction, "",
+      { "-MMD", "-MT", DepFilePath.str(), "-MF", DepFilePath.str() }));
+  EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str()));
+  EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str()));
+}
+
 struct CheckSyntaxOnlyAdjuster: public ArgumentsAdjuster {
   bool &Found;
   bool &Ran;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to