Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/goPublic

Commit78b4303

Browse files
committed
cmd/go: refactor usage ofworkFilePath
This commit refactors usage of the global variable `workFilePath` tothe global LoaderState field of the same name.This commit is part of the overall effort to eliminate globalmodloader state.[git-generate]cd src/cmd/go/internal/modloadrf 'ex { workFilePath -> LoaderState.workFilePath }'rf 'add State.requirements \// Set to the path to the go.work file, or "" if workspace mode is\// disabled'rf 'rm workFilePath'Change-Id: I53cdbc3cc619914421513db74a74a04ab10b3e33Reviewed-on:https://go-review.googlesource.com/c/go/+/698062Reviewed-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>
1 parentbb1ca7a commit78b4303

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

‎src/cmd/go/internal/modload/buildlist.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ func newRequirements(pruning modPruning, rootModules []module.Version, direct ma
108108
mustHaveGoRoot(rootModules)
109109

110110
ifpruning!=workspace {
111-
ifworkFilePath!="" {
111+
ifLoaderState.workFilePath!="" {
112112
panic("in workspace mode, but pruning is not workspace in newRequirements")
113113
}
114114
}
115115

116116
ifpruning!=workspace {
117-
ifworkFilePath!="" {
117+
ifLoaderState.workFilePath!="" {
118118
panic("in workspace mode, but pruning is not workspace in newRequirements")
119119
}
120120
fori,m:=rangerootModules {

‎src/cmd/go/internal/modload/init.go‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var (
6060
funcEnterModule(ctx context.Context,enterModrootstring) {
6161
LoaderState.MainModules=nil// reset MainModules
6262
LoaderState.requirements=nil
63-
workFilePath=""// Force module mode
63+
LoaderState.workFilePath=""// Force module mode
6464
modfetch.Reset()
6565

6666
LoaderState.modRoots= []string{enterModroot}
@@ -97,12 +97,6 @@ func EnterWorkspace(ctx context.Context) (exit func(), err error) {
9797
},nil
9898
}
9999

100-
// Variable set in InitWorkfile
101-
var (
102-
// Set to the path to the go.work file, or "" if workspace mode is disabled.
103-
workFilePathstring
104-
)
105-
106100
typeMainModuleSetstruct {
107101
// versions are the module.Version values of each of the main modules.
108102
// For each of them, the Path fields are ordinary module paths and the Version
@@ -349,7 +343,7 @@ func InitWorkfile() {
349343
iferr:=fsys.Init();err!=nil {
350344
base.Fatal(err)
351345
}
352-
workFilePath=FindGoWork(base.Cwd())
346+
LoaderState.workFilePath=FindGoWork(base.Cwd())
353347
}
354348

355349
// FindGoWork returns the name of the go.work file for this command,
@@ -378,7 +372,7 @@ func FindGoWork(wd string) string {
378372
// WorkFilePath returns the absolute path of the go.work file, or "" if not in
379373
// workspace mode. WorkFilePath must be called after InitWorkfile.
380374
funcWorkFilePath()string {
381-
returnworkFilePath
375+
returnLoaderState.workFilePath
382376
}
383377

384378
// Reset clears all the initialized, cached state about the use of modules,
@@ -404,7 +398,7 @@ func setState(s State) State {
404398
cfg.ModulesEnabled=s.modulesEnabled
405399
LoaderState.MainModules=s.MainModules
406400
LoaderState.requirements=s.requirements
407-
workFilePath=s.workFilePath
401+
LoaderState.workFilePath=s.workFilePath
408402
// The modfetch package's global state is used to compute
409403
// the go.sum file, so save and restore it along with the
410404
// modload state.
@@ -441,7 +435,10 @@ type State struct {
441435
// commitRequirements functions. All other functions that need or
442436
// produce a *Requirements should accept and/or return an explicit
443437
// parameter.
444-
requirements*Requirements
438+
requirements*Requirements
439+
440+
// Set to the path to the go.work file, or "" if workspace mode is
441+
// disabled
445442
workFilePathstring
446443
modfetchState modfetch.State
447444
}
@@ -507,7 +504,7 @@ func Init() {
507504
base.Fatalf("go: -modfile cannot be used with commands that ignore the current module")
508505
}
509506
LoaderState.modRoots=nil
510-
}elseifworkFilePath!="" {
507+
}elseifLoaderState.workFilePath!="" {
511508
// We're in workspace mode, which implies module mode.
512509
ifcfg.ModFile!="" {
513510
base.Fatalf("go: -modfile cannot be used in workspace mode")
@@ -651,7 +648,7 @@ func inWorkspaceMode() bool {
651648
if!Enabled() {
652649
returnfalse
653650
}
654-
returnworkFilePath!=""
651+
returnLoaderState.workFilePath!=""
655652
}
656653

657654
// HasModRoot reports whether a main module or main modules are present.
@@ -888,15 +885,15 @@ func loadModFile(ctx context.Context, opts *PackageOpts) (*Requirements, error)
888885
varworkFile*modfile.WorkFile
889886
ifinWorkspaceMode() {
890887
varerrerror
891-
workFile,LoaderState.modRoots,err=LoadWorkFile(workFilePath)
888+
workFile,LoaderState.modRoots,err=LoadWorkFile(LoaderState.workFilePath)
892889
iferr!=nil {
893890
returnnil,err
894891
}
895892
for_,modRoot:=rangeLoaderState.modRoots {
896893
sumFile:=strings.TrimSuffix(modFilePath(modRoot),".mod")+".sum"
897894
modfetch.WorkspaceGoSumFiles=append(modfetch.WorkspaceGoSumFiles,sumFile)
898895
}
899-
modfetch.GoSumFile=workFilePath+".sum"
896+
modfetch.GoSumFile=LoaderState.workFilePath+".sum"
900897
}elseiflen(LoaderState.modRoots)==0 {
901898
// We're in module mode, but not inside a module.
902899
//
@@ -1542,8 +1539,8 @@ func setDefaultBuildMod() {
15421539
}
15431540
}
15441541
vendorDir:=""
1545-
ifworkFilePath!="" {
1546-
vendorDir=filepath.Join(filepath.Dir(workFilePath),"vendor")
1542+
ifLoaderState.workFilePath!="" {
1543+
vendorDir=filepath.Join(filepath.Dir(LoaderState.workFilePath),"vendor")
15471544
}else {
15481545
iflen(LoaderState.modRoots)!=1 {
15491546
panic(fmt.Errorf("outside workspace mode, but have %v modRoots",LoaderState.modRoots))

‎src/cmd/go/internal/modload/modfile.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func replacementFrom(mod module.Version) (r module.Version, modroot string, from
356356
return module.Version{},"",""
357357
}
358358
if_,r,ok:=replacement(mod,LoaderState.MainModules.WorkFileReplaceMap());ok {
359-
returnr,"",workFilePath
359+
returnr,"",LoaderState.workFilePath
360360
}
361361
for_,v:=rangeLoaderState.MainModules.Versions() {
362362
ifindex:=LoaderState.MainModules.Index(v);index!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp