diff --git a/Dockerfile.test b/Dockerfile.test index ba856a6..d6b1a49 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -1,28 +1,12 @@ -ARG IMG=chibi -FROM docker.io/schemers/${IMG} -RUN apt-get update && apt-get install -y \ - build-essential git wget ca-certificates guile-3.0 guile-3.0-dev libcurl4 \ - xz-utils - -WORKDIR /build -RUN wget https://gitlab.com/-/project/6808260/uploads/094ce726ce3c6cf8c14560f1e31aaea0/akku-1.1.0.amd64-linux.tar.xz && tar -xf akku-1.1.0.amd64-linux.tar.xz -RUN git clone https://github.com/ashinn/chibi-scheme.git --depth=1 - -WORKDIR /build/akku-1.1.0.amd64-linux -RUN ./install.sh - -WORKDIR /build/chibi-scheme -RUN make -RUN make install - -WORKDIR /workdir -RUN mkdir -p ${HOME}/.snow && echo "()" > ${HOME}/.snow/config.scm -ENV PATH=/root/.local/bin:${PATH} -ENV LD_LIBRARY_PATH=/root/.local/lib +ARG SCHEME=chibi +FROM docker.io/schemers/${SCHEME}:head +ARG SCHEME=chibi +ENV SCHEME=${SCHEME} +ARG RNRS=r7rs +ENV RNRS=${RNRS} +RUN apt-get update && apt-get install -y gcc curl make git COPY Makefile . -COPY test.scm . COPY test.sps . -COPY compile-test.scm . -COPY compile-test.sps . +COPY test.scm . COPY scheme-venv . -ENV SCHEME_VENV_DEBUG=true +RUN ./scheme-venv ${SCHEME} ${RNRS} testvenv diff --git a/Jenkinsfile b/Jenkinsfile index e21b7c3..3f7ae26 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,7 +29,7 @@ pipeline { params.R6RS_SCHEMES.split().each { SCHEME -> stage("${SCHEME}") { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { - sh "make SCHEME=${SCHEME} test-r6rs-script-docker | grep 'scheme-venv-script-test-success-Hello' || exit 1" + sh "make SCHEME=${SCHEME} RNRS=r6rs test-script-docker | grep 'scheme-venv-script-test-success-Hello' || exit 1" } } } @@ -42,7 +42,7 @@ pipeline { params.R6RS_SCHEMES.split().each { SCHEME -> stage("${SCHEME}") { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { - sh "make SCHEME=${SCHEME} test-r6rs-compile-docker | grep 'scheme-venv-compile-test-success-Hello' || exit 1" + sh "make SCHEME=${SCHEME} RNRS=r6rs test-compile-docker | grep 'scheme-venv-compile-test-success-Hello' || exit 1" } } } @@ -55,7 +55,7 @@ pipeline { params.R7RS_SCHEMES.split().each { SCHEME -> stage("${SCHEME}") { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { - sh "make SCHEME=${SCHEME} test-r7rs-script-docker | grep 'scheme-venv-script-test-success-Hello' || exit 1" + sh "make SCHEME=${SCHEME} RNRS=r7rs test-script-docker | grep 'scheme-venv-script-test-success-Hello' || exit 1" } } } @@ -68,7 +68,7 @@ pipeline { params.R7RS_SCHEMES.split().each { SCHEME -> stage("${SCHEME}") { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { - sh "make SCHEME=${SCHEME} test-r7rs-compile-docker | grep 'scheme-venv-compile-test-success-Hello' || exit 1" + sh "make SCHEME=${SCHEME} RNRS=r7rs test-compile-docker | grep 'scheme-venv-compile-test-success-Hello' || exit 1" } } } diff --git a/Makefile b/Makefile index 13dda73..b8b8235 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ PREFIX=/usr/local SCHEME=chibi +RNRS=r7rs DOCKER_IMG=scheme-venv-test-${SCHEME} all: build @@ -7,50 +8,29 @@ all: build build: @echo "No build step, just install" -test-r6rs-script: - @echo "Starting test Scheme: ${SCHEME}, RNRS: R6RS" - @rm -rf testvenv/ \ - && ./scheme-venv ${SCHEME} r6rs testvenv \ - && ./testvenv/bin/akku install chez-srfi \ - && ./testvenv/bin/scheme-script test.sps +testvenv: + ./scheme-venv ${SCHEME} ${RNRS} testvenv -test-r6rs-compile: - @echo "Starting test Scheme: ${SCHEME}, RNRS: R6RS" - @rm -rf testvenv/ \ - && ./scheme-venv ${SCHEME} r6rs testvenv \ - && ./testvenv/bin/akku install chez-srfi \ - && ./testvenv/bin/scheme-compile compile-test.sps \ - && ./compile-test +test-script: testvenv + @if [ "${RNRS}" = "r6rs" ]; then ./testvenv/bin/akku install chez-srfi; fi + @if [ "${RNRS}" = "r6rs" ]; then ./testvenv/bin/scheme-script test.sps; fi + @if [ "${RNRS}" = "r7rs" ]; then ./testvenv/bin/snow-chibi install --always-yes retropikzel.hello; fi + @if [ "${RNRS}" = "r7rs" ]; then ./testvenv/bin/scheme-script test.scm; fi -test-r7rs-script: - @echo "Starting test Scheme: ${SCHEME}, RNRS: R7RS" - @rm -rf testvenv/ \ - && ./scheme-venv ${SCHEME} r7rs testvenv \ - && ./testvenv/bin/snow-chibi install --always-yes retropikzel.hello \ - && ./testvenv/bin/scheme-script test.scm - -test-r7rs-compile: - @echo "Starting test Scheme: ${SCHEME}, RNRS: R7RS" - @rm -rf testvenv/ \ - && ./scheme-venv ${SCHEME} r7rs testvenv \ - && ./testvenv/bin/snow-chibi install --always-yes retropikzel.hello \ - && ./testvenv/bin/scheme-compile compile-test.scm \ - && ./compile-test +test-compile: testvenv + @if [ "${RNRS}" = "r6rs" ]; then ./testvenv/bin/akku install chez-srfi; fi + @if [ "${RNRS}" = "r6rs" ]; then ./testvenv/bin/scheme-compile test.sps && ./test; fi + @if [ "${RNRS}" = "r7rs" ]; then ./testvenv/bin/snow-chibi install --always-yes retropikzel.hello; fi + @if [ "${RNRS}" = "r7rs" ]; then ./testvenv/bin/scheme-compile test.scm && ./test; fi build-test-docker-image: - docker build --build-arg IMG=${SCHEME}:head -f Dockerfile.test --tag=${DOCKER_IMG} . + docker build --build-arg SCHEME=${SCHEME} --build-arg RNRS=${RNRS} -f Dockerfile.test --tag=${DOCKER_IMG} . -test-r6rs-script-docker: build-test-docker-image - @docker run ${DOCKER_IMG} bash -c "make SCHEME=${SCHEME} test-r6rs-script" +test-script-docker: build-test-docker-image + docker run ${DOCKER_IMG} bash -c "make SCHEME=${SCHEME} RNRS=${RNRS} test-script" -test-r6rs-compile-docker: build-test-docker-image - @docker run ${DOCKER_IMG} bash -c "make SCHEME=${SCHEME} test-r6rs-compile" - -test-r7rs-script-docker: build-test-docker-image - @docker run ${DOCKER_IMG} bash -c "make SCHEME=${SCHEME} test-r7rs-script" - -test-r7rs-compile-docker: build-test-docker-image - @docker run ${DOCKER_IMG} bash -c "make SCHEME=${SCHEME} test-r7rs-compile" +test-compile-docker: build-test-docker-image testvenv + @docker run ${DOCKER_IMG} bash -c "make SCHEME=${SCHEME} RNRS=${RNRS} test-compile" install: @mkdir -p ${PREFIX}/bin @@ -58,3 +38,6 @@ install: uninstall: @-rm ${PREFIX}/bin/scheme-venv + +clean: + rm -rf testvenv diff --git a/compile-test.scm b/compile-test.scm deleted file mode 100644 index 52e868b..0000000 --- a/compile-test.scm +++ /dev/null @@ -1,8 +0,0 @@ -(import (scheme base) - (scheme write) - (scheme process-context) - (retropikzel hello)) - -(display "scheme-venv-compile-test-success-") -(hello) -(exit 0) diff --git a/compile-test.sps b/compile-test.sps deleted file mode 100644 index 1681dcb..0000000 --- a/compile-test.sps +++ /dev/null @@ -1,6 +0,0 @@ -(import (rnrs) - (srfi :64)) - -(display "scheme-venv-compile-test-success-Hello") -(newline) -(exit 0) diff --git a/scheme-venv b/scheme-venv index b24e6d3..ffb3ef6 100755 --- a/scheme-venv +++ b/scheme-venv @@ -1,7 +1,8 @@ #!/bin/sh - # vi: ft=bash +set -eu + stringContain() { case $2 in *$1* ) return 0;; *) return 1;; esac ;} supported_rnrs="r6rs r7rs" @@ -52,12 +53,15 @@ fi implementation="${1}" rnrs="${2}" venvpath=$(realpath "${3}") -schemebinpath="${venvpath}/bin/scheme" +downloadpath="${venvpath}/downloads" +toolinstallprefix="${venvpath}/tools" scheme_compile_cmd="" scheme_cmd="" scheme_script_cmd="" scheme_type="interpreter" +echo "scheme-venv version 1.0.0, scheme: ${implementation}, rnrs: ${rnrs}" + ## Create venv directories mkdir "${venvpath}" mkdir "${venvpath}/bin" @@ -69,64 +73,9 @@ case "${implementation}" in "gambit") scheme_type=compiler ;; esac -## bin/snow-chibi -if [ "${rnrs}" = "r6rs" ]; then -{ -cat << EOF -#!/bin/sh -echo "if [ ! \"\${SCHEME_VENV_DEBUG}\" = \"\" ]; then set -x; fi" -if [ "\${1}" = "install" ]; then - shift - PATH="${PATH}" $(which snow-chibi) install \ - --impls=generic \ - --install-source-dir=${venvpath}/lib \ - --install-library-dir=${venvpath}/lib \ - --install-data-dir=${venvpath}/lib \ - --install-binary-dir=${venvpath}/bin \ - "\$@" -else - snow-chibi "\$@" -fi -EOF -} > "${venvpath}/bin/snow-chibi" -chmod +x "${venvpath}/bin/snow-chibi" -else -{ -cat << EOF -#!/bin/sh -echo "if [ ! \"\${SCHEME_VENV_DEBUG}\" = \"\" ]; then set -x; fi" -if [ "\${1}" = "install" ]; then - shift - PATH="${PATH}" $(which snow-chibi) install \ - --impls=${implementation} \ - --install-source-dir=${venvpath}/lib \ - --install-library-dir=${venvpath}/lib \ - --install-data-dir=${venvpath}/lib \ - "\$@" -else - snow-chibi "\$@" -fi -EOF -} > "${venvpath}/bin/snow-chibi" -chmod +x "${venvpath}/bin/snow-chibi" -fi - -## bin/akku -{ -cat << EOF -#!/bin/sh -echo "if [ ! \"\${SCHEME_VENV_DEBUG}\" = \"\" ]; then set -x; fi" -cd "${venvpath}/lib" -$(which akku) update -$(which akku) "\$@" -EOF -} > "${venvpath}/bin/akku" -chmod +x "${venvpath}/bin/akku" - ## bin/activate { cat << EOF -echo "if [ ! \"\${SCHEME_VENV_DEBUG}\" = \"\" ]; then set -x; fi" deactivate () { unset SCHEME unset COMPILE_R7RS @@ -264,8 +213,8 @@ else scheme_cmd="meevax -I \"${venvpath}/lib\" \"\${IF}\"" ;; "mit-scheme") - #scheme_cmd="mit-scheme --prepend-library \"${venvpath}/lib/\" --batch-mode --load \"\${IF}\" --eval \"(exit 0)\" --args" - scheme_cmd="echo \"MIT-scheme script not supported\" && exit 1" + scheme_cmd="mit-scheme --prepend-library=\"${venvpath}/lib/\" --batch-mode --load \"\${IF}\" --eval \"(exit 0)\" --args" + #scheme_cmd="echo \"MIT-scheme script not supported\" && exit 1" scheme_compile_cmd="echo \"MIT-scheme compile not supported\" && exit 1" ;; "mosh") @@ -300,7 +249,6 @@ fi ## bin/scheme-script { echo "#!/bin/sh" - echo "if [ ! \"\${SCHEME_VENV_DEBUG}\" = \"\" ]; then set -x; fi" echo "if [ \"\${1}\" = \"\" ]; then echo 'scheme-venv (${implementation} ${rnrs}) Give script file as argument' && exit 1; fi" echo "if [ \"\${1}\" = \"--help\" ]; then echo 'scheme-venv (${implementation} ${rnrs}) Give script file as argument' && exit 1; fi" echo "IF=\"\${1}\"" @@ -313,9 +261,9 @@ chmod +x "${venvpath}/bin/scheme-script" if [ "${scheme_type}" = "interpreter" ]; then { echo "#!/bin/sh" - echo "if [ ! \"\${SCHEME_VENV_DEBUG}\" = \"\" ]; then set -x; fi" echo "IF=\"\$(realpath \"\${1}\")\"" - echo "if [ "${rnrs}" = "r6rs" ]; then OF=\"\${IF%.sps}\"; else OF=\"\${IF%.scm}\"; fi" + echo "if [ \"${rnrs}\" = \"r6rs\" ]; then OF=\"\${IF%.sps}\"; else OF=\"\${IF%.scm}\"; fi" + # shellcheck disable=SC2028 echo "printf \"\n#|\nexec ${venvpath}/bin/scheme-script \\\"\\\${0}\\\" \\\"\\\$@\\\"\n|#\n\" > \"\${OF}\"" echo "cat \"\${IF}\" >> \"\${OF}\"" echo "chmod +x \"\${OF}\"" @@ -324,12 +272,88 @@ if [ "${scheme_type}" = "interpreter" ]; then else { echo "#!/bin/sh" - echo "if [ ! \"\${SCHEME_VENV_DEBUG}\" = \"\" ]; then set -x; fi" echo "IF=\$(realpath \"\${1}\")" - echo "if [ "${rnrs}" = "r6rs" ]; then OF=\"\${IF%.sps}\"; else OF=\"\${IF%.scm}\"; fi" + echo "if [ \"${rnrs}\" = \"r6rs\" ]; then OF=\"\${IF%.sps}\"; else OF=\"\${IF%.scm}\"; fi" echo "cd ${venvpath}/lib" echo "${scheme_compile_cmd}" } > "${venvpath}/bin/scheme-compile" chmod +x "${venvpath}/bin/scheme-compile" fi +if [ "${rnrs}" = "r6rs" ];then + sleep 0 +fi + +## Check if system has snow-chibi +if command -v snow-chibi >/dev/null 2>&1; then + echo "Found local snow-chibi at $(which snow-chibi)" + snow_chibi_path=$(which snow-chibi) + snow_chibi_prefix="" +else + echo "Did not found local snow-chibi, installing" + mkdir -p "${downloadpath}" + mkdir -p "${toolinstallprefix}" + git clone https://github.com/ashinn/chibi-scheme.git "${downloadpath}/chibi-scheme" --depth=1 + make -C "${downloadpath}/chibi-scheme" PREFIX="${toolinstallprefix}" + make -C "${downloadpath}/chibi-scheme" PREFIX="${toolinstallprefix}" install + snow_chibi_path="${toolinstallprefix}/bin/snow-chibi" + snow_chibi_prefix="LD_LIBRARY_PATH=\"${toolinstallprefix}/lib\" PATH=\"${toolinstallprefix}/bin:${PATH}\"" +fi + +## bin/snow-chibi +impls=${implementation} +if [ "${rnrs}" = "r6rs" ]; then + impls=generic +fi + +{ +cat << EOF +#!/bin/sh +if [ "\${1}" = "install" ]; then + shift + ${snow_chibi_prefix} "${snow_chibi_path}" install \ + --impls=${impls} \ + --install-source-dir=${venvpath}/lib \ + --install-library-dir=${venvpath}/lib \ + --install-data-dir=${venvpath}/lib \ + --install-binary-dir=${venvpath}/bin \ + "\$@" +else + ${snow_chibi_prefix} "${snow_chibi_path}" "\$@" +fi +EOF +} > "${venvpath}/bin/snow-chibi" +chmod +x "${venvpath}/bin/snow-chibi" + +if [ "${rnrs}" = "r6rs" ]; then +## Check if system has akku +if command -v akku >/dev/null 2>&1; then + echo "Found local akku at $(which akku)" + akku_path=$(which akku) + akku_prefix="" +else + echo "Did not found local akku, installing" + mkdir -p "${downloadpath}" + mkdir -p "${toolinstallprefix}/akku" + mkdir -p "${toolinstallprefix}/bin" + curl -o "${downloadpath}/akku.tar.xz" https://gitlab.com/-/project/6808260/uploads/094ce726ce3c6cf8c14560f1e31aaea0/akku-1.1.0.amd64-linux.tar.xz + tar -C "${toolinstallprefix}/akku" --strip-components 1 -xf "${downloadpath}/akku.tar.xz" + akku_install_path="${toolinstallprefix}/akku/lib/x86_64-linux-gnu/akku" + echo "exec \"${akku_install_path}/petite\" -b \"${akku_install_path}/petite.boot\" --program \"${akku_install_path}/akku\" \"\$@\"" > "${toolinstallprefix}/bin/akku" + chmod +x "${toolinstallprefix}/bin/akku" + akku_path="${toolinstallprefix}/bin/akku" + akku_prefix="PATH=\"${toolinstallprefix}/bin:${PATH}\"" +fi + +## bin/akku +{ +cat << EOF +#!/bin/sh +cd "${venvpath}/lib" +"${akku_prefix}" "${akku_path}" update +${akku_prefix} "${akku_path}" "\$@" +EOF +} > "${venvpath}/bin/akku" +chmod +x "${venvpath}/bin/akku" +fi +