Skip to content

Commit 707cadd

Browse files
committed
cmd/go: split out cmd/go/internal/clean,doc,fix,generate,list,run,tool,version,vet
This is one CL in a long sequence of changes to break up the go command from one package into a plausible group of packages. This sequence is concerned only with moving code, not changing or cleaning up code. There will still be more cleanup after this sequence. The entire sequence will be submitted together: it is not a goal for the tree to build at every step. For #18653. Change-Id: Ib22fc435827d4a05a77a5200ac437ce00e2a4da3 Reviewed-on: https://go-review.googlesource.com/36204 Reviewed-by: David Crawshaw <[email protected]>
1 parent 76db88a commit 707cadd

File tree

16 files changed

+80
-57
lines changed

16 files changed

+80
-57
lines changed

src/cmd/dist/deps.go

Lines changed: 16 additions & 1 deletion
Large diffs are not rendered by default.

src/cmd/go/clean.go renamed to src/cmd/go/internal/clean/clean.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package clean
66

77
import (
88
"fmt"
@@ -17,7 +17,7 @@ import (
1717
"cmd/go/internal/work"
1818
)
1919

20-
var cmdClean = &base.Command{
20+
var CmdClean = &base.Command{
2121
UsageLine: "clean [-i] [-r] [-n] [-x] [build flags] [packages]",
2222
Short: "remove object files",
2323
Long: `
@@ -68,15 +68,15 @@ var cleanR bool // clean -r flag
6868

6969
func init() {
7070
// break init cycle
71-
cmdClean.Run = runClean
71+
CmdClean.Run = runClean
7272

73-
cmdClean.Flag.BoolVar(&cleanI, "i", false, "")
74-
cmdClean.Flag.BoolVar(&cleanR, "r", false, "")
73+
CmdClean.Flag.BoolVar(&cleanI, "i", false, "")
74+
CmdClean.Flag.BoolVar(&cleanR, "r", false, "")
7575
// -n and -x are important enough to be
7676
// mentioned explicitly in the docs but they
7777
// are part of the build flags.
7878

79-
work.AddBuildFlags(cmdClean)
79+
work.AddBuildFlags(CmdClean)
8080
}
8181

8282
func runClean(cmd *base.Command, args []string) {

src/cmd/go/doc.go renamed to src/cmd/go/internal/doc/doc.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:generate ./mkalldocs.sh
6-
7-
package main
5+
package doc
86

97
import (
108
"cmd/go/internal/base"
119
"cmd/go/internal/cfg"
1210
)
1311

14-
var cmdDoc = &base.Command{
12+
var CmdDoc = &base.Command{
1513
Run: runDoc,
1614
UsageLine: "doc [-u] [-c] [package|[package.]symbol[.method]]",
1715
CustomFlags: true,

src/cmd/go/fix.go renamed to src/cmd/go/internal/fix/fix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package fix
66

77
import (
88
"cmd/go/internal/base"
@@ -11,7 +11,7 @@ import (
1111
"cmd/go/internal/str"
1212
)
1313

14-
var cmdFix = &base.Command{
14+
var CmdFix = &base.Command{
1515
Run: runFix,
1616
UsageLine: "fix [packages]",
1717
Short: "run go tool fix on packages",

src/cmd/go/generate.go renamed to src/cmd/go/internal/generate/generate.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package generate
66

77
import (
88
"bufio"
99
"bytes"
10-
"cmd/go/internal/base"
11-
"cmd/go/internal/cfg"
12-
"cmd/go/internal/load"
13-
"cmd/go/internal/work"
1410
"fmt"
1511
"io"
1612
"log"
@@ -20,9 +16,14 @@ import (
2016
"regexp"
2117
"strconv"
2218
"strings"
19+
20+
"cmd/go/internal/base"
21+
"cmd/go/internal/cfg"
22+
"cmd/go/internal/load"
23+
"cmd/go/internal/work"
2324
)
2425

25-
var cmdGenerate = &base.Command{
26+
var CmdGenerate = &base.Command{
2627
Run: runGenerate,
2728
UsageLine: "generate [-run regexp] [-n] [-v] [-x] [build flags] [file.go... | packages]",
2829
Short: "generate Go files by processing source",
@@ -135,8 +136,8 @@ var (
135136
)
136137

137138
func init() {
138-
work.AddBuildFlags(cmdGenerate)
139-
cmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "")
139+
work.AddBuildFlags(CmdGenerate)
140+
CmdGenerate.Flag.StringVar(&generateRunFlag, "run", "", "")
140141
}
141142

142143
func runGenerate(cmd *base.Command, args []string) {

src/cmd/go/generate_test.go renamed to src/cmd/go/internal/generate/generate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package generate
66

77
import (
88
"reflect"

src/cmd/go/pkg_test.go renamed to src/cmd/go/internal/get/pkg_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package get
66

77
import (
88
"cmd/go/internal/load"

src/cmd/go/tag_test.go renamed to src/cmd/go/internal/get/tag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package get
66

77
import "testing"
88

src/cmd/go/vcs_test.go renamed to src/cmd/go/internal/get/vcs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package get
66

77
import (
88
"errors"

src/cmd/go/context.go renamed to src/cmd/go/internal/list/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package list
66

77
import (
88
"go/build"

src/cmd/go/list.go renamed to src/cmd/go/internal/list/list.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package list
66

77
import (
88
"bufio"
@@ -17,7 +17,7 @@ import (
1717
"text/template"
1818
)
1919

20-
var cmdList = &base.Command{
20+
var CmdList = &base.Command{
2121
UsageLine: "list [-e] [-f format] [-json] [build flags] [packages]",
2222
Short: "list packages",
2323
Long: `
@@ -140,13 +140,13 @@ For more about specifying packages, see 'go help packages'.
140140
}
141141

142142
func init() {
143-
cmdList.Run = runList // break init cycle
144-
work.AddBuildFlags(cmdList)
143+
CmdList.Run = runList // break init cycle
144+
work.AddBuildFlags(CmdList)
145145
}
146146

147-
var listE = cmdList.Flag.Bool("e", false, "")
148-
var listFmt = cmdList.Flag.String("f", "{{.ImportPath}}", "")
149-
var listJson = cmdList.Flag.Bool("json", false, "")
147+
var listE = CmdList.Flag.Bool("e", false, "")
148+
var listFmt = CmdList.Flag.String("f", "{{.ImportPath}}", "")
149+
var listJson = CmdList.Flag.Bool("json", false, "")
150150
var nl = []byte{'\n'}
151151

152152
func runList(cmd *base.Command, args []string) {

src/cmd/go/run.go renamed to src/cmd/go/internal/run/run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package run
66

77
import (
88
"fmt"
@@ -16,7 +16,7 @@ import (
1616
"cmd/go/internal/work"
1717
)
1818

19-
var cmdRun = &base.Command{
19+
var CmdRun = &base.Command{
2020
UsageLine: "run [build flags] [-exec xprog] gofiles... [arguments...]",
2121
Short: "compile and run Go program",
2222
Long: `
@@ -40,10 +40,10 @@ See also: go build.
4040
}
4141

4242
func init() {
43-
cmdRun.Run = runRun // break init loop
43+
CmdRun.Run = runRun // break init loop
4444

45-
work.AddBuildFlags(cmdRun)
46-
cmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
45+
work.AddBuildFlags(CmdRun)
46+
CmdRun.Flag.Var((*base.StringsFlag)(&work.ExecCmd), "exec", "")
4747
}
4848

4949
func printStderr(args ...interface{}) (int, error) {

src/cmd/go/tool.go renamed to src/cmd/go/internal/tool/tool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package tool
66

77
import (
88
"fmt"
@@ -15,7 +15,7 @@ import (
1515
"cmd/go/internal/cfg"
1616
)
1717

18-
var cmdTool = &base.Command{
18+
var CmdTool = &base.Command{
1919
Run: runTool,
2020
UsageLine: "tool [-n] command [args...]",
2121
Short: "run specified go tool",
@@ -33,7 +33,7 @@ For more about each tool command, see 'go tool command -h'.
3333
var toolN bool
3434

3535
func init() {
36-
cmdTool.Flag.BoolVar(&toolN, "n", false, "")
36+
CmdTool.Flag.BoolVar(&toolN, "n", false, "")
3737
}
3838

3939
func runTool(cmd *base.Command, args []string) {

src/cmd/go/version.go renamed to src/cmd/go/internal/version/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package version
66

77
import (
88
"cmd/go/internal/base"
99
"fmt"
1010
"runtime"
1111
)
1212

13-
var cmdVersion = &base.Command{
13+
var CmdVersion = &base.Command{
1414
Run: runVersion,
1515
UsageLine: "version",
1616
Short: "print Go version",

src/cmd/go/vet.go renamed to src/cmd/go/internal/vet/vet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package main
5+
package vet
66

77
import (
88
"path/filepath"
@@ -15,10 +15,10 @@ import (
1515
)
1616

1717
func init() {
18-
work.AddBuildFlags(cmdVet)
18+
work.AddBuildFlags(CmdVet)
1919
}
2020

21-
var cmdVet = &base.Command{
21+
var CmdVet = &base.Command{
2222
Run: runVet,
2323
UsageLine: "vet [-n] [-x] [build flags] [packages]",
2424
Short: "run go tool vet on packages",

src/cmd/go/main.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:generate ./mkalldocs.sh
6+
57
package main
68

79
import (
@@ -16,32 +18,41 @@ import (
1618
"cmd/go/internal/base"
1719
"cmd/go/internal/bug"
1820
"cmd/go/internal/cfg"
21+
"cmd/go/internal/clean"
22+
"cmd/go/internal/doc"
1923
"cmd/go/internal/env"
24+
"cmd/go/internal/fix"
2025
fmtcmd "cmd/go/internal/fmt"
26+
"cmd/go/internal/generate"
2127
"cmd/go/internal/get"
2228
"cmd/go/internal/help"
29+
"cmd/go/internal/list"
30+
"cmd/go/internal/run"
2331
"cmd/go/internal/test"
32+
"cmd/go/internal/tool"
33+
"cmd/go/internal/version"
34+
"cmd/go/internal/vet"
2435
"cmd/go/internal/work"
2536
)
2637

2738
func init() {
2839
base.Commands = []*base.Command{
2940
work.CmdBuild,
30-
cmdClean,
31-
cmdDoc,
41+
clean.CmdClean,
42+
doc.CmdDoc,
3243
env.CmdEnv,
3344
bug.CmdBug,
34-
cmdFix,
45+
fix.CmdFix,
3546
fmtcmd.CmdFmt,
36-
cmdGenerate,
47+
generate.CmdGenerate,
3748
get.CmdGet,
3849
work.CmdInstall,
39-
cmdList,
40-
cmdRun,
50+
list.CmdList,
51+
run.CmdRun,
4152
test.CmdTest,
42-
cmdTool,
43-
cmdVersion,
44-
cmdVet,
53+
tool.CmdTool,
54+
version.CmdVersion,
55+
vet.CmdVet,
4556

4657
help.HelpC,
4758
help.HelpBuildmode,
@@ -130,8 +141,6 @@ func main() {
130141
base.Exit()
131142
}
132143

133-
var usage func()
134-
135144
func init() {
136145
base.Usage = mainUsage
137146
}

0 commit comments

Comments
 (0)