Skip to content

Commit

Permalink
[INFRA] scripts that creates all.hpp files
Browse files Browse the repository at this point in the history
  • Loading branch information
SGSSGene committed Nov 1, 2021
1 parent a4d511c commit 4dbb3a6
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions test/scripts/create_all_hpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------------------------------
# Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
# Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
# This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
# shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
# -----------------------------------------------------------------------------------------------------
#
# Usage: create_all_hpp.sh <SeqAn3 root directory>
# Will create all.hpp in all subdirectories

# Directories (+ subdirectories) to ignore (not creating any all.hpp files in these folders)
exceptionList=(
include/seqan3/std
include/seqan3/contrib
/detail
/exposition_only
include/seqan3/core/concept
include/seqan3/utility/concept
)

# prints the header of a typical all.hpp file
print_header()
{
cat << EOF
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------
EOF
}

# prints a list of "#include <file>" lines, typical for all.hpp files
print_includes()
{
directory="$1"
echo -ne "\n#pragma once\n\n"

for path in $(find "${directory}"/* -maxdepth 0); do
incl_path="$(realpath --relative-to include "${path}")"
if [ "${path}" == "${directory}/all.hpp" ]; then
continue
elif [ -f "${path}" ]; then
if [[ "${path}" == *.hpp ]] || [[ "${path}" == *.h ]]; then
echo "#include <${incl_path}>"
fi
elif [[ "${path}" == */detail ]] || [[ "${path}" == */exposition_only ]]; then
# Only add the all.hpp include, if `detail` has an all.hpp file
if [ -f "${path}/all.hpp" ]; then
echo "#include <${incl_path}/all.hpp>"
else
for subpath in $(find "${path}"/* -maxdepth 0 -type f); do
if [[ "${subpath}" == *.hpp ]] || [[ "${subpath}" == *.h ]]; then
incl_subpath="$(realpath --relative-to include "${subpath}")"
echo "#include <${incl_subpath}>"
fi
done
fi
else
# In every subdirectory (excluding detail) we generate a all.hpp file
echo "#include <${incl_path}/all.hpp>"
fi
done
}

if [[ $# -ne 1 ]]; then
echo "Usage: create_all_hpp.sh <SeqAn3 root directory>"
exit 1
fi

if [[ ! -d $1 ]]; then
echo "The directory $1 does not exist."
exit 1
fi

if [[ ! -f $1/include/seqan3/version.hpp ]]; then
echo "The directory $1 does not seem to be the SeqAn3 root directory."
echo "Cannot find $1/include/seqan3/version.hpp."
exit 1
fi

# Iterate through all folders
for directory in $(find include/seqan3/* -type d); do
# check if directory is in the exception list
found=0
for entry in "${exceptionList[@]}"; do
if [ ! -z $(echo "${directory}" | grep $entry) ]; then
found=1;
break;
fi
done
if [ ${found} -eq 1 ]; then
continue
fi

# create all.hpp
if [ ! -f "${directory}/all.hpp" ]; then
echo "missing all.hpp file in ${directory}"
(
print_header
print_includes "${directory}"

) > "${directory}/all.hpp"
else
# check if license text has changed
HEADER_LINES=$(print_header | wc -l)
licence_changes=$(head -n ${HEADER_LINES} "${directory}/all.hpp" | diff /dev/stdin <( print_header ) | wc -c)

# check if include list has changed
INCLUDE_LINES=$(print_includes "${directory}" | wc -l)
include_changes=$(tail -n ${INCLUDE_LINES} "${directory}/all.hpp" | diff /dev/stdin <( print_includes "${directory}" ) | wc -c)

if [ "$licence_changes" -gt 0 ] || [ "$include_changes" -gt 0 ]; then
echo "License text or includes changed, updating ${directory}/all.hpp"
tmp_file=$(mktemp);
# create new license text and include list, but keep doxygen documentation
cp "${directory}/all.hpp" "${tmp_file}"
(
PRAGMA_LINE=$(cat "${tmp_file}" | grep -n "#pragma once" | cut -f 1 -d ':')
print_header
tail ${tmp_file} -n +$(expr 1 + ${HEADER_LINES}) | grep -v "#include" | grep -v "#pragma once"
print_includes "${directory}"
) | cat -s | sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' > "${directory}/all.hpp"
rm $tmp_file
fi
fi
done

0 comments on commit 4dbb3a6

Please sign in to comment.