|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright (c) 2021, Lawrence Livermore National Security, LLC. Produced at |
| 4 | +# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights |
| 5 | +# reserved. See files LICENSE and NOTICE for details. |
| 6 | +# |
| 7 | +# This file is part of CEED, a collection of benchmarks, miniapps, software |
| 8 | +# libraries and APIs for efficient high-order finite element and spectral |
| 9 | +# element discretizations for exascale applications. For more information and |
| 10 | +# source code availability see http://github.com/ceed. |
| 11 | +# |
| 12 | +# The CEED research is supported by the Exascale Computing Project (17-SC-20-SC) |
| 13 | +# a collaborative effort of two U.S. Department of Energy organizations (Office |
| 14 | +# of Science and the National Nuclear Security Administration) responsible for |
| 15 | +# the planning and preparation of a capable exascale ecosystem, including |
| 16 | +# software, applications, hardware, advanced system engineering and early |
| 17 | +# testbed platforms, in support of the nation's exascale computing imperative. |
| 18 | + |
| 19 | +function main() |
| 20 | +{ |
| 21 | + cd $(dirname "$0") |
| 22 | + fms_astyle_file="fms.astylerc" |
| 23 | + if [[ ! -r "${fms_astyle_file}" ]]; then |
| 24 | + echo "FMS's astyle format file not found: '${fms_astyle_file}'. Stop." |
| 25 | + exit 21 |
| 26 | + fi |
| 27 | + |
| 28 | + find_astyle |
| 29 | + |
| 30 | + local old_IFS="${IFS}" |
| 31 | + IFS=$'\n' |
| 32 | + format_files=($(git ls-files "*.[ch]" "*.[ch]pp")) |
| 33 | + if [[ "$?" -ne 0 ]]; then |
| 34 | + echo "Error getting list of C/C++ source files from Git. Stop." |
| 35 | + exit 22 |
| 36 | + fi |
| 37 | + IFS="${old_IFS}" |
| 38 | + |
| 39 | + if ${astyle_bin} --options="${fms_astyle_file}" "${format_files[@]}" | \ |
| 40 | + grep "Formatted"; then |
| 41 | + printf "\nPlease make sure the changes are committed.\n\n" |
| 42 | + return 1 |
| 43 | + else |
| 44 | + printf "All source files are properly formatted.\n" |
| 45 | + fi |
| 46 | + return 0 |
| 47 | +} # end of function 'main' |
| 48 | + |
| 49 | +function find_astyle() |
| 50 | +{ |
| 51 | + astyle_req_version="Artistic Style Version 3.1" |
| 52 | + astyle_bin_list=("${ASTYLE_BIN:-astyle}" astyle-3.1) |
| 53 | + for astyle_bin in "${astyle_bin_list[@]}"; do |
| 54 | + if ! command -v "${astyle_bin}" > /dev/null 2>&1; then |
| 55 | + continue |
| 56 | + fi |
| 57 | + astyle_version="$("${astyle_bin}" --version)" |
| 58 | + if [[ "${astyle_version}" != "${astyle_req_version}" ]]; then |
| 59 | + continue |
| 60 | + fi |
| 61 | + return 0 |
| 62 | + done |
| 63 | + echo "Required astyle version not found: '${astyle_req_version}'." |
| 64 | + printf "Astyle commands tried:" |
| 65 | + printf " '%s'" "${astyle_bin_list[@]}" |
| 66 | + printf ".\n" |
| 67 | + exit 23 |
| 68 | +} # end of function 'find_astyle' |
| 69 | + |
| 70 | + |
| 71 | +# Invoke the 'main' function |
| 72 | +main "$@" |
0 commit comments