110

First of all, I am new to MacOS, and what I want is to be able to see the output of llc -view-dag-combine1-dags sum.ll. On Mac, llc will generate dot in /tmp directory, and try open App to show the dot file. I have tried Graphviz, but it doesn't work (the program crash). I would like try something else, like xdot for example. I install it by brew install xdot, but don't know how to let the MacOS use the xdot I just installed to open the dot file.

Or any other better tool to view the dot file? I would like to keep thing as simple as possible.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
chenwj
  • 1,989
  • 2
  • 16
  • 30
  • `xdot /tmp/dotfile`? – arrowd Apr 12 '17 at 14:59
  • @arrowd `llc` will call MacOS `open` command to invoke the App be able to open the dot file. I don't want to do it manually. Besides, `llc` will delete the temporary dot file if it fail to open. – chenwj Apr 12 '17 at 15:15
  • `/usr/local/bin/xdot /tmp/dotfile` probably. – Mark Setchell Apr 12 '17 at 15:59
  • Or maybe `open -a /usr/local/bin/xdot --args /tmp/dotfile` – Mark Setchell Apr 12 '17 at 16:01
  • @MarkSetchell I feel it's like associating App with file type, but here we only have the command line `xdot`. Your command is only one-shot. What I want is every time I click the dot file, Mac will launch `xdot` for me. – chenwj Apr 13 '17 at 14:22
  • Have you tried [Gephi](https://gephi.org) or [Cytoscape](http://cytoscape.org) instead of Graphviz? – chb Dec 15 '17 at 17:14
  • @chb, nope. From their webpage, seems it's overkill. What I need is Graphviz viewer. – chenwj Dec 16 '17 at 13:42
  • FYI Error: invalid option: --with-app comes from https://github.com/Homebrew/homebrew-core/issues/31510 – kula85 Mar 22 '19 at 15:49
  • xdot works fine for me in 2021. It's unfortunate that Graphviz.app isn't maintained and this is the next best thing. – Sridhar Sarnobat Aug 11 '21 at 00:21

5 Answers5

216

I never used 'llc' before.

But in my case to deal with the .dot file

I used brew install graphviz

Then used the following command to convert .dot to .png

dot -Tpng DocName.dot -o DocName.png

It works every time without crash.

Leowang
  • 2,359
  • 1
  • 9
  • 12
  • 2
    Well, I think the question is not so clear, my apologize. `llc` will `open` graphviz viewer (gui apparently) after generating dot file, I want to make the `open` work automatically. :-) – chenwj May 24 '17 at 14:14
43

You can also build the Graphviz GUI app using homebrew if you have Xcode installed:

brew install graphviz --with-app

If you already installed the graphviz brew, you will want to do this:

brew reinstall graphviz --with-app

At the time of writing, this doesn't appear to install a symlink to the app into /Applications like cask does, so if you want that you'll need to do it manually (or copy the application out).

To find the location of the app bundle, have a look at the build log, you should see a line like this:

./configure --prefix=/usr/local/Cellar/graphviz/2.40.1

If you don't have the build log anymore, you can determine this path by running brew list graphviz or brew info graphviz.

Open up the folder (replace this with the actual path you determined in the previous step):

open /usr/local/Cellar/graphviz/2.40.1

Inside here you should see Graphviz.app. You can move/copy it to /Applications or create an alias by dragging it to /Applications and holding the and option keys.

Warning! May currently be broken on Mojave.

Please see comment below from Kim Stacks:

As of 2018-12-21, for macOS mojave, there's an issue with using the --with-app flag in the brew install command. See gitlab.com/graphviz/graphviz/issues/1445. Will update this when the fix is working.

It appears as if there is an issue with Graphviz itself currently preventing builds on macOS Mojave. Please do not comment on this answer saying that it doesn't work, it will accomplish nothing. You may follow the issue above for more updates and we'll try to update this answer if/when the situation is resolved by the Graphviz devs.

If people want to help get this fixed, there is a partially implemented upgrade PR that needs some love to take it over the finish line (see comments.)~~

Update: build is fixed, but homebrew has removed GUI support

The saga continues. The upstream build breakage with Graphviz was resolved in August 2020. However, the homebrew team has apparently instituted a new policy to remove all build options from Homebrew formulae. The --with-app option was removed from graphviz formula in January 2019.

I'm afraid I don't have a new solution for how to do this other than manually building from source. If somebody has any ideas, please share them in the comments. I am going to keep this answer up as I think this should be the right way to do this, we just need more advocacy (and volunteer devs) to improve the user experience for Graphviz users on macOS.

Eliot
  • 5,450
  • 3
  • 32
  • 30
  • @PhillPafford I wasn't aware that it was possible to install "just the CLI" but I expect it would probably get the job done. I think you basically just need a Cococa SDK with command line tools available for homebrew to compile against. Give it a shot and let us know how it works out! – Eliot Nov 14 '18 at 02:23
  • 2
    As of 2018-12-21, for macOS mojave, there's an issue with using the `--with-app` flag in the `brew install` command. See https://gitlab.com/graphviz/graphviz/issues/1445. Will update this when the fix is working. – Kim Stacks Dec 21 '18 at 02:51
  • @zeliboba Please see above comment - this is an issue in graphviz that is being tracked at https://gitlab.com/graphviz/graphviz/issues/1445 – Eliot Feb 14 '19 at 21:43
  • 8
    Error: invalid option: --with-app – Davide Feb 24 '19 at 16:05
  • @Davide -- I get this error, too. This answer should probably be removed. – Robert P. Goldman Mar 31 '19 at 18:21
  • 2
    I get the "--with-app" error also on 10.13.6, so it's not limited to Mojave and later, but probably affects the recent brew updates on all macOS versions. – Thomas Tempelmann Nov 04 '19 at 17:47
  • If people want to help get this fixed, there is a partially implemented upgrade PR at https://gitlab.com/graphviz/graphviz/-/merge_requests/1302 that needs some love to take it over the finish line (see comments.) – Eliot Feb 27 '20 at 14:58
  • I'm getting "Error: invalid option: --with-app" with Homebrew 3.0.1, macOS 10.15.5 – Greg Feb 15 '21 at 04:07
  • @Greg good catch - I looked into this and it looks like the homebrew devs removed this on purpose. We just can't catch a break here. See post for more details. – Eliot Feb 19 '21 at 00:45
  • what is the alternative now to be able to access dot on mac ? – AKFourSeven Mar 05 '21 at 08:29
  • 1
    @AKFourSeven I think for now the only option is to build from source by hand, or use the graphviz command line app, sorry. You could also try commercial graphing software like OmniGraffle that can open dot files. – Eliot Mar 05 '21 at 16:44
  • OmniGraffle's dot implementation is severely limited to a small subset of dot. Standard dot files fail with errors. – John Smith Jan 21 '23 at 07:09
10

Homebrew has graphviz which is command line only. I would suggest using MacPorts to install graphviz-gui, that will save us from a lot of trouble.

chenwj
  • 1,989
  • 2
  • 16
  • 30
  • 6
    brew install graphviz --with-app should give you the GUI version of graphviz using Homebrew. – Jonathon Hodges Aug 03 '18 at 16:17
  • just re-installing graphviz on 10.13 (HighSierra), and using homebrew cuz that's what i generally use. FYI: homebrew also depends on MacPorts! >> ==> Installing graphviz --with-app >> ==> Downloading https://www.mirrorservice.org/sites/distfiles.macports.org/graphviz/graphviz-2.40.1.tar.gz >> ==> ./configure --prefix=/usr/local/Cellar/graphviz/2.40.1 --disable-php --disable-swig -... >> ==> make install >> ==> xcodebuild ... – rikb Dec 05 '18 at 22:30
  • 5
    Not sure which version of brew you're using but on Mojave I get the error: "invalid option: --with-app" @JonathonHodges – marknuzz Feb 21 '19 at 20:12
  • 12
    I'm still on High Sierra, but I also find that the `with-app` option is no longer available. – Robert P. Goldman Mar 31 '19 at 18:21
  • 2
    anyone else figured out what the `--with-app` is in 2021? – dcsan Jun 19 '21 at 19:48
  • `with-app` does not work in 2021 – Exploring Jun 24 '21 at 06:27
3

You can install graphviz via brew. BrewInstall is a handy website to get steps of installing all mac apps. I found the below answer on BrewInstall.

Install brew first with the following command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

Now install graphviz with brew with the following command

brew install graphviz

To install it with GUI version, run the following command instead of above command:

brew install graphviz --with-app
Ajeet Khan
  • 8,582
  • 8
  • 42
  • 65
-7

New versions on macOS allow you to toggle the ability to view/work with hidden files.

For those developing on macOS - pressing down Command + Shift + Period (Command + Shift + .) in the file system of macOS will hide or show invisible files. This will allow you to toggle the ability to create and work with dot files.

For simple viewing or editing of dot files, this approach would probably work the best. Note that, while this toggle is active, seems to be a system wide switch, allowing other apps to access/open the dot files as you would any text file.

Rohan
  • 1
  • 2
    While this is true for hidden files (i.e. files that begin with a dot, e.g. "`.gitignore`"), this question is about files in the [DOT format](https://en.wikipedia.org/wiki/DOT_(graph_description_language)). Hence this answer does not relate to the question. – Gerrit-K Jan 07 '21 at 07:50