Fork me on GitHub
#babashka
<
2023-04-20
>
mmer08:04:17

I am trying to use fs/copy with a wildcard: (fs/copy (str "./" relpath "/lifecycle/*.yml") (str "working/" relpath "/Lifecycle/ansible/scripts/") ) where relpath is a relative path to a directory. I get the error: java.nio.file.NoSuchFileException for the path: ./resources/firstres/0.4/lifecycle/*.yml . however that path exists and ls with the path works. What am I missing. Also could someone please give an example with the options set. I am confused about what they should look like - I have tried the variations in the API.md file but there are two forms and I am not sure which it should be.

borkdude08:04:00

you should first glob the files, and then copy those individually. fs/copy doesn't support globs

mmer08:04:39

Hi Borkdude, sorry I must be missing something: I get: (fs/copy (fs/glob "." (str relpath "/lifecycle/*.yml")) (str "working/" relpath "/Lifecycle/ansible/scripts/") ) ^--- No implementation of method: :as-file of protocol: #'http://clojure.java.io/Coercions found for class: clojure.lang.PersistentVector

borkdude09:04:53

(doseq [f (fs/glob ...)]
  (fs/copy f dir))

borkdude09:04:17

although I guess copy could support a vector in the future

mmer10:04:08

Could you explain the options: I see: (copy src dest {:keys [:replace-existing :copy-attributes :nofollow-links]}) and (copy-tree src dest {:keys [:replace-existing :copy-attributes :nofollow-links], :as opts}) but the second caused an error - which is the right one?

borkdude10:04:06

(copy src dest {:replace-existing true :copy-attributes true :nofollow-links true})
is how you should call this

mmer10:04:11

Thank you.

👍 2
Leah Neukirchen10:04:48

@borkdude if you have a free minute, could you look at https://github.com/graalvm/mandrel/issues/485 and see if that rings a bell? Babashka built from Mandrel seems to work fine else, not sure why it can't exec however.

Leah Neukirchen10:04:11

from a strings output, I can see that the ProcessProperties stuff is not included in our mandrel bb builds, but they exist in the upstream graalvm builds. But I'm not sure why this is the case.

Leah Neukirchen10:04:22

yes, but if you look at that java code there, mandrel supports exec

Leah Neukirchen10:04:30

i think the question is why bb doesn't pick it up?

borkdude10:04:36

@U01FQSYHRCY Perhaps they build the uberjar using non-graal and then compile using graal native image

borkdude10:04:03

you should build both the uberjar and the native image using the same Graal JDK preferably

borkdude10:04:13

(or Mandrel)

Leah Neukirchen10:04:16

export GRAALVM_HOME=/usr/lib/jvm/mandrel17
        lein deps
        script/uberjar
        script/compile

Leah Neukirchen10:04:23

that's essentially what i do

borkdude10:04:24

also export JAVA_HOME

borkdude10:04:34

and also set the PATH, might also help

Leah Neukirchen10:04:41

doesn't make a difference 😕

Leah Neukirchen10:04:50

can I check from the .jar if it's builtin already?

borkdude10:04:45

what is the exact error you're getting with exec?

Leah Neukirchen10:04:04

• 72,405 (65.64%) of 110,314 methods reachable + 72,405 (65.63%) of 110,315 methods reachable

Leah Neukirchen10:04:11

that's the only difference between the two jvm? oO

😆 2
Leah Neukirchen10:04:44

clojure.lang.ExceptionInfo: exec is not supported in non-GraalVM environments

borkdude10:04:49

if #'process/has-exec? is false, then it means that already at compile time the process thing wasn't detected

Leah Neukirchen10:04:08

let's see if i can just patch that check out

borkdude10:04:18

you can try to run this in a clj REPL with your mandrel JDK:

(def ^:private has-exec?
  (boolean (try (.getMethod ^Class
                            (resolve 'org.graalvm.nativeimage.ProcessProperties) "exec"
                            (into-array [java.nio.file.Path (Class/forName "[Ljava.lang.String;") java.util.Map]))
                (catch Exception _ false))))

borkdude10:04:24

does that return true or false?

borkdude10:04:40

and (resolve 'org.graalvm.nativeimage.ProcessProperties)?

borkdude10:04:51

or just org.graalvm.nativeimage.ProcessProperties for that matter

borkdude10:04:12

if that returns false, then that's your answer

borkdude10:04:56

perhaps you need the svm jar on your classpath for this to work

Leah Neukirchen10:04:01

but the class is in the graalvm-sdk

Leah Neukirchen10:04:52

-rw-r--r-- 0 0 0 3076 Mar 16 06:42 org/graalvm/nativeimage/ProcessProperties.class

borkdude10:04:56

why are you using mandrel again?

Leah Neukirchen10:04:55

because i couldn't compile graalvm on a musl host

Leah Neukirchen10:04:19

ok, now i fiddled it into the classpath

Leah Neukirchen10:04:28

now let's see how to make the build scripts use it

Leah Neukirchen10:04:45

so i think the problem is the uberjar classpath doesn't contain it, then it's disabled, and it doesn't help that native-image would include it because nothing uses it

borkdude10:04:10

If it helps, we could allow one extra classpath entry via an env var or so?

Leah Neukirchen10:04:59

what happened to the good old days when $CLASSPATH was simply respected. 😄

borkdude10:04:21

I don't even remember those days :)

Leah Neukirchen10:04:38

/masterdir/builddir/babashka-1.2.174/bb -e '(babashka.process/exec "ls")'

Leah Neukirchen10:04:18

i hacked it into :resource-paths

Leah Neukirchen10:04:38

80% of things i know about java are from a java 1.1 book my dad had, you know 😉

Leah Neukirchen10:04:24

i'll just patch this locally, no need for you to change things

borkdude10:04:28

I suppressed most things I knew about Java until I used Clojure ;)