forked from libre-chip/cpu
		
	add scripts/check-copyright.sh
This commit is contained in:
		
							parent
							
								
									f65fc1d616
								
							
						
					
					
						commit
						30c02e2b98
					
				
					 1 changed files with 67 additions and 0 deletions
				
			
		
							
								
								
									
										67
									
								
								scripts/check-copyright.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										67
									
								
								scripts/check-copyright.sh
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,67 @@ | |||
| #!/bin/bash | ||||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||||
| # See Notices.txt for copyright information | ||||
| set -e | ||||
| 
 | ||||
| function fail() | ||||
| { | ||||
|     local error="$1" | ||||
|     echo "error: $error" >&2 | ||||
|     exit 1 | ||||
| } | ||||
| 
 | ||||
| function fail_file() | ||||
| { | ||||
|     local file="$1" line="$2" error="$3" | ||||
|     fail "$file:$((line + 1)): $error" | ||||
| } | ||||
| 
 | ||||
| function check_file() | ||||
| { | ||||
|     local file="$1" regexes=("${@:2}") | ||||
|     local lines | ||||
|     mapfile -t lines < "$file" | ||||
|     local line | ||||
|     for line in "${!regexes[@]}"; do | ||||
|         eval '[[ "${lines[i]}" =~ '"${regexes[i]}"' ]]' || | ||||
|             fail_file "$file" "$line" "doesn't match regex: ${regexes[i]}" | ||||
|     done | ||||
| } | ||||
| 
 | ||||
| POUND_HEADER=('^"# SPDX-License-Identifier: LGPL-3.0-or-later"$' '^"# See Notices.txt for copyright information"$') | ||||
| SLASH_HEADER=('^"// SPDX-License-Identifier: LGPL-3.0-or-later"$' '^"// See Notices.txt for copyright information"$') | ||||
| MD_HEADER=('^"<!--"$' '^"SPDX-License-Identifier: LGPL-3.0-or-later"$' '^"See Notices.txt for copyright information"$') | ||||
| 
 | ||||
| function main() | ||||
| { | ||||
|     local IFS=$'\n' | ||||
|     [[ -z "$(git status --porcelain)" ]] || fail "git repo is dirty" | ||||
|     local file | ||||
|     for file in $(git ls-tree --name-only --full-tree -r HEAD); do | ||||
|         case "/$file" in | ||||
|         /Cargo.lock) | ||||
|             # generated file | ||||
|             ;; | ||||
|         */LICENSE.md|*/Notices.txt) | ||||
|             # copyright file | ||||
|             ;; | ||||
|         /.forgejo/workflows/*.yml|*/.gitignore|*.toml) | ||||
|             check_file "$file" "${POUND_HEADER[@]}" | ||||
|             ;; | ||||
|         *.md) | ||||
|             check_file "$file" "${MD_HEADER[@]}" | ||||
|             ;; | ||||
|         *.sh) | ||||
|             check_file "$file" '^'\''#!'\' "${POUND_HEADER[@]}" | ||||
|             ;; | ||||
|         *.rs) | ||||
|             check_file "$file" "${SLASH_HEADER[@]}" | ||||
|             ;; | ||||
|         *) | ||||
|             fail_file "$file" 0 "unimplemented file kind -- you need to add it to $0" | ||||
|             ;; | ||||
|         esac | ||||
|     done | ||||
| } | ||||
| 
 | ||||
| main | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue