summaryrefslogtreecommitdiffhomepage
path: root/util/codegen
AgeCommit message (Collapse)AuthorFilesLines
2024-07-19cmd/viewer, types/views, util/codegen: add viewer support for custom ↵Nick Khyl1-0/+8
container types This adds support for container-like types such as Container[T] that don't explicitly specify a view type for T. Instead, a package implementing a container type should also implement and export a ContainerView[T, V] type and a ContainerViewOf(*Container[T]) ContainerView[T, V] function, which returns a view for the specified container, inferring the element view type V from the element type T. Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-07-11cmd/cloner, cmd/viewer, util/codegen: add support for generic types and ↵Nick Khyl2-8/+275
interfaces This adds support for generic types and interfaces to our cloner and viewer codegens. It updates these packages to determine whether to make shallow or deep copies based on the type parameter constraints. Additionally, if a template parameter or an interface type has View() and Clone() methods, we'll use them for getters and the cloner of the owning structure. Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-04-16all: use Go 1.22 range-over-intBrad Fitzpatrick1-2/+2
Updates #11058 Change-Id: I35e7ef9b90e83cac04ca93fd964ad00ed5b48430 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-05-09util/codegen: support embedded fieldsBrad Fitzpatrick1-2/+7
I noticed cmd/{cloner,viewer} didn't support structs with embedded fields while working on a change in another repo. This adds support. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-03-27util/codegen: add -copyright to control presence of copyright headersJosh Bleecher Snyder1-1/+6
Fixes #7702 Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
2023-01-27all: update tools that manage copyright headersWill Norris1-62/+6
Update all code generation tools, and those that check for license headers to use the new standard header. Also update copyright statement in LICENSE file. Fixes #6865 Signed-off-by: Will Norris <will@tailscale.com>
2023-01-27all: update copyright and license headersWill Norris1-3/+2
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
2023-01-03util/codegen: permit running in directories without copyright headersBrad Fitzpatrick1-7/+10
It broke in our corp repo that lacks copyright headers. Change-Id: Iafc433e6b6affe83b45477899455527658dc4f12 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-01-02util/codegen, all: use latest year, not time.Now, in generated filesBrad Fitzpatrick1-5/+59
Updates #6865 Change-Id: I6b86c646968ebbd4553cf37df5e5612fbf5c5f7d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-25all: convert more code to use net/netip directlyBrad Fitzpatrick1-1/+1
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.) perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. ) goimports -w . Then delete some stuff from the net/netaddr shim package which is no longer neeed. Updates #5162 Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-25net/netaddr: start migrating to net/netip via new netaddr adapter packageBrad Fitzpatrick1-1/+1
Updates #5162 Change-Id: Id7bdec303b25471f69d542f8ce43805328d56c12 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-05-06cmd/cloner,util/codegen: refactor cloner internals to allow reuseMaisem Ali1-18/+132
Also run go generate again for Copyright updates. Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-04-29util/codegen: format generated code with goimports, not gofmtBrad Fitzpatrick1-2/+7
goimports is a superset of gofmt that also groups imports. (the goimports tool also adds/removes imports as needed, but that part is disabled here) Change-Id: Iacf0408dfd9497f4ed3da4fa50e165359ce38498 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-03-17all: use any instead of interface{}Josh Bleecher Snyder1-1/+1
My favorite part of generics. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-09-17util/codegen: reorder AssertStructUnchanged argsJosh Bleecher Snyder1-2/+2
The fully qualified name of the type is thisPkg.tname, so write the args like that too. Suggested-by: Joe Tsai <joetsai@digital-static.net> Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-09-17util/codegen: add ContainsPointersJosh Bleecher Snyder1-0/+35
And use it in cmd/cloner. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-09-17util/codegen: add NamedTypesJosh Bleecher Snyder1-0/+30
And use it in cmd/cloner. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-09-17util/codegen: add AssertStructUnchangedJosh Bleecher Snyder1-0/+41
Refactored out from cmd/cloner. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-09-17util/codegen: add packageJosh Bleecher Snyder1-0/+40
This is a package for shared utilities used in doing codegen programs. The inaugural API is for writing gofmt'd code to a file. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>