Skip to content

Commit

Permalink
Merge branch 'master' into 80-inline-truth
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Jan 27, 2012
2 parents 54a3049 + 0a50e20 commit 0e54a3c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 11 deletions.
16 changes: 15 additions & 1 deletion script/test
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ bin/cljsc test {:optimizations :advanced} > out/core-advanced-test.js
if [ "$V8_HOME" == "" ]; then
echo "V8_HOME not set, skipping V8 tests"
else
echo "Testing with V8"
${V8_HOME}/d8 out/core-advanced-test.js
# TODO: figure out path problem when not in advanced mode
# ${V8_HOME}/d8 out/core-test.js
fi

# TODO : run tests with rhino if available
if [ "$SPIDERMONKEY_HOME" == "" ]; then
echo "SPIDERMONKEY_HOME not set, skipping SpiderMonkey tests"
else
echo "Testing with SpiderMonkey"
${SPIDERMONKEY_HOME}/js -f out/core-advanced-test.js
fi

if [ "$JSC_HOME" == "" ]; then
echo "JSC_HOME not set, skipping JavaScriptCore tests"
else
echo "Testing with JavaScriptCore"
${JSC_HOME}/jsc -f out/core-advanced-test.js
fi

65 changes: 55 additions & 10 deletions src/clj/cljs/closure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,54 @@
(set-options opts compiler-options)
compiler-options)))



(defn jar-entry-names* [jar-path]
(with-open [z (java.util.zip.ZipFile. jar-path)]
(doall (map #(.getName %) (enumeration-seq (.entries z))))))

(def jar-entry-names (memoize jar-entry-names*))

(defn find-js-jar
"finds js resources from a given path in a jar file"
[jar-path lib-path]
(doall
(map #(io/resource %)
(filter #(do
(and
(.startsWith % lib-path)
(.endsWith % ".js")))
(jar-entry-names jar-path)))))
(declare to-url)
(defn find-js-fs
"finds js resources from a path on the files system"
[path]
(let [file (io/file path)]
(when (.exists file)
(map to-url (filter #(.endsWith (.getName %) ".js") (file-seq (io/file path)))))))


(defn find-js-classpath [path]
"finds all js files on the classpath matching the path provided"
(let [process-entry #(if (.endsWith % ".jar")
(find-js-jar % path)
(find-js-fs (str % "/" path)))
cpath-list (let [sysp (System/getProperty "java.class.path" )]
(if (.contains sysp ";")
(string/split sysp #";")
(string/split sysp #":")))]
(doall (reduce #(let [p (process-entry %2)]
(if p (concat %1 p) %1)) [] cpath-list))))

(defn find-js-resources [path]
"finds js resources in a given path on either the file system or
the classpath"
(let [file (io/file path)]
(if (.exists file)
(find-js-fs path)
(find-js-classpath path))))


(defn load-externs
"Externs are JavaScript files which contain empty definitions of
functions which will be provided by the envorinment. Any function in
Expand All @@ -104,16 +152,14 @@
the default externs should be excluded."
[{:keys [externs use-only-custom-externs target]}]
(letfn [(filter-js [paths]
(for [p paths f (file-seq (io/file p))
:when (.endsWith (.toLowerCase (.getName f)) ".js")]
(.getAbsolutePath f)))
(for [p paths u (find-js-resources p)] u))
(add-target [ext]
(if (= :nodejs target)
(cons (.getFile (io/resource "cljs/nodejs_externs.js"))
(cons (io/resource "cljs/nodejs_externs.js")
(or ext []))
ext))
(load-js [ext]
(map #(js-source-file % (io/input-stream %)) ext))]
(map #(js-source-file (.getFile %) (slurp %)) ext))]
(let [js-sources (-> externs filter-js add-target load-js)]
(if use-only-custom-externs
js-sources
Expand Down Expand Up @@ -393,7 +439,6 @@
and :url"
[lib-spec]
(merge lib-spec {:foreign true
:requires nil
:url (find-url (:file lib-spec))}))

(def load-foreign-library (memoize load-foreign-library*))
Expand All @@ -403,12 +448,12 @@
containing Javascript files, return a list of maps
containing :provides, :requires, :file and :url."
[path]
(letfn [(graph-node [f]
(-> (io/reader f)
(letfn [(graph-node [u]
(-> (io/reader u)
line-seq
parse-js-ns
(assoc :file (.getPath f) :url (to-url f))))]
(let [js-sources (filter #(.endsWith (.getName %) ".js") (file-seq (io/file path)))]
(assoc :url u)))]
(let [js-sources (find-js-resources path)]
(filter #(seq (:provides %)) (map graph-node js-sources)))))

(def load-library (memoize load-library*))
Expand Down

0 comments on commit 0e54a3c

Please sign in to comment.