Skip to content

Commit

Permalink
use an appropriate location for system profiles on windows
Browse files Browse the repository at this point in the history
move os detection into leiningen.core.utils
  • Loading branch information
djpowell committed Mar 18, 2013
1 parent d27ec33 commit 05bf3de
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
39 changes: 12 additions & 27 deletions leiningen-core/src/leiningen/core/eval.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,23 @@
[leiningen.core.utils :as utils])
(:import [com.hypirion.io Pipe ClosingPipe]))

;; # OS detection

(defn- get-by-pattern
"Gets a value from map m, but uses the keys as regex patterns, trying
to match against k instead of doing an exact match."
[m k]
(m (first (drop-while #(nil? (re-find (re-pattern %) k))
(keys m)))))

(def ^:private native-names
{"Mac OS X" :macosx "Windows" :windows "Linux" :linux
"FreeBSD" :freebsd "OpenBSD" :openbsd
"amd64" :x86_64 "x86_64" :x86_64 "x86" :x86 "i386" :x86
"arm" :arm "SunOS" :solaris "sparc" :sparc "Darwin" :macosx})

(def ^:private arch-options
{:x86 ["-d32"] :x86_64 ["-d64"]})

(defn get-os
"Returns a keyword naming the host OS."
[]
(get-by-pattern native-names (System/getProperty "os.name")))
(def ^:deprecated get-os
"Returns a keyword naming the host OS. Deprecated, use
leiningen.core.utils/get-os instead."
utils/get-os)

(defn get-arch
"Returns a keyword naming the host architecture"
[]
(get-by-pattern native-names (System/getProperty "os.arch")))
(def ^:deprecated get-arch
"Returns a keyword naming the host architecture. Deprecated, use
leiningen.core.utils/get-arch instead."
utils/get-arch)

(defn platform-nullsink []
(io/file (if (= :windows (get-os))
"NUL"
"/dev/null")))
(def ^:deprecated platform-nullsink
"Returns a file destination that will discard output. Deprecated, use
leiningen.core.utils/platform-nullsink instead."
utils/platform-nullsink)

;; # Preparing for eval-in-project

Expand Down
5 changes: 4 additions & 1 deletion leiningen-core/src/leiningen/core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@
(alter-var-root #'warn-user-profile memoize)

(defn- system-profiles []
(user/load-profiles (io/file "/etc" "leiningen")))
(let [sys-profile-dir (if (= :windows (utils/get-os))
(io/file (System/getenv "AllUsersProfile") "Leiningen")
(io/file "/etc" "leiningen"))]
(user/load-profiles sys-profile-dir)))

(defn- project-profiles [project]
(let [profiles (utils/read-file (io/file (:root project) "profiles.clj"))]
Expand Down
32 changes: 32 additions & 0 deletions leiningen-core/src/leiningen/core/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,35 @@
(require ns)))
(resolve sym))))
([ns sym] (require-resolve (symbol ns sym))))

;; # OS detection

(defn- get-by-pattern
"Gets a value from map m, but uses the keys as regex patterns, trying
to match against k instead of doing an exact match."
[m k]
(m (first (drop-while #(nil? (re-find (re-pattern %) k))
(keys m)))))

(def ^:private native-names
{"Mac OS X" :macosx "Windows" :windows "Linux" :linux
"FreeBSD" :freebsd "OpenBSD" :openbsd
"amd64" :x86_64 "x86_64" :x86_64 "x86" :x86 "i386" :x86
"arm" :arm "SunOS" :solaris "sparc" :sparc "Darwin" :macosx})

(defn get-os
"Returns a keyword naming the host OS."
[]
(get-by-pattern native-names (System/getProperty "os.name")))

(defn get-arch
"Returns a keyword naming the host architecture"
[]
(get-by-pattern native-names (System/getProperty "os.arch")))

(defn platform-nullsink
"Returns a file destination that will discard output."
[]
(io/file (if (= :windows (get-os))
"NUL"
"/dev/null")))

0 comments on commit 05bf3de

Please sign in to comment.