-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from LiZhenCheng9527/copyright-check
add Copyright check
- Loading branch information
Showing
101 changed files
with
256 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/bin/bash | ||
|
||
ROOT_DIR=$(git rev-parse --show-toplevel) | ||
|
||
go_copyright_path=$ROOT_DIR/hack/copyright/apache.txt | ||
|
||
c_copyright_path1=$ROOT_DIR/hack/copyright/BSDandGPL1.txt | ||
c_copyright_path2=$ROOT_DIR/hack/copyright/BSDandGPL2.txt | ||
|
||
go_dirs="$ROOT_DIR/pkg" | ||
c_dirs="$ROOT_DIR/bpf" | ||
|
||
function check_go_copyright() { | ||
target_file=$1 | ||
copyright_file=$go_copyright_path | ||
|
||
if [ ! -f "$target_file" ]; then | ||
echo "Target file $target_file does not exist." | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f "$copyright_file" ]; then | ||
echo "Copyright file $copyright_file does not exist." | ||
exit 1 | ||
fi | ||
|
||
all_lines_present=true | ||
while IFS= read -r line; do | ||
if ! grep -qF -- "$line" "$target_file"; then | ||
all_lines_present=false | ||
break | ||
fi | ||
done < "$copyright_file" | ||
|
||
if [ "$all_lines_present" != true ]; then | ||
echo "The target file does not contain all lines from the copyright file." | ||
echo $target_file | ||
fi | ||
} | ||
|
||
function check_c_copyright() { | ||
target_file=$1 | ||
copyright_file1=$c_copyright_path1 | ||
copyright_file2=$c_copyright_path2 | ||
|
||
if [ ! -f "$target_file" ]; then | ||
echo "Target file $target_file does not exist." | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f "$copyright_file1" ]; then | ||
echo "Copyright file $copyright_file1 does not exist." | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f "$copyright_file2" ]; then | ||
echo "Copyright file $copyright_file2 does not exist." | ||
exit 1 | ||
fi | ||
|
||
all_lines_present1=true | ||
while IFS= read -r line; do | ||
if ! grep -qF -- "$line" "$target_file"; then | ||
all_lines_present1=false | ||
break | ||
fi | ||
done < "$copyright_file1" | ||
|
||
all_lines_present2=true | ||
while IFS= read -r line; do | ||
if ! grep -qF -- "$line" "$target_file"; then | ||
all_lines_present2=false | ||
break | ||
fi | ||
done < "$copyright_file2" | ||
|
||
if [ "$all_lines_present1" != true ] && [ "$all_lines_present2" != true ]; then | ||
echo "The target file does not contain all lines from the copyright file." | ||
echo $target_file | ||
fi | ||
} | ||
|
||
function go_check_dir() { | ||
dir=$1 | ||
find $dir -type f -name "*.go" | while read file; do | ||
# echo $file | ||
if ! echo $exclude_dirs | grep -q $(dirname $file); then | ||
check_go_copyright $file | ||
fi | ||
done | ||
} | ||
|
||
function c_check_dir() { | ||
dir=$1 | ||
find $dir -type f -name "*.c" -o -name "*.h" | while read file; do | ||
# echo $file | ||
if ! echo $exclude_dirs | grep -q $(dirname $file); then | ||
check_c_copyright $file | ||
fi | ||
done | ||
} | ||
|
||
function copyright_check() { | ||
for dir in ${go_dirs}; do | ||
go_check_dir $dir | ||
done | ||
|
||
for dir in ${c_dirs}; do | ||
c_check_dir $dir | ||
done | ||
} | ||
|
||
# Confirmation of whether there are files with wrong copyright | ||
if [ -z "$1" -o "$1" == "-c" -o "$1" == "--check" ]; then | ||
result=$(copyright_check | grep -c 'not contain') | ||
if [ "$result" != 0 ]; then | ||
echo "ERROR: Some files need to be update copyright, please run "./hack/copyright-check -g" and update and include any changed files in your PR" | ||
exit 1 | ||
else | ||
echo "pass copyright check" | ||
fi | ||
fi | ||
|
||
# Obtaining the name of a file that with wrong copyright | ||
if [ "$1" == "-g" -o "$1" == "--get" ]; then | ||
copyright_check | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | ||
/* Copyright Authors of Kmesh */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ | ||
/* Copyright Authors of Kmesh */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright The Kmesh Authors. | ||
* | ||
* Licensed 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. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.