@@ -16,37 +16,31 @@ import (
1616 "sync"
1717)
1818
19- var (
20- stdlibPkgfileMap map [string ]string
21- stdlibPkgfileErr error
22- once sync.Once
23- )
19+ var stdlibPkgfileMap , stdlibPkgfileErr = sync .OnceValues (func () (map [string ]string , error ) {
20+ m := make (map [string ]string )
21+ output , err := exec .Command ("go" , "list" , "-export" , "-e" , "-f" , "{{.ImportPath}} {{.Export}}" , "std" , "cmd" ).Output ()
22+ if err != nil {
23+ return m , err
24+ }
25+ for line := range strings .SplitSeq (string (output ), "\n " ) {
26+ if line == "" {
27+ continue
28+ }
29+ sp := strings .SplitN (line , " " , 2 )
30+ if len (sp ) != 2 {
31+ return m , fmt .Errorf ("determining pkgfile map: invalid line in go list output: %q" , line )
32+ }
33+ importPath , export := sp [0 ], sp [1 ]
34+ if export != "" {
35+ m [importPath ] = export
36+ }
37+ }
38+ return m , nil
39+ })()
2440
2541// PkgfileMap returns a map of package paths to the location on disk
2642// of the .a file for the package.
2743// The caller must not modify the map.
2844func PkgfileMap () (map [string ]string , error ) {
29- once .Do (func () {
30- m := make (map [string ]string )
31- output , err := exec .Command ("go" , "list" , "-export" , "-e" , "-f" , "{{.ImportPath}} {{.Export}}" , "std" , "cmd" ).Output ()
32- if err != nil {
33- stdlibPkgfileErr = err
34- }
35- for line := range strings .SplitSeq (string (output ), "\n " ) {
36- if line == "" {
37- continue
38- }
39- sp := strings .SplitN (line , " " , 2 )
40- if len (sp ) != 2 {
41- err = fmt .Errorf ("determining pkgfile map: invalid line in go list output: %q" , line )
42- return
43- }
44- importPath , export := sp [0 ], sp [1 ]
45- if export != "" {
46- m [importPath ] = export
47- }
48- }
49- stdlibPkgfileMap = m
50- })
5145 return stdlibPkgfileMap , stdlibPkgfileErr
5246}
0 commit comments