From b22e8dee415bc3800513ddd461e8bcd00d694759 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Wed, 30 Aug 2023 10:54:12 -0600 Subject: [PATCH] scripts: Split installing Rust to its own script Signed-off-by: Tim Crawford --- Jenkinsfile | 2 +- README.md | 4 ++-- scripts/{deps.sh => install-deps.sh} | 24 +++------------------ scripts/install-rust.sh | 31 ++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 24 deletions(-) rename scripts/{deps.sh => install-deps.sh} (80%) create mode 100755 scripts/install-rust.sh diff --git a/Jenkinsfile b/Jenkinsfile index 3f39aa2..56386df 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -72,7 +72,7 @@ pipeline { sh """#!/bin/bash # Install dependencies - #./scripts/deps.sh + #./scripts/install-deps.sh . "${HOME}/.cargo/env" # Reset diff --git a/README.md b/README.md index 1eb8ae6..bfc9d87 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ For a list of important changes please see the [changelog](./CHANGELOG.md). Dependencies can be installed with the provided script. -``` -./scripts/deps.sh +```sh +./scripts/install-deps.sh ``` If rustup was installed for the first time, it will be required to source the diff --git a/scripts/deps.sh b/scripts/install-deps.sh similarity index 80% rename from scripts/deps.sh rename to scripts/install-deps.sh index 8662518..63524f4 100755 --- a/scripts/deps.sh +++ b/scripts/install-deps.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0-only set -eE @@ -101,22 +102,8 @@ curl -sSf https://review.coreboot.org/tools/hooks/commit-msg \ -o .git/modules/coreboot/hooks/commit-msg && \ chmod +x .git/modules/coreboot/hooks/commit-msg -RUSTUP_NEW_INSTALL=0 -if which rustup &> /dev/null; then - msg "Updating rustup" - rustup self update -else - RUSTUP_NEW_INSTALL=1 - msg "Installing Rust" - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ - | sh -s -- -y --default-toolchain stable - - msg "Loading Rust environment" - source "${HOME}/.cargo/env" -fi - -msg "Installing pinned Rust toolchain and components" -rustup show +msg "Installing Rust toolchain and components" +./scripts/install-rust.sh msg "Installing EC dependencies" pushd ec @@ -129,10 +116,5 @@ make CPUS="$(nproc)" crossgcc-i386 make CPUS="$(nproc)" crossgcc-x64 popd -if [[ $RUSTUP_NEW_INSTALL = 1 ]]; then - msg "\x1B[33m>> rustup was just installed. Ensure cargo is on the PATH with:" - echo -e " source ~/.cargo/env\n" -fi - msg "\x1B[32mSuccessfully installed dependencies" echo "Ready to run ./scripts/build.sh [model]" >&2 diff --git a/scripts/install-rust.sh b/scripts/install-rust.sh new file mode 100755 index 0000000..69e49fe --- /dev/null +++ b/scripts/install-rust.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-only + +# Install Rust via rustup, along with the pinned toolchain. + +# shellcheck shell=dash +# shellcheck disable=SC1091 + +set -Ee + +RUSTUP_NEW_INSTALL=0 + +# NOTE: rustup is used to allow multiple toolchain installations. +if command -v rustup >/dev/null 2>&1; then + rustup self update +else + RUSTUP_NEW_INSTALL=1 + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ + | sh -s -- -y --default-toolchain stable + + . "${HOME}/.cargo/env" +fi + +# XXX: rustup has no command to install a toolchain from a TOML file. +# Rely on the fact that `show` will install the default toolchain. +rustup show + +if [ "$RUSTUP_NEW_INSTALL" = "1" ]; then + printf "\e[33m>> rustup was just installed. Ensure cargo is on the PATH with:\e[0m\n" + printf " source ~/.cargo/env\n\n" +fi