@@ -909,8 +909,20 @@ func loadPackages(modPath, modRoot, loadDir string, goModData, goSumData []byte)
909
909
// We can't just load example.com/mod/... because that might include packages
910
910
// in nested modules. We also can't filter packages from the output of
911
911
// packages.Load, since it doesn't tell us which module they came from.
912
+ //
913
+ // TODO(golang.org/issue/41456): this command fails in -mod=readonly mode
914
+ // if sums are missing, which they always are for downloaded modules. In
915
+ // Go 1.16, -mod=readonly is the default, and -mod=mod may eventually be
916
+ // removed, so we should avoid -mod=mod here. Lazy loading may also require
917
+ // changes to temporary module requirements.
918
+ //
919
+ // Instead of running this command, we should make a list of importable
920
+ // packages by walking the directory tree. With such a list,
921
+ // in prepareLoadDir, we could generate a temporary package that imports
922
+ // all of them, then 'go get -d' that package to ensure no requirements
923
+ // or sums are missing.
912
924
format := fmt .Sprintf (`{{if .Module}}{{if eq .Module.Path %q}}{{.ImportPath}}{{end}}{{end}}` , modPath )
913
- cmd := exec .Command ("go" , "list" , "-e" , "-f" , format , "--" , modPath + "/..." )
925
+ cmd := exec .Command ("go" , "list" , "-mod=mod" , "- e" , "-f" , format , "--" , modPath + "/..." )
914
926
cmd .Dir = loadDir
915
927
out , err := cmd .Output ()
916
928
if err != nil {
0 commit comments