mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: inject state parameter into clean.runClean
This command modifies the call tree starting at `clean.runClean` to
inject a `State` parameter to every function that is currently using
the global `modload.LoaderState` variable. By explicilty passing a
`State` parameter, we can begin to eliminate the usage of the global
`modload.LoaderState`.
This commit is part of the overall effort to eliminate global
modloader state.
[git-generate]
cd src/cmd/go/internal/clean
rf '
inject modload.LoaderState runClean
add clean.go var moduleLoaderState *modload.State
ex {
import "cmd/go/internal/modload";
modload.LoaderState -> moduleLoaderState
}
add runClean://+0 moduleLoaderState := modload.NewState()
rm clean.go:/var moduleLoaderState \*modload.State/
'
cd ..
./rf-cleanup.zsh
Change-Id: I2e30e44cfff7e533801dabd7159fa760ac6bb824
Reviewed-on: https://go-review.googlesource.com/c/go/+/710296
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
58a8fdb6cf
commit
f7eaea02fd
1 changed files with 4 additions and 3 deletions
|
|
@ -120,7 +120,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runClean(ctx context.Context, cmd *base.Command, args []string) {
|
func runClean(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
modload.InitWorkfile(modload.LoaderState)
|
moduleLoaderState := modload.NewState()
|
||||||
|
modload.InitWorkfile(moduleLoaderState)
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
cacheFlag := ""
|
cacheFlag := ""
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -142,13 +143,13 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
// either the flags and arguments explicitly imply a package,
|
// either the flags and arguments explicitly imply a package,
|
||||||
// or no other target (such as a cache) was requested to be cleaned.
|
// or no other target (such as a cache) was requested to be cleaned.
|
||||||
cleanPkg := len(args) > 0 || cleanI || cleanR
|
cleanPkg := len(args) > 0 || cleanI || cleanR
|
||||||
if (!modload.Enabled(modload.LoaderState) || modload.HasModRoot(modload.LoaderState)) &&
|
if (!modload.Enabled(moduleLoaderState) || modload.HasModRoot(moduleLoaderState)) &&
|
||||||
!cleanCache && !cleanModcache && !cleanTestcache && !cleanFuzzcache {
|
!cleanCache && !cleanModcache && !cleanTestcache && !cleanFuzzcache {
|
||||||
cleanPkg = true
|
cleanPkg = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if cleanPkg {
|
if cleanPkg {
|
||||||
for _, pkg := range load.PackagesAndErrors(modload.LoaderState, ctx, load.PackageOpts{}, args) {
|
for _, pkg := range load.PackagesAndErrors(moduleLoaderState, ctx, load.PackageOpts{}, args) {
|
||||||
clean(pkg)
|
clean(pkg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue