File: create_all_hpp.sh

package info (click to toggle)
seqan3 3.4.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,580 kB
  • sloc: cpp: 145,192; sh: 307; xml: 264; javascript: 95; makefile: 70; perl: 29; php: 15
file content (122 lines) | stat: -rwxr-xr-x 4,181 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash

# SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause

# 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()
{
CURRENT_YEAR=$1
cat << EOF
# SPDX-FileCopyrightText: 2006-${CURRENT_YEAR} Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-${CURRENT_YEAR} Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: BSD-3-Clause
EOF
}

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

    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 ]]) && [[ ! "${path}" == */detail.hpp ]]; then
                hasIncludes=1
               echo "#include <${incl_path}>"
            fi
        elif [[ "${path}" == */detail ]] || [[ "${path}" == */exposition_only ]]; then
            continue
        else
            # In every subdirectory (excluding detail) we generate a all.hpp file
            echo "#include <${incl_path}/all.hpp>"
            hasIncludes=1
        fi
    done
    if [[ "${hasIncludes}" -eq "0" ]]; then
        echo "#include <seqan3/core/platform.hpp>"
    fi
}

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
CURRENT_YEAR=$(date "+%Y")

# 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 ${CURRENT_YEAR}
            print_includes "${directory}"

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