Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 9e23214

Browse files
authored
Add license headers & check for inappropriate language (#4)
* Add license header validation script * Add naming validation script
1 parent fbec855 commit 9e23214

File tree

6 files changed

+233
-1
lines changed

6 files changed

+233
-1
lines changed

Sources/Baggage/BaggageContext.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Baggage Context open source project
4+
//
5+
// Copyright (c) 2020 Moritz Lang and the Swift Baggage Context project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
//
10+
// SPDX-License-Identifier: Apache-2.0
11+
//
12+
//===----------------------------------------------------------------------===//
13+
114
/// A `BaggageContext` is a heterogeneous storage type with value semantics for keyed values in a type-safe
215
/// fashion. Its values are uniquely identified via `BaggageContextKey`s. These keys also dictate the type of
316
/// value allowed for a specific key-value pair through their associated type `Value`.

Tests/BaggageTests/BaggageContextTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Baggage Context open source project
4+
//
5+
// Copyright (c) 2020 Moritz Lang and the Swift Baggage Context project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
//
10+
// SPDX-License-Identifier: Apache-2.0
11+
//
12+
//===----------------------------------------------------------------------===//
13+
114
import Baggage
215
import XCTest
316

scripts/sanity.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
#!/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+
##===----------------------------------------------------------------------===##
214

315
set -eu
416
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
517

6-
# bash $here/validate_license_header.sh
18+
bash $here/validate_license_headers.sh
719
bash $here/validate_format.sh
20+
bash $here/validate_naming.sh

scripts/validate_format.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
11
#!/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+
##===----------------------------------------------------------------------===##
228

329
set -u
430

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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"

scripts/validate_naming.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
printf "=> Checking for unacceptable language... "
30+
# This greps for unacceptable terminology. The square bracket[s] are so that
31+
# "git grep" doesn't find the lines that greps :).
32+
unacceptable_terms=(
33+
-e blacklis[t]
34+
-e whitelis[t]
35+
-e slav[e]
36+
)
37+
if git grep --color=never -i "${unacceptable_terms[@]}" > /dev/null; then
38+
printf "\033[0;31mUnacceptable language found.\033[0m\n"
39+
git grep -i "${unacceptable_terms[@]}"
40+
exit 1
41+
fi
42+
printf "\033[0;32mokay.\033[0m\n"

0 commit comments

Comments
 (0)