]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: do not install .a files for packages in std
authorBryan C. Mills <bcmills@google.com>
Mon, 21 Nov 2022 21:57:52 +0000 (16:57 -0500)
committerGopher Robot <gobot@golang.org>
Mon, 21 Nov 2022 22:43:41 +0000 (22:43 +0000)
As of CL 450739, we do not need install targets for cgo files when a C
compiler is not present because cgo is not enabled by default.
(Without a C compiler, builds will proceed with cgo disabled.)

Fixes #47257.
Fixes #56888.

Change-Id: I274c50a60b5b1382e291df86a5464da8ad3695a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/452457
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

misc/cgo/testcshared/cshared_test.go
src/cmd/go/go_test.go
src/cmd/go/internal/modindex/read.go
src/cmd/go/testdata/script/cgo_stale.txt
src/cmd/go/testdata/script/install_goroot_targets.txt
src/go/build/build.go
src/go/build/build_test.go

index 0d1b0ad9b79d7671811214aeb0f31de3dd9f7a90..7bb5a2dba56bf62eef107ec086668f8108686a87 100644 (file)
@@ -31,7 +31,7 @@ var exeSuffix string
 
 var GOOS, GOARCH, GOROOT string
 var installdir, androiddir string
-var libSuffix, libgoname string
+var libgoname string
 
 func TestMain(m *testing.M) {
        os.Exit(testMain(m))
@@ -153,18 +153,6 @@ func testMain(m *testing.M) int {
                log.Panic(err)
        }
 
-       // Directory where cgo headers and outputs will be installed.
-       // The installation directory format varies depending on the platform.
-       output, err := exec.Command("go", "list",
-               "-buildmode=c-shared",
-               "-f", "{{.Target}}",
-               "runtime/cgo").CombinedOutput()
-       if err != nil {
-               log.Panicf("go list failed: %v\n%s", err, output)
-       }
-       runtimeCgoTarget := string(bytes.TrimSpace(output))
-       libSuffix = strings.TrimPrefix(filepath.Ext(runtimeCgoTarget), ".")
-
        defer func() {
                if installdir != "" {
                        err := os.RemoveAll(installdir)
@@ -300,7 +288,7 @@ func createHeaders() error {
        if err != nil {
                return err
        }
-       libgoname = "libgo." + libSuffix
+       libgoname = "libgo.a"
 
        args = []string{"go", "build", "-buildmode=c-shared", "-o", filepath.Join(installdir, libgoname), "./libgo"}
        cmd = exec.Command(args[0], args[1:]...)
@@ -335,46 +323,30 @@ func createHeaders() error {
                if err != nil {
                        return fmt.Errorf("unable to find dlltool path: %v\n%s\n", err, out)
                }
-               dlltoolpath := strings.TrimSpace(string(out))
-               if filepath.Ext(dlltoolpath) == "" {
-                       // Some compilers report slash-separated paths without extensions
-                       // instead of ordinary Windows paths.
-                       // Try to find the canonical name for the path.
-                       if lp, err := exec.LookPath(dlltoolpath); err == nil {
-                               dlltoolpath = lp
-                       }
-               }
+               args := []string{strings.TrimSpace(string(out)), "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
 
-               args := []string{dlltoolpath, "-D", args[6], "-l", libgoname, "-d", "libgo.def"}
-
-               if filepath.Ext(dlltoolpath) == "" {
-                       // This is an unfortunate workaround for
-                       // https://github.com/mstorsjo/llvm-mingw/issues/205 in which
-                       // we basically reimplement the contents of the dlltool.sh
-                       // wrapper: https://git.io/JZFlU.
-                       // TODO(thanm): remove this workaround once we can upgrade
-                       // the compilers on the windows-arm64 builder.
-                       dlltoolContents, err := os.ReadFile(args[0])
-                       if err != nil {
-                               return fmt.Errorf("unable to read dlltool: %v\n", err)
+               // This is an unfortunate workaround for https://github.com/mstorsjo/llvm-mingw/issues/205 in which
+               // we basically reimplement the contents of the dlltool.sh wrapper: https://git.io/JZFlU
+               dlltoolContents, err := os.ReadFile(args[0])
+               if err != nil {
+                       return fmt.Errorf("unable to read dlltool: %v\n", err)
+               }
+               if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
+                       base, name := filepath.Split(args[0])
+                       args[0] = filepath.Join(base, "llvm-dlltool")
+                       var machine string
+                       switch prefix, _, _ := strings.Cut(name, "-"); prefix {
+                       case "i686":
+                               machine = "i386"
+                       case "x86_64":
+                               machine = "i386:x86-64"
+                       case "armv7":
+                               machine = "arm"
+                       case "aarch64":
+                               machine = "arm64"
                        }
-                       if bytes.HasPrefix(dlltoolContents, []byte("#!/bin/sh")) && bytes.Contains(dlltoolContents, []byte("llvm-dlltool")) {
-                               base, name := filepath.Split(args[0])
-                               args[0] = filepath.Join(base, "llvm-dlltool")
-                               var machine string
-                               switch prefix, _, _ := strings.Cut(name, "-"); prefix {
-                               case "i686":
-                                       machine = "i386"
-                               case "x86_64":
-                                       machine = "i386:x86-64"
-                               case "armv7":
-                                       machine = "arm"
-                               case "aarch64":
-                                       machine = "arm64"
-                               }
-                               if len(machine) > 0 {
-                                       args = append(args, "-m", machine)
-                               }
+                       if len(machine) > 0 {
+                               args = append(args, "-m", machine)
                        }
                }
 
@@ -578,7 +550,7 @@ func TestUnexportedSymbols(t *testing.T) {
 
        cmd := "testp2"
        bin := cmdToRun(cmd)
-       libname := "libgo2." + libSuffix
+       libname := "libgo2.a"
 
        run(t,
                nil,
@@ -636,7 +608,7 @@ func TestMainExportedOnAndroid(t *testing.T) {
 }
 
 func testSignalHandlers(t *testing.T, pkgname, cfile, cmd string) {
-       libname := pkgname + "." + libSuffix
+       libname := pkgname + ".a"
        run(t,
                nil,
                "go", "build",
@@ -838,7 +810,7 @@ func TestGo2C2Go(t *testing.T) {
        }
        defer os.RemoveAll(tmpdir)
 
-       lib := filepath.Join(tmpdir, "libtestgo2c2go."+libSuffix)
+       lib := filepath.Join(tmpdir, "libtestgo2c2go.a")
        var env []string
        if GOOS == "windows" && strings.HasSuffix(lib, ".a") {
                env = append(env, "CGO_LDFLAGS=-Wl,--out-implib,"+lib, "CGO_LDFLAGS_ALLOW=.*")
index d162dc8e2c022f11d4b26409c91148a227442286..c51f2120256253e68ba3798a5014f53a072f8624 100644 (file)
@@ -2918,35 +2918,3 @@ func TestExecInDeletedDir(t *testing.T) {
        // `go version` should not fail
        tg.run("version")
 }
-
-// A missing C compiler should not force the net package to be stale.
-// Issue 47215.
-func TestMissingCC(t *testing.T) {
-       if !canCgo {
-               t.Skip("test is only meaningful on systems with cgo")
-       }
-       cc := os.Getenv("CC")
-       if cc == "" {
-               cc = "gcc"
-       }
-       if filepath.IsAbs(cc) {
-               t.Skipf(`"CC" (%s) is an absolute path`, cc)
-       }
-       _, err := exec.LookPath(cc)
-       if err != nil {
-               t.Skipf(`"CC" (%s) not on PATH`, cc)
-       }
-
-       tg := testgo(t)
-       defer tg.cleanup()
-       netStale, _ := tg.isStale("net")
-       if netStale {
-               t.Skip(`skipping test because "net" package is currently stale`)
-       }
-
-       tg.setenv("PATH", "") // No C compiler on PATH.
-       netStale, _ = tg.isStale("net")
-       if netStale {
-               t.Error(`clearing "PATH" causes "net" to be stale`)
-       }
-}
index eaf921b6dfd7e5d8d5def4daebb3168d51a41cd5..7c4fa7a6eecbf09ea870c1ca9a8142a3926258ff 100644 (file)
@@ -629,12 +629,6 @@ func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *b
                }
        }
 
-       // Now that p.CgoFiles has been set, use it to determine whether
-       // a package in GOROOT gets an install target:
-       if len(p.CgoFiles) != 0 && p.Root != "" && p.Goroot && pkga != "" {
-               p.PkgObj = ctxt.joinPath(p.Root, pkga)
-       }
-
        p.EmbedPatterns, p.EmbedPatternPos = cleanDecls(embedPos)
        p.TestEmbedPatterns, p.TestEmbedPatternPos = cleanDecls(testEmbedPos)
        p.XTestEmbedPatterns, p.XTestEmbedPatternPos = cleanDecls(xTestEmbedPos)
index 9e46855eadb1e687458cbb035705a76324185a86..0d30aeaa9d41df08764303e99cc56b9c1e4df231 100644 (file)
@@ -12,21 +12,21 @@ stale runtime/cgo
 
 
 # If we then build a package that uses cgo, runtime/cgo should be rebuilt and
-# cached with the new flag, but not installed to GOROOT (and thus still stale).
+# cached with the new flag, but not installed to GOROOT.
+# It has no install target, and thus is never stale.
 
 env GOCACHE=$WORK/cache  # Use a fresh cache to avoid interference between runs.
 
 go build -x .
 stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo'
-stale runtime/cgo
+stale runtime/cgo
 
 
-# After runtime/cgo has been rebuilt and cached, it should not be rebuilt again
-# even though it is still reported as stale.
+# After runtime/cgo has been rebuilt and cached, it should not be rebuilt again.
 
 go build -x .
 ! stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo'
-stale runtime/cgo
+stale runtime/cgo
 
 
 -- go.mod --
index 25b97b4b735613879a13582ef020639401bc9b0f..f26ee828fa6efac95af610a480d60285e703c4f0 100644 (file)
@@ -1,18 +1,11 @@
 [short] skip
 
-# Most packages in std do not have an install target.
+# Packages in std do not have an install target.
 go list -f '{{.Target}}' fmt
 ! stdout .
 go list -export -f '{{.Export}}' fmt
 stdout $GOCACHE
 
-# Packages that use cgo still do.
-[cgo] go list -f '{{.Target}}' runtime/cgo
-[cgo] stdout .
-[cgo] go list -export -f '{{.Export}}' runtime/cgo
-[cgo] ! stdout $GOCACHE
-[cgo] stdout cgo\.a
-
 # With GODEBUG=installgoroot=all, fmt has a target.
 # (Though we can't try installing it without modifying goroot).
 env GODEBUG=installgoroot=all
index 53d4b27e10dbce550248216c558567efbc47e1e0..420873c256586969031ba6110f001be773f6764b 100644 (file)
@@ -1003,12 +1003,6 @@ Found:
                }
        }
 
-       // Now that p.CgoFiles has been set, use it to determine whether
-       // a package in GOROOT gets an install target:
-       if len(p.CgoFiles) != 0 && p.Root != "" && p.Goroot && pkga != "" {
-               p.PkgObj = ctxt.joinPath(p.Root, pkga)
-       }
-
        for tag := range allTags {
                p.AllTags = append(p.AllTags, tag)
        }
index 3eebfd8e9eb867baafcd9aa84744f7ba2917fc40..2e60ecc5cc45672228f6a3a34bd07c373587cd2b 100644 (file)
@@ -671,24 +671,6 @@ func TestImportPackageOutsideModule(t *testing.T) {
        }
 }
 
-func TestImportDirTarget(t *testing.T) {
-       testenv.MustHaveGoBuild(t) // really must just have source
-       ctxt := Default
-       ctxt.GOPATH = ""
-       // In GOROOT only a handful of packages have install targets. Most stdlib packages will
-       // only be built and placed in the build cache.
-       p, err := ctxt.ImportDir(filepath.Join(testenv.GOROOT(t), "src/runtime/cgo"), 0)
-       if err != nil {
-               t.Fatal(err)
-       }
-       if p.PkgTargetRoot == "" {
-               t.Errorf("p.PkgTargetRoot == %q, want non-empty", p.PkgTargetRoot)
-       }
-       if testenv.HasCGO() && p.PkgObj == "" {
-               t.Errorf("p.PkgObj == %q, want non-empty", p.PkgObj)
-       }
-}
-
 // TestIssue23594 prevents go/build from regressing and populating Package.Doc
 // from comments in test files.
 func TestIssue23594(t *testing.T) {