1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 // DebugDeprecatedImportcfg is installed as the undocumented -debug-deprecated-importcfg build flag.
15 // It is useful for debugging subtle problems in the go command logic but not something
16 // we want users to depend on. The hope is that the "deprecated" will make that clear.
17 // We intend to remove this flag in Go 1.11.
18 var DebugDeprecatedImportcfg debugDeprecatedImportcfgFlag
20 type debugDeprecatedImportcfgFlag
struct {
22 Import
map[string]string
23 Pkg
map[string]*debugDeprecatedImportcfgPkg
26 type debugDeprecatedImportcfgPkg
struct {
28 Import
map[string]string
32 debugDeprecatedImportcfgMagic
= []byte("# debug-deprecated-importcfg\n")
33 errImportcfgSyntax
= errors
.New("malformed syntax")
36 func (f
*debugDeprecatedImportcfgFlag
) String() string { return "" }
38 func (f
*debugDeprecatedImportcfgFlag
) Set(x
string) error
{
40 *f
= debugDeprecatedImportcfgFlag
{}
43 data
, err
:= ioutil
.ReadFile(x
)
48 if !bytes
.HasPrefix(data
, debugDeprecatedImportcfgMagic
) {
49 return errImportcfgSyntax
51 data
= data
[len(debugDeprecatedImportcfgMagic
):]
55 if err
:= json
.Unmarshal(data
, &f
); err
!= nil {
56 return errImportcfgSyntax
62 func (f
*debugDeprecatedImportcfgFlag
) lookup(parent
*Package
, path
string) (dir
, newPath
string) {
64 if p
:= f
.Import
[path
]; p
!= "" {
68 if p1
:= f
.Pkg
[parent
.ImportPath
]; p1
!= nil {
69 if p
:= p1
.Import
[path
]; p
!= "" {
74 if p2
:= f
.Pkg
[newPath
]; p2
!= nil {
75 return p2
.Dir
, newPath