|
| 1 | +#!/bin/bash |
| 2 | +##===----------------------------------------------------------------------===## |
| 3 | +## |
| 4 | +## This source file is part of the Swift Baggage Context open source project |
| 5 | +## |
| 6 | +## Copyright (c) 2020 Moritz Lang and the Swift Baggage Context project authors |
| 7 | +## Licensed under Apache License v2.0 |
| 8 | +## |
| 9 | +## See LICENSE.txt for license information |
| 10 | +## |
| 11 | +## SPDX-License-Identifier: Apache-2.0 |
| 12 | +## |
| 13 | +##===----------------------------------------------------------------------===## |
| 14 | + |
| 15 | +##===----------------------------------------------------------------------===## |
| 16 | +## |
| 17 | +## This source file is part of the SwiftNIO open source project |
| 18 | +## |
| 19 | +## Copyright (c) 2017-2019 Apple Inc. and the SwiftNIO project authors |
| 20 | +## Licensed under Apache License v2.0 |
| 21 | +## |
| 22 | +## See LICENSE.txt for license information |
| 23 | +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors |
| 24 | +## |
| 25 | +## SPDX-License-Identifier: Apache-2.0 |
| 26 | +## |
| 27 | +##===----------------------------------------------------------------------===## |
| 28 | + |
| 29 | +set -eu |
| 30 | +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 31 | + |
| 32 | +function replace_acceptable_years() { |
| 33 | + # this needs to replace all acceptable forms with 'YEARS' |
| 34 | + sed -e 's/2019-2020/YEARS/' -e 's/2020/YEARS/' |
| 35 | +} |
| 36 | + |
| 37 | +printf "=> Checking license headers\n" |
| 38 | +tmp=$(mktemp /tmp/.swift-baggage-context-sanity_XXXXXX) |
| 39 | + |
| 40 | +for language in swift-or-c bash dtrace; do |
| 41 | + printf " * $language... " |
| 42 | + declare -a matching_files |
| 43 | + declare -a exceptions |
| 44 | + expections=( ) |
| 45 | + matching_files=( -name '*' ) |
| 46 | + case "$language" in |
| 47 | + swift-or-c) |
| 48 | + exceptions=( -name c_nio_http_parser.c -o -name c_nio_http_parser.h -o -name cpp_magic.h -o -name Package.swift -o -name CNIOSHA1.h -o -name c_nio_sha1.c -o -name ifaddrs-android.c -o -name ifaddrs-android.h) |
| 49 | + matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' ) |
| 50 | + cat > "$tmp" <<"EOF" |
| 51 | +//===----------------------------------------------------------------------===// |
| 52 | +// |
| 53 | +// This source file is part of the Swift Baggage Context open source project |
| 54 | +// |
| 55 | +// Copyright (c) YEARS Moritz Lang and the Swift Baggage Context project authors |
| 56 | +// Licensed under Apache License v2.0 |
| 57 | +// |
| 58 | +// See LICENSE.txt for license information |
| 59 | +// |
| 60 | +// SPDX-License-Identifier: Apache-2.0 |
| 61 | +// |
| 62 | +//===----------------------------------------------------------------------===// |
| 63 | +EOF |
| 64 | + ;; |
| 65 | + bash) |
| 66 | + matching_files=( -name '*.sh' ) |
| 67 | + cat > "$tmp" <<"EOF" |
| 68 | +#!/bin/bash |
| 69 | +##===----------------------------------------------------------------------===## |
| 70 | +## |
| 71 | +## This source file is part of the Swift Baggage Context open source project |
| 72 | +## |
| 73 | +## Copyright (c) YEARS Moritz Lang and the Swift Baggage Context project authors |
| 74 | +## Licensed under Apache License v2.0 |
| 75 | +## |
| 76 | +## See LICENSE.txt for license information |
| 77 | +## |
| 78 | +## SPDX-License-Identifier: Apache-2.0 |
| 79 | +## |
| 80 | +##===----------------------------------------------------------------------===## |
| 81 | +EOF |
| 82 | + ;; |
| 83 | + dtrace) |
| 84 | + matching_files=( -name '*.d' ) |
| 85 | + cat > "$tmp" <<"EOF" |
| 86 | +#!/usr/sbin/dtrace -q -s |
| 87 | +/*===----------------------------------------------------------------------===* |
| 88 | + * |
| 89 | + * This source file is part of the Swift Baggage Context open source project |
| 90 | + * |
| 91 | + * Copyright (c) YEARS Moritz Lang and the Swift Baggage Context project authors |
| 92 | + * Licensed under Apache License v2.0 |
| 93 | + * |
| 94 | + * See LICENSE.txt for license information |
| 95 | + * |
| 96 | + * SPDX-License-Identifier: Apache-2.0 |
| 97 | + * |
| 98 | + *===----------------------------------------------------------------------===*/ |
| 99 | +EOF |
| 100 | + ;; |
| 101 | + *) |
| 102 | + echo >&2 "ERROR: unknown language '$language'" |
| 103 | + ;; |
| 104 | + esac |
| 105 | + |
| 106 | + expected_lines=$(cat "$tmp" | wc -l) |
| 107 | + expected_sha=$(cat "$tmp" | shasum) |
| 108 | + |
| 109 | + ( |
| 110 | + cd "$here/.." |
| 111 | + find . \ |
| 112 | + \( \! -path './.build/*' -a \ |
| 113 | + \( "${matching_files[@]}" \) -a \ |
| 114 | + \( \! \( "${exceptions[@]}" \) \) \) | while read line; do |
| 115 | + if [[ "$(cat "$line" | replace_acceptable_years | head -n $expected_lines | shasum)" != "$expected_sha" ]]; then |
| 116 | + printf "\033[0;31mmissing headers in file '$line'!\033[0m\n" |
| 117 | + diff -u <(cat "$line" | replace_acceptable_years | head -n $expected_lines) "$tmp" |
| 118 | + exit 1 |
| 119 | + fi |
| 120 | + done |
| 121 | + printf "\033[0;32mokay.\033[0m\n" |
| 122 | + ) |
| 123 | +done |
| 124 | + |
| 125 | +rm "$tmp" |
0 commit comments