| 1 |
|
| 2 |
|
| 3 |
import sys |
| 4 |
import glob |
| 5 |
|
| 6 |
correct_licence = """\ |
| 7 |
|
| 8 |
// Copyright Catch2 Authors |
| 9 |
// Distributed under the Boost Software License, Version 1.0. |
| 10 |
// (See accompanying file LICENSE.txt or copy at |
| 11 |
// https://www.boost.org/LICENSE_1_0.txt) |
| 12 |
|
| 13 |
// SPDX-License-Identifier: BSL-1.0 |
| 14 |
""" |
| 15 |
|
| 16 |
def check_licence_in_file(filename: str) -> bool: |
| 17 |
with open(filename, 'r') as f: |
| 18 |
file_preamble = ''.join(f.readlines()[:7]) |
| 19 |
|
| 20 |
if correct_licence != file_preamble: |
| 21 |
print('File {} does not have proper licence'.format(filename)) |
| 22 |
return False |
| 23 |
return True |
| 24 |
|
| 25 |
def check_licences_in_path(path: str) -> int: |
| 26 |
failed = 0 |
| 27 |
files_to_check = glob.glob(path + '/**/*.cpp', recursive=True) \ |
| 28 |
+ glob.glob(path + '/**/*.hpp', recursive=True) |
| 29 |
for file in files_to_check: |
| 30 |
if not check_licence_in_file(file): |
| 31 |
failed += 1 |
| 32 |
return failed |
| 33 |
|
| 34 |
def check_licences(): |
| 35 |
failed = 0 |
| 36 |
roots = ['src/catch2', 'tests'] |
| 37 |
for root in roots: |
| 38 |
failed += check_licences_in_path(root) |
| 39 |
|
| 40 |
if failed: |
| 41 |
print('{} files are missing licence'.format(failed)) |
| 42 |
sys.exit(1) |
| 43 |
|
| 44 |
if __name__ == "__main__": |
| 45 |
check_licences() |