[llvm] r234031 - [GraphWriter] Attempt to open .dot files with xdg-open/open first

Matthias Braun matze at braunis.de
Fri Apr 3 10:22:36 PDT 2015


Author: matze
Date: Fri Apr  3 12:22:36 2015
New Revision: 234031

URL: http://llvm.org/viewvc/llvm-project?rev=234031&view=rev
Log:
[GraphWriter] Attempt to open .dot files with xdg-open/open first

Most desktop environments let the users specify his preferred application per
file type. On mac/linux we can use open/xdg-open for that and should try this
first before starting a heuristic search for various programs.

Differential Revision: http://reviews.llvm.org/D6534

Modified:
    llvm/trunk/lib/Support/GraphWriter.cpp

Modified: llvm/trunk/lib/Support/GraphWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/GraphWriter.cpp?rev=234031&r1=234030&r2=234031&view=diff
==============================================================================
--- llvm/trunk/lib/Support/GraphWriter.cpp (original)
+++ llvm/trunk/lib/Support/GraphWriter.cpp Fri Apr  3 12:22:36 2015
@@ -140,6 +140,29 @@ bool llvm::DisplayGraph(StringRef Filena
   std::string ViewerPath;
   GraphSession S;
 
+#ifdef __APPLE__
+  if (S.TryFindProgram("open", ViewerPath)) {
+    std::vector<const char *> args;
+    args.push_back(ViewerPath.c_str());
+    if (wait)
+      args.push_back("-W");
+    args.push_back(Filename.c_str());
+    args.push_back(nullptr);
+    errs() << "Trying 'open' program... ";
+    if (!ExecGraphViewer(ViewerPath, args, Filename, wait, ErrMsg))
+      return false;
+  }
+#endif
+  if (S.TryFindProgram("xdg-open", ViewerPath)) {
+    std::vector<const char *> args;
+    args.push_back(ViewerPath.c_str());
+    args.push_back(Filename.c_str());
+    args.push_back(nullptr);
+    errs() << "Trying 'xdg-open' program... ";
+    if (!ExecGraphViewer(ViewerPath, args, Filename, wait, ErrMsg))
+      return false;
+  }
+
   // Graphviz
   if (S.TryFindProgram("Graphviz", ViewerPath)) {
     std::vector<const char *> args;





More information about the llvm-commits mailing list