|
4 | 4 | import hashlib
|
5 | 5 | import json
|
6 | 6 | import glob
|
7 |
| -import pathlib |
| 7 | +from pathlib import Path, PurePosixPath, PureWindowsPath |
8 | 8 | import subprocess
|
9 | 9 | import sys
|
10 | 10 | import urllib.request
|
11 | 11 | import typing
|
12 | 12 |
|
13 |
| -CPYTHON_ROOT_DIR = pathlib.Path(__file__).parent.parent.parent |
| 13 | +CPYTHON_ROOT_DIR = Path(__file__).parent.parent.parent |
14 | 14 |
|
15 | 15 | # Before adding a new entry to this list, double check that
|
16 | 16 | # the license expression is a valid SPDX license expression:
|
@@ -119,9 +119,16 @@ def filter_gitignored_paths(paths: list[str]) -> list[str]:
|
119 | 119 | # 1 means matches, 0 means no matches.
|
120 | 120 | assert git_check_ignore_proc.returncode in (0, 1)
|
121 | 121 |
|
| 122 | + # Paths may or may not be quoted, Windows quotes paths. |
| 123 | + git_check_ignore_re = re.compile(r"^::\s+(\"([^\"]+)\"|(.+))\Z") |
| 124 | + |
122 | 125 | # Return the list of paths sorted
|
123 | 126 | git_check_ignore_lines = git_check_ignore_proc.stdout.decode().splitlines()
|
124 |
| - return sorted([line.split()[-1] for line in git_check_ignore_lines if line.startswith("::")]) |
| 127 | + git_check_not_ignored = [] |
| 128 | + for line in git_check_ignore_lines: |
| 129 | + if match := git_check_ignore_re.fullmatch(line): |
| 130 | + git_check_not_ignored.append(match.group(2) or match.group(3)) |
| 131 | + return sorted(git_check_not_ignored) |
125 | 132 |
|
126 | 133 |
|
127 | 134 | def get_externals() -> list[str]:
|
@@ -238,12 +245,20 @@ def create_source_sbom() -> None:
|
238 | 245 | )
|
239 | 246 |
|
240 | 247 | for path in paths:
|
| 248 | + |
| 249 | + # Normalize the filename from any combination of slashes. |
| 250 | + path = str(PurePosixPath(PureWindowsPath(path))) |
| 251 | + |
241 | 252 | # Skip directories and excluded files
|
242 | 253 | if not (CPYTHON_ROOT_DIR / path).is_file() or path in exclude:
|
243 | 254 | continue
|
244 | 255 |
|
245 | 256 | # SPDX requires SHA1 to be used for files, but we provide SHA256 too.
|
246 | 257 | data = (CPYTHON_ROOT_DIR / path).read_bytes()
|
| 258 | + # We normalize line-endings for consistent checksums. |
| 259 | + # This is a rudimentary check for binary files. |
| 260 | + if b"\x00" not in data: |
| 261 | + data = data.replace(b"\r\n", b"\n") |
247 | 262 | checksum_sha1 = hashlib.sha1(data).hexdigest()
|
248 | 263 | checksum_sha256 = hashlib.sha256(data).hexdigest()
|
249 | 264 |
|
|
0 commit comments