Copyright headers for auto-generated files?
roger peppe
roger.peppe at canonical.com
Fri Jan 8 09:05:56 UTC 2016
I agree with Nate that we should not have to use internal
generate tools when external ones will do the job
(stringer is a good example).
We have a similar issue - we're using the stringer tool
in various places, and we also auto-generate API
client code from the server implementation.
We don't add a copyright notice, just a comment at the
top saying something like:
// The code in this file was automatically generated by running
// <generate command line>
// DO NOT EDIT
For external tools, perhaps the copyright status is arguable
anyway - isn't the author of that code as much the author of
the tool as the person that ran it?
Anyway, if we decide that we *do* need to incorporate copyright notices
into generated code, then it should be possible to
write a tool to do it.
For example, consider something like:
go-add-copyright [-m message] [file...]
go-add-copyright adds a copyright message to all the
named Go files, or leaves it intact if it finds it there.
The message is taken from the value of the -m flag;
if not specified, it is determined by reading source
files in the current directory and using the copyright
message found there (with the year replaced by the
current year).
A copyright comment must be the first comment in a file,
separated from the package statement by at least one newline
and contain the string Copyright or ©.
If no files are specified, it adds a copyright message to
all files that don't have one.
Given this, one could write:
//go:generate stringer -type MyType
//go:generate go-add-copyright mytype_string.go
Generate directives are guaranteed to run sequentially
in source code order, so this should work OK, and it
wouldn't be much work to implement.
cheers,
rog.
On 6 January 2016 at 22:18, Katherine Cox-Buday
<katherine.cox-buday at canonical.com> wrote:
> Nate ran into an interesting problem yesterday. If we begin to use go
> generate directives to auto-generate code, do we care that this code doesn't
> have a Copyright header? We check the generated file into source control,
> but as the file is meant to be regenerated in the event of a change, we
> don't want to edit it by hand to add the header.
>
> --
> -
> Katherine
>
>
> --
> Juju-dev mailing list
> Juju-dev at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/juju-dev
More information about the Juju-dev
mailing list