Skip to content

Commit

Permalink
Merge pull request technomancy#1911 from montoux/ft-reader-conditionals
Browse files Browse the repository at this point in the history
Add support for reader conditional files (cljc) (technomancy#1827)
  • Loading branch information
technomancy committed Jul 25, 2015
2 parents 7045e66 + f413b6d commit 1f43aa0
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 27 deletions.
2 changes: 1 addition & 1 deletion doc/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ middleware.

## Clojure Version

Leiningen 2.4.0 and on uses Clojure 1.6.0. If you need to use a
Leiningen 2.5.2 and on uses Clojure 1.7.0. If you need to use a
different version of Clojure from within a Leiningen plugin, you can
use `eval-in-project` with a dummy project argument:

Expand Down
4 changes: 2 additions & 2 deletions leiningen-core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:description "Library for core functionality of Leiningen."
:dependencies [[org.clojure/clojure "1.6.0"]
[bultitude "0.2.6"]
:dependencies [[org.clojure/clojure "1.7.0"]
[bultitude "0.2.8"]
[classlojure "0.6.6"]
[robert/hooke "1.3.0"]
[com.cemerick/pomegranate "0.3.0"]
Expand Down
2 changes: 1 addition & 1 deletion leiningen-core/src/leiningen/core/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
(subs 1)
(str suffix)
io/resource))
[".clj" (str clojure.lang.RT/LOADER_SUFFIX ".class")]))
[".clj" ".cljc" (str clojure.lang.RT/LOADER_SUFFIX ".class")]))

(defn error [& args]
(binding [*out* *err*] ;; TODO: use main/warn for this in 3.0
Expand Down
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
:url "https://github.com/technomancy/leiningen"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[leiningen-core "2.5.1"]
:dependencies [[leiningen-core "2.5.2-SNAPSHOT"]
[org.clojure/data.xml "0.0.3"]
[commons-io "2.4"]
[bultitude "0.2.6"]
[bultitude "0.2.8"]
[stencil "0.3.5" :exclusions [org.clojure/core.cache]]
[org.apache.maven.indexer/indexer-core "4.1.3"
:exclusions [org.apache.maven/maven-model
Expand Down
2 changes: 1 addition & 1 deletion resources/leiningen/new/app/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]]
:dependencies [[org.clojure/clojure "1.7.0"]]
:main ^:skip-aot {{namespace}}
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
2 changes: 1 addition & 1 deletion resources/leiningen/new/default/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]])
:dependencies [[org.clojure/clojure "1.7.0"]])
22 changes: 14 additions & 8 deletions src/leiningen/compile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[bultitude.core :as b]
[clojure.java.io :as io])
(:refer-clojure :exclude [compile])
(:import (java.io PushbackReader)))
(:import (java.io PushbackReader File)))

(defn- regex? [str-or-re]
(instance? java.util.regex.Pattern str-or-re))
Expand Down Expand Up @@ -34,13 +34,17 @@
out-of-date class files."
[project]
(for [namespace (compilable-namespaces project)
:let [rel-source (b/path-for namespace)
source (first (sort-by (fn [f] (not (.exists f)))
(for [source-path (:source-paths project)
:let [file (io/file source-path rel-source)]]
file)))]
:let [[rel-source source]
(or (first (for [source-path (:source-paths project)
rel-source (map (partial b/path-for namespace) ["clj" "cljc"])
:let [file (io/file source-path rel-source)]
:when (.exists ^File file)]
[rel-source file]))
(let [rel-source (b/path-for namespace)]
;; always return a source file location (#1205)
[rel-source (io/file (first (:source-paths project)) rel-source)]))]
:when source
:let [rel-compiled (.replaceFirst rel-source "\\.clj$" "__init.class")
:let [rel-compiled (.replaceFirst rel-source "\\.cljc?$" "__init.class")
compiled (io/file (:compile-path project) rel-compiled)]
:when (>= (.lastModified source) (.lastModified compiled))]
namespace))
Expand Down Expand Up @@ -68,7 +72,9 @@
(defn- source-in-project?
"Tests if a file found in the compile path exists in the source path."
[parent compile-path source-path]
(.exists (io/file (str (.replace parent compile-path source-path) ".clj"))))
(let [path (.replace parent compile-path source-path)]
(or (.exists (io/file (str path ".clj")))
(.exists (io/file (str path ".cljc"))))))

(defn- class-in-project? [project f]
(or (has-source-package? project f (:source-paths project))
Expand Down
3 changes: 2 additions & 1 deletion src/leiningen/jar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@

(defn- compile-main? [{:keys [main source-paths] :as project}]
(and main (not (:skip-aot (meta main)))
(some #(.exists (io/file % (b/path-for main))) source-paths)))
(some #(or (.exists (io/file % (b/path-for main "clj")))
(.exists (io/file % (b/path-for main "cljc")))) source-paths)))

(def ^:private implicit-aot-warning
(delay
Expand Down
2 changes: 1 addition & 1 deletion src/leiningen/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
vars))])

(defn- convert-to-ns [possible-file]
(if (and (.endsWith possible-file ".clj") (.exists (io/file possible-file)))
(if (and (re-matches #".*\.cljc?" possible-file) (.exists (io/file possible-file)))
(str (second (b/ns-form-for-file possible-file)))
possible-file))

Expand Down
8 changes: 8 additions & 0 deletions test/leiningen/test/compile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[leiningen.compile]
[leiningen.test.helper :only [sample-project delete-file-recursively
sample-failing-project
sample-reader-cond-project
tricky-name-project
more-gen-classes-project
with-system-err-str]])
Expand Down Expand Up @@ -39,6 +40,13 @@
(is (not (.exists (file "test_projects" "more-gen-classes" "target"
"classes" "more_gen_classes" "foo.class")))))

(deftest test-compile-cljc
(compile sample-reader-cond-project)
(is (.exists (file "test_projects" "sample-reader-cond" "target"
"classes" "nom" "nom" "clj__init.class")))
(is (.exists (file "test_projects" "sample-reader-cond" "target"
"classes" "nom" "nom" "cljc__init.class"))))

(def eip-check (atom false))

(deftest ^:online test-plugin
Expand Down
2 changes: 2 additions & 0 deletions test/leiningen/test/helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

(def sample-profile-meta-project (read-test-project "sample-profile-meta"))

(def sample-reader-cond-project (read-test-project "sample-reader-cond"))

(def tricky-name-project (read-test-project "tricky-name"))

(def native-project (read-test-project "native"))
Expand Down
7 changes: 6 additions & 1 deletion test/leiningen/test/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(:require [clojure.test :refer :all]
[leiningen.test :refer :all]
[leiningen.test.helper :refer [tmp-dir sample-no-aot-project
sample-reader-cond-project
sample-failing-project
with-system-err-str]]
[clojure.java.io :as io]
Expand Down Expand Up @@ -68,6 +69,10 @@
(test sample-no-aot-project "selectors")
(is (= (ran?) #{:regular :not-custom :int2 :fixture})))

(deftest test-reader-conditional-tests
(test sample-reader-cond-project)
(is (= (ran?) #{:clj-test :cljc-test})))

(deftest test-invalid-namespace-argument
(is (.contains
(with-system-err-str
Expand All @@ -87,7 +92,7 @@
(let [project (project/merge-profiles sample-failing-project
[{:aot ^:replace []
:dependencies ^:replace
[['org.clojure/clojure "1.6.0"]]}])]
[['org.clojure/clojure "1.7.0"]]}])]
(binding [main/*exit-process?* false]
(is (= "EOF while reading" (try (test project) false
(catch Exception e
Expand Down
4 changes: 2 additions & 2 deletions test/leiningen/test/update_in.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
":repl-options:port" "inc" "--" "repl" ":headless"]
["repl" (prj-map {:repl-options {:port 2}}) ":headless"]

[(prj-map {:dependencies [['clojure.core "1.6.0"]]})
[(prj-map {:dependencies [['clojure.core "1.7.0"]]})
":dependencies" "conj" "[slamhound \"1.1.3\"]" "--" "repl"]
["repl" (prj-map {:dependencies [['clojure.core "1.6.0"]
["repl" (prj-map {:dependencies [['clojure.core "1.7.0"]
['slamhound "1.1.3"]]})]]
(partition 2))]
(let [[in-prj key-path f & args] in-args
Expand Down
2 changes: 1 addition & 1 deletion test_projects/bad-require/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]]
:dependencies [[org.clojure/clojure "1.7.0"]]
:main bad-require.core)
2 changes: 1 addition & 1 deletion test_projects/file-not-found-thrower/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]])
:dependencies [[org.clojure/clojure "1.7.0"]])
2 changes: 1 addition & 1 deletion test_projects/java-main/project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject java-main "0.1.0-SNAPSHOT"
:java-source-paths ["src/java"]
:dependencies [[org.clojure/clojure "1.6.0"]] ;; lein run errors if not there.
:dependencies [[org.clojure/clojure "1.7.0"]] ;; lein run errors if not there.
:main my.java.Main)
2 changes: 1 addition & 1 deletion test_projects/jvm-opts/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

(defproject custom/args "0.0.1-SNAPSHOT"
:description "A test project"
:dependencies [[org.clojure/clojure "1.6.0"]]
:dependencies [[org.clojure/clojure "1.7.0"]]
:profiles {:no-op {}
:ascii {:jvm-opts ["-Dfile.encoding=ASCII"]}})
2 changes: 1 addition & 1 deletion test_projects/more-gen-classes/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]])
:dependencies [[org.clojure/clojure "1.7.0"]])
10 changes: 10 additions & 0 deletions test_projects/sample-reader-cond/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; This project is used for leiningen's test suite, so don't change
;; any of these values without updating the relevant tests. If you
;; just want a basic project to work from, generate a new one with
;; "lein new".

(defproject nomnomnom "0.5.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.7.0"]
[janino "2.5.15"]]
:aot :all
:uberjar-exclusions [#"DUMMY"])
1 change: 1 addition & 0 deletions test_projects/sample-reader-cond/src/nom/nom/clj.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns nom.nom.clj)
1 change: 1 addition & 0 deletions test_projects/sample-reader-cond/src/nom/nom/cljc.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns nom.nom.cljc)
7 changes: 7 additions & 0 deletions test_projects/sample-reader-cond/test/clj_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns clj-test
(:use [clojure.test]
[selectors :only [record-ran]]))

(deftest clojure-test
(record-ran :clj-test)
(is true))
8 changes: 8 additions & 0 deletions test_projects/sample-reader-cond/test/cljc_test.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns cljc-test
(:use #?(:clj [clojure.test]
:cljs [cljs.test])
[selectors :only [record-ran]]))

(deftest conditional-test
(record-ran :cljc-test)
(is true))
10 changes: 10 additions & 0 deletions test_projects/sample-reader-cond/test/selectors.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns selectors
(:use [clojure.test]
[clojure.java.io]))

(defn record-ran [t]
(let [file-name (format "%s/lein-test-ran"
(System/getProperty "java.io.tmpdir"))]
(with-open [w (writer file-name :append true)]
(.write w (str t "\n")))))

2 changes: 1 addition & 1 deletion test_projects/uberjar-merging/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
;; "lein new".

(defproject nomnomnom "0.5.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
:dependencies [[org.clojure/clojure "1.7.0"]
[janino "2.5.15"]
[org.platypope/method-fn "0.1.0"]]
:uberjar-exclusions [#"DUMMY"]
Expand Down

0 comments on commit 1f43aa0

Please sign in to comment.