Skip to content

Commit

Permalink
Context directive: give warning for c4* protocols, indicating they ar…
Browse files Browse the repository at this point in the history
…e not compatible with %context. #184
  • Loading branch information
chen-factual committed Oct 5, 2015
1 parent 13817e4 commit 99da1e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/drake/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[drake.steps :refer [add-dependencies calc-step-dirs]]
[drake.utils :as utils :refer [clip ensure-final-newline]]
[drake.parser_utils :refer :all]
[drake.protocol-c4 :as c4]
[drake-interface.core :as di]
[name.choi.joshua.fnparse :as p]
[fs.core :as fs]))
Expand Down Expand Up @@ -658,9 +659,22 @@
p/emptiness)]
(dissoc prod :vars)))

(defn- attach-exec-dir
(def ^:private ^:const context-incompatible-protocols
(set c4/c4-protocols))

(defn- check-context-incompatible-protocols
[steps]
(doall
(some (fn [step]
(let [protocol (-> step :opts :protocol)]
(when (contains? context-incompatible-protocols protocol)
(throw+ {:msg (str "protocol " protocol " not supported with %context")}))))
steps)))

(defn- postprocess-context
[prod file-path]
(let [exec-dir (dfs/get-directory-path file-path)]
(check-context-incompatible-protocols (:steps prod))
(update-in prod [:steps]
(fn [steps]
(mapv #(assoc % :exec-dir exec-dir) steps)))))
Expand Down Expand Up @@ -702,7 +716,7 @@
(condp = directive
directive-include prod ;call-or-include line will merge vars+methods from prod into parent's vars
directive-call (dissoc prod :vars :methods) ;but vars+methods from %call should not affect parent
directive-context (attach-exec-dir prod file-path)))))
directive-context (postprocess-context prod file-path)))))

(def inclusion-directive-line
"input: directive to call/include another Drake workflow. ie.,
Expand Down
2 changes: 2 additions & 0 deletions src/drake/protocol_c4.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
(run [_ step]
(exec-or-passthru step func)))))

(def ^:const c4-protocols ["c4" "c4row" "c4rows"])

(dorun (map register-c4-protocol! [["c4" exec-c4]
["c4row" exec-row-xform]
["c4rows" exec-rows]]))
Expand Down

0 comments on commit 99da1e3

Please sign in to comment.