forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_check.sh
executable file
·143 lines (127 loc) · 7.12 KB
/
pr_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
#!/bin/bash
# This script is designed to ensure all relevant header and source files contain correct copyright
set +e
sudo apt-get install dos2unix
ok=0
fixed=0
function check_folder {
for filename in $(find $1 -type f \( -iname \*.cpp -o -iname \*.h -o -iname \*.hpp -o -iname \*.js -o -iname \*.bat -o -iname \*.sh -o -iname \*.txt \)); do
if [[ $(grep -oP "Software License Agreement" $filename | wc -l) -ne 0 ]]; then
echo "[WARNING] $filename contains 3rd-party license agreement"
else
if [[ ! $filename == *"usbhost"* ]]; then
# Only check files that are not .gitignore-d
if [[ $(git check-ignore $filename | wc -l) -eq 0 ]]; then
if [[ $(grep -oP "(?<=\(c\) )(.*)(?= Intel)" $filename | wc -l) -eq 0 ]]; then
echo "[ERROR] $filename is missing the copyright notice"
ok=$((ok+1))
if [[ $2 == *"fix"* ]]; then
if [[ $(date +%Y) == "2019" ]]; then
if [[ $filename == *".hpp"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|// Copyright(c) 2019 Intel Corporation. All Rights Reserved.' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".cpp"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|// Copyright(c) 2019 Intel Corporation. All Rights Reserved.' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".h"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|/* Copyright(c) 2019 Intel Corporation. All Rights Reserved. */' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".js"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|// Copyright(c) 2019 Intel Corporation. All Rights Reserved.' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".txt"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|# Copyright(c) 2019 Intel Corporation. All Rights Reserved.' -cx $filename
fixed=$((fixed+1))
fi
else
echo Please update pr_check to auto-resolve missing copyright
fi
fi
fi
if [[ $(grep -oP "Apache 2.0" $filename | wc -l) -eq 0 ]]; then
echo "[ERROR] $filename is missing license notice"
ok=$((ok+1))
if [[ $2 == *"fix"* ]]; then
if [[ $filename == *".hpp"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|// License: Apache 2.0. See LICENSE file in root directory.' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".cpp"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|// License: Apache 2.0. See LICENSE file in root directory.' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".h"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|/* License: Apache 2.0. See LICENSE file in root directory. */' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".js"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|// License: Apache 2.0. See LICENSE file in root directory.' -cx $filename
fixed=$((fixed+1))
fi
if [[ $filename == *".txt"* ]]; then
echo "Trying to auto-resolve...";
ex -sc '1i|# License: Apache 2.0. See LICENSE file in root directory.' -cx $filename
fixed=$((fixed+1))
fi
fi
fi
if [[ $(grep -o -P '\t' $filename | wc -l) -ne 0 ]]; then
echo "[ERROR] $filename has tabs (this project is using spaces as delimiters)"
ok=$((ok+1))
if [[ $2 == *"fix"* ]]; then
echo "Trying to auto-resolve...";
sed -i.bak $'s/\t/ /g' $filename
fixed=$((fixed+1))
fi
fi
if [[ $(file ${filename} | grep -o -P 'CRLF' | wc -l) -ne 0 ]]; then
echo "[ERROR] $filename is using DOS line endings (this project is using Unix line-endings)"
ok=$((ok+1))
if [[ $2 == *"fix"* ]]; then
echo "Trying to auto-resolve...";
dos2unix $filename
fixed=$((fixed+1))
fi
fi
fi
fi
fi
done
}
if [[ $1 == *"help"* ]]; then
echo Pull-Request Check tool
echo "Usage: (run from repo scripts directory)"
echo " ./pr_check.sh [--help] [--fix]"
echo " --fix Try to auto-fix defects"
exit 0
fi
cd ..
check_folder include $1
check_folder src $1
check_folder examples $1
check_folder third-party/libtm $1
check_folder tools $1
cd scripts
if [[ ${fixed} -ne 0 ]]; then
echo "Re-running pr_check..."
./pr_check.sh
else
if [[ ${ok} -ne 0 ]]; then
echo Pull-Request check failed, please address ${ok} the errors reported above
exit 1
fi
fi
exit 0