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 ## Todo
- Add template projects for testing commands. - Add template projects for testing commands.
- Command `search` is for searching packages.
- Add gpm working principle design. - Add gpm working principle design.
- Add support for downloading tarballs from user sources. - 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. - 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() { func init() {
cmdBuild.Run = runBuild 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) { func runBuild(cmd *Command, args []string) {
// Check flags.
num := checkFlags(cmd.Flags, args, printBuildPrompt)
if num == -1 {
return
}
args = args[num:]
var cmdArgs []string var cmdArgs []string
cmdArgs = append(cmdArgs, "install") cmdArgs = append(cmdArgs, "install")
cmdArgs = append(cmdArgs, args...) if cmdBuild.Flags["-v"] {
cmdArgs = append(cmdArgs, "-v")
}
executeCommand("go", cmdArgs)
wd, _ := os.Getwd() wd, _ := os.Getwd()
wd = strings.Replace(wd, "\\", "/", -1) wd = strings.Replace(wd, "\\", "/", -1)
@ -34,8 +57,6 @@ func runBuild(cmd *Command, args []string) {
proName += ".exe" proName += ".exe"
} }
executeCommand("go", cmdArgs)
// Find executable in GOPATH and copy to current directory. // Find executable in GOPATH and copy to current directory.
paths := utils.GetGOPATH() paths := utils.GetGOPATH()
@ -51,6 +72,11 @@ func runBuild(cmd *Command, args []string) {
err := os.Rename(v+"/bin/"+proName, wd+"/"+proName) err := os.Rename(v+"/bin/"+proName, wd+"/"+proName)
if err == nil { if err == nil {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["MovedFile"]), v, wd) 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 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: 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 -v
print the names of packages as they are compiled. print the names of packages as they are compiled.
-work -r
print the name of the temporary work directory and run program after built.
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.
The list flags accept a space-separated list of strings. To embed spaces 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. 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. // let them know what's going on.
func printPrompt(flag string) { func printInstallPrompt(flag string) {
switch flag { switch flag {
case "-p": case "-p":
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["PureDownload"])) 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. // 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. num := 0 // Number of valid flags, use to cut out.
for i, f := range args { for i, f := range args {
// Check flag prefix '-'. // Check flag prefix '-'.
@ -68,9 +68,9 @@ func checkFlags(args []string) int {
// Check if it a valid flag. // Check if it a valid flag.
/* Here we use ok pattern to check it because /* Here we use ok pattern to check it because
this way can avoid same flag appears multiple times.*/ this way can avoid same flag appears multiple times.*/
if _, ok := cmdInstall.Flags[f]; ok { if _, ok := flags[f]; ok {
cmdInstall.Flags[f] = true flags[f] = true
printPrompt(f) print(f)
} else { } else {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["UnknownFlag"]), f) fmt.Printf(fmt.Sprintf("%s\n", promptMsg["UnknownFlag"]), f)
return -1 return -1
@ -96,7 +96,7 @@ func checkVCSTool() {
func runInstall(cmd *Command, args []string) { func runInstall(cmd *Command, args []string) {
// Check flags. // Check flags.
num := checkFlags(args) num := checkFlags(cmd.Flags, args, printInstallPrompt)
if num == -1 { if num == -1 {
return return
} }

Loading…
Cancel
Save