mirror of
https://github.com/golang/go.git
synced 2025-10-27 06:44:13 +00:00
cmd/go: reject embedded files that can't be packed into modules
If the file won't be packed into a module, don't put those files into embeds. Otherwise people will be surprised when things work locally but not when imported by another module. Observed on CL 290709 Change-Id: Ia0ef7d0e0f5e42473c2b774e57c843e68a365bc7 Reviewed-on: https://go-review.googlesource.com/c/go/+/290809 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
e5b08e6d5c
commit
930c2c9a68
1 changed files with 5 additions and 0 deletions
|
|
@ -36,6 +36,8 @@ import (
|
||||||
"cmd/go/internal/str"
|
"cmd/go/internal/str"
|
||||||
"cmd/go/internal/trace"
|
"cmd/go/internal/trace"
|
||||||
"cmd/internal/sys"
|
"cmd/internal/sys"
|
||||||
|
|
||||||
|
"golang.org/x/mod/module"
|
||||||
)
|
)
|
||||||
|
|
||||||
var IgnoreImports bool // control whether we ignore imports in packages
|
var IgnoreImports bool // control whether we ignore imports in packages
|
||||||
|
|
@ -2090,6 +2092,9 @@ func validEmbedPattern(pattern string) bool {
|
||||||
// can't or won't be included in modules and therefore shouldn't be treated
|
// can't or won't be included in modules and therefore shouldn't be treated
|
||||||
// as existing for embedding.
|
// as existing for embedding.
|
||||||
func isBadEmbedName(name string) bool {
|
func isBadEmbedName(name string) bool {
|
||||||
|
if err := module.CheckFilePath(name); err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
switch name {
|
switch name {
|
||||||
// Empty string should be impossible but make it bad.
|
// Empty string should be impossible but make it bad.
|
||||||
case "":
|
case "":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue