|
| 1 | +#!/bin/sh |
| 2 | +# @copyright Copyright (c) contributors to Project Ocre, |
| 3 | +# which has been established as Project Ocre a Series of LF Projects, LLC |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | + |
| 7 | +# Checks all C/C++ files for license banner |
| 8 | + |
| 9 | +set -e |
| 10 | + |
| 11 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 12 | +ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 13 | +SRC_DIR="$ROOT_DIR/src" |
| 14 | + |
| 15 | +check_license_banner() { |
| 16 | + local file="$1" |
| 17 | + local file_header |
| 18 | + |
| 19 | + file_header=$(head -n 6 "$file") |
| 20 | + |
| 21 | + # Expected license banner |
| 22 | + local expected_banner="/** |
| 23 | + * @copyright Copyright (c) contributors to Project Ocre, |
| 24 | + * which has been established as Project Ocre a Series of LF Projects, LLC |
| 25 | + * |
| 26 | + * SPDX-License-Identifier: Apache-2.0 |
| 27 | + */" |
| 28 | + |
| 29 | + if [ "$file_header" != "$expected_banner" ]; then |
| 30 | + echo "ERROR: Missing or incorrect license banner in $file" |
| 31 | + return 1 |
| 32 | + fi |
| 33 | + |
| 34 | + return 0 |
| 35 | +} |
| 36 | + |
| 37 | +echo "Checking license banners." |
| 38 | +ERROR_FOUND=0 |
| 39 | +for file in $(find . -type f \( -name '*.c' -o -name '*.h' \) \ |
| 40 | + ! -name 'utlist.h' \ |
| 41 | + ! -name 'CMakeCCompilerId.c' \ |
| 42 | + ! -path './tests/Unity/*' \ |
| 43 | + ! -path './build/*' \ |
| 44 | + ! -path './wasm-micro-runtime/*' \ |
| 45 | + ! -path './ocre-sdk/*' \ |
| 46 | + ! -path './src/shell/sha256/*' \ |
| 47 | + ! -path './src/runtime/wamr-wasip1/ocre_api/utils/*' \ |
| 48 | + | sort); do |
| 49 | + |
| 50 | + if ! check_license_banner "$file"; then |
| 51 | + ERROR_FOUND=1 |
| 52 | + fi |
| 53 | +done |
| 54 | + |
| 55 | +if [ $ERROR_FOUND -ne 0 ]; then |
| 56 | + echo "License check failed." |
| 57 | + exit 1 |
| 58 | +fi |
0 commit comments