| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced |
| 4 |
# at the Lawrence Livermore National Laboratory. All Rights reserved. See files |
| 5 |
# LICENSE and NOTICE for details. LLNL-CODE-806117. |
| 6 |
# |
| 7 |
# This file is part of the MFEM library. For more information and source code |
| 8 |
# availability visit https://mfem.org. |
| 9 |
# |
| 10 |
# MFEM is free software; you can redistribute it and/or modify it under the |
| 11 |
# terms of the BSD-3 license. We welcome feedback and contributions, see file |
| 12 |
# CONTRIBUTING.md for details. |
| 13 |
|
| 14 |
option=${1:-""} |
| 15 |
|
| 16 |
if [[ "${option}" == "--help" ]]; then |
| 17 |
echo "This script runs checks on the repository." |
| 18 |
echo "It has 2 modes: with and without an option." |
| 19 |
echo "" |
| 20 |
echo "Options are used in GitHub Actions and can be:" |
| 21 |
echo " --copyright" |
| 22 |
echo " --license" |
| 23 |
echo " --release" |
| 24 |
echo " --math" |
| 25 |
echo " --style" |
| 26 |
echo " --history" |
| 27 |
echo "" |
| 28 |
echo "As a githook, the script is used without options." |
| 29 |
echo "In that case, it will run all the checks except style." |
| 30 |
echo "" |
| 31 |
echo "Use --help to print this help message." |
| 32 |
fi |
| 33 |
|
| 34 |
cd $(git rev-parse --show-toplevel) |
| 35 |
|
| 36 |
# copyright check |
| 37 |
copyright=true |
| 38 |
if [[ "${option}" == "--copyright" || "${option}" == "" ]]; then |
| 39 |
if git grep -n "^\(#\|//\).*Copyright.*2010-20\(2[^5]\|[^2].\)" > matches.txt; then |
| 40 |
echo "Please update the following files to Copyright (c) 2010-2025:" |
| 41 |
cat matches.txt |
| 42 |
copyright=false |
| 43 |
fi |
| 44 |
fi |
| 45 |
|
| 46 |
# license check |
| 47 |
license=true |
| 48 |
if [[ "${option}" == "--license" || "${option}" == "" ]]; then |
| 49 |
if git grep -li "^\(#\|//\).*GNU\ Lesser\ General\ Public\ License" > matches.txt; then |
| 50 |
echo "Please update the following files to the BSD-3 license:" |
| 51 |
cat matches.txt |
| 52 |
license=false |
| 53 |
fi |
| 54 |
fi |
| 55 |
|
| 56 |
# release check |
| 57 |
release=true |
| 58 |
if [[ "${option}" == "--release" || "${option}" == "" ]]; then |
| 59 |
if git grep -l "^\(#\|//\).*LLNL\-CODE\-443211" > matches.txt |
| 60 |
then |
| 61 |
echo "Please update the following files to LLNL-CODE-806117:" |
| 62 |
cat matches.txt |
| 63 |
release=false |
| 64 |
fi |
| 65 |
fi |
| 66 |
|
| 67 |
# math in doxygen check |
| 68 |
math=true |
| 69 |
if [[ "${option}" == "--math" || "${option}" == "" ]]; then |
| 70 |
if grep '\\f' -R doc/CodeDocumentation.dox mfem.hpp config general linalg mesh fem examples miniapps | grep -v '\\frac' | grep -v fem/picojson.h | grep -v config/githooks/pre-push > matches.txt |
| 71 |
then |
| 72 |
echo "Please use $..$ and \$\$..\$\$ for LaTeX formulas in the following" |
| 73 |
echo "comments instead of the Doxygen style \f$..\f$, \f[..\f], etc." |
| 74 |
cat matches.txt |
| 75 |
math=false |
| 76 |
fi |
| 77 |
fi |
| 78 |
|
| 79 |
# wrap-up |
| 80 |
code=0 |
| 81 |
if ! $copyright ; then |
| 82 |
echo "copyright check failed, unroll log for details" |
| 83 |
code=1 |
| 84 |
fi |
| 85 |
if ! $license ; then |
| 86 |
echo "license check failed, unroll log for details" |
| 87 |
code=1 |
| 88 |
fi |
| 89 |
if ! $release ; then |
| 90 |
echo "release check failed, unroll log for details" |
| 91 |
code=1 |
| 92 |
fi |
| 93 |
if ! $math ; then |
| 94 |
echo "math in doxygen check failed, unroll log for details" |
| 95 |
code=1 |
| 96 |
fi |
| 97 |
|
| 98 |
# `code-style` is not just a check, it will actually reformat the code if |
| 99 |
# necessary. This means that if one pushes while the repo is in dirty state |
| 100 |
# (changes not staged), those changes may be mixed with format changes. |
| 101 |
# To activate this, you will need to hard-copy this hook script in the hook |
| 102 |
# directory and uncomment only then. (See README.md) |
| 103 |
# |
| 104 |
## style check |
| 105 |
#if [[ "${option}" == "--style" || "${option}" == "" ]]; then |
| 106 |
if [[ "${option}" == "--style" ]]; then |
| 107 |
if which astyle && [[ "$(astyle --version)" == "Artistic Style Version 3.1" ]]; then |
| 108 |
cd tests/scripts |
| 109 |
if ! ./runtest code-style; then code=1; fi |
| 110 |
cd - |
| 111 |
else |
| 112 |
echo "Warning: astyle not found or version is not 3.1" |
| 113 |
fi |
| 114 |
fi |
| 115 |
|
| 116 |
# branch-history |
| 117 |
if [[ "${option}" == "--history" || "${option}" == "" ]]; then |
| 118 |
git fetch origin master:master |
| 119 |
cd tests/scripts |
| 120 |
if ! ./runtest branch-history; then code=1; fi |
| 121 |
cd - |
| 122 |
fi |
| 123 |
|
| 124 |
exit $code |