Skip to content

Commit 1341a3d

Browse files
committed
cmd/go: add documentation for the -overlay flag
Also add -overlay to the Go 1.16 release notes. For #40700 Fixes #39958 Fixes #42893 Change-Id: Ifd397549e368b255e7b8800986cfa0563a942af5 Reviewed-on: https://go-review.googlesource.com/c/go/+/274714 Trust: Michael Matloob <[email protected]> Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent e508c1c commit 1341a3d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

doc/go1.16.html

+14
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,20 @@ <h4 id="list-buildid">The <code>list</code> command</h4>
271271
but without the extra step.
272272
</p>
273273

274+
<h4 id="overlay-flag">The <code>-overlay</code> flag</h4>
275+
276+
<p><!-- golang.org/issue/39958 -->
277+
The <code>-overlay</code> flag specifies a JSON configuration file containing
278+
a set of file path replacements. The <code>-overlay</code> flag may be used
279+
with all build commands and <code>go</code> <code>mod</code> subcommands.
280+
It is primarily intended to be used by editor tooling such as gopls to
281+
understand the effects of unsaved changes to source files. The config file
282+
maps actual file paths to replacement file paths and the <code>go</code>
283+
command and its builds will run as if the actual file paths exist with the
284+
contents given by the replacement file paths, or don't exist if the replacement
285+
file paths are empty.
286+
</p>
287+
274288
<h3 id="cgo">Cgo</h3>
275289

276290
<p><!-- CL 252378 -->

src/cmd/go/alldocs.go

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/work/build.go

+11
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ and test commands:
124124
directory, but it is not accessed. When -modfile is specified, an
125125
alternate go.sum file is also used: its path is derived from the
126126
-modfile flag by trimming the ".mod" extension and appending ".sum".
127+
-overlay file
128+
read a JSON config file that provides an overlay for build operations.
129+
The file is a JSON struct with a single field, named 'Replace', that
130+
maps each disk file path (a string) to its backing file path, so that
131+
a build will run as if the disk file path exists with the contents
132+
given by the backing file paths, or as if the disk file path does not
133+
exist if its backing file path is empty. Support for the -overlay flag
134+
has some limitations:importantly, cgo files included from outside the
135+
include path must be in the same directory as the Go package they are
136+
included from, and overlays will not appear when binaries and tests are
137+
run through go run and go test respectively.
127138
-pkgdir dir
128139
install and load all packages from dir instead of the usual locations.
129140
For example, when building with a non-standard configuration,

0 commit comments

Comments
 (0)