From: Russ Cox Date: Fri, 13 Oct 2017 13:20:11 +0000 (-0400) Subject: cmd/go: move internal/load.PluginPath to internal/work X-Git-Tag: go1.10beta1~650 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1992ab7e65a1cd83c02c36df293971c1fb3aeec7;p=gostls13.git cmd/go: move internal/load.PluginPath to internal/work It uses the build ID, which is soon to be internal to package work. Luckily it is also only called from package work. Change-Id: I5e6662cfe667bdc9190f086be733105ad65a3191 Reviewed-on: https://go-review.googlesource.com/70670 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: David Crawshaw --- diff --git a/src/cmd/dist/deps.go b/src/cmd/dist/deps.go index 47560cf33b..3e74942873 100644 --- a/src/cmd/dist/deps.go +++ b/src/cmd/dist/deps.go @@ -332,6 +332,7 @@ var builddeps = map[string][]string{ "cmd/go/internal/str", // cmd/go/internal/work "cmd/internal/buildid", // cmd/go/internal/work "container/heap", // cmd/go/internal/work + "crypto/sha1", // cmd/go/internal/work "crypto/sha256", // cmd/go/internal/work "debug/elf", // cmd/go/internal/work "encoding/json", // cmd/go/internal/work diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 9b44687e8f..4e87a73609 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -1689,29 +1689,6 @@ func pkgInputFiles(p *Package) []string { ) } -// PluginPath computes the package path for a plugin main package. -// -// This is typically the import path of the main package p, unless the -// plugin is being built directly from source files. In that case we -// combine the package build ID with the contents of the main package -// source files. This allows us to identify two different plugins -// built from two source files with the same name. -func PluginPath(p *Package) string { - if p.ImportPath != "command-line-arguments" { - return p.ImportPath - } - h := sha1.New() - fmt.Fprintf(h, "build ID: %s\n", p.Internal.BuildID) - for _, file := range str.StringList(p.GoFiles, p.CgoFiles, p.SFiles) { - data, err := ioutil.ReadFile(filepath.Join(p.Dir, file)) - if err != nil { - base.Fatalf("go: %s", err) - } - h.Write(data) - } - return fmt.Sprintf("plugin/unnamed-%x", h.Sum(nil)) -} - // computeBuildID computes the build ID for p, leaving it in p.Internal.BuildID. // Build ID is a hash of the information we want to detect changes in. // See the long comment in isStale for details. diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index c7127f6ec8..38aa84934d 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -8,6 +8,7 @@ import ( "bufio" "bytes" "container/heap" + "crypto/sha1" "crypto/sha256" "debug/elf" "encoding/json" @@ -2501,7 +2502,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, a pkgpath := p.ImportPath if cfg.BuildBuildmode == "plugin" { - pkgpath = load.PluginPath(p) + pkgpath = pluginPath(p) } else if p.Name == "main" { pkgpath = "main" } @@ -2814,6 +2815,29 @@ func setextld(ldflags []string, compiler []string) []string { return ldflags } +// pluginPath computes the package path for a plugin main package. +// +// This is typically the import path of the main package p, unless the +// plugin is being built directly from source files. In that case we +// combine the package build ID with the contents of the main package +// source files. This allows us to identify two different plugins +// built from two source files with the same name. +func pluginPath(p *load.Package) string { + if p.ImportPath != "command-line-arguments" { + return p.ImportPath + } + h := sha1.New() + fmt.Fprintf(h, "build ID: %s\n", p.Internal.BuildID) + for _, file := range str.StringList(p.GoFiles, p.CgoFiles, p.SFiles) { + data, err := ioutil.ReadFile(filepath.Join(p.Dir, file)) + if err != nil { + base.Fatalf("go: %s", err) + } + h.Write(data) + } + return fmt.Sprintf("plugin/unnamed-%x", h.Sum(nil)) +} + func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string) error { cxx := len(root.Package.CXXFiles) > 0 || len(root.Package.SwigCXXFiles) > 0 for _, a := range root.Deps { @@ -2829,7 +2853,7 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string) ldflags = append(ldflags, "-s", "-w") } if cfg.BuildBuildmode == "plugin" { - ldflags = append(ldflags, "-pluginpath", load.PluginPath(root.Package)) + ldflags = append(ldflags, "-pluginpath", pluginPath(root.Package)) } // TODO(rsc): This is probably wrong - see golang.org/issue/22155.