From e5d80bc0b1e93239364fd283ae1292baa936073b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 17 Sep 2026 14:06:31 +0200 Subject: [PATCH 1/3] Add Apache 2.0 licensing and enforce SPDX headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- LICENSE | 202 ++++++++++++++++++ Makefile | 6 +- README.md | 4 + client/client.go | 3 + client/client_test.go | 3 + clientpoint/clientpoint.go | 3 + cmd/mobyextgen/descriptor.go | 3 + cmd/mobyextgen/generation_test.go | 3 + cmd/mobyextgen/main.go | 3 + cmd/mobyextgen/model.go | 3 + cmd/mobyextgen/names.go | 3 + cmd/mobyextgen/names_test.go | 3 + cmd/mobyextgen/parse.go | 3 + cmd/mobyextgen/parse_test.go | 3 + cmd/mobyextgen/proto.go | 3 + cmd/mobyextgen/testdata/singlemsg/contract.go | 3 + cmd/mobyextgen/wire.go | 3 + core.go | 3 + core_test.go | 3 + example/greeter/v0/greeter.go | 3 + extpoints/service/v0/service.go | 3 + extpoints/service/v0/service_test.go | 3 + fanout.go | 3 + fanout_test.go | 3 + grpcproxy/proxy.go | 3 + grpcproxy/proxy_test.go | 3 + grpcproxy/routes_test.go | 3 + hack/lint-license.sh | 23 ++ host/dependency_test.go | 3 + host/host.go | 3 + host/host_internal_test.go | 3 + host/options_test.go | 3 + host/socket_test.go | 3 + host/testdata/lifecycle/main.go | 3 + internal/broker/broker.go | 3 + internal/broker/broker_test.go | 3 + internal/extensiondecl/declaration.go | 3 + internal/extensiondecl/declaration_test.go | 3 + internal/launcher/declarations.go | 3 + internal/launcher/discovery.go | 3 + internal/launcher/echo/v1/echo.go | 3 + internal/launcher/launcher.go | 3 + internal/launcher/launcher_test.go | 3 + internal/launcher/owner_other.go | 3 + internal/launcher/owner_unix.go | 3 + internal/launcher/owner_windows.go | 3 + internal/launcher/process_linux.go | 3 + internal/launcher/process_linux_test.go | 3 + internal/launcher/process_other.go | 3 + internal/launcher/process_unix.go | 3 + internal/launcher/process_unix_nonlinux.go | 3 + internal/launcher/process_unix_test.go | 3 + internal/launcher/process_windows.go | 3 + internal/launcher/process_windows_test.go | 3 + internal/launcher/shutdown.go | 3 + internal/launcher/shutdown_test.go | 3 + internal/launcher/signal_other.go | 3 + internal/launcher/signal_unix.go | 3 + internal/launcher/signal_windows.go | 3 + internal/launcher/testdata/exthook/main.go | 3 + internal/testutils/staticresolver.go | 3 + internal/testutils/staticresolver_test.go | 3 + sdk/callback.go | 3 + sdk/internal/dependencyresolver/resolver.go | 3 + .../dependencyresolver/resolver_test.go | 3 + sdk/main.go | 3 + sdk/protocol.go | 3 + sdk/registration.go | 3 + sdk/runtime.go | 3 + sdk/sdk.go | 3 + sdk/sdk_test.go | 3 + sdk/sdkapi/runtime.go | 3 + sdk/sdkapi/runtime_test.go | 3 + sdk/serve.go | 3 + serverpoint/serverpoint.go | 3 + servicegrpc/servicegrpc.go | 3 + servicegrpc/servicegrpc_test.go | 3 + testdata/greeter/cmd/greeter/main.go | 3 + testdata/greeter/greeter.go | 3 + testdata/greeterdep/cmd/greeterdep/main.go | 3 + testdata/greeterdep/greeterdep.go | 3 + 81 files changed, 465 insertions(+), 1 deletion(-) create mode 100644 LICENSE create mode 100644 hack/lint-license.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile index 69d20c3..787bd0a 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ LINT_IMAGE ?= golang:$(GO_VERSION) ci: lint validate .PHONY: lint -lint: +lint: lint-license @if [ -z "$(GO_VERSION)" ] || \ [ -z "$(ACTIONLINT_VERSION)" ] || \ [ -z "$(MODERNIZE_VERSION)" ] || \ @@ -38,6 +38,10 @@ lint: $(LINT_IMAGE) \ make host-lint +.PHONY: lint-license +lint-license: + bash hack/lint-license.sh + .PHONY: host-lint host-lint: $(GO) run github.com/rhysd/actionlint/cmd/actionlint@$(ACTIONLINT_VERSION) diff --git a/README.md b/README.md index a5c5fdb..96d68b2 100644 --- a/README.md +++ b/README.md @@ -373,3 +373,7 @@ extension API. - The mental model, principles, authoring flow, and glossary provide the short normative rules and definitions. - [DESIGN.md](./docs/DESIGN.md) - current behavior, constraints, wire protocol, and discovery security. - [AUTHORING.md](./docs/AUTHORING.md) - procedures, commands, code, and checklists. + +## License + +Licensed under the [Apache License, Version 2.0](LICENSE). diff --git a/client/client.go b/client/client.go index e42a230..78b1082 100644 --- a/client/client.go +++ b/client/client.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package client provides typed, lazy clients for extension points. // // Generated wire bindings expose a ClientPoint registration containing the diff --git a/client/client_test.go b/client/client_test.go index ff164c4..0efa757 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package client import ( diff --git a/clientpoint/clientpoint.go b/clientpoint/clientpoint.go index 30f8667..7ea34d6 100644 --- a/clientpoint/clientpoint.go +++ b/clientpoint/clientpoint.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package clientpoint defines the host-side registration for generated // out-of-process point providers. It has no dependency on the host runtime so // generated code can reference it. diff --git a/cmd/mobyextgen/descriptor.go b/cmd/mobyextgen/descriptor.go index 8156f9c..46e8496 100644 --- a/cmd/mobyextgen/descriptor.go +++ b/cmd/mobyextgen/descriptor.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import ( diff --git a/cmd/mobyextgen/generation_test.go b/cmd/mobyextgen/generation_test.go index 15ad884..97daaf2 100644 --- a/cmd/mobyextgen/generation_test.go +++ b/cmd/mobyextgen/generation_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import ( diff --git a/cmd/mobyextgen/main.go b/cmd/mobyextgen/main.go index 5b4dc24..069ca64 100644 --- a/cmd/mobyextgen/main.go +++ b/cmd/mobyextgen/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Command mobyextgen generates an extension point or service's wire contract // and transport code from a Go interface and pb-tagged message structs. // diff --git a/cmd/mobyextgen/model.go b/cmd/mobyextgen/model.go index a3abf59..05f5642 100644 --- a/cmd/mobyextgen/model.go +++ b/cmd/mobyextgen/model.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main // model diff --git a/cmd/mobyextgen/names.go b/cmd/mobyextgen/names.go index fd6c218..ff462d1 100644 --- a/cmd/mobyextgen/names.go +++ b/cmd/mobyextgen/names.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import "strings" diff --git a/cmd/mobyextgen/names_test.go b/cmd/mobyextgen/names_test.go index d1e723e..7e29316 100644 --- a/cmd/mobyextgen/names_test.go +++ b/cmd/mobyextgen/names_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import ( diff --git a/cmd/mobyextgen/parse.go b/cmd/mobyextgen/parse.go index 1edc5c1..82006f0 100644 --- a/cmd/mobyextgen/parse.go +++ b/cmd/mobyextgen/parse.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import ( diff --git a/cmd/mobyextgen/parse_test.go b/cmd/mobyextgen/parse_test.go index 1fe591d..fcb52e1 100644 --- a/cmd/mobyextgen/parse_test.go +++ b/cmd/mobyextgen/parse_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import ( diff --git a/cmd/mobyextgen/proto.go b/cmd/mobyextgen/proto.go index fc01178..262c3e6 100644 --- a/cmd/mobyextgen/proto.go +++ b/cmd/mobyextgen/proto.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import ( diff --git a/cmd/mobyextgen/testdata/singlemsg/contract.go b/cmd/mobyextgen/testdata/singlemsg/contract.go index 29ec763..f8bcc31 100644 --- a/cmd/mobyextgen/testdata/singlemsg/contract.go +++ b/cmd/mobyextgen/testdata/singlemsg/contract.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package singlemsg is a mobyextgen fixture for a single embedded message. package singlemsg diff --git a/cmd/mobyextgen/wire.go b/cmd/mobyextgen/wire.go index f52bc09..a75d639 100644 --- a/cmd/mobyextgen/wire.go +++ b/cmd/mobyextgen/wire.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package main import ( diff --git a/core.go b/core.go index d80d965..39af0b0 100644 --- a/core.go +++ b/core.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package extensions import ( diff --git a/core_test.go b/core_test.go index 3065f76..430776b 100644 --- a/core_test.go +++ b/core_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package extensions import ( diff --git a/example/greeter/v0/greeter.go b/example/greeter/v0/greeter.go index 5d7c3f4..222d7dd 100644 --- a/example/greeter/v0/greeter.go +++ b/example/greeter/v0/greeter.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:generate go run github.com/moby/extensions/cmd/mobyextgen // Package greeterv0 is an example service point used to exercise socket diff --git a/extpoints/service/v0/service.go b/extpoints/service/v0/service.go index e318d36..147a790 100644 --- a/extpoints/service/v0/service.go +++ b/extpoints/service/v0/service.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package servicev0 defines metadata through which extensions offer ordinary // Points for Host-controlled publication. package servicev0 diff --git a/extpoints/service/v0/service_test.go b/extpoints/service/v0/service_test.go index 6d01ad6..6feafed 100644 --- a/extpoints/service/v0/service_test.go +++ b/extpoints/service/v0/service_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package servicev0 import ( diff --git a/fanout.go b/fanout.go index 3c2c15a..6cdb69c 100644 --- a/fanout.go +++ b/fanout.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package extensions import ( diff --git a/fanout_test.go b/fanout_test.go index dfc0d2c..9db3c08 100644 --- a/fanout_test.go +++ b/fanout_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package extensions import ( diff --git a/grpcproxy/proxy.go b/grpcproxy/proxy.go index 69205d4..a597e99 100644 --- a/grpcproxy/proxy.go +++ b/grpcproxy/proxy.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package grpcproxy forwards gRPC calls by service name without importing the // service's proto. It is used to publish extension services on the daemon socket. package grpcproxy diff --git a/grpcproxy/proxy_test.go b/grpcproxy/proxy_test.go index 3211acd..bc773ad 100644 --- a/grpcproxy/proxy_test.go +++ b/grpcproxy/proxy_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package grpcproxy_test import ( diff --git a/grpcproxy/routes_test.go b/grpcproxy/routes_test.go index 592f8fb..e2c42ac 100644 --- a/grpcproxy/routes_test.go +++ b/grpcproxy/routes_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package grpcproxy import ( diff --git a/hack/lint-license.sh b/hack/lint-license.sh new file mode 100644 index 0000000..960c767 --- /dev/null +++ b/hack/lint-license.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright The Moby Authors +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +# Check tracked sources only; vendored code keeps its upstream licensing. +git ls-files -z -- '*.go' '*.sh' '*.proto' ':!:vendor/**' | ( + status=0 + while IFS= read -r -d '' path; do + if ! sed -n '1,5p' "$path" | grep -Eq '^(//|#) SPDX-FileCopyrightText: Copyright The Moby Authors[[:space:]]*$'; then + printf '%s: missing Moby copyright SPDX header in the first five lines\n' "$path" >&2 + status=1 + fi + if ! sed -n '1,5p' "$path" | grep -Eq '^(//|#) SPDX-License-Identifier: Apache-2\.0[[:space:]]*$'; then + printf '%s: missing Apache-2.0 SPDX header in the first five lines\n' "$path" >&2 + status=1 + fi + done + exit "$status" +) diff --git a/host/dependency_test.go b/host/dependency_test.go index 51b7c34..96fba40 100644 --- a/host/dependency_test.go +++ b/host/dependency_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package host_test import ( diff --git a/host/host.go b/host/host.go index 295c6b9..9fc083c 100644 --- a/host/host.go +++ b/host/host.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package host runs extensions and resolves their point providers for a host // process such as the Moby daemon. package host diff --git a/host/host_internal_test.go b/host/host_internal_test.go index 54a8478..b538497 100644 --- a/host/host_internal_test.go +++ b/host/host_internal_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package host import ( diff --git a/host/options_test.go b/host/options_test.go index 8328d55..f2aab83 100644 --- a/host/options_test.go +++ b/host/options_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package host_test import ( diff --git a/host/socket_test.go b/host/socket_test.go index 356954f..d0186ff 100644 --- a/host/socket_test.go +++ b/host/socket_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package host_test import ( diff --git a/host/testdata/lifecycle/main.go b/host/testdata/lifecycle/main.go index 7a2fbd2..bc5513a 100644 --- a/host/testdata/lifecycle/main.go +++ b/host/testdata/lifecycle/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Command lifecycle is an out-of-process extension fixture used by host // resource-ownership tests. package main diff --git a/internal/broker/broker.go b/internal/broker/broker.go index 1436d12..1adbc17 100644 --- a/internal/broker/broker.go +++ b/internal/broker/broker.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package broker import ( diff --git a/internal/broker/broker_test.go b/internal/broker/broker_test.go index 6fc6311..860f475 100644 --- a/internal/broker/broker_test.go +++ b/internal/broker/broker_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package broker import ( diff --git a/internal/extensiondecl/declaration.go b/internal/extensiondecl/declaration.go index b7b4213..3a00e7e 100644 --- a/internal/extensiondecl/declaration.go +++ b/internal/extensiondecl/declaration.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package extensiondecl converts and validates declarations reported by // externally hosted extensions. package extensiondecl diff --git a/internal/extensiondecl/declaration_test.go b/internal/extensiondecl/declaration_test.go index ae7ef95..dbf8fa1 100644 --- a/internal/extensiondecl/declaration_test.go +++ b/internal/extensiondecl/declaration_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package extensiondecl import ( diff --git a/internal/launcher/declarations.go b/internal/launcher/declarations.go index 9bca0af..3e3b7a4 100644 --- a/internal/launcher/declarations.go +++ b/internal/launcher/declarations.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/discovery.go b/internal/launcher/discovery.go index 53edc93..545a67f 100644 --- a/internal/launcher/discovery.go +++ b/internal/launcher/discovery.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/echo/v1/echo.go b/internal/launcher/echo/v1/echo.go index bb28523..c36363a 100644 --- a/internal/launcher/echo/v1/echo.go +++ b/internal/launcher/echo/v1/echo.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:generate go run github.com/moby/extensions/cmd/mobyextgen // Package echov1 is the minimal extension point used by launcher tests. diff --git a/internal/launcher/launcher.go b/internal/launcher/launcher.go index 3957629..47b4e85 100644 --- a/internal/launcher/launcher.go +++ b/internal/launcher/launcher.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/launcher_test.go b/internal/launcher/launcher_test.go index 65e2a82..663cb74 100644 --- a/internal/launcher/launcher_test.go +++ b/internal/launcher/launcher_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/owner_other.go b/internal/launcher/owner_other.go index 18395b4..c203324 100644 --- a/internal/launcher/owner_other.go +++ b/internal/launcher/owner_other.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build !unix && !windows package launcher diff --git a/internal/launcher/owner_unix.go b/internal/launcher/owner_unix.go index 55b5ea7..6483068 100644 --- a/internal/launcher/owner_unix.go +++ b/internal/launcher/owner_unix.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build unix package launcher diff --git a/internal/launcher/owner_windows.go b/internal/launcher/owner_windows.go index 1a19326..027bb86 100644 --- a/internal/launcher/owner_windows.go +++ b/internal/launcher/owner_windows.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import "io/fs" diff --git a/internal/launcher/process_linux.go b/internal/launcher/process_linux.go index d3ae625..47eaf04 100644 --- a/internal/launcher/process_linux.go +++ b/internal/launcher/process_linux.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/process_linux_test.go b/internal/launcher/process_linux_test.go index ef4d5a0..473ebf0 100644 --- a/internal/launcher/process_linux_test.go +++ b/internal/launcher/process_linux_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/process_other.go b/internal/launcher/process_other.go index d9444c3..a895bf0 100644 --- a/internal/launcher/process_other.go +++ b/internal/launcher/process_other.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build !unix && !windows package launcher diff --git a/internal/launcher/process_unix.go b/internal/launcher/process_unix.go index 10d8280..82bb893 100644 --- a/internal/launcher/process_unix.go +++ b/internal/launcher/process_unix.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build unix package launcher diff --git a/internal/launcher/process_unix_nonlinux.go b/internal/launcher/process_unix_nonlinux.go index da60c90..865c813 100644 --- a/internal/launcher/process_unix_nonlinux.go +++ b/internal/launcher/process_unix_nonlinux.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build unix && !linux package launcher diff --git a/internal/launcher/process_unix_test.go b/internal/launcher/process_unix_test.go index 1a1410b..58bcfd6 100644 --- a/internal/launcher/process_unix_test.go +++ b/internal/launcher/process_unix_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build unix package launcher diff --git a/internal/launcher/process_windows.go b/internal/launcher/process_windows.go index 26b7a80..dc91cf4 100644 --- a/internal/launcher/process_windows.go +++ b/internal/launcher/process_windows.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/process_windows_test.go b/internal/launcher/process_windows_test.go index b286b3d..15ea05a 100644 --- a/internal/launcher/process_windows_test.go +++ b/internal/launcher/process_windows_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/shutdown.go b/internal/launcher/shutdown.go index b8fbeb7..16d4afb 100644 --- a/internal/launcher/shutdown.go +++ b/internal/launcher/shutdown.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/shutdown_test.go b/internal/launcher/shutdown_test.go index 27ab36f..133dfef 100644 --- a/internal/launcher/shutdown_test.go +++ b/internal/launcher/shutdown_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import ( diff --git a/internal/launcher/signal_other.go b/internal/launcher/signal_other.go index c0254ef..40b93ad 100644 --- a/internal/launcher/signal_other.go +++ b/internal/launcher/signal_other.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build !unix && !windows package launcher diff --git a/internal/launcher/signal_unix.go b/internal/launcher/signal_unix.go index 0d26953..a7600b6 100644 --- a/internal/launcher/signal_unix.go +++ b/internal/launcher/signal_unix.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:build unix package launcher diff --git a/internal/launcher/signal_windows.go b/internal/launcher/signal_windows.go index 2bb80c4..a0da978 100644 --- a/internal/launcher/signal_windows.go +++ b/internal/launcher/signal_windows.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package launcher import "os" diff --git a/internal/launcher/testdata/exthook/main.go b/internal/launcher/testdata/exthook/main.go index 4bf4ea7..a936e6d 100644 --- a/internal/launcher/testdata/exthook/main.go +++ b/internal/launcher/testdata/exthook/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Command exthook is the out-of-process extension used by launcher tests. package main diff --git a/internal/testutils/staticresolver.go b/internal/testutils/staticresolver.go index dfe34d2..8eda690 100644 --- a/internal/testutils/staticresolver.go +++ b/internal/testutils/staticresolver.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package testutils provides test doubles for the extension framework. package testutils diff --git a/internal/testutils/staticresolver_test.go b/internal/testutils/staticresolver_test.go index f8855f1..1cdafd3 100644 --- a/internal/testutils/staticresolver_test.go +++ b/internal/testutils/staticresolver_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package testutils import ( diff --git a/sdk/callback.go b/sdk/callback.go index af85203..56766b8 100644 --- a/sdk/callback.go +++ b/sdk/callback.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import ( diff --git a/sdk/internal/dependencyresolver/resolver.go b/sdk/internal/dependencyresolver/resolver.go index 3ca62ca..da61651 100644 --- a/sdk/internal/dependencyresolver/resolver.go +++ b/sdk/internal/dependencyresolver/resolver.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package dependencyresolver resolves providers served through a gRPC // connection. package dependencyresolver diff --git a/sdk/internal/dependencyresolver/resolver_test.go b/sdk/internal/dependencyresolver/resolver_test.go index 59edb63..6ab28ad 100644 --- a/sdk/internal/dependencyresolver/resolver_test.go +++ b/sdk/internal/dependencyresolver/resolver_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package dependencyresolver import ( diff --git a/sdk/main.go b/sdk/main.go index 6025119..ea8bd46 100644 --- a/sdk/main.go +++ b/sdk/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import ( diff --git a/sdk/protocol.go b/sdk/protocol.go index 2896af9..4adaef0 100644 --- a/sdk/protocol.go +++ b/sdk/protocol.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import "github.com/moby/extensions" diff --git a/sdk/registration.go b/sdk/registration.go index 792b66e..0377dee 100644 --- a/sdk/registration.go +++ b/sdk/registration.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import ( diff --git a/sdk/runtime.go b/sdk/runtime.go index bc4a954..3284ea4 100644 --- a/sdk/runtime.go +++ b/sdk/runtime.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import ( diff --git a/sdk/sdk.go b/sdk/sdk.go index 98c873d..57e1539 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import ( diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index d7eb741..97ab43a 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import ( diff --git a/sdk/sdkapi/runtime.go b/sdk/sdkapi/runtime.go index 6d3ae63..e2d9fc0 100644 --- a/sdk/sdkapi/runtime.go +++ b/sdk/sdkapi/runtime.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + //go:generate go run github.com/moby/extensions/cmd/mobyextgen -service=moby.extension.runtime.v1.Extension // Package sdkapi defines the runtime protocol served by every out-of-process diff --git a/sdk/sdkapi/runtime_test.go b/sdk/sdkapi/runtime_test.go index 82c653c..b6bec30 100644 --- a/sdk/sdkapi/runtime_test.go +++ b/sdk/sdkapi/runtime_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdkapi_test import ( diff --git a/sdk/serve.go b/sdk/serve.go index 4236791..dfbb515 100644 --- a/sdk/serve.go +++ b/sdk/serve.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package sdk import ( diff --git a/serverpoint/serverpoint.go b/serverpoint/serverpoint.go index f1106d4..8a16f9a 100644 --- a/serverpoint/serverpoint.go +++ b/serverpoint/serverpoint.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package serverpoint defines the SDK-side registration for generated // out-of-process point providers. It has no dependency on the SDK server so // generated code can reference it. diff --git a/servicegrpc/servicegrpc.go b/servicegrpc/servicegrpc.go index 25885e9..96b14d8 100644 --- a/servicegrpc/servicegrpc.go +++ b/servicegrpc/servicegrpc.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package servicegrpc adapts published ordinary generated points to the gRPC // transport without replacing their generated handlers. package servicegrpc diff --git a/servicegrpc/servicegrpc_test.go b/servicegrpc/servicegrpc_test.go index 871de39..cdacd74 100644 --- a/servicegrpc/servicegrpc_test.go +++ b/servicegrpc/servicegrpc_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + package servicegrpc import ( diff --git a/testdata/greeter/cmd/greeter/main.go b/testdata/greeter/cmd/greeter/main.go index 24af4a7..4fa29a3 100644 --- a/testdata/greeter/cmd/greeter/main.go +++ b/testdata/greeter/cmd/greeter/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Command greeter serves the greeter fixture as an out-of-process extension // that opts into socket exposure, for the integration test. package main diff --git a/testdata/greeter/greeter.go b/testdata/greeter/greeter.go index 206955f..e043d45 100644 --- a/testdata/greeter/greeter.go +++ b/testdata/greeter/greeter.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package greeter is the socket-exposure integration-test fixture. package greeter diff --git a/testdata/greeterdep/cmd/greeterdep/main.go b/testdata/greeterdep/cmd/greeterdep/main.go index 5567bdc..0c6306a 100644 --- a/testdata/greeterdep/cmd/greeterdep/main.go +++ b/testdata/greeterdep/cmd/greeterdep/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Command greeterdep serves the greeterdep fixture as an out-of-process // extension that depends on the greeter point and calls it at init. package main diff --git a/testdata/greeterdep/greeterdep.go b/testdata/greeterdep/greeterdep.go index 160b735..748d15a 100644 --- a/testdata/greeterdep/greeterdep.go +++ b/testdata/greeterdep/greeterdep.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Package greeterdep is the out-of-process dependency-test fixture. package greeterdep From 587697f6a50a72273efee739a34016e77fb47ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 17 Sep 2026 14:06:54 +0200 Subject: [PATCH 2/3] cmd/mobyextgen: Preserve contract copyright and license notices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- cmd/mobyextgen/descriptor.go | 1 + cmd/mobyextgen/generation_test.go | 55 +++++++++++++++++++ cmd/mobyextgen/model.go | 21 +++---- cmd/mobyextgen/parse.go | 21 +++++++ cmd/mobyextgen/proto.go | 1 + cmd/mobyextgen/wire.go | 1 + example/greeter/v0/greeter.proto | 3 + example/greeter/v0/protogen/greeter.pb.go | 3 + example/greeter/v0/protogen/wire.gen.go | 3 + internal/launcher/echo/v1/echo.proto | 3 + internal/launcher/echo/v1/protogen/echo.pb.go | 3 + .../launcher/echo/v1/protogen/wire.gen.go | 3 + sdk/sdkapi/extension.proto | 3 + sdk/sdkapi/protogen/extension.pb.go | 3 + sdk/sdkapi/protogen/wire.gen.go | 3 + 15 files changed, 117 insertions(+), 10 deletions(-) diff --git a/cmd/mobyextgen/descriptor.go b/cmd/mobyextgen/descriptor.go index 46e8496..813bfd2 100644 --- a/cmd/mobyextgen/descriptor.go +++ b/cmd/mobyextgen/descriptor.go @@ -51,6 +51,7 @@ func emitMessages(pt point) ([]byte, error) { // Keep generated code aligned with the module's Go version until // protoc-gen-go emits reflect.TypeFor itself. content = strings.Replace(content, "reflect.TypeOf(x{}).PkgPath()", "reflect.TypeFor[x]().PkgPath()", 1) + content = pt.licenseHeader + content return []byte(content), nil } diff --git a/cmd/mobyextgen/generation_test.go b/cmd/mobyextgen/generation_test.go index 97daaf2..7997e9a 100644 --- a/cmd/mobyextgen/generation_test.go +++ b/cmd/mobyextgen/generation_test.go @@ -4,12 +4,67 @@ package main import ( + "os" + "path/filepath" "strings" "testing" "gotest.tools/v3/assert" ) +func TestGeneratedFilesInheritContractNotices(t *testing.T) { + t.Parallel() + for _, tc := range []struct { + name string + header string + }{ + { + name: "Moby notices", + header: "// SPDX-FileCopyrightText: Copyright The Moby Authors\n" + + "// SPDX-License-Identifier: Apache-2.0\n\n", + }, + { + name: "multiple copyright holders and another license expression", + header: "// SPDX-FileCopyrightText: Copyright Example Authors\n" + + "// SPDX-FileCopyrightText: Copyright Other Authors\n" + + "// SPDX-License-Identifier: MIT OR Apache-2.0\n\n", + }, + {name: "license only", header: "// SPDX-License-Identifier: Apache-2.0\n\n"}, + {name: "copyright only", header: "// SPDX-FileCopyrightText: Copyright Example Authors\n\n"}, + {name: "no notices"}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + dir := t.TempDir() + assert.NilError(t, os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module example.com/contract\n"), 0o644)) + const contract = `package contract + +// SPDX-FileCopyrightText: ignore comments after the package clause +// SPDX-License-Identifier: ignore comments after the package clause +type Runtime interface{ Do(ctx interface{}, req *Req) (*Resp, error) } +type Req struct{} +type Resp struct{} +` + assert.NilError(t, os.WriteFile(filepath.Join(dir, "contract.go"), []byte(tc.header+contract), 0o644)) + // A different file's notices must not override the interface's notices. + const other = `// SPDX-FileCopyrightText: Copyright Unrelated Authors +// SPDX-License-Identifier: BSD-3-Clause + +package contract +` + assert.NilError(t, os.WriteFile(filepath.Join(dir, "other.go"), []byte(other), 0o644)) + assert.NilError(t, run(dir, "example.contract.v1.Runtime")) + for _, name := range []string{"runtime.proto", "protogen/runtime.pb.go", "protogen/wire.gen.go"} { + content, err := os.ReadFile(filepath.Join(dir, name)) + assert.NilError(t, err) + header, _, ok := strings.Cut(string(content), "// Code generated") + assert.Assert(t, ok, "%s must have a generated code marker", name) + assert.Equal(t, header, tc.header, "%s must preserve only the contract notices", name) + } + }) + } +} + func TestSingleMessageField(t *testing.T) { pt, err := parsePoint("testdata/singlemsg") assert.NilError(t, err) diff --git a/cmd/mobyextgen/model.go b/cmd/mobyextgen/model.go index 05f5642..969ee4d 100644 --- a/cmd/mobyextgen/model.go +++ b/cmd/mobyextgen/model.go @@ -6,16 +6,17 @@ package main // model type point struct { - pkgName string // Go package name - importPath string // package import path - protoPath string // module-relative path of the .proto - id string // proto package: the point id, or the explicit package in service mode - service string // gRPC service name: the contract interface name - iface string // Go service interface name - isPoint bool // whether the contract declares an extensions.Point - isSingle bool // whether the point was declared with DefineSinglePoint - methods []method - messages []message + pkgName string // Go package name + importPath string // package import path + protoPath string // module-relative path of the .proto + licenseHeader string // SPDX notices from the contract interface's source file + id string // proto package: the point id, or the explicit package in service mode + service string // gRPC service name: the contract interface name + iface string // Go service interface name + isPoint bool // whether the contract declares an extensions.Point + isSingle bool // whether the point was declared with DefineSinglePoint + methods []method + messages []message } // grpcService returns the fully-qualified gRPC service name. diff --git a/cmd/mobyextgen/parse.go b/cmd/mobyextgen/parse.go index 82006f0..7675a74 100644 --- a/cmd/mobyextgen/parse.go +++ b/cmd/mobyextgen/parse.go @@ -77,6 +77,27 @@ func parseContract(dir, serviceIdentity string) (point, error) { if ifaceType == nil { return point{}, fmt.Errorf("interface %q not found", pt.iface) } + // Inherit the contract's copyright and license rather than imposing the + // generator's notices on output produced for other projects. + for _, f := range files { + if ifaceType.Pos() < f.Pos() || ifaceType.End() > f.End() { + continue + } + for _, group := range f.Comments { + if group.Pos() > f.Package { + break + } + for _, comment := range group.List { + if strings.HasPrefix(comment.Text, "// SPDX-FileCopyrightText:") || + strings.HasPrefix(comment.Text, "// SPDX-License-Identifier:") { + pt.licenseHeader += comment.Text + "\n" + } + } + } + } + if pt.licenseHeader != "" { + pt.licenseHeader += "\n" + } pt.methods, err = parseMethods(ifaceType) if err != nil { return point{}, err diff --git a/cmd/mobyextgen/proto.go b/cmd/mobyextgen/proto.go index 262c3e6..4a7423a 100644 --- a/cmd/mobyextgen/proto.go +++ b/cmd/mobyextgen/proto.go @@ -13,6 +13,7 @@ import ( func emitProto(pt point) ([]byte, error) { var b strings.Builder + b.WriteString(pt.licenseHeader) fmt.Fprintln(&b, "// Code generated by mobyextgen. DO NOT EDIT.") fmt.Fprintln(&b) fmt.Fprintln(&b, `syntax = "proto3";`) diff --git a/cmd/mobyextgen/wire.go b/cmd/mobyextgen/wire.go index a75d639..bfff345 100644 --- a/cmd/mobyextgen/wire.go +++ b/cmd/mobyextgen/wire.go @@ -16,6 +16,7 @@ func emitWire(pt point) ([]byte, error) { var b strings.Builder cpkg := pt.pkgName svc, iface := pt.service, pt.iface + b.WriteString(pt.licenseHeader) fmt.Fprintln(&b, "// Code generated by mobyextgen. DO NOT EDIT.") fmt.Fprintf(&b, "package %s\n\n", path.Base(pt.protogenImport())) fmt.Fprintln(&b, "import (") diff --git a/example/greeter/v0/greeter.proto b/example/greeter/v0/greeter.proto index 1caf36e..c153eb2 100644 --- a/example/greeter/v0/greeter.proto +++ b/example/greeter/v0/greeter.proto @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by mobyextgen. DO NOT EDIT. syntax = "proto3"; diff --git a/example/greeter/v0/protogen/greeter.pb.go b/example/greeter/v0/protogen/greeter.pb.go index 19e6448..6e46292 100644 --- a/example/greeter/v0/protogen/greeter.pb.go +++ b/example/greeter/v0/protogen/greeter.pb.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11-devel diff --git a/example/greeter/v0/protogen/wire.gen.go b/example/greeter/v0/protogen/wire.gen.go index dad7d6d..cc3f62c 100644 --- a/example/greeter/v0/protogen/wire.gen.go +++ b/example/greeter/v0/protogen/wire.gen.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by mobyextgen. DO NOT EDIT. package protogen diff --git a/internal/launcher/echo/v1/echo.proto b/internal/launcher/echo/v1/echo.proto index a546a9e..abbb3f3 100644 --- a/internal/launcher/echo/v1/echo.proto +++ b/internal/launcher/echo/v1/echo.proto @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by mobyextgen. DO NOT EDIT. syntax = "proto3"; diff --git a/internal/launcher/echo/v1/protogen/echo.pb.go b/internal/launcher/echo/v1/protogen/echo.pb.go index 503d410..124bc4e 100644 --- a/internal/launcher/echo/v1/protogen/echo.pb.go +++ b/internal/launcher/echo/v1/protogen/echo.pb.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11-devel diff --git a/internal/launcher/echo/v1/protogen/wire.gen.go b/internal/launcher/echo/v1/protogen/wire.gen.go index f2f797f..41f3760 100644 --- a/internal/launcher/echo/v1/protogen/wire.gen.go +++ b/internal/launcher/echo/v1/protogen/wire.gen.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by mobyextgen. DO NOT EDIT. package protogen diff --git a/sdk/sdkapi/extension.proto b/sdk/sdkapi/extension.proto index 4581ce5..0a8603b 100644 --- a/sdk/sdkapi/extension.proto +++ b/sdk/sdkapi/extension.proto @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by mobyextgen. DO NOT EDIT. syntax = "proto3"; diff --git a/sdk/sdkapi/protogen/extension.pb.go b/sdk/sdkapi/protogen/extension.pb.go index 6a9d829..8ed6c08 100644 --- a/sdk/sdkapi/protogen/extension.pb.go +++ b/sdk/sdkapi/protogen/extension.pb.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11-devel diff --git a/sdk/sdkapi/protogen/wire.gen.go b/sdk/sdkapi/protogen/wire.gen.go index 5c08a86..764f7ae 100644 --- a/sdk/sdkapi/protogen/wire.gen.go +++ b/sdk/sdkapi/protogen/wire.gen.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright The Moby Authors +// SPDX-License-Identifier: Apache-2.0 + // Code generated by mobyextgen. DO NOT EDIT. package protogen From 3b3ce52964175ff34d2f10fc020c9a7671f3a870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 17 Sep 2026 15:16:42 +0200 Subject: [PATCH 3/3] Makefile: Check generated files during lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- Makefile | 9 ++++++++- hack/lint-generate.sh | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 hack/lint-generate.sh diff --git a/Makefile b/Makefile index 787bd0a..70bfb45 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,9 @@ lint: lint-license --env GOMODCACHE=/root/.cache/go-mod \ --env GOLANGCI_LINT_CACHE=/root/.cache/golangci-lint \ --env GOFLAGS=-buildvcs=false \ + --env GIT_CONFIG_COUNT=1 \ + --env GIT_CONFIG_KEY_0=safe.directory \ + --env GIT_CONFIG_VALUE_0=$(LINT_WORKDIR) \ --workdir $(LINT_WORKDIR) \ $(LINT_IMAGE) \ make host-lint @@ -43,11 +46,15 @@ lint-license: bash hack/lint-license.sh .PHONY: host-lint -host-lint: +host-lint: lint-generate $(GO) run github.com/rhysd/actionlint/cmd/actionlint@$(ACTIONLINT_VERSION) $(GO) run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@$(MODERNIZE_VERSION) ./... $(GO) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run ./... +.PHONY: lint-generate +lint-generate: + GO="$(GO)" bash hack/lint-generate.sh + .PHONY: validate validate: @set -e; \ diff --git a/hack/lint-generate.sh b/hack/lint-generate.sh new file mode 100644 index 0000000..33791c7 --- /dev/null +++ b/hack/lint-generate.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright The Moby Authors +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +# Copy tracked working-tree files to include local edits without scratch files. +# Generate in a copy so lint also works with a read-only checkout. +workdir="$(mktemp -d)" +trap 'rm -rf "$workdir"' EXIT +mkdir "$workdir/original" "$workdir/generated" +git ls-files -z | + tar --null -T - -cf - | tar -xf - -C "$workdir/original" +cp -a "$workdir/original/." "$workdir/generated/" +( + cd "$workdir/generated" + "${GO:-go}" generate ./... +) + +if ! diff -ru "$workdir/original" "$workdir/generated"; then + echo 'generated files are out of date; run go generate ./...' >&2 + exit 1 +fi