Skip to content
This repository has been archived by the owner on Dec 14, 2017. It is now read-only.

Commit

Permalink
only bind *command-line-args* in the run task, setting them to everyt…
Browse files Browse the repository at this point in the history
…hing after the script name. add cake/*args* which stores the literal ARGV passed from the client script
  • Loading branch information
ninjudd committed Jan 12, 2011
1 parent f5a9e75 commit a5ddc8a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions bake/cake.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(def ^{:dynamic true} *context* (comment context))
(def ^{:dynamic true} *script* nil)
(def ^{:dynamic true} *opts* nil)
(def ^{:dynamic true} *args* nil)
(def ^{:dynamic true} *pwd* nil)
(def ^{:dynamic true} *env* nil)
(def ^{:dynamic true} *vars* nil)
Expand Down
2 changes: 1 addition & 1 deletion bin/cake
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def parse_opts!
$opts = {}
ARGV[1..-1].each do |opt|
case opt
when "--" then break # stop parsing options
when /^@([-\w]+)$/ then add_opt!(:context, $1)
when /^--$/ then break # Other REs will match, so check first.
when /^-(\w+)$/ then $1.split('').each {|c| add_opt!(c, '')}
when /^--?([-\w]+)=(.+)$/ then add_opt!($1, *$2.split(','))
when /^--?([-\w]+)$/ then add_opt!($1, "")
Expand Down
4 changes: 4 additions & 0 deletions src/cake/file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
(defn global-file [& path]
(apply file *global-root* path))

(defmacro with-root [root & forms]
`(binding [*root* ~root]
~@forms))

(use 'uncle.core)

(defn cp [from to & opts]
Expand Down
2 changes: 1 addition & 1 deletion src/cake/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
(let [form (read), vars (read)]
(clojure.main/with-bindings
(reload)
(set! *command-line-args* (:args vars))
(set! *warn-on-reflection* (:warn-on-reflection *project*))
(binding [*vars* vars
*pwd* (:pwd vars)
*env* (:env vars)
*opts* (:opts vars)
*args* (:args vars)
*script* (:script vars)]
(with-context (current-context)
(if (keyword? form)
Expand Down
2 changes: 1 addition & 1 deletion src/cake/tasks/deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
(defn install-subprojects []
(doseq [type [:dependencies :dev-dependencies], [dep opts] (*project* type)]
(when-let [path (subproject-path dep)]
(binding [*root* path]
(with-root path
(cake-exec "install")))))

(defn extract-native [jars dest]
Expand Down
11 changes: 4 additions & 7 deletions src/cake/tasks/eval.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns cake.tasks.eval
(:use cake
[cake.core :only [deftask bake]]
[cake.file :only [file]]
[cake.file :only [with-root file]]
[bake.repl :only [repl]]))

(defn- read-form [string]
Expand Down Expand Up @@ -32,12 +32,9 @@
(deftask run #{compile}
"Execute a script in the project jvm."
{[script] :run}
(bake [script (str
(let [fscript (java.io.File. script)]
(if (.isAbsolute fscript)
fscript
(file *pwd* script))))]
(binding [*command-line-args* (-> *opts* :run rest)]
(bake [script (with-root *pwd* (str (file script)))
args (rest (drop-while (partial not= script) *args*))]
(binding [*command-line-args* args]
(load-file script))))

(deftask repl #{compile}
Expand Down
4 changes: 2 additions & 2 deletions tasks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
snapshot? (snapshot? version)
version (if snapshot? (snapshot-timestamp version) version)
jar (format "jars/cake-%s.jar" version)]
(binding [*root* (file "releases")]
(with-root (file "releases")
(git "pull"))
(ant Copy {:file (uberjarfile) :tofile (file "releases" jar)})
(spit (file "releases/current") version)
(when-not snapshot?
(ant Copy {:file (file "bin" "cake") :tofile (file "releases" "cake")})
(spit (file "releases/stable") version))
(binding [*root* (file "releases")]
(with-root (file "releases")
(git "add" jar "cake" "current" "stable")
(git "commit" "--allow-empty" "-m" (format "'release cake %s'" (:version *project*)))
(git "push"))
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(ns helpers
(:use cake
[cake.file :only [file]]
[cake.file :only [file with-root]]
[uncle.core :only [in-project]]
[clojure.java.shell :only [sh with-sh-dir]]))

(defn in-test-project [f]
(binding [*root* (file "examples/test")]
(with-root (file "examples/test")
(in-project *outs* (f))))

(defn cake [& args]
Expand Down

0 comments on commit a5ddc8a

Please sign in to comment.