Skip to content

Commit 86933e6

Browse files
committed
Update license checker
updated checker algoritm, added exception files, added correct license where needed, added calling checker
1 parent e82e88f commit 86933e6

32 files changed

+103
-61
lines changed

.github/workflows/reusable_checks.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Basic checks on the code, incl. coding style, spelling, bandit analysis.
2-
# TODO: add license check
32
name: Basic checks
43

54
on: workflow_call
@@ -52,6 +51,14 @@ jobs:
5251
- name: Check Python formatting
5352
run: cmake --build build --target black-format-check
5453

54+
- name: Run check-license
55+
run: |
56+
bash ./check_license/check-headers.sh . "Apache-2.0 WITH LLVM-exception" -v
57+
58+
- name: Run copyright-format
59+
run: |
60+
bash ./check_license/check-headers.sh . "Apache-2.0 WITH LLVM-exception" -d
61+
5562
- name: Run a spell check
5663
uses: crate-ci/typos@b63f421581dce830bda2f597a678cb7776b41877 # v1.18.2
5764
with:

CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,6 @@ else()
184184

185185
add_custom_target(jemalloc_prod
186186
DEPENDS ${jemalloc_targ_BINARY_DIR}/lib/libjemalloc.a)
187-
add_custom_target(check-license
188-
COMMAND ${PMEMSTREAM_ROOT_DIR}/check_license/check-headers.sh
189-
${PMEMSTREAM_ROOT_DIR}
190-
Apache-2.0 WITH LLVM-exception -v)
191-
add_custom_target(copyright-format
192-
COMMAND ${PMEMSTREAM_ROOT_DIR}/check_license/check-headers.sh
193-
${PMEMSTREAM_ROOT_DIR}
194-
Apache-2.0 WITH LLVM-exception -d)
195187

196188
add_library(jemalloc INTERFACE)
197189
target_link_libraries(

check_license/check-headers.sh

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env bash
2-
# SPDX-License-Identifier: BSD-3-Clause
3-
# Copyright 2016-2022, Intel Corporation
2+
# Copyright (C) 2024 Intel Corporation
3+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
45

56
# check-headers.sh - check copyright and license in source files
67

78
SELF=$0
89

910
function usage() {
10-
echo "Usage: $SELF <source_root_path> <license_tag> [-h|-v|-a]"
11+
echo "Usage: $SELF <source_root_path> <license_tag> [-h|-v|-a|-d]"
1112
echo " -h, --help this help message"
1213
echo " -v, --verbose verbose mode"
1314
echo " -a, --all check all files (only modified files are checked by default)"
@@ -83,18 +84,15 @@ else
8384
GIT_COMMAND="diff --name-only $MERGE_BASE $CURRENT_COMMIT"
8485
fi
8586

86-
FILES=$($GIT $GIT_COMMAND | ${SOURCE_ROOT}/utils/check_license/file-exceptions.sh | \
87-
grep -E -e '*\.[chs]$' -e '*\.[ch]pp$' -e '*\.sh$' -e '*\.py$' \
88-
-e 'TEST*' -e 'Makefile*' -e 'CMakeLists.txt$' -e '*\.cmake$' \
89-
-e '*\.link$' -e '*\.map$' -e '*\.Dockerfile$' -e 'LICENSE$' \
90-
-e '/common.inc$' -e '/match$' -e '/check_whitespace$' -e '/cppstyle$' | \
91-
xargs)
87+
FILES=$($GIT $GIT_COMMAND | ${SOURCE_ROOT}/check_license/file-exceptions.sh)
9288

9389
RV=0
90+
9491
for file in $FILES ; do
9592
if [ $VERBOSE -eq 1 ]; then
9693
echo "Checking file: $file"
9794
fi
95+
9896
# The src_path is a path which should be used in every command except git.
9997
# git is called with -C flag so filepaths should be relative to SOURCE_ROOT
10098
src_path="${SOURCE_ROOT}/$file"
@@ -130,10 +128,10 @@ for file in $FILES ; do
130128
FIRST=`head -n1 $TMP2`
131129
LAST=` tail -n1 $TMP2`
132130

133-
YEARS=`sed '
134-
/Copyright [0-9-]\+.*, Intel Corporation/!d
135-
s/.*Copyright \([0-9]\+\)-\([0-9]\+\),.*/\1-\2/
136-
s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
131+
YEARS=$(sed '
132+
/.*Copyright (C) \+.*[0-9-]\+ Intel Corporation/!d
133+
s/.*Copyright (C) \([0-9]\+\)-\([0-9]\+\).*/\1-\2/
134+
s/.*Copyright (C) \([0-9]\+\).*/\1/' "$src_path")
137135
if [ -z "$YEARS" ]; then
138136
echo >&2 "No copyright years in $src_path"
139137
RV=1
@@ -145,22 +143,36 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
145143

146144
COMMIT_FIRST=`echo $FIRST | cut -d"-" -f1`
147145
COMMIT_LAST=` echo $LAST | cut -d"-" -f1`
146+
148147
if [ "$COMMIT_FIRST" != "" -a "$COMMIT_LAST" != "" ]; then
149-
if [ $HEADER_LAST -lt $COMMIT_LAST ]; then
150-
if [ $HEADER_FIRST -lt $COMMIT_FIRST ]; then
151-
COMMIT_FIRST=$HEADER_FIRST
148+
if [[ -n "$COMMIT_FIRST" && -n "$COMMIT_LAST" ]]; then
149+
FL=0
150+
if [[ $HEADER_FIRST -lt $COMMIT_FIRST ]]; then
151+
FL=1
152152
fi
153+
153154
COMMIT_LAST=`date +%G`
154-
if [ $COMMIT_FIRST -eq $COMMIT_LAST ]; then
155-
NEW=$COMMIT_LAST
155+
156+
if [[ $FL -eq 1 ]]; then
157+
NEW=$HEADER_FIRST-$COMMIT_LAST
156158
else
157-
NEW=$COMMIT_FIRST-$COMMIT_LAST
159+
160+
if [[ $COMMIT_FIRST -eq $COMMIT_LAST ]]; then
161+
NEW=$COMMIT_LAST
162+
else
163+
NEW=$COMMIT_FIRST-$COMMIT_LAST
164+
fi
158165
fi
159-
if [ ${UPDATE_DATES} -eq 1 ]; then
160-
sed -i "s/Copyright ${YEARS}/Copyright ${NEW}/g" "${src_path}"
161-
else
162-
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
163-
RV=1
166+
167+
if [[ "$YEARS" == "$NEW" ]]; then
168+
echo "No change needed: $YEARS"
169+
else
170+
if [[ ${UPDATE_DATES} -eq 1 ]]; then
171+
sed -i "s/Copyright ${YEARS}/Copyright ${NEW}/g" "${src_path}"
172+
else
173+
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
174+
RV=1
175+
fi
164176
fi
165177
fi
166178
else

check_license/file-exceptions.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh -e
2+
# Copyright (C) 2024 Intel Corporation
3+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
# You can add an exception file
7+
grep -v -E -e 'src/uthash/.*' \
8+
-e 'benchmark/ubench.h' \
9+
-e 'include/umf/proxy_lib_new_delete.h' \
10+
-e 'scripts/docs_config/conf.py' \
11+
-e 'src/uthash/utlist.h' \
12+
-e 'src/uthash/uthash.h' \
13+
-e '\.yml$'\
14+
-e '\.clang-format$' \
15+
-e '\.md$' \
16+
-e '\.cmake-format$' \
17+
-e 'CODEOWNERS$' \
18+
-e 'scripts/assets/images/.*' \
19+
-e 'scripts/docs_config/.*' \
20+
-e '\.xml$' \
21+
-e '\.txt$' \
22+
-e 'test/supp/.*' \
23+
-e '\.json$' \
24+
-e 'LICENSE.TXT' \
25+
-e '.github/workflows/.spellcheck-conf.toml' \
26+
-e '.gitignore' \
27+
-e '.mailmap' \
28+
-e '.trivyignore' \
29+
-e 'ChangeLog' \
30+
-e '\.cmake.in$' \
31+
-e '\.patch$'

include/umf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023 Intel Corporation
3+
* Copyright (C) 2023-2024 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

include/umf/memory_pool_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023 Intel Corporation
3+
* Copyright (C) 2023-2024 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

include/umf/pools/pool_jemalloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023 Intel Corporation
3+
* Copyright (C) 2023-2024 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

include/umf/pools/pool_scalable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2023 Intel Corporation
3+
* Copyright (C) 2023-2024 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

src/libumf.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;;;; Begin Copyright Notice
2-
; Copyright (C) 2024 Intel Corporation
2+
; Copyright (C) 2023-2024 Intel Corporation
33
; Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
44
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55
;;;; End Copyright Notice

src/libumf.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2024 Intel Corporation
1+
# Copyright (C) 2023-2024 Intel Corporation
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

0 commit comments

Comments
 (0)