Build constraints and preceding non-line comments

33 views
Skip to first unread message

Neil Schellenberger

unread,
May 13, 2019, 1:40:01 PM5/13/19
to golang-nuts
Hi Folks,

The documentation of build constraints says, in part (emphasis mine):

Constraints may appear in any kind of source file (not just Go), but they must appear near the top of the file, preceded only by blank lines and other line comments.

The current implementation (and presumably all past implementations) explicitly enforces the constraint that a preceding general (i.e. non-line) comment is not permitted.

Does anyone remember the rationale for that?  Something to do with avoiding undesired coincidental matching of comments in non-Go files?  I've done a little forensic digging, but it quickly gets tricky as the code originated in cmd/vet.

I ran across this recently when attempting to insert a build constraint into some of our existing Go code with a boilerplate corporate copyright which started life in C/C++ source files.  It took me quite a while to figure out what was going on....  :-)

Regards,
Neil

Ian Lance Taylor

unread,
May 13, 2019, 1:47:41 PM5/13/19
to Neil Schellenberger, golang-nuts
The current approach lets you find all build constraints reliably with
a simple sed or awk script. This is sometimes convenient.

Ian
Reply all
Reply to author
Forward
0 new messages