-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.license-check.sh
executable file
·190 lines (171 loc) · 8.34 KB
/
.license-check.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash
# Licensed to Systerel under one or more contributor license
# agreements. See the NOTICE file distributed with this work
# for additional information regarding copyright ownership.
# Systerel licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Checks license is present as expected in the header of the source code files
# of the project.
# Create temporary files
# Helper script holds the head | diff, so that its compatible with find | xargs
HELPER_SCRIPT=$(mktemp)
HEADER_C=$(mktemp)
HEADER_PY=$(mktemp)
HEADER_SH=$(mktemp)
HEADER_XSL=$(mktemp)
# Helper script takes the reference header and the file to test
echo '#!/bin/bash
if [[ -z $1 || -z "$2" ]] ; then
exit 2
fi
n_lines=$(wc -l < $1)
if [[ $n_lines -eq 0 ]] ; then
echo Empty header file $1
exit 3
fi
head -n $n_lines "$2" | diff - $1 > /dev/null
last=$?
if [[ ! $last -eq 0 ]] ; then
echo Invalid copyright header in file $2
exit 1
fi' > $HELPER_SCRIPT
chmod +x $HELPER_SCRIPT
# C copyright
echo '/*
* Licensed to Systerel under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Systerel licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
' > $HEADER_C
# Py header
echo '#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Licensed to Systerel under one or more contributor license
# agreements. See the NOTICE file distributed with this work
# for additional information regarding copyright ownership.
# Systerel licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
' > $HEADER_PY
# Script header
echo '#!/bin/bash
# Licensed to Systerel under one or more contributor license
# agreements. See the NOTICE file distributed with this work
# for additional information regarding copyright ownership.
# Systerel licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
' > $HEADER_SH
# XSL header
echo '<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to Systerel under one or more contributor license
agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership.
Systerel licenses this file to you under the Apache
License, Version 2.0 (the "License"); you may not use this
file except in compliance with the License. You may obtain
a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
' > $HEADER_XSL
# Do the finds
err=0
# Exclude some files
read -d '' exclusions <<-EOF
src/Common/opcua_types/opcua_identifiers.h
src/Common/opcua_types/opcua_statuscodes.h
src/Common/opcua_types/sopc_types.h
src/Common/opcua_types/sopc_enum_types.h
src/Common/opcua_types/sopc_types.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/FreeRTOSConfig.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/lwipopts.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/semihost_hardfault.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/fsl_phy.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/MIMXRT1064_features.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/peripherals.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/pin_mux.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/pin_mux.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/peripherals.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/fsl_phy.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/src/board.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/src/clock_config.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/src/clock_config.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/src/board.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/des_alt.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/des_alt.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/ksdk_mbedtls_config.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/ksdk_mbedtls.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/ksdk_mbedtls.c
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/sha1_alt.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/sha256_alt.h
tests/ClientServer/unit_tests/freertos/test_helpers_platform_dep/board_specific/mbedtls_port/ksdk/threading_alt.h
EOF
for f in $exclusions; do
mv $f $f"_"
done
find src tests -name "*.[hc]" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_C || { echo 'Expected header:' ; cat $HEADER_C ; err=1 ; }
for f in $exclusions; do
mv $f"_" $f
done
find bsrc -maxdepth 1 -name "*.[im]??" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_C || { echo 'Expected header:' ; cat $HEADER_C ; err=1 ; }
find bsrc -maxdepth 1 -name "*.pmm" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_C || { echo 'Expected header:' ; cat $HEADER_C ; err=1 ; }
find bsrc -maxdepth 1 -name "*.ref" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_C || { echo 'Expected header:' ; cat $HEADER_C ; err=1 ; }
find . -name "*.py" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_PY || { echo 'Expected header:' ; cat $HEADER_PY ; err=1 ; }
find . -name "*.sh" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_SH || { echo 'Expected header:' ; cat $HEADER_SH ; err=1 ; }
find . -type f -name "make*" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_SH || { echo 'Expected header:' ; cat $HEADER_SH ; err=1 ; }
find . -name "*.xsl" -print0 | xargs -0 -n 1 $HELPER_SCRIPT $HEADER_XSL || { echo 'Expected header:' ; cat $HEADER_XSL ; err=1 ; }
if [[ 0 -eq $err ]] ; then
echo "All copyrights are OK"
fi
exit $err