Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run ShellCheck on CI. #421

Merged
merged 2 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/bors.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
block_labels = ["needs-decision"]
delete_merged_branches = true
required_approvals = 1
status = ["rust-embedded.cross"]
status = ["rust-embedded.cross", "shellcheck"]
timeout_sec = 21600
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on: [pull_request, push]

name: CI

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ShellCheck
uses: azohra/shell-linter@v0.3.0
10 changes: 5 additions & 5 deletions build-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
set -x
set -euo pipefail

version="$(cargo metadata --format-version 1 | jq --raw-output '.packages[] | select(.name == "cross") | .version')"

cd docker

run() {
local dockerfile="Dockerfile.${1}"
local image_name="rustembedded/cross:${1}"
local cache_from_args=
local cache_from_args=()

if ! docker image inspect "${image_name}" &>/dev/null; then
if docker pull "${image_name}"; then
cache_from_args=(--cache-from "${image_name}")
fi
fi

docker build ${cache_from_args[@]} --pull -t "${image_name}" -f "${dockerfile}" .

local version="$(cargo metadata --format-version 1 | jq --raw-output '.packages[] | select(.name == "cross") | .version')"
docker build ${cache_from_args[@]+"${cache_from_args[@]}"} --pull -t "${image_name}" -f "${dockerfile}" .

if ! [[ "${version}" =~ alpha ]] && ! [[ "${version}" =~ dev ]]; then
local versioned_image_name="${image_name}-${version}"
docker tag "${image_name}" "${versioned_image_name}"
fi
}

if [ -z "${@:-}" ]; then
if [[ -z "${*}" ]]; then
for t in Dockerfile.*; do
run "${t##Dockerfile.}"
done
Expand Down
98 changes: 49 additions & 49 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ set -x
set -euo pipefail

function retry {
local tries=${TRIES-5}
local timeout=${TIMEOUT-1}
local tries="${TRIES-5}"
local timeout="${TIMEOUT-1}"
local try=0
local exit_code=0

while (( ${try} < ${tries} )); do
while (( try < tries )); do
if "${@}"; then
return 0
else
exit_code=$?
fi

sleep ${timeout}
sleep "${timeout}"
echo "Retrying ..." 1>&2
try=$(( try + 1 ))
timeout=$(( timeout * 2 ))
Expand All @@ -28,7 +28,7 @@ function retry {
main() {
local td=

if [ "${BRANCH-}" = master ] || [[ "${TAG-}" =~ ^v.* ]]; then
if [[ "${BRANCH-}" = master ]] || [[ "${TAG-}" =~ ^v.* ]]; then
return
fi

Expand All @@ -40,136 +40,136 @@ main() {
if (( ${STD:-0} )); then
# test `cross check`
td=$(mktemp -d)
cargo init --lib --name foo $td
pushd $td
cargo init --lib --name foo "${td}"
pushd "${td}"
echo '#![no_std]' > src/lib.rs
cross check --target $TARGET
cross check --target "${TARGET}"
popd
rm -rf $td
rm -rf "${td}"
else
# `cross build` test for targets where `std` is not available
td=$(mktemp -d)

git clone \
--depth 1 \
--recursive \
https://github.com/rust-lang-nursery/compiler-builtins $td
https://github.com/rust-lang-nursery/compiler-builtins "${td}"

pushd $td
pushd "${td}"
cat > Cross.toml <<EOF
[build]
xargo = true
EOF
retry cargo fetch
cross build --lib --target $TARGET
cross build --lib --target "${TARGET}"
popd

rm -rf $td
rm -rf "${td}"

return
fi

# `cross build` test for the other targets
if [[ "$TARGET" == *-unknown-emscripten ]]; then
if [[ "${TARGET}" == *-unknown-emscripten ]]; then
td=$(mktemp -d)

pushd $td
pushd "${td}"
cargo init --lib --name foo .
retry cargo fetch
cross build --target $TARGET
cross build --target "${TARGET}"
popd

rm -rf $td
elif [[ "$TARGET" != thumb* ]]; then
rm -rf "${td}"
elif [[ "${TARGET}" != thumb* ]]; then
td=$(mktemp -d)

pushd $td
pushd "${td}"
# test that linking works
cargo init --bin --name hello .
retry cargo fetch
cross build --target $TARGET
cross build --target "${TARGET}"
popd

rm -rf $td
rm -rf "${td}"
fi

if (( ${RUN:-0} )); then
# `cross test` test
if (( ${DYLIB:-0} )); then
td=$(mktemp -d)

pushd $td
pushd "${td}"
cargo init --lib --name foo .
cross_test --target $TARGET
cross_bench --target $TARGET
cross_test --target "${TARGET}"
cross_bench --target "${TARGET}"
popd

rm -rf $td
rm -rf "${td}"
fi

# `cross run` test
case $TARGET in
case "${TARGET}" in
thumb*-none-eabi*)
td=$(mktemp -d)

git clone \
--depth 1 \
--recursive \
https://github.com/japaric/cortest $td
https://github.com/japaric/cortest "${td}"

pushd $td
cross_run --target $TARGET --example hello --release
pushd "${td}"
cross_run --target "${TARGET}" --example hello --release
popd

rm -rf $td
rm -rf "${td}"
;;
*)
td=$(mktemp -d)

cargo init --bin --name hello $td
cargo init --bin --name hello "${td}"

pushd $td
pushd "${td}"
mkdir examples tests
echo "fn main() { println!(\"Example!\"); }" > examples/e.rs
echo "#[test] fn t() {}" > tests/t.rs
cross_run --target $TARGET
cross_run --target $TARGET --example e
cross_test --target $TARGET
cross_bench --target $TARGET
cross_run --target "${TARGET}"
cross_run --target "${TARGET}" --example e
cross_test --target "${TARGET}"
cross_bench --target "${TARGET}"
popd

rm -rf $td
rm -rf "${td}"
;;
esac

fi

# Test C++ support
if (( ${CPP:-0} )); then
td=$(mktemp -d)
td="$(mktemp -d)"

git clone --depth 1 https://github.com/japaric/hellopp $td
git clone --depth 1 https://github.com/japaric/hellopp "${td}"

pushd $td
pushd "${td}"
cargo update -p gcc
retry cargo fetch
if (( ${RUN:-0} )); then
cross_run --target $TARGET
cross_run --target "${TARGET}"
else
cross build --target $TARGET
cross build --target "${TARGET}"
fi
popd

rm -rf $td
rm -rf "${td}"
fi
}

cross_run() {
if [[ -z "${RUNNERS:-}" ]]; then
cross run "$@"
else
for runner in $RUNNERS; do
echo -e "[target.$TARGET]\nrunner = \"$runner\"" > Cross.toml
for runner in ${RUNNERS}; do
echo -e "[target.${TARGET}]\nrunner = \"${runner}\"" > Cross.toml
cross run "$@"
done
fi
Expand All @@ -179,8 +179,8 @@ cross_test() {
if [[ -z "${RUNNERS:-}" ]]; then
cross test "$@"
else
for runner in $RUNNERS; do
echo -e "[target.$TARGET]\nrunner = \"$runner\"" > Cross.toml
for runner in ${RUNNERS}; do
echo -e "[target.${TARGET}]\nrunner = \"${runner}\"" > Cross.toml
cross test "$@"
done
fi
Expand All @@ -190,8 +190,8 @@ cross_bench() {
if [[ -z "${RUNNERS:-}" ]]; then
cross bench "$@"
else
for runner in $RUNNERS; do
echo -e "[target.$TARGET]\nrunner = \"$runner\"" > Cross.toml
for runner in ${RUNNERS}; do
echo -e "[target.${TARGET}]\nrunner = \"${runner}\"" > Cross.toml
cross bench "$@"
done
fi
Expand Down
29 changes: 15 additions & 14 deletions docker/android-ndk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set -euo pipefail
NDK_URL=https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip

main() {
local arch=$1 \
api=$2
local arch="${1}" \
api="${2}"

local dependencies=(
curl
Expand All @@ -17,33 +17,34 @@ main() {

apt-get update
local purge_list=()
for dep in ${dependencies[@]}; do
if ! dpkg -L $dep; then
apt-get install --no-install-recommends --assume-yes $dep
purge_list+=( $dep )
for dep in "${dependencies[@]}"; do
if ! dpkg -L "${dep}"; then
apt-get install --assume-yes --no-install-recommends "${dep}"
purge_list+=( "${dep}" )
fi
done

td=$(mktemp -d)
local td
td="$(mktemp -d)"

pushd $td
curl -O $NDK_URL
pushd "${td}"
curl -O "${NDK_URL}"
unzip -q android-ndk-*.zip
pushd android-ndk-*
./build/tools/make_standalone_toolchain.py \
--install-dir /android-ndk \
--arch $arch \
--api $api
--arch "${arch}" \
--api "${api}"

if (( ${#purge_list[@]} )); then
apt-get purge --auto-remove -y ${purge_list[@]}
apt-get purge --assume-yes --auto-remove "${purge_list[@]}"
fi

popd
popd

rm -rf $td
rm $0
rm -rf "${td}"
rm "${0}"
}

main "${@}"
Loading