You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
modload.Import previously performed two otherwise-separable tasks:
1. Identify which module in the build list contains the requested
package.
2. If no such module exists, search available modules to try to find
the missing package.
This change splits those two tasks into two separate unexported
functions, and reports import-resolution errors by attaching them to
the package rather than emitting them directly to stderr. That allows
'list' to report the errors, but 'list -e' to ignore them.
With the two tasks now separate, it will be easier to avoid the
overhead of resolving missing packages during lazy loading if we
discover that some existing dependency needs to be promoted to the top
level (potentially altering the main module's selected versions, and
thus suppling packages that were previously missing).
For #36460
Updates #26909
Change-Id: I32bd853b266d7cd231d1f45f92b0650d95c4bcbd
Reviewed-on: https://go-review.googlesource.com/c/go/+/251445
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
returnfmt.Sprintf("package %s provided by %s at latest version %s but not at required version %s", e.Path, e.Module.Path, e.Module.Version, e.newMissingVersion)
56
+
}
57
+
51
58
returnfmt.Sprintf("missing module for import: %s@%s provides %s", e.Module.Path, e.Module.Version, e.Path)
52
59
}
53
60
@@ -100,18 +107,20 @@ func (e *AmbiguousImportError) Error() string {
100
107
101
108
var_ load.ImportPathError=&AmbiguousImportError{}
102
109
103
-
// Import finds the module and directory in the build list
104
-
// containing the package with the given import path.
105
-
// The answer must be unique: Import returns an error
106
-
// if multiple modules attempt to provide the same package.
107
-
// Import can return a module with an empty m.Path, for packages in the standard library.
108
-
// Import can return an empty directory string, for fake packages like "C" and "unsafe".
110
+
// importFromBuildList finds the module and directory in the build list
111
+
// containing the package with the given import path. The answer must be unique:
112
+
// importFromBuildList returns an error if multiple modules attempt to provide
113
+
// the same package.
114
+
//
115
+
// importFromBuildList can return a module with an empty m.Path, for packages in
116
+
// the standard library.
117
+
//
118
+
// importFromBuildList can return an empty directory string, for fake packages
119
+
// like "C" and "unsafe".
109
120
//
110
121
// If the package cannot be found in the current build list,
111
-
// Import returns an ImportMissingError as the error.
112
-
// If Import can identify a module that could be added to supply the package,
base.Fatalf("go: %s: package provided by %s at latest version %s but not at required version %s", pkg.stackText(), err.Module.Path, err.Module.Version, err.newMissingVersion)
956
-
}
957
-
fmt.Fprintf(os.Stderr, "go: found %s in %s %s\n", pkg.path, err.Module.Path, err.Module.Version)
958
-
ifaddedModuleFor[pkg.path] {
959
-
base.Fatalf("go: %s: looping trying to add package", pkg.stackText())
960
-
}
961
-
addedModuleFor[pkg.path] =true
962
-
if!haveMod[err.Module] {
963
-
haveMod[err.Module] =true
964
-
modAddedBy[err.Module] =pkg
965
-
buildList=append(buildList, err.Module)
966
-
}
948
+
ifpkg.err!=errImportMissing {
949
+
// Leave other errors for Import or load.Packages to report.
967
950
continue
968
951
}
969
-
// Leave other errors for Import or load.Packages to report.
0 commit comments