From c05511413a6f900dcb6bd5c866d81c81c30b1cd1 Mon Sep 17 00:00:00 2001 From: Max Radermacher Date: Thu, 26 Mar 2026 19:21:14 -0500 Subject: [PATCH] Stop fixing license headers --- Scripts/lint/lint-license-headers | 103 ++++-------------- Scripts/precommit.py | 2 +- .../Protos/Backups/Backup.pb.swift | 5 - .../Generated/CallQualitySurvey.pb.swift | 5 - .../Protos/Generated/DeviceTransfer.pb.swift | 5 - .../Protos/Generated/Fingerprint.pb.swift | 5 - .../Protos/Generated/Groups.pb.swift | 5 - .../Protos/Generated/Provisioning.pb.swift | 5 - .../Protos/Generated/Registration.pb.swift | 5 - .../Protos/Generated/SessionRecord.pb.swift | 5 - .../Protos/Generated/SignalIOS.pb.swift | 5 - .../Protos/Generated/SignalService.pb.swift | 5 - .../Protos/Generated/StorageService.pb.swift | 5 - .../Generated/WebSocketResources.pb.swift | 5 - .../Protos/Generated/svr2.pb.swift | 5 - 15 files changed, 21 insertions(+), 149 deletions(-) diff --git a/Scripts/lint/lint-license-headers b/Scripts/lint/lint-license-headers index f5de201277..7a76c91445 100755 --- a/Scripts/lint/lint-license-headers +++ b/Scripts/lint/lint-license-headers @@ -1,95 +1,39 @@ #!/usr/bin/env python3 -from functools import cache from pathlib import Path -from tempfile import mkstemp from typing import Iterable import argparse import re -import subprocess import sys -from util import EXTENSIONS_TO_CHECK - COPYRIGHT_LINE_RE = re.compile(r"^// Copyright 2\d\d\d Signal Messenger, LLC\n$") SPDX_LINE = "// SPDX-License-Identifier: AGPL-3.0-only\n" -def read_first_lines(line_count: int, path: Path) -> list[str]: - if line_count == 0: - return "" - result = [] - with open(path, "rt", encoding="utf8") as file: - for line in file: - result.append(line) - if len(result) >= line_count: - break - return result - - def has_shebang(line: str) -> bool: return line.startswith("#!") -def has_swift_tools_version(line: str) -> bool: - return line.startswith("// swift-tools-version:") - - -def is_first_line_important(line: str) -> bool: - return has_shebang(line) or has_swift_tools_version(line) - - def has_valid_license_header(path: Path) -> bool: - first_six_lines = read_first_lines(6, path) - if is_first_line_important(first_six_lines[0]): - lines_to_consider = first_six_lines[1:] - else: - lines_to_consider = first_six_lines[:-1] - return ( - (lines_to_consider[0] == "//\n") - and (COPYRIGHT_LINE_RE.match(lines_to_consider[1]) is not None) - and (lines_to_consider[2] == SPDX_LINE) - and (lines_to_consider[3] == "//\n") - and (lines_to_consider[4] == "\n") - ) + copyright_len = 0 + license_len = 0 + with open(path, "rt", encoding="utf8") as file: + for line in file: + if has_shebang(line): + continue + if len(line.rstrip()) == 0: + continue + if COPYRIGHT_LINE_RE.match(line) is not None: + copyright_len += 1 + continue + if line == SPDX_LINE: + license_len += 1 + continue + if line.startswith("//"): + continue + break -@cache -def get_staging_file_path() -> Path: - path_str = mkstemp(prefix="signal-ios-license-staging-file-")[1] - return Path(path_str) - - -def get_creation_year_for(path: Path) -> str: - dates_changed = subprocess.check_output( - ["git", "log", "--follow", "--format=%as", "--date=short", path.resolve()], - text=True, - ).splitlines() - return dates_changed[-1][0:4] - - -def lines_with_license_header_added(path: Path) -> Iterable[str]: - with open(path, "rt", encoding="utf8") as source_file: - for index, line in enumerate(source_file): - if index == 0: - if is_first_line_important(line): - yield line - yield "//\n" - yield f"// Copyright {get_creation_year_for(path)} Signal Messenger, LLC\n" - yield SPDX_LINE - yield "//\n" - yield "\n" - if not is_first_line_important(line): - yield line - else: - yield line - - -def add_license_header_to(path: Path) -> None: - staging_file_path = get_staging_file_path() - with open(staging_file_path, "wt", encoding="utf8") as staging_file: - for line in lines_with_license_header_added(path): - staging_file.write(line) - staging_file_path.replace(path) + return copyright_len == 1 and license_len == 1 def main() -> None: @@ -97,21 +41,14 @@ def main() -> None: description="Check license headers across the project" ) parser.add_argument("path", nargs="*", help="A path to process") - parser.add_argument( - "--fix", action="store_true", help="Attempt to auto-add license headers" - ) ns = parser.parse_args() - should_fix = ns.fix all_good = True for path in ns.path: path = Path(path) if not has_valid_license_header(path): - if should_fix: - add_license_header_to(path) - else: - print(f"{path} has an invalid license header", file=sys.stderr) - all_good = False + print(f"{path} has an invalid license header", file=sys.stderr) + all_good = False if not all_good: sys.exit(1) diff --git a/Scripts/precommit.py b/Scripts/precommit.py index f82d4006ee..d9dc0eb268 100755 --- a/Scripts/precommit.py +++ b/Scripts/precommit.py @@ -220,7 +220,7 @@ if __name__ == "__main__": result = True print("Checking license headers...", flush=True) - proc = subprocess.run(["Scripts/lint/lint-license-headers", "--fix", *file_paths]) + proc = subprocess.run(["Scripts/lint/lint-license-headers", *file_paths]) if proc.returncode != 0: result = False print("") diff --git a/SignalServiceKit/Protos/Backups/Backup.pb.swift b/SignalServiceKit/Protos/Backups/Backup.pb.swift index fb5651fb85..e48dbf749a 100644 --- a/SignalServiceKit/Protos/Backups/Backup.pb.swift +++ b/SignalServiceKit/Protos/Backups/Backup.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2024 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/CallQualitySurvey.pb.swift b/SignalServiceKit/Protos/Generated/CallQualitySurvey.pb.swift index 4cc20d2edc..f2181293cb 100644 --- a/SignalServiceKit/Protos/Generated/CallQualitySurvey.pb.swift +++ b/SignalServiceKit/Protos/Generated/CallQualitySurvey.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2026 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/DeviceTransfer.pb.swift b/SignalServiceKit/Protos/Generated/DeviceTransfer.pb.swift index 0d73579cb7..c7696d454f 100644 --- a/SignalServiceKit/Protos/Generated/DeviceTransfer.pb.swift +++ b/SignalServiceKit/Protos/Generated/DeviceTransfer.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2020 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/Fingerprint.pb.swift b/SignalServiceKit/Protos/Generated/Fingerprint.pb.swift index 8057bb1d52..cd91580760 100644 --- a/SignalServiceKit/Protos/Generated/Fingerprint.pb.swift +++ b/SignalServiceKit/Protos/Generated/Fingerprint.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2018 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/Groups.pb.swift b/SignalServiceKit/Protos/Generated/Groups.pb.swift index c27bf61b92..abf3c2a3c1 100644 --- a/SignalServiceKit/Protos/Generated/Groups.pb.swift +++ b/SignalServiceKit/Protos/Generated/Groups.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2019 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/Provisioning.pb.swift b/SignalServiceKit/Protos/Generated/Provisioning.pb.swift index 7f4d8b6934..15707adfa3 100644 --- a/SignalServiceKit/Protos/Generated/Provisioning.pb.swift +++ b/SignalServiceKit/Protos/Generated/Provisioning.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2018 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/Registration.pb.swift b/SignalServiceKit/Protos/Generated/Registration.pb.swift index 244b758072..9a4b8da3ae 100644 --- a/SignalServiceKit/Protos/Generated/Registration.pb.swift +++ b/SignalServiceKit/Protos/Generated/Registration.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2025 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/SessionRecord.pb.swift b/SignalServiceKit/Protos/Generated/SessionRecord.pb.swift index 67f1a04841..c8cd2e4be1 100644 --- a/SignalServiceKit/Protos/Generated/SessionRecord.pb.swift +++ b/SignalServiceKit/Protos/Generated/SessionRecord.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2020 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/SignalIOS.pb.swift b/SignalServiceKit/Protos/Generated/SignalIOS.pb.swift index 666ae06329..bc7934b230 100644 --- a/SignalServiceKit/Protos/Generated/SignalIOS.pb.swift +++ b/SignalServiceKit/Protos/Generated/SignalIOS.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2018 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/SignalService.pb.swift b/SignalServiceKit/Protos/Generated/SignalService.pb.swift index 743bd53b8d..abf695adff 100644 --- a/SignalServiceKit/Protos/Generated/SignalService.pb.swift +++ b/SignalServiceKit/Protos/Generated/SignalService.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2018 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/StorageService.pb.swift b/SignalServiceKit/Protos/Generated/StorageService.pb.swift index 3e2b0ed07c..3d1cf526d7 100644 --- a/SignalServiceKit/Protos/Generated/StorageService.pb.swift +++ b/SignalServiceKit/Protos/Generated/StorageService.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2019 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/WebSocketResources.pb.swift b/SignalServiceKit/Protos/Generated/WebSocketResources.pb.swift index 781645bc7d..71b211fc75 100644 --- a/SignalServiceKit/Protos/Generated/WebSocketResources.pb.swift +++ b/SignalServiceKit/Protos/Generated/WebSocketResources.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2018 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all diff --git a/SignalServiceKit/Protos/Generated/svr2.pb.swift b/SignalServiceKit/Protos/Generated/svr2.pb.swift index fc51d9b456..7b0b5ff053 100644 --- a/SignalServiceKit/Protos/Generated/svr2.pb.swift +++ b/SignalServiceKit/Protos/Generated/svr2.pb.swift @@ -1,8 +1,3 @@ -// -// Copyright 2023 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only -// - // DO NOT EDIT. // swift-format-ignore-file // swiftlint:disable all