|
| 1 | +#!/usr/bin/env bash |
| 2 | +# This script checks for the presence of the required license header in Rust source files. |
| 3 | + |
| 4 | +# Get the repository root |
| 5 | +REPO_ROOT="$(git rev-parse --show-toplevel)" |
| 6 | +cd "$REPO_ROOT" || exit 1 |
| 7 | + |
| 8 | +# Define the license header pattern to look for |
| 9 | +LICENSE_PATTERN="Copyright .* The Hyperlight Authors..*Licensed under the Apache License, Version 2.0" |
| 10 | + |
| 11 | +# Define the full license header for files that need it |
| 12 | +LICENSE_HEADER='/* |
| 13 | +Copyright 2026 The Hyperlight Authors. |
| 14 | +
|
| 15 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 16 | +you may not use this file except in compliance with the License. |
| 17 | +You may obtain a copy of the License at |
| 18 | +
|
| 19 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | +
|
| 21 | +Unless required by applicable law or agreed to in writing, software |
| 22 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 23 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | +See the License for the specific language governing permissions and |
| 25 | +limitations under the License. |
| 26 | +*/ |
| 27 | +
|
| 28 | +' |
| 29 | + |
| 30 | +# Initialize a variable to track missing headers |
| 31 | +MISSING_HEADERS=0 |
| 32 | +MISSING_FILES="" |
| 33 | + |
| 34 | +# Find all Rust files |
| 35 | +while IFS= read -r -d $'\0' file; do |
| 36 | + # Check if the file has the license header (allowing for multi-line matching) |
| 37 | + if ! grep -q -z "$LICENSE_PATTERN" "$file"; then |
| 38 | + echo "Missing or invalid license header in $file" |
| 39 | + MISSING_FILES="$MISSING_FILES\n $file" |
| 40 | + MISSING_HEADERS=$((MISSING_HEADERS + 1)) |
| 41 | + fi |
| 42 | +done < <(find src -name "*.rs" -type f -print0) |
| 43 | + |
| 44 | +if [ $MISSING_HEADERS -gt 0 ]; then |
| 45 | + echo "Found $MISSING_HEADERS files with missing or invalid license headers:" |
| 46 | + echo -e "$MISSING_FILES" |
| 47 | + echo "" |
| 48 | + echo "Please add the following license header to these files:" |
| 49 | + echo "$LICENSE_HEADER" |
| 50 | + echo "You can also run: just check-license-headers to verify your changes." |
| 51 | + exit 1 |
| 52 | +else |
| 53 | + echo "All Rust files have the required license header" |
| 54 | + exit 0 |
| 55 | +fi |
0 commit comments