]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: move internal/load.PluginPath to internal/work
authorRuss Cox <rsc@golang.org>
Fri, 13 Oct 2017 13:20:11 +0000 (09:20 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 20 Oct 2017 18:35:26 +0000 (18:35 +0000)
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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/dist/deps.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/work/build.go

index 47560cf33bf6ba3cc897c24676de24fa0ab3f81f..3e749428739ad607311f7a4ad4077ad828070e3d 100644 (file)
@@ -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
index 9b44687e8f1412fd069fcc8d6c590579698a8939..4e87a736098dc7c563b25b85f9995169c87523a7 100644 (file)
@@ -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.
index c7127f6ec8901cf711e489c868ac50546e46e98b..38aa84934de63815ebee1547521012c481c8d633 100644 (file)
@@ -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.