Skip to content

Add missing header to *.cpp, *.h, and *.hpp files and add header checking to the CI

Issue/feature addressed

Some *.cpp, *.hpp, and *, h files are missing filename or MIT Licence header.

Proposed solution

The proposed solution consist to add check in the CI to check for header.

Implementation

First, the following bash script was used to add missing MIT Licence header to relevant *.cpp, *.hpp, and *.h files

#!/bin/bash
addHeader() {
file=$1
rm -f tmp
cat <<EOT>> tmp
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// 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.
//
// Description:
//
///////////////////////////////////////////////////////////////////////////////

EOT
cat $file >> tmp
mv tmp $file
sed -i "1i //" $file
sed -i "1i // File: ${file##*/}" $file
sed -i "1i //" $file
sed -i "1i ///////////////////////////////////////////////////////////////////////////////" $file
}

for file in $(find -type f); do
    filename=${file##*/}
    if [[ ! $(grep -F "MIT License" $file) ]]; then
        if [[ "${filename##*.}" == "h" ]]; then
            echo $file does not contains MIT License
            addHeader $file
        fi
        if [[ "${filename##*.}" == "cpp" ]]; then
            echo $file does not contains MIT License
            addHeader $file
        fi
        if [[ "${filename##*.}" == "hpp" ]]; then
            echo $file does not contains MIT License
            addHeader $file
        fi
    fi
done

Then two bash files are added to the CI to check if MIT Licence is missing or if the file contains the correct file name

#!/bin/bash
error=0
for file in $(find -type f); do
    filename=${file##*/}
    if [[ ! $(grep -F "MIT License" $file) ]]; then
        if [[ "${filename##*.}" == "h" ]]; then
            echo $file does not contains MIT License
            error=1
        fi
        if [[ "${filename##*.}" == "cpp" ]]; then
            echo $file does not contains MIT License
            error=1
        fi
        if [[ "${filename##*.}" == "hpp" ]]; then
            echo $file does not contains MIT License
            error=1
        fi
    fi
done

if [[ $error -eq 1 ]]; then
    exit 1 # exit with an error
fi
#!/bin/bash
error=0
for file in $(find -type f); do
    filename=${file##*/}
    if [[ ! $(grep -F "$filename" $file) ]]; then
        if [[ "${filename##*.}" == "h" ]]; then
            echo $file does not contains file name
            error=1
        fi
        if [[ "${filename##*.}" == "cpp" ]]; then
            echo $file does not contains file name
            error=1
        fi
        if [[ "${filename##*.}" == "hpp" ]]; then
            echo $file does not contains file name
            error=1
        fi
    fi
done

if [[ $error -eq 1 ]]; then
    exit 1 # exit with an error
fi

Checklist

  • [ ] Functions and classes, or changes to them, are documented.
  • [ ] User guide/documentation is updated.
  • Changelog is updated.
  • [ ] Suitable tests added for new functionality.
  • Contributed code is correctly formatted. (See the contributing guidelines).
  • License added to any new files.
  • No extraneous files have been added (e.g. compiler output or test data files).

Warning

On the 19.07 the code formatting (code style) was standardised using clang-format, over the whole Nektar++ code. This means changes in your branch will conflict with formatting changes on the master branch. To resolve these conflicts , see #295 (closed)

Edited by Jacques Xing

Merge request reports

Loading