diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7b8c8debc..dc8c8f2e1 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,7 +1,8 @@ FROM ubuntu:24.04 AS spython-base RUN export DEBIAN_FRONTEND=noninteractive RUN apt-get update -RUN apt-get install -y --no-install-recommends git +RUN apt-get install -y --no-install-recommends git gh +RUN apt-get install -y --no-install-recommends less RUN apt-get install -y --no-install-recommends python3 RUN apt-get install -y --no-install-recommends python3.12-venv python3-pip RUN apt-get install -y --no-install-recommends build-essential diff --git a/bin/.container-tag b/bin/.container-tag index 2f4536184..be5863417 100644 --- a/bin/.container-tag +++ b/bin/.container-tag @@ -1 +1 @@ -0.2 \ No newline at end of file +0.3 diff --git a/bin/bash b/bin/bash new file mode 100755 index 000000000..3b0899f26 --- /dev/null +++ b/bin/bash @@ -0,0 +1,6 @@ +#!/bin/bash + +ROOT=$(dirname $(realpath $BASH_SOURCE[0])) +source $ROOT/setup + +$BASH "$@" diff --git a/bin/node b/bin/node index 2481feadb..64063b5d9 100755 --- a/bin/node +++ b/bin/node @@ -3,4 +3,4 @@ ROOT=$(dirname $(realpath $BASH_SOURCE[0])) source $ROOT/setup -$NODE "$@" \ No newline at end of file +$NODE "$@" diff --git a/bin/npx b/bin/npx index 643237ba9..68138f347 100755 --- a/bin/npx +++ b/bin/npx @@ -3,4 +3,4 @@ ROOT=$(dirname $(realpath $BASH_SOURCE[0])) source $ROOT/setup -$NPX "$@" \ No newline at end of file +$NPX "$@" diff --git a/bin/pip b/bin/pip new file mode 100755 index 000000000..fb39a98d5 --- /dev/null +++ b/bin/pip @@ -0,0 +1,10 @@ +#!/bin/bash + +ROOT=$(dirname $(realpath $BASH_SOURCE[0])) +source $ROOT/setup + +if [ ! -v VIRTUAL_ENV ]; then + source ${ROOT}/.home/.venv/bin/activate +fi + +$PIP "$@" diff --git a/bin/pre-commit b/bin/pre-commit new file mode 100755 index 000000000..b7b56416c --- /dev/null +++ b/bin/pre-commit @@ -0,0 +1,6 @@ +#!/bin/bash + +ROOT=$(dirname $(dirname $(realpath $BASH_SOURCE[0]))) + +${ROOT}/bin/bash -c "source ${ROOT}/.home/.venv/bin/activate && pre-commit $@" + diff --git a/bin/python b/bin/python new file mode 100755 index 000000000..db423ddc5 --- /dev/null +++ b/bin/python @@ -0,0 +1,6 @@ +#!/bin/bash + +ROOT=$(dirname $(realpath $BASH_SOURCE[0])) +source $ROOT/setup + +$PYTHON "$@" diff --git a/bin/ruby b/bin/ruby index c57a0e523..669e2add7 100755 --- a/bin/ruby +++ b/bin/ruby @@ -3,4 +3,4 @@ ROOT=$(dirname $(realpath $BASH_SOURCE[0])) source $ROOT/setup -$RUBY "$@" \ No newline at end of file +$RUBY "$@" diff --git a/bin/setup b/bin/setup index d5d652458..2ec418816 100755 --- a/bin/setup +++ b/bin/setup @@ -25,70 +25,83 @@ if [ -f $ROOT/.git ]; then HOME_OPT="${HOME_OPT} --bind ${GIT_PATH}:${GIT_PATH}" fi +if [ -v DEVCONTAINER_ENV ]; then + RUN="" +else + RUN="singularity run ${HOME_OPT} ${CONTAINER_PATH} " +fi + if [ ! -d $ROOT/.home ]; then mkdir $ROOT/.home fi -if [ ! -f ${CONTAINER_PATH} ]; then - echo "Fetching container..." - if [ ! -d "${ROOT}/.singularity" ]; then - mkdir -p ${ROOT}/.singularity +if [ ! -v DEVCONTAINER_ENV ]; then + if [ ! -f ${CONTAINER_PATH} ]; then + echo "Fetching container..." + if [ ! -d "${ROOT}/.singularity" ]; then + mkdir -p ${ROOT}/.singularity + fi + singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG fi - singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG fi if [ ! -f $ROOT/.bundle/config ]; then OLDDIR=$PWD cd $ROOT - singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle config set --local path ${ROOT}/.home/.gems - singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle config set --local cache_path ${ROOT}/.home/.cache + ${RUN} bundle config set --local path ${ROOT}/.home/.gems + ${RUN} bundle config set --local cache_path ${ROOT}/.home/.cache cd $OLDDIR fi if [ ! -d $ROOT/.home/.gems ]; then OLDDIR=$PWD cd $ROOT - singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle install + ${RUN} bundle install cd $OLDDIR fi -if [ ! -f $ROOT/ext/riscv-opcodes/README.md ]; then - git submodule update --init ext/riscv-opcodes +if [ ! -d $ROOT/.home/.venv ]; then + ${RUN} /usr/bin/python3 -m venv ${ROOT}/.home/.venv +fi +source ${ROOT}/.home/.venv/bin/activate +if [ ! -f ${ROOT}/.home/.venv/bin/pre-commit ]; then + ${RUN} ${ROOT}/.home/.venv/bin/pip install -r requirements.txt fi +# if [ ! -f $ROOT/ext/riscv-opcodes/README.md ]; then +# git submodule update --init ext/riscv-opcodes +# fi + if [[ ! -z "$DEVELOPMENT" && $DEVELOPMENT -eq 1 ]]; then if [ ! -d "${ROOT}/.home/.yard/gem_index"]; then - singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri - singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec --gemfile ${ROOT}/Gemfile yard gems + ${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri + ${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard gems touch ${ROOT}/.stamps/dev_gems fi fi -if [[ ! -z "$VSCODE" && $VSCODE -eq 1 ]]; then - declare -a exts=( - castwide.solargraph, - redhat.vscode-yaml, - onnovalkering.vscode-singularity, - asciidoctor.asciidoctor-vscode - ) - for ext in "${exts[@]}"; do - ignore=`code --list-extensions | grep "${ext}"` - if [ $? -eq 1 ]; then - echo "Installing VS Code extension ${ext}" - code --install-extension ${ext} - else - echo "Extension ${ext} already installed" - fi - done -fi - if [ ! -d ${ROOT}/node_modules ]; then - singularity run ${HOME_OPT} ${CONTAINER_PATH} npm i + ${RUN} npm i fi -BUNDLE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle" -RUBY="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby" -RAKE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake" -NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm" -NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx" -NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node" +if [ -v DEVCONTAINER_ENV ]; then + BUNDLE="bundle" + RUBY="bundle exec ruby" + RAKE="bundle exec rake" + NPM="npm" + NPX="npx" + NODE="node" + PYTHON="python3" + PIP="${ROOT}/.home/.venv/bin/pip" + BASH="bash" +else + BUNDLE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle" + RUBY="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby" + RAKE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake" + NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm" + NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx" + NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node" + PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} python3" + PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/pip" + BASH="singularity run ${HOME_OPT} ${CONTAINER_PATH} bash" +fi diff --git a/container.def b/container.def index a803345c6..534320d65 100644 --- a/container.def +++ b/container.def @@ -7,11 +7,14 @@ From: ubuntu:24.04 # package.json $HOME/ %post - export DEBIAN_FRONTEND=noninteractive + export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install -y --no-install-recommends git + apt-get install -y --no-install-recommends gh + + apt-get install -y --no-install-recommends less apt-get install -y --no-install-recommends python3 apt-get install -y --no-install-recommends python3.12-venv python3-pip @@ -34,4 +37,3 @@ From: ubuntu:24.04 # npm i wavedrom-cli # npm i i -E @antora/cli@3.1 @antora/site-generator@3.1 @antora/lunr-extension asciidoctor-kroki - diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..2d2633076 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pre_commit==4.0.1 +PyYAML==6.0.2