Skip to content

Commit

Permalink
fix(#3): make native binary working
Browse files Browse the repository at this point in the history
Fix all the things that GraalVM does not support
  • Loading branch information
krvital committed Jul 25, 2024
1 parent f3a44b6 commit 20c9227
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ generate_reflect_config:
COMPILE_OPTS := \
--no-fallback \
--features=clj_easy.graal_build_time.InitClojureClasses \
--enable-url-protocols=http,https \
-H:ReflectionConfigurationFiles=$(project_dir)/META/reflect-config.json \
-H:Name=aidbox-sdk
compile_native_image: generate_reflect_config
Expand Down
14 changes: 8 additions & 6 deletions src/aidbox_sdk/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

(set! *warn-on-reflection* true)

(defn url
(defn url?
"Safe version of as-url function"
[s]
(try
(io/as-url s)
(catch java.net.MalformedURLException _ nil)
(catch java.net.URISyntaxException _ nil)))
(let [_ (io/as-url s)]
true)
(catch java.net.MalformedURLException _ false)
(catch java.net.URISyntaxException _ false)))

(defn resource [path]
(or (url path)
(io/as-file path)))
(if (url? path)
{:type :url :source path}
{:type :file :source path}))

(defn -main [& args]
(let [[input output] args]
Expand Down
3 changes: 2 additions & 1 deletion src/aidbox_sdk/generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,11 @@
(filter #(and
(constraint? %)
(not (from-extension? %)))))]

(prepare-target-directory! output)

(println "---")
;; create base namespace (all FHIR datatypes) file
(println "---")
(println "Generating base namespace")
(->> all-schemas
(filter base-schema?)
Expand Down
26 changes: 10 additions & 16 deletions src/aidbox_sdk/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@
(assoc % :package))
schemas))

(defmulti retrieve class)
(defmulti retrieve :type)

;; ! According to an example here:
;; ! https://clojuredocs.org/clojure.java.io/file
;; ! it's possible to create a File instance from url, which may lead to bugs
(defmethod retrieve java.io.File
[source]
(defmethod retrieve :file
[{:keys [source]}]
(println "Retrieving packages from: " (str source))
(->> (get-packages-from-directory source)
(->> (get-packages-from-directory (io/as-file source))
(mapv parse-package)
(verify/check-compatibility!)
(flatten)
Expand All @@ -81,26 +78,23 @@
(try
(f)
(catch Throwable _
(Thread/sleep timeout)
(Thread/sleep ^long timeout)
(retry f {:timeout (next-timeout timeout)
:trials (dec trials)})))))

(defn fetch-n-parse [url]
(let [url-string (if (instance? java.net.URL url)
(.toString url)
url)
result (retry #(http.client/get url-string))]
(let [result (retry #(http.client/get url))]
(some-> result :body parse-json)))

(defn skip-root-package [packages]
(rest packages))

(defmethod retrieve java.net.URL
[source]
(let [extract-link (fn [package] (-> package :href io/as-url))
(defmethod retrieve :url
[{:keys [source]}]
(let [extract-link (fn [package] (-> package :href))
extract-name (fn [package] (str (:name package) "#" (:version package)))
fhir-packages (do
(println "Downloading list of dependencies from:" (.toString source))
(println "Downloading list of dependencies from:" source)
(-> (fetch-n-parse source)
(skip-root-package)))]

Expand Down

0 comments on commit 20c9227

Please sign in to comment.