Get os name & arch at runtime instead of compile

...so we can override them to download pods for other OS / arch platforms
This commit is contained in:
Wes Morgan 2022-09-06 15:07:04 -06:00
parent 8c70709927
commit 917b854803
No known key found for this signature in database
GPG key ID: 5639E4CBFA17DC84

View file

@ -15,36 +15,38 @@
"x86_64"
arch))
(def os {:os/name (or (System/getenv "OS_NAME") (System/getProperty "os.name"))
:os/arch (let [arch (or (System/getenv "OS_ARCH")
(System/getProperty "os.arch"))]
(normalize-arch arch))})
(def os
(delay
{:os/name (or (System/getenv "OS_NAME") (System/getProperty "os.name"))
:os/arch (let [arch (or (System/getenv "OS_ARCH")
(System/getProperty "os.arch"))]
(normalize-arch arch))}))
(defn warn [& strs]
(binding [*out* *err*]
(apply println strs)))
(defn match-artifacts
([package] (match-artifacts package (:os/arch os)))
([package] (match-artifacts package (:os/arch @os)))
([package arch]
(let [artifacts (:pod/artifacts package)
res (filter (fn [{os-name :os/name
os-arch :os/arch}]
(let [os-arch (normalize-arch os-arch)]
(and (re-matches (re-pattern os-name) (:os/name os))
(and (re-matches (re-pattern os-name) (:os/name @os))
(re-matches (re-pattern os-arch)
arch))))
artifacts)]
(if (empty? res)
(if (and (= "Mac OS X" (:os/name os))
(= "aarch64" (:os/arch os)))
(if (and (= "Mac OS X" (:os/name @os))
(= "aarch64" (:os/arch @os)))
;; Rosetta2 fallback on Apple M1 machines
(match-artifacts package "x86_64")
(throw (IllegalArgumentException. (format "No executable found for pod %s (%s) and OS %s/%s"
(:pod/name package)
(:pod/version package)
(:os/name os)
(:os/arch os)))))
(:os/name @os)
(:os/arch @os)))))
res))))
(defn unzip [{:keys [^java.io.File zip-file