Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
abelino committed Aug 18, 2024
0 parents commit 65bb005
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
11 changes: 11 additions & 0 deletions bin/exec-env
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions bin/latest-stable
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail

source $(dirname $0)/utils.bash

list_all_versions
17 changes: 17 additions & 0 deletions bin/utils.bash
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions shims/west
Original file line number Diff line number Diff line change
@@ -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 $@
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0

0 comments on commit 65bb005

Please sign in to comment.