From 65bb0057a26122032578fc3671aebba22a0f7481 Mon Sep 17 00:00:00 2001 From: abelino Date: Sun, 18 Aug 2024 14:14:07 -0700 Subject: [PATCH] Initial commit --- .github/workflows/test.yml | 27 ++++++++++++++++++++++++ LICENSE | 13 ++++++++++++ README.md | 15 ++++++++++++++ bin/exec-env | 11 ++++++++++ bin/install | 42 ++++++++++++++++++++++++++++++++++++++ bin/latest-stable | 18 ++++++++++++++++ bin/list-all | 7 +++++++ bin/utils.bash | 17 +++++++++++++++ shims/west | 10 +++++++++ version.txt | 1 + 10 files changed, 161 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100755 bin/exec-env create mode 100755 bin/install create mode 100755 bin/latest-stable create mode 100755 bin/list-all create mode 100755 bin/utils.bash create mode 100755 shims/west create mode 100644 version.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..689d48e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: tests + +on: push + +jobs: + test: + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout asdf-zephyr plugin + uses: actions/checkout@v4 + with: + path: plugin + - name: Install asdf + uses: actions/checkout@v4 + with: + repository: asdf-vm/asdf + path: .asdf + ref: v0.14.0 + - name: Test asdf-zephyr plugin + run: | + source .asdf/asdf.sh + asdf plugin test zephyr plugin "west --version" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fc6f1a7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright 2024 Redwire Labs LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba88ab3 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# asdf-zephyr +[![Test](https://github.com/redwirelabs/asdf-zephyr/actions/workflows/test.yml/badge.svg)](https://github.com/redwirelabs/asdf-zephyr/actions/workflows/test.yml) + +An [asdf](https://asdf-vm.com) plugin for managing +[Zephyr RTOS](https://docs.zephyrproject.org/latest/) repositories. + +## Install + +**Note**: Ensure python3 and +[python3-venv](https://docs.python.org/3/library/venv.html) are installed on +your host system. + +```shell +asdf plugin add zephyr https://github.com/redwirelabs/asdf-zephyr.git +``` diff --git a/bin/exec-env b/bin/exec-env new file mode 100755 index 0000000..dea2de7 --- /dev/null +++ b/bin/exec-env @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +export ZEPHYR_VERSION=$ASDF_INSTALL_VERSION +export ZEPHYR_BASE=$ASDF_INSTALL_PATH/zephyr +export VIRTUAL_ENV=$ASDF_INSTALL_PATH/.venv + +sdk=$(asdf where zephyr-sdk) +if [ $? -eq 0 ]; then + export ZEPHYR_SDK_INSTALL_DIR=$sdk + export ZEPHYR_TOOLCHAIN_VARIANT=zephyr +fi diff --git a/bin/install b/bin/install new file mode 100755 index 0000000..2aaa3c1 --- /dev/null +++ b/bin/install @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -euo pipefail + +setup_venv() { + local destination=$1 + + python3 -m venv $destination/.venv + source $destination/.venv/bin/activate +} + +install_west() { + pip install west +} + +install_zephyr() { + local version=$1 + local destination=$2 + + west init --mr "v${version}" $destination + + pushd $destination + + west update + west zephyr-export + pip install -r zephyr/scripts/requirements.txt + + popd +} + +install_shims() { + local source=$1 + local destination=$2 + + mkdir $destination/bin/ + cp $source/shims/* $destination/bin/ +} + +setup_venv $ASDF_INSTALL_PATH +install_west +install_zephyr $ASDF_INSTALL_VERSION $ASDF_INSTALL_PATH +install_shims "${BASH_SOURCE[0]%/*/*}" $ASDF_INSTALL_PATH diff --git a/bin/latest-stable b/bin/latest-stable new file mode 100755 index 0000000..e10cc46 --- /dev/null +++ b/bin/latest-stable @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source $(dirname $0)/utils.bash + +get_latest_release() { + curl -sD - "${GH_REPO}/releases/latest" \ + | sed -n -e "s/^location: *//p" +} + +latest_url=$(get_latest_release) + +if [[ "${latest_url}" == "${GH_REPO}/releases" ]]; then + list_all_versions | tail -n1 +else + basename $latest_url | sed 's/^v//' | tr -d '[:space:]' +fi diff --git a/bin/list-all b/bin/list-all new file mode 100755 index 0000000..26e4b72 --- /dev/null +++ b/bin/list-all @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source $(dirname $0)/utils.bash + +list_all_versions diff --git a/bin/utils.bash b/bin/utils.bash new file mode 100755 index 0000000..40f6dea --- /dev/null +++ b/bin/utils.bash @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -euo pipefail + +GH_REPO="https://github.com/zephyrproject-rtos/zephyr" +TOOL_NAME="zephyr" + +list_all_versions() { + git ls-remote --tags --refs $GH_REPO \ + | grep -o 'refs/tags/.*' \ + | cut -d/ -f3- \ + | grep -v '^zephyr' \ + | grep -v '-' \ + | sed 's/^v//' \ + | sort -V \ + | xargs echo +} diff --git a/shims/west b/shims/west new file mode 100755 index 0000000..437c3ea --- /dev/null +++ b/shims/west @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +sdk=$(asdf where zephyr-sdk) +if [ $? -eq 0 ]; then + export PATH=$sdk/sysroots/x86_64-pokysdk-linux/bin:$PATH +fi + +export PATH=$VIRTUAL_ENV/bin:$PATH + +west $@ diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.1.0