[clang] 0304aa2 - [dataflow] allow specifying path to dot with $GRAPHVIZ_DOT

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 20 20:30:10 PDT 2023


Author: Sam McCall
Date: 2023-04-21T05:29:11+02:00
New Revision: 0304aa25e0be5f322a76d16c6b6069eb9e153430

URL: https://github.com/llvm/llvm-project/commit/0304aa25e0be5f322a76d16c6b6069eb9e153430
DIFF: https://github.com/llvm/llvm-project/commit/0304aa25e0be5f322a76d16c6b6069eb9e153430.diff

LOG: [dataflow] allow specifying path to dot with $GRAPHVIZ_DOT

I'd like to use this in a CI system where it's easier to tell the
program about paths than manipulate $PATH.

Added: 
    

Modified: 
    clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
index cbf7a22bf7fa7..b229194bc8f44 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -394,10 +394,16 @@ class HTMLLogger : public Logger {
 
 // Nothing interesting here, just subprocess/temp-file plumbing.
 llvm::Expected<std::string> renderSVG(llvm::StringRef DotGraph) {
-  auto Dot = llvm::sys::findProgramByName("dot");
-  if (!Dot)
-    return llvm::createStringError(Dot.getError(),
-                                   "Can't draw CFG: 'dot' not found on PATH");
+  std::string DotPath;
+  if (const auto *FromEnv = ::getenv("GRAPHVIZ_DOT"))
+    DotPath = FromEnv;
+  else {
+    auto FromPath = llvm::sys::findProgramByName("dot");
+    if (!FromPath)
+      return llvm::createStringError(FromPath.getError(),
+                                     "'dot' not found on PATH");
+    DotPath = FromPath.get();
+  }
 
   // Create input and output files for `dot` subprocess.
   // (We create the output file as empty, to reserve the temp filename).
@@ -419,7 +425,7 @@ llvm::Expected<std::string> renderSVG(llvm::StringRef DotGraph) {
       /*stderr=*/std::nullopt};
   std::string ErrMsg;
   int Code = llvm::sys::ExecuteAndWait(
-      *Dot, {"dot", "-Tsvg"}, /*Env=*/std::nullopt, Redirects,
+      DotPath, {"dot", "-Tsvg"}, /*Env=*/std::nullopt, Redirects,
       /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg);
   if (!ErrMsg.empty())
     return llvm::createStringError(llvm::inconvertibleErrorCode(),


        


More information about the cfe-commits mailing list