-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#!/usr/bin/env bash | ||
|
||
# toolchain-avr-gcc | ||
# | ||
# Copyright 2019-2024, Andrew Countryman <apcountryman@gmail.com> and the | ||
# toolchain-avr-gcc contributors | ||
# | ||
# 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. | ||
|
||
# Description: CI build script. | ||
|
||
function error() | ||
{ | ||
local -r message="$1" | ||
|
||
( >&2 echo "$mnemonic: $message" ) | ||
} | ||
|
||
function abort() | ||
{ | ||
if [[ "$#" -gt 0 ]]; then | ||
local -r message="$1" | ||
|
||
error "$message, aborting" | ||
fi | ||
|
||
exit 1 | ||
} | ||
|
||
function validate_script() | ||
{ | ||
if ! shellcheck "$script"; then | ||
abort | ||
fi | ||
} | ||
|
||
function display_help_text() | ||
{ | ||
printf "%b" \ | ||
"NAME\n" \ | ||
" $mnemonic - Ensure no build errors are present.\n" \ | ||
"SYNOPSIS\n" \ | ||
" $mnemonic --help\n" \ | ||
" $mnemonic --version\n" \ | ||
" $mnemonic\n" \ | ||
"OPTIONS\n" \ | ||
" --help\n" \ | ||
" Display this help text.\n" \ | ||
" --version\n" \ | ||
" Display the version of this script.\n" \ | ||
"EXAMPLES\n" \ | ||
" $mnemonic --help\n" \ | ||
" $mnemonic --version\n" \ | ||
" $mnemonic\n" \ | ||
"" | ||
} | ||
|
||
function display_version() | ||
{ | ||
echo "$mnemonic, version $version" | ||
} | ||
|
||
function ensure_no_build_errors_are_present() | ||
{ | ||
local -r toolchain_file="$repository/toolchain.cmake" | ||
local -r build_directory="$repository/build" | ||
|
||
if ! cmake -DCMAKE_TOOLCHAIN_FILE="$toolchain_file" -S "$repository" -B "$build_directory"; then | ||
abort | ||
fi | ||
|
||
if ! cmake --build "$build_directory" -j "$( nproc )"; then | ||
abort | ||
fi | ||
} | ||
|
||
function main() | ||
{ | ||
local -r script=$( readlink -f "$0" ) | ||
local -r mnemonic=$( basename "$script" ) | ||
|
||
validate_script | ||
|
||
local -r repository=$( readlink -f "$( dirname "$script" )/.." ) | ||
local -r version=$( git -C "$repository" describe --match=none --always --dirty --broken ) | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
local argument="$1"; shift | ||
|
||
case "$argument" in | ||
--help) | ||
display_help_text | ||
exit | ||
;; | ||
--version) | ||
display_version | ||
exit | ||
;; | ||
--*) | ||
;& | ||
-*) | ||
abort "'$argument' is not a supported option" | ||
;; | ||
*) | ||
abort "'$argument' is not a valid argument" | ||
;; | ||
esac | ||
done | ||
|
||
ensure_no_build_errors_are_present | ||
} | ||
|
||
main "$@" |