(commit, target_files)
| 106 | # |
| 107 | # Check copyright dates for modified files |
| 108 | def VerifyCopyrights(commit, target_files): |
| 109 | retval = 0 |
| 110 | is_lunarg_author = False |
| 111 | authors = check_output(['git', 'log', '-n' , '1', '--format=%ae', commit]) |
| 112 | for author in authors.split(b'\n'): |
| 113 | if author.endswith(b'@lunarg.com'): |
| 114 | is_lunarg_author = True |
| 115 | break |
| 116 | |
| 117 | if not is_lunarg_author: |
| 118 | return 0 |
| 119 | |
| 120 | # Handle year changes by respecting when the author wrote the code, rather |
| 121 | # the day the script runs. This isn't exactly right yet, because really |
| 122 | # we should evaluate it commit's files against that commit's date. |
| 123 | commit_year = None |
| 124 | # get all the author dates in YYYY-MM-DD format |
| 125 | commit_dates = check_output(['git', 'log', '-n', '1', '--format=%as', commit]) |
| 126 | for cd in commit_dates.split(b'\n'): |
| 127 | if len(cd) == 0: |
| 128 | continue |
| 129 | year = cd.split(b'-')[0] |
| 130 | if not commit_year or int(commit_year) < int(year): |
| 131 | commit_year = year.decode('utf-8') |
| 132 | for file in target_files: |
| 133 | if file is None: |
| 134 | continue |
| 135 | file_path = repo_relative(file) |
| 136 | if not os.path.isfile(file_path): |
| 137 | continue |
| 138 | for company in ["LunarG", "Valve"]: |
| 139 | # Capture the last year on the line as a separate match. It should be the highest (or only year of the range) |
| 140 | copyright_match = re.search(r'Copyright .*(\d{4}) ' + company, open(file_path, encoding="utf-8", errors='ignore').read(1024)) |
| 141 | if copyright_match: |
| 142 | copyright_year = copyright_match.group(1) |
| 143 | if int(commit_year) > int(copyright_year): |
| 144 | msg = f'Change written in {commit_year} but copyright ends in {copyright_year}.' |
| 145 | CPrint('ERR_MSG', f'\n{file_path} has an out-of-date {company} copyright notice. {msg}') |
| 146 | retval = 1 |
| 147 | return retval |
| 148 | # |
| 149 | # |
| 150 | # Check commit message formats for commits in this PR/Branch |
no test coverage detected