Skip to content

Commit

Permalink
Make %context exec-dir inherited by further includes. #218
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguo committed Jun 30, 2016
1 parent 3659c11 commit 2996450
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/drake/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@
exec-dir)))

(defn- postprocess-context
"Ensure all steps use context directory"
[prod file-path]
(let [exec-dir (dfs/get-directory-path file-path)
set-exec-dir (partial set-step-exec-dir exec-dir)]
Expand All @@ -691,11 +692,15 @@
(def ^:const ^:private directive-context "context")

(defn- make-inclusion-directive-state
[directive tokens vars methods file-path]
[directive tokens vars methods file-path exec-dir]
(merge (assoc (make-state (ensure-final-newline tokens) vars methods 0 0)
:file-path file-path)
(when (= directive directive-context)
{:exec-dir (dfs/get-directory-path file-path)})))
:file-path file-path)
;; exec-dir handling:
;; - context: use file-path as new exec-dir
;; - non-context: use existing exec-dir
(if (= directive directive-context)
{:exec-dir (dfs/get-directory-path file-path)}
{:exec-dir exec-dir})))

(defn- resolve-include-path
"Apply context exec dir to include file path if necessary"
Expand Down Expand Up @@ -726,7 +731,7 @@
file-path (resolve-include-path file-path exec-dir)
;; Need to use fs/file here to honor cwd
^String tokens (slurp (fs/file file-path))
state (make-inclusion-directive-state directive tokens vars methods file-path)
state (make-inclusion-directive-state directive tokens vars methods file-path exec-dir)
prod (parse-state state)]
(condp = directive
directive-include prod ;call-or-include line will merge vars+methods from prod into parent's vars
Expand Down

0 comments on commit 2996450

Please sign in to comment.