# Template file for 'babashka'
pkgname=babashka
version=1.13.219
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=140ef9dcd770a54457a02fa29c3a2f643f4968d4
_sci_commit=64163c4560e085ffdcf47951b406f62f753b7f4c
_babashka_curl_commit=e936acd40544eb637b6041c7e89454b21eb7ee34
_babashka_nrepl_commit=fb44874128d8cc2622f164e6a499ed4f00e5aae9
_depstar_commit=b8b6183d2c574b628d29b1d7100e6293f906c9cb
_process_commit=43bdd65e189f2ccacc56662c53a21f5470ff1500
_pods_commit=ed5e1f3390b9dfca564f66b6e79c739c3cd82d78
_deps_clj_commit=7c70e8e04f19fc662d3653609da6929173a4981c
_fs_commit=5b273b8a943a622593fbc85fca6761c5a39d6d66
_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="8112d5466ef104083b96b2e82d0a7bf08119c023fbfa1f412369f45784f3a3e0
 693f6948c2da477756ff21bf041ada6e6919b713f1c510357f81f13141a773ee
 6e60865ae2d4522c3de55b3b1daed51b42bb9bb6095b1d2fbd3620facece3257
 683f82e7615bb218b74c900e0d309bde04e181dcb6632a9a5ec80d43a1549b34
 83b44490ac11cee1f1dca8bf06c6bf63477c230d62a42320011329c3da91b989
 93839befc9abb1a4394858612e482f3a16dfa2e6cd3bcfaeddfeefc8e550f8cd
 9ebb707bfb9f6ef5177c838223c3b1860aaee9805e8ecc4789ab9b484927d6ed
 9b42a97bbbf0363d158632a0635c20454b6219a3165ccaeacd19c2f0ccbf468b
 aeec595268a19c3098d148c9f94bbf4ccc7d73785b0d8d9d8303f83dadb99a3d
 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

	vsed -i -e '/SharedArenaSupport/d' script/compile
}

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
}
