@@ -112,30 +112,47 @@ func newModuleResolver(e *ProcessEnv, moduleCacheCache *DirInfoCache) (*ModuleRe
112
112
}
113
113
114
114
vendorEnabled := false
115
- var mainModVendor * gocommand.ModuleJSON
115
+ var mainModVendor * gocommand.ModuleJSON // for module vendoring
116
+ var mainModsVendor []* gocommand.ModuleJSON // for workspace vendoring
116
117
117
- // Module vendor directories are ignored in workspace mode:
118
- // https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
119
- if len (r .env .Env ["GOWORK" ]) == 0 {
118
+ goWork := r .env .Env ["GOWORK" ]
119
+ if len (goWork ) == 0 {
120
120
// TODO(rfindley): VendorEnabled runs the go command to get GOFLAGS, but
121
121
// they should be available from the ProcessEnv. Can we avoid the redundant
122
122
// invocation?
123
123
vendorEnabled , mainModVendor , err = gocommand .VendorEnabled (context .TODO (), inv , r .env .GocmdRunner )
124
124
if err != nil {
125
125
return nil , err
126
126
}
127
+ } else {
128
+ vendorEnabled , mainModsVendor , err = gocommand .WorkspaceVendorEnabled (context .Background (), inv , r .env .GocmdRunner )
129
+ if err != nil {
130
+ return nil , err
131
+ }
127
132
}
128
133
129
- if mainModVendor != nil && vendorEnabled {
130
- // Vendor mode is on, so all the non-Main modules are irrelevant,
131
- // and we need to search /vendor for everything.
132
- r .mains = []* gocommand.ModuleJSON {mainModVendor }
133
- r .dummyVendorMod = & gocommand.ModuleJSON {
134
- Path : "" ,
135
- Dir : filepath .Join (mainModVendor .Dir , "vendor" ),
134
+ if vendorEnabled {
135
+ if mainModVendor != nil {
136
+ // Module vendor mode is on, so all the non-Main modules are irrelevant,
137
+ // and we need to search /vendor for everything.
138
+ r .mains = []* gocommand.ModuleJSON {mainModVendor }
139
+ r .dummyVendorMod = & gocommand.ModuleJSON {
140
+ Path : "" ,
141
+ Dir : filepath .Join (mainModVendor .Dir , "vendor" ),
142
+ }
143
+ r .modsByModPath = []* gocommand.ModuleJSON {mainModVendor , r .dummyVendorMod }
144
+ r .modsByDir = []* gocommand.ModuleJSON {mainModVendor , r .dummyVendorMod }
145
+ } else {
146
+ // Workspace vendor mode is on, so all the non-Main modules are irrelevant,
147
+ // and we need to search /vendor for everything.
148
+ r .mains = mainModsVendor
149
+ r .dummyVendorMod = & gocommand.ModuleJSON {
150
+ Path : "" ,
151
+ Dir : filepath .Join (filepath .Dir (goWork ), "vendor" ),
152
+ }
153
+ r .modsByModPath = append (append ([]* gocommand.ModuleJSON {}, mainModsVendor ... ), r .dummyVendorMod )
154
+ r .modsByDir = append (append ([]* gocommand.ModuleJSON {}, mainModsVendor ... ), r .dummyVendorMod )
136
155
}
137
- r .modsByModPath = []* gocommand.ModuleJSON {mainModVendor , r .dummyVendorMod }
138
- r .modsByDir = []* gocommand.ModuleJSON {mainModVendor , r .dummyVendorMod }
139
156
} else {
140
157
// Vendor mode is off, so run go list -m ... to find everything.
141
158
err := r .initAllMods ()
0 commit comments