mirror of https://github.com/gogits/gogs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.7 KiB
80 lines
1.7 KiB
12 years ago
|
// Copyright (c) 2013 GPMGo Members. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
12 years ago
|
package cmd
|
||
12 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
|
||
12 years ago
|
"github.com/GPMGo/gopm/utils"
|
||
12 years ago
|
)
|
||
|
|
||
12 years ago
|
var CmdBuild = &Command{
|
||
12 years ago
|
UsageLine: "build [build flags] [packages]",
|
||
12 years ago
|
}
|
||
|
|
||
|
func init() {
|
||
12 years ago
|
CmdBuild.Run = runBuild
|
||
|
CmdBuild.Flags = map[string]bool{
|
||
12 years ago
|
"-v": false,
|
||
|
"-r": false,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// printBuildPrompt prints prompt information to users to
|
||
|
// let them know what's going on.
|
||
|
func printBuildPrompt(flag string) {
|
||
|
switch flag {
|
||
|
|
||
|
}
|
||
12 years ago
|
}
|
||
|
|
||
|
func runBuild(cmd *Command, args []string) {
|
||
12 years ago
|
// Check flags.
|
||
12 years ago
|
num := checkFlags(cmd.Flags, Config.AutoEnable.Build, args, printBuildPrompt)
|
||
12 years ago
|
if num == -1 {
|
||
|
return
|
||
|
}
|
||
|
args = args[num:]
|
||
|
|
||
12 years ago
|
var cmdArgs []string
|
||
|
cmdArgs = append(cmdArgs, "install")
|
||
12 years ago
|
if CmdBuild.Flags["-v"] {
|
||
12 years ago
|
cmdArgs = append(cmdArgs, "-v")
|
||
|
}
|
||
|
|
||
|
executeCommand("go", cmdArgs)
|
||
12 years ago
|
|
||
|
// Find executable in GOPATH and copy to current directory.
|
||
12 years ago
|
wd, _ := os.Getwd()
|
||
|
proName := utils.GetExecuteName(wd)
|
||
12 years ago
|
paths := utils.GetGOPATH()
|
||
|
|
||
12 years ago
|
for _, v := range paths {
|
||
|
if utils.IsExist(v + "/bin/" + proName) {
|
||
12 years ago
|
if utils.IsExist(wd + "/" + proName) {
|
||
|
err := os.Remove(wd + "/" + proName)
|
||
|
if err != nil {
|
||
12 years ago
|
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] %s\n", PromptMsg["RemoveFile"]), err))
|
||
12 years ago
|
return
|
||
|
}
|
||
12 years ago
|
}
|
||
12 years ago
|
err := os.Rename(v+"/bin/"+proName, wd+"/"+proName)
|
||
12 years ago
|
if err == nil {
|
||
12 years ago
|
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("<SUCCESS>$ %s\n", PromptMsg["MovedFile"]), v, wd))
|
||
12 years ago
|
// Check if need to run program.
|
||
12 years ago
|
if CmdBuild.Flags["-r"] {
|
||
12 years ago
|
cmdArgs = make([]string, 0)
|
||
|
executeCommand(proName, cmdArgs)
|
||
|
}
|
||
12 years ago
|
return
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
fmt.Printf(fmt.Sprintf("%s\n", PromptMsg["MoveFile"]), v, wd)
|
||
12 years ago
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|