From d5ed5837e588b4481daf85e94b25408699823d1c Mon Sep 17 00:00:00 2001 From: Misha Chornyi <99709299+mc-nv@users.noreply.github.com> Date: Fri, 17 Jul 2026 22:20:37 -0700 Subject: [PATCH 1/2] ci: Remove SPDX pre-commit hook Drop the local add-spdx-license hook and its tools/add_spdx_header.py script. Existing two-line SPDX headers remain valid: the centralized add-license hook maintains the copyright year on the string both header forms share. --- .pre-commit-config.yaml | 17 ----- tools/add_spdx_header.py | 157 --------------------------------------- 2 files changed, 174 deletions(-) delete mode 100644 tools/add_spdx_header.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b59184680a..e692186006 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,20 +54,3 @@ repos: rev: v0.1.0 hooks: - id: add-license -- repo: local - hooks: - # Incremental SPDX-header adoption: migrate each source file to the two-line - # SPDX header the first time it is touched. pre-commit runs hooks only on the - # files staged in a commit, so scoping by file type (below) -- not by directory - # -- rolls SPDX out gradually as files change. The hook maintains an existing - # SPDX header, replaces a legacy long-form NVIDIA BSD header in place, or - # inserts one. It runs after add-license above, which only maintains the - # copyright year on the string both headers share. - - id: add-spdx-license - name: Add SPDX License Header - entry: python tools/add_spdx_header.py - language: python - files: \.(py|pyi|sh|bash|yaml|yml|cc|cpp|cxx|h|hpp|cu|cuh)$ - stages: [pre-commit] - verbose: true - require_serial: true diff --git a/tools/add_spdx_header.py b/tools/add_spdx_header.py deleted file mode 100644 index f78b90b758..0000000000 --- a/tools/add_spdx_header.py +++ /dev/null @@ -1,157 +0,0 @@ -# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause - -"""Insert / maintain / migrate to an SPDX license header on source files. - -Pre-commit hook that adopts the two-line SPDX header on every file it is run -against. Because pre-commit runs hooks on the files staged in a commit, scoping -this hook by file type (rather than by directory) migrates each source file to -SPDX *the first time it is touched* -- a low-risk, incremental rollout. - -The header uses a copyright *year range*, mirroring the repo convention (the -``LICENSE`` file and ``add_copyright.py`` use ``-``):: - - # SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. - # SPDX-License-Identifier: BSD-3-Clause - -Per file, the hook does exactly one of: - -* **Maintain** -- already SPDX: bump the copyright end year to the current year. -* **Migrate** -- carries the legacy long-form NVIDIA BSD header: replace that - whole block in place with the two SPDX lines, preserving the comment style - (``#`` or ``//``), the shebang, and the block's start year. -* **Insert** -- no NVIDIA header: add the SPDX header (after a shebang if any). - -Idempotent, and coexists with ``add_copyright.py`` (which runs first and only -maintains the copyright year on the legacy/SPDX string it recognizes). -""" - -import os -import re -import sys -from datetime import datetime - -ROOT_DIR = os.path.join(os.path.dirname(__file__), os.pardir) -LICENSE_PATH = os.path.join(ROOT_DIR, "LICENSE") -CURRENT_YEAR = str(datetime.now().year) - -_SPDX_MARKER = "SPDX-License-Identifier" -_LICENSE_ID = "BSD-3-Clause" - -# Start year of the project-wide LICENSE (used only when inserting into a file -# that has no NVIDIA copyright at all). -_LICENSE_YEAR_PAT = re.compile(r"Copyright \(c\) (\d{4})(?:-\d{4})?, NVIDIA") -# Existing SPDX copyright line (for year maintenance). -_SPDX_YEAR_PAT = re.compile( - r"(SPDX-FileCopyrightText: Copyright \(c\) )(\d{4})(?:-\d{4})?(, NVIDIA)" -) -# First line of a legacy long-form NVIDIA BSD header (captures comment prefix + -# start year). The block ends at the standard BSD "SUCH DAMAGE" line. -_LEGACY_COPY_PAT = re.compile( - r"^(#|//) ?Copyright(?: \(c\))? (\d{4})(?:-\d{4})?,? NVIDIA CORPORATION" -) -_LEGACY_END_MARK = "POSSIBILITY OF SUCH DAMAGE" - -_CPP_EXTS = (".cc", ".cpp", ".cxx", ".h", ".hpp", ".cu", ".cuh") - - -def _year_range(start): - return start if start == CURRENT_YEAR else "{}-{}".format(start, CURRENT_YEAR) - - -def _license_start_year(): - try: - with open(LICENSE_PATH, "r", encoding="utf-8") as f: - match = _LICENSE_YEAR_PAT.search(f.read()) - if match: - return match.group(1) - except OSError: - # LICENSE not readable here; fall through to the current-year default. - pass - return CURRENT_YEAR - - -def _spdx_lines(prefix, years): - return ( - "{p} SPDX-FileCopyrightText: Copyright (c) {y}, NVIDIA CORPORATION " - "& AFFILIATES. All rights reserved.\n" - "{p} SPDX-License-Identifier: {lic}\n".format( - p=prefix, y=years, lic=_LICENSE_ID - ) - ) - - -def _maintain(content): - def _bump(match): - return match.group(1) + _year_range(match.group(2)) + match.group(3) - - return _SPDX_YEAR_PAT.sub(_bump, content) - - -def _migrate_legacy(content): - """Replace a legacy long-form NVIDIA BSD header with the SPDX lines. Returns - the new content, or None if no legacy header is found.""" - lines = content.splitlines(keepends=True) - start = prefix = start_year = None - for i, line in enumerate(lines): - match = _LEGACY_COPY_PAT.match(line) - if match: - start, prefix, start_year = i, match.group(1), match.group(2) - break - if start is None: - return None - end = None - for j in range(start, len(lines)): - if _LEGACY_END_MARK in lines[j]: - end = j - break - if end is None: - return None - header = _spdx_lines(prefix, _year_range(start_year)) - return "".join(lines[:start]) + header + "".join(lines[end + 1 :]) - - -def _insert(path, content): - prefix = "//" if path.endswith(_CPP_EXTS) else "#" - header = _spdx_lines(prefix, _year_range(_license_start_year())) + "\n" - lines = content.splitlines(keepends=True) - if lines and lines[0].startswith("#!"): - return lines[0] + header + "".join(lines[1:]) - return header + content - - -def process(path): - """Bring ``path`` to an SPDX header (maintain/migrate/insert). Returns True if - the file was modified.""" - try: - with open(path, "r", encoding="utf-8") as f: - content = f.read() - except (OSError, UnicodeDecodeError): - return False - - if _SPDX_MARKER in content: - updated = _maintain(content) - else: - updated = _migrate_legacy(content) - if updated is None: - updated = _insert(path, content) - - if updated == content: - return False - with open(path, "w", encoding="utf-8") as f: - f.write(updated) - return True - - -def main(argv): - changed = False - for path in argv[1:]: - if process(path): - print("Updated SPDX header: {}".format(path)) - changed = True - # Non-zero exit tells pre-commit the file was modified so it re-stages. - return 1 if changed else 0 - - -if __name__ == "__main__": - sys.exit(main(sys.argv)) From 82cf9596187d9d36680394c4bc0bf44024cedca7 Mon Sep 17 00:00:00 2001 From: Misha Chornyi <99709299+mc-nv@users.noreply.github.com> Date: Fri, 17 Jul 2026 22:26:39 -0700 Subject: [PATCH 2/2] ci: Replace SPDX headers with LICENSE header Restore the long-form BSD LICENSE header on the files that were migrated to (or created with) the two-line SPDX header, preserving each file's copyright year range. --- .pre-commit-config.yaml | 27 +++++++++++++++++++++-- build.py | 27 +++++++++++++++++++++-- qa/L2_build_presets/README.md | 27 +++++++++++++++++++++-- qa/L2_build_presets/build_presets_test.py | 27 +++++++++++++++++++++-- qa/L2_build_presets/test.sh | 27 +++++++++++++++++++++-- tools/build/build_presets.py | 27 +++++++++++++++++++++-- 6 files changed, 150 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e692186006..45de7708f2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,28 @@ -# SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. repos: - repo: https://github.com/PyCQA/isort diff --git a/build.py b/build.py index b473b76739..a497a527cf 100755 --- a/build.py +++ b/build.py @@ -1,6 +1,29 @@ #!/usr/bin/env python3 -# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import argparse import importlib.util diff --git a/qa/L2_build_presets/README.md b/qa/L2_build_presets/README.md index 870e1864d5..77e239ce75 100644 --- a/qa/L2_build_presets/README.md +++ b/qa/L2_build_presets/README.md @@ -1,6 +1,29 @@ # L2_build_presets diff --git a/qa/L2_build_presets/build_presets_test.py b/qa/L2_build_presets/build_presets_test.py index 30c24c9cbd..b1e0c0a88e 100644 --- a/qa/L2_build_presets/build_presets_test.py +++ b/qa/L2_build_presets/build_presets_test.py @@ -1,5 +1,28 @@ -# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Validate the documented experimental build-presets scenarios. diff --git a/qa/L2_build_presets/test.sh b/qa/L2_build_presets/test.sh index 329c100aea..db537cf785 100755 --- a/qa/L2_build_presets/test.sh +++ b/qa/L2_build_presets/test.sh @@ -1,6 +1,29 @@ #!/bin/bash -# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # Validate the documented build-presets scenarios via build.py --dryrun (no GPU, # container, or real build). Runs from the server source tree; see README.md. diff --git a/tools/build/build_presets.py b/tools/build/build_presets.py index 1e7788feee..6177430469 100644 --- a/tools/build/build_presets.py +++ b/tools/build/build_presets.py @@ -1,5 +1,28 @@ -# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of NVIDIA CORPORATION nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Experimental build presets for build.py.