@@ -684,6 +684,15 @@ const (
684
684
// GetTestDeps is for download (part of "go get") and indicates
685
685
// that test dependencies should be fetched too.
686
686
GetTestDeps
687
+
688
+ // The remainder are internal modes for calls to loadImport.
689
+
690
+ // cmdlinePkg is for a package mentioned on the command line.
691
+ cmdlinePkg
692
+
693
+ // cmdlinePkgLiteral is for a package mentioned on the command line
694
+ // without using any wildcards or meta-patterns.
695
+ cmdlinePkgLiteral
687
696
)
688
697
689
698
// LoadImport scans the directory named by path, which must be an import path,
@@ -738,18 +747,30 @@ func loadImport(ctx context.Context, opts PackageOpts, pre *preload, path, srcDi
738
747
return p
739
748
}
740
749
750
+ setCmdline := func (p * Package ) {
751
+ if mode & cmdlinePkg != 0 {
752
+ p .Internal .CmdlinePkg = true
753
+ }
754
+ if mode & cmdlinePkgLiteral != 0 {
755
+ p .Internal .CmdlinePkgLiteral = true
756
+ }
757
+ }
758
+
741
759
importPath := bp .ImportPath
742
760
p := packageCache [importPath ]
743
761
if p != nil {
744
762
stk .Push (path )
745
763
p = reusePackage (p , stk )
746
764
stk .Pop ()
765
+ setCmdline (p )
747
766
} else {
748
767
p = new (Package )
749
768
p .Internal .Local = build .IsLocalImport (path )
750
769
p .ImportPath = importPath
751
770
packageCache [importPath ] = p
752
771
772
+ setCmdline (p )
773
+
753
774
// Load package.
754
775
// loadPackageData may return bp != nil even if an error occurs,
755
776
// in order to return partial information.
@@ -2849,15 +2870,15 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string)
2849
2870
if pkg == "" {
2850
2871
panic (fmt .Sprintf ("ImportPaths returned empty package for pattern %s" , m .Pattern ()))
2851
2872
}
2852
- p := loadImport (ctx , opts , pre , pkg , base .Cwd (), nil , & stk , nil , 0 )
2853
- p .Match = append (p .Match , m .Pattern ())
2854
- p .Internal .CmdlinePkg = true
2873
+ mode := cmdlinePkg
2855
2874
if m .IsLiteral () {
2856
2875
// Note: do not set = m.IsLiteral unconditionally
2857
2876
// because maybe we'll see p matching both
2858
2877
// a literal and also a non-literal pattern.
2859
- p . Internal . CmdlinePkgLiteral = true
2878
+ mode |= cmdlinePkgLiteral
2860
2879
}
2880
+ p := loadImport (ctx , opts , pre , pkg , base .Cwd (), nil , & stk , nil , mode )
2881
+ p .Match = append (p .Match , m .Pattern ())
2861
2882
if seenPkg [p ] {
2862
2883
continue
2863
2884
}
0 commit comments