Skip to content

Make %context exec-dir inherited by further includes. #218 #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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