From 8f9b89e0cd70c3f562544c39fd832fbeeec0e9d3 Mon Sep 17 00:00:00 2001 From: Damiano Amatruda <damiano.amatruda@skywarder.eu> Date: Mon, 8 Nov 2021 20:47:39 +0100 Subject: [PATCH] [SBS] Create wrapper script 'sbs' v3.0 It is a script implemented in sh that wraps CMake commands and uses the same args as the Python script for SBS v2.0 (except '--all-test', '--all-entrypoint' and '--no-colors' that are no longer needed). This allows to continue calling `./sbs` without knowing the underlying build system technology. --- sbs | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100755 sbs diff --git a/sbs b/sbs new file mode 100755 index 000000000..f02005aca --- /dev/null +++ b/sbs @@ -0,0 +1,124 @@ +#!/bin/sh + +# Copyright (c) 2021 Skyward Experimental Rocketry +# Authors: Damiano Amatruda +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +print_banner() { + cat <<EOF ++---------------------------------------------------------------+ +| ____ _ _ | +| / ___|| | ___ ___ ____ _ _ __ __| | | +| \\___ \\| |/ / | | \\ \\ /\\ / / _\` | '__/ _\` | | +| ___) | <| |_| |\\ V V / (_| | | | (_| | | +| |____/|_|\\_\\\\__, | \\_/\\_/ \\__,_|_| \\__,_| | +| ____ |___/ _ ____ _ | +| | __ ) _ _(_) | __| | / ___| _ _ ___| |_ ___ _ __ ___ | +| | _ \\| | | | | |/ _\` | \\___ \\| | | / __| __/ _ \\ '_ \` _ \\ | +| | |_) | |_| | | | (_| | ___) | |_| \\__ \\ || __/ | | | | | | +| |____/ \\__,_|_|_|\\__,_| |____/ \\__, |___/\\__\\___|_| |_| |_| | ++----------------------------------|___/-------------------v3.0-+ + +EOF +} + +configure() { + mkdir -p "$build_dir" && \ + cd "$build_dir" && \ + cmake \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_TOOLCHAIN_FILE="$sbs_base/libs/miosix-kernel/miosix/_tools/toolchain.cmake" \ + -GNinja \ + $config_verbose \ + "$source_dir" && \ + cd "$source_dir" +} + +clean() { [ -d "$build_dir" ] && cmake --build "$build_dir" $build_jobs --target clean; rm -rf "$build_dir"; } + +build_all() { check_configured && cmake --build "$build_dir" $build_jobs; } + +build() { check_configured && cmake --build "$build_dir" $build_jobs --target "$1"; } + +list() { check_configured && echo "All SBS targets available:" && \ + cmake --build "$build_dir" $build_jobs --target help | grep -o '^[^/]*\.bin' | cut -f 1 -d '.'; } + +lint() { "$sbs_base/scripts/linter.sh" "$source_dir/src/shared"; } + +check_configured() { ([ ! -d "$build_dir" ] || [ ! -f "$build_dir/CMakeCache.txt" ] && rm -rf "$build_dir") && configure && echo || true; } + +set_verbose() { config_verbose="-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"; } + +set_jobs() { build_jobs="-j $1"; } + +usage() { + cat <<EOF +Usage: $(basename "$0") [OPTIONS] + +OPTIONS: + -h, --help Show this help message and exit + -c, --clean Clean the working tree + -b TARGET, --build TARGET + Build a specific target + -l, --list List all possible configurations + -v, --verbose Print a verbose output + -n, --lint Run the linter + -j JOBS, --jobs JOBS Build in parallel using the given number of jobs +EOF +} + +print_banner + +sbs_base="$(cd -- "$(dirname "$0")" > /dev/null 2>&1; pwd -P)" +source_dir="$PWD" +build_dir="$source_dir/build" +config_verbose= +build_jobs= + +for arg in "$@"; do + shift + case "$arg" in + --help) set -- "$@" "-h";; + --clean) set -- "$@" "-c";; + --build) set -- "$@" "-b";; + --list) set -- "$@" "-l";; + --verbose) set -- "$@" "-v";; + --lint) set -- "$@" "-n";; + --jobs) set -- "$@" "-j";; + *) set -- "$@" "$arg" + esac +done + +while getopts hcb:lvnj: opt; do + case "$opt" in + h) usage; exit 0;; + c) clean; exit 0;; + b) build "$OPTARG"; exit 0;; + l) list; exit 0;; + v) set_verbose;; + n) lint; exit 0;; + j) set_jobs "$OPTARG";; + ?) usage; exit 2;; + esac +done +shift $((OPTIND - 1)) + +build_all -- GitLab