# Template file for 'babashka'
pkgname=babashka
version=1.12.218
revision=1
create_wrksrc=yes
hostmakedepends="mandrel leiningen git"
makedepends="zlib-devel"
checkdepends="clojure curl tar"
short_desc="Native, fast starting Clojure interpreter for scripting"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="EPL-1.0"
homepage="https://babashka.org/"
changelog="https://github.com/babashka/babashka/raw/master/CHANGELOG.md"
_babashka_sha=0fb349c414e717800be775ba9cb77c95a9eb700d
_sci_commit=77c7827394bbb0cd39a24d9cf9b903daaf473c07
_babashka_curl_commit=e936acd40544eb637b6041c7e89454b21eb7ee34
_babashka_nrepl_commit=305aad17df4d8e9a473862540d56d24665eebb24
_depstar_commit=b8b6183d2c574b628d29b1d7100e6293f906c9cb
_process_commit=16a84e0af0da51b8c84e289970f6b7cc35b35d18
_pods_commit=ed5e1f3390b9dfca564f66b6e79c739c3cd82d78
_deps_clj_commit=7bf2a869a70fc6dd7aaf722465cff19e7b368753
_fs_commit=3fdcbcb8de6af0c880a0082700a295c55ffd2ecd
_babashka_core_commit=52a6037bd4b632bffffb04394fb4efd0cdab6b1e
distfiles="https://github.com/babashka/babashka/archive/refs/tags/v${version}.tar.gz
 https://github.com/borkdude/sci/archive/${_sci_commit}.tar.gz
 https://github.com/babashka/babashka.curl/archive/${_babashka_curl_commit}.tar.gz
 https://github.com/babashka/babashka.nrepl/archive/${_babashka_nrepl_commit}.tar.gz
 https://github.com/babashka/depstar/archive/${_depstar_commit}.tar.gz
 https://github.com/babashka/process/archive/${_process_commit}.tar.gz
 https://github.com/babashka/pods/archive/${_pods_commit}.tar.gz
 https://github.com/borkdude/deps.clj/archive/${_deps_clj_commit}.tar.gz
 https://github.com/babashka/fs/archive/${_fs_commit}.tar.gz
 https://github.com/babashka/babashka.core/archive/${_babashka_core_commit}.tar.gz"
checksum="19ccacb340d5244585957a4b274e82881b99065dfcf8ea8227b8024c2983087f
 b11e7d1e8c1fe254e179029de0c981e6009eb3d33fb8ab0f027682774d3183ae
 6e60865ae2d4522c3de55b3b1daed51b42bb9bb6095b1d2fbd3620facece3257
 e587e70508c25cef4df4a84ae43bc0dd0e8f140eb569ac6572cc3bc5d5c446f5
 83b44490ac11cee1f1dca8bf06c6bf63477c230d62a42320011329c3da91b989
 892527beda30b97ba05b64d44615ab087908e8f100b46a48df8e7100f1b315cc
 9ebb707bfb9f6ef5177c838223c3b1860aaee9805e8ecc4789ab9b484927d6ed
 69c52a274c4945ca469f2eb1ac04eaf86032dc9a75f8a1e702eaaf410414f567
 ce1de7fb26bb2c6fb8df948a10b4b3406b1543ba21fb9c7814e7f0c94486f26a
 bad285812bcc7de7e0dd905c5df99045d7f92d6e2e191fc2768c06adbaaeb709"

nocross="https://build.voidlinux.org/builders/aarch64_builder/builds/33769/steps/shell_3/logs/stdio"

post_extract() {
	mv babashka-$version/* babashka-$version/.??* .
	rmdir babashka-$version
	for dir in sci babashka.core babashka.curl babashka.nrepl \
		depstar process pods deps.clj fs
	do
		rmdir $dir
		mv "$dir"-* $dir
	done

	# Mandrel doesn't have GraalVM-SDK in the default classpath,
	# but some Babashka features require it.
	vsed -i -e '/:resource-paths/s@]@ "/usr/lib/jvm/mandrel21/lib/jvmci/nativeimage.jar"]@' project.clj

	# idk why this is needed
	vsed -i -e /sun.security.ssl.SSLAlgorithmConstraints/d resources/META-INF/native-image/babashka/babashka/native-image.properties
	vsed -i -e /ForeignAPISupport/d resources/META-INF/native-image/babashka/babashka/native-image.properties
}

do_build() {
	export GRAALVM_HOME=/usr/lib/jvm/mandrel21
	export PATH=${GRAALVM_HOME}/bin:$PATH
	export BABASHKA_SHA=${_babashka_sha}
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		export BABASHKA_MUSL=true
		export BABASHKA_STATIC=true  # mandrel workaround
	fi

	lein deps
	script/uberjar
	script/compile --initialize-at-build-time=org.jsoup,org.jline

}

do_check() {
	export GRAALVM_HOME=/usr/lib/jvm/mandrel21
	export BABASHKA_TEST_ENV=native
	script/test
	script/run_lib_tests
}

do_install() {
	vbin bb
	vlicense LICENSE
}
