Skip to content

Commit

Permalink
Add support for --graph=dot as requested on mailing list
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed Feb 9, 2015
1 parent dc4fda4 commit 6ec6913
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
29 changes: 18 additions & 11 deletions src/drake/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
(:gen-class :methods [#^{:static true} [run_opts [java.util.Map] void]
#^{:static true} [run_opts_with_event_bus [java.util.Map com.google.common.eventbus.EventBus] void]]))

(defn- shutdown [exit-code]
(throw+ {:exit-code exit-code}))

(def VERSION "0.1.6")
(def DEFAULT-VARS-SPLIT-REGEX-STR ; matches and consumes a comma; requires that an even number of "
; characters exist between the comma and end of string
Expand Down Expand Up @@ -590,13 +593,20 @@

(defn graph-steps
"Shows a graph visualizing workflow of steps to run, and saves it to drake.png"
[parse-tree steps-to-run]
(require 'rhizome.dot 'rhizome.viz)
(let [img (viz dot->image (viz/step-tree parse-tree steps-to-run))]
(viz save-image img "drake.png")
(println "Image saved to drake.png")
(deref ;; returns a future we can block on
(viz view-image {:title "Workflow visualization"} img))))
[mode parse-tree steps-to-run]
(require 'rhizome.dot)
(let [dot (viz/step-tree parse-tree steps-to-run)]
(case mode
("dot") (do (spit "drake.dot" dot)
(println "DOT file saved to drake.dot"))
(true "png") (do (require 'rhizome.viz)
(let [img (viz dot->image dot)]
(viz save-image img "drake.png")
(println "Image saved to drake.png")
(deref ;; returns a future we can block on
(viz view-image {:title "Workflow visualization"} img))))
(throw+ {:msg (format "Unrecognized --graph mode '%s'" mode)
:exit-code -1}))))

(defn print-steps
"Prints inputs and outputs of steps to run."
Expand Down Expand Up @@ -626,7 +636,7 @@
(:print *options*)
(print-steps parse-tree steps-to-run)
(:graph *options*)
(graph-steps parse-tree steps-to-run)
(graph-steps (:graph *options*) parse-tree steps-to-run)
(:preview *options*)
(println (steps-report parse-tree steps-to-run))
:else
Expand All @@ -641,9 +651,6 @@
(get "sun.java.command"))]
(.endsWith ^String java-cmd "nailgun.NGServer")))

(defn- shutdown [exit-code]
(throw+ {:exit-code exit-code}))

(defn parse-cli-vars [vars-str split-regex-str]
(when-not (empty? vars-str)
(let [pairs (str/split vars-str (re-pattern split-regex-str))]
Expand Down
6 changes: 3 additions & 3 deletions src/drake/options.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns drake.options
(:require [clojopts.ui :as clojopts]
[clojopts.core :refer [clojopts with-arg no-arg]])
[clojopts.core :refer [clojopts with-arg no-arg optional-arg]])
(:refer-clojure :exclude [file-seq]))

;; This namespace is responsible for the keeping track of
Expand Down Expand Up @@ -60,8 +60,8 @@
:user-name "name")
(no-arg print p
"Runs Drake in \"print\" mode. Instead of executing steps, Drake just prints inputs, outputs and tags of each step that is scheduled to run to stdout. This is useful if some outside actions need to be taken before or after running Drake. Standard target matching rules apply. Inputs are prepended by I, outputs by O, and input and output tags by %I and %O respectively. It also outputs \"S\" to signify beginning of each step.")
(no-arg graph g
"Runs Drake in \"graph\" mode. Instead of executing steps, Drake just draws a graph of all the inputs and outputs in the workflow, with color-coding to indicate which will be run. The graph is saved to a file named drake.png in the current directory. Files which will be built are colored green, and those which were forced will be outlined in black as well.")
(optional-arg graph g
"Runs Drake in \"graph\" mode. Instead of executing steps, Drake just draws a graph of all the inputs and outputs in the workflow, with color-coding to indicate which will be run. The graph is saved to a file named drake.png in the current directory. Files which will be built are colored green, and those which were forced will be outlined in black as well. You can specify --graph=dot to output a .dot file instead of displaying the image and outputting a png.")
(with-arg logfile l
"Specify the log file. If not absolute, will be relative to the workflow file, default is drake.log in the directory of the workflow file."
:type :str
Expand Down

0 comments on commit 6ec6913

Please sign in to comment.