summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/tools/internal/goroot
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-02-27 10:51:12 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-27 10:51:12 +0100
commit8696a8cdf0ecb6ae6b324dc4b9d691aa398c06da (patch)
tree3759ea8648cdd8575b8af0259572b966cfccc638 /vendor/golang.org/x/tools/internal/goroot
parent[chore] Better diff for envparsing test (#1562) (diff)
downloadgotosocial-8696a8cdf0ecb6ae6b324dc4b9d691aa398c06da.tar.xz
[chore]: Bump github.com/miekg/dns from 1.1.50 to 1.1.51 (#1566)
Bumps [github.com/miekg/dns](https://github.com/miekg/dns) from 1.1.50 to 1.1.51. - [Release notes](https://github.com/miekg/dns/releases) - [Changelog](https://github.com/miekg/dns/blob/master/Makefile.release) - [Commits](https://github.com/miekg/dns/compare/v1.1.50...v1.1.51) --- updated-dependencies: - dependency-name: github.com/miekg/dns dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/golang.org/x/tools/internal/goroot')
-rw-r--r--vendor/golang.org/x/tools/internal/goroot/importcfg.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/golang.org/x/tools/internal/goroot/importcfg.go b/vendor/golang.org/x/tools/internal/goroot/importcfg.go
new file mode 100644
index 000000000..6575cfb9d
--- /dev/null
+++ b/vendor/golang.org/x/tools/internal/goroot/importcfg.go
@@ -0,0 +1,71 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package goroot is a copy of package internal/goroot
+// in the main GO repot. It provides a utility to produce
+// an importcfg and import path to package file map mapping
+// standard library packages to the locations of their export
+// data files.
+package goroot
+
+import (
+ "bytes"
+ "fmt"
+ "os/exec"
+ "strings"
+ "sync"
+)
+
+// Importcfg returns an importcfg file to be passed to the
+// Go compiler that contains the cached paths for the .a files for the
+// standard library.
+func Importcfg() (string, error) {
+ var icfg bytes.Buffer
+
+ m, err := PkgfileMap()
+ if err != nil {
+ return "", err
+ }
+ fmt.Fprintf(&icfg, "# import config")
+ for importPath, export := range m {
+ if importPath != "unsafe" && export != "" { // unsafe
+ fmt.Fprintf(&icfg, "\npackagefile %s=%s", importPath, export)
+ }
+ }
+ s := icfg.String()
+ return s, nil
+}
+
+var (
+ stdlibPkgfileMap map[string]string
+ stdlibPkgfileErr error
+ once sync.Once
+)
+
+// PkgfileMap returns a map of package paths to the location on disk
+// of the .a file for the package.
+// The caller must not modify the map.
+func PkgfileMap() (map[string]string, error) {
+ once.Do(func() {
+ m := make(map[string]string)
+ output, err := exec.Command("go", "list", "-export", "-e", "-f", "{{.ImportPath}} {{.Export}}", "std", "cmd").Output()
+ if err != nil {
+ stdlibPkgfileErr = err
+ }
+ for _, line := range strings.Split(string(output), "\n") {
+ if line == "" {
+ continue
+ }
+ sp := strings.SplitN(line, " ", 2)
+ if len(sp) != 2 {
+ err = fmt.Errorf("determining pkgfile map: invalid line in go list output: %q", line)
+ return
+ }
+ importPath, export := sp[0], sp[1]
+ m[importPath] = export
+ }
+ stdlibPkgfileMap = m
+ })
+ return stdlibPkgfileMap, stdlibPkgfileErr
+}