Browse Source

add flag -r for command build, run program after bulit.

pull/103/head
Unknown 12 years ago
parent
commit
3ab478ff79
  1. 1
      README.md
  2. 32
      build.go
  3. 37
      i18n/en-US/usage_build.txt
  4. 14
      install.go

1
README.md

@ -30,6 +30,7 @@ This application still in experiment, any change could happen, but it doesn't af
## Todo
- Add template projects for testing commands.
- Command `search` is for searching packages.
- Add gpm working principle design.
- Add support for downloading tarballs from user sources.
- After downloaded all packages in bundles or snapshots, need to check if all dependencies have been downloaded as well.

32
build.go

@ -20,12 +20,35 @@ var cmdBuild = &Command{
func init() {
cmdBuild.Run = runBuild
cmdBuild.Flags = map[string]bool{
"-v": false,
"-r": false,
}
}
// printBuildPrompt prints prompt information to users to
// let them know what's going on.
func printBuildPrompt(flag string) {
switch flag {
}
}
func runBuild(cmd *Command, args []string) {
// Check flags.
num := checkFlags(cmd.Flags, args, printBuildPrompt)
if num == -1 {
return
}
args = args[num:]
var cmdArgs []string
cmdArgs = append(cmdArgs, "install")
cmdArgs = append(cmdArgs, args...)
if cmdBuild.Flags["-v"] {
cmdArgs = append(cmdArgs, "-v")
}
executeCommand("go", cmdArgs)
wd, _ := os.Getwd()
wd = strings.Replace(wd, "\\", "/", -1)
@ -34,8 +57,6 @@ func runBuild(cmd *Command, args []string) {
proName += ".exe"
}
executeCommand("go", cmdArgs)
// Find executable in GOPATH and copy to current directory.
paths := utils.GetGOPATH()
@ -51,6 +72,11 @@ func runBuild(cmd *Command, args []string) {
err := os.Rename(v+"/bin/"+proName, wd+"/"+proName)
if err == nil {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["MovedFile"]), v, wd)
// Check if need to run program.
if cmdBuild.Flags["-r"] {
cmdArgs = make([]string, 0)
executeCommand(proName, cmdArgs)
}
return
}

37
i18n/en-US/usage_build.txt

@ -15,43 +15,10 @@ name is the base name of the containing directory.
The build flags are shared by the build and test commands:
-a
force rebuilding of packages that are already up-to-date.
-n
print the commands but do not run them.
-p n
the number of builds that can be run in parallel.
The default is the number of CPUs available.
-race
enable data race detection.
Supported only on linux/amd64, darwin/amd64 and windows/amd64.
-v
print the names of packages as they are compiled.
-work
print the name of the temporary work directory and
do not delete it when exiting.
-x
print the commands.
-ccflags 'arg list'
arguments to pass on each 5c, 6c, or 8c compiler invocation.
-compiler name
name of compiler to use, as in runtime.Compiler (gccgo or gc).
-gccgoflags 'arg list'
arguments to pass on each gccgo compiler/linker invocation.
-gcflags 'arg list'
arguments to pass on each 5g, 6g, or 8g compiler invocation.
-installsuffix suffix
a suffix to use in the name of the package installation directory,
in order to keep output separate from default builds.
If using the -race flag, the install suffix is automatically set to race
or, if set explicitly, has _race appended to it.
-ldflags 'flag list'
arguments to pass on each 5l, 6l, or 8l linker invocation.
-tags 'tag list'
a list of build tags to consider satisfied during the build.
See the documentation for the go/build package for
more information about build tags.
-r
run program after built.
The list flags accept a space-separated list of strings. To embed spaces
in an element in the list, surround it with either single or double quotes.

14
install.go

@ -40,9 +40,9 @@ func init() {
}
}
// printPrompt prints prompt information to users to
// printInstallPrompt prints prompt information to users to
// let them know what's going on.
func printPrompt(flag string) {
func printInstallPrompt(flag string) {
switch flag {
case "-p":
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["PureDownload"]))
@ -56,7 +56,7 @@ func printPrompt(flag string) {
}
// checkFlags checks if the flag exists with correct format.
func checkFlags(args []string) int {
func checkFlags(flags map[string]bool, args []string, print func(string)) int {
num := 0 // Number of valid flags, use to cut out.
for i, f := range args {
// Check flag prefix '-'.
@ -68,9 +68,9 @@ func checkFlags(args []string) int {
// Check if it a valid flag.
/* Here we use ok pattern to check it because
this way can avoid same flag appears multiple times.*/
if _, ok := cmdInstall.Flags[f]; ok {
cmdInstall.Flags[f] = true
printPrompt(f)
if _, ok := flags[f]; ok {
flags[f] = true
print(f)
} else {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["UnknownFlag"]), f)
return -1
@ -96,7 +96,7 @@ func checkVCSTool() {
func runInstall(cmd *Command, args []string) {
// Check flags.
num := checkFlags(args)
num := checkFlags(cmd.Flags, args, printInstallPrompt)
if num == -1 {
return
}

Loading…
Cancel
Save