Browse Source

Done build and install

pull/103/head
Unknown 11 years ago
parent
commit
7326b09b3d
  1. 7
      README.md
  2. 42
      cmd/build.go
  3. 45
      cmd/gopath.go
  4. 47
      cmd/install.go
  5. 5
      cmd/run.go
  6. 7
      gopm.go

7
README.md

@ -5,7 +5,7 @@ gopm - Go Package Manager
Gopm(Go Package Manager) is a Go package manage tool for search, install, update and share packages in Go.
Current Version: **v0.5.1**
Current Version: **v0.5.5**
# Requirement
@ -40,11 +40,14 @@ USAGE:
gopm [global options] command [command options] [arguments...]
VERSION:
0.5.2.1109
0.5.5.1111
COMMANDS:
get fetch remote package(s) and dependencies to local repository
gen generate a gopmfile according current go project
run link dependencies and go run
build link dependencies and go build
install link dependencies and go install
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:

42
cmd/build.go

@ -15,37 +15,33 @@
package cmd
import (
"github.com/Unknwon/com"
)
"github.com/codegangsta/cli"
var CmdBuild = &Command{
UsageLine: "build",
Short: "build according a gopmfile",
Long: `
build just like go build
`,
}
"github.com/gpmgo/gopm/log"
)
func init() {
CmdBuild.Run = runBuild
CmdBuild.Flags = map[string]bool{}
}
var CmdBuild = cli.Command{
Name: "build",
Usage: "link dependencies and go build",
Description: `Command build links dependencies according to gopmfile,
and execute 'go build'
func printBuildPrompt(flag string) {
gopm build <go build commands>`,
Action: runBuild,
}
func runBuild(cmd *Command, args []string) {
//genNewGoPath()
func runBuild(ctx *cli.Context) {
genNewGoPath(ctx)
com.ColorLog("[INFO] building ...\n")
log.Trace("Building...")
cmds := []string{"go", "build"}
cmds = append(cmds, args...)
err := execCmd(newGoPath, newCurPath, cmds...)
cmdArgs := []string{"go", "build"}
cmdArgs = append(cmdArgs, ctx.Args()...)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
com.ColorLog("[ERRO] build failed: %v\n", err)
return
log.Error("Build", "Fail to build program")
log.Fatal("", err.Error())
}
com.ColorLog("[SUCC] build successfully!\n")
log.Success("SUCC", "Build", "Command execute successfully!")
}

45
cmd/gopath.go

@ -1,6 +1,7 @@
package cmd
import (
"fmt"
"go/build"
"os"
"os/exec"
@ -110,44 +111,54 @@ var newGoPath string
func execCmd(gopath, curPath string, args ...string) error {
cwd, err := os.Getwd()
if err != nil {
return err
log.Error("", "Fail to get work directory")
log.Fatal("", err.Error())
}
com.ColorLog("[INFO] change current dir from %v to %v\n", cwd, curPath)
err = os.Chdir(filepath.Join(cwd, "vendor"))
if err != nil {
com.ColorLog("[ERRO] change current directory error %v\n", err)
return err
}
log.Log("Changing work directory to %s", curPath)
err = os.Chdir(curPath)
if err != nil {
com.ColorLog("[ERRO] change current directory error %v\n", err)
return err
log.Error("", "Fail to change work directory")
log.Fatal("", err.Error())
}
defer os.Chdir(cwd)
defer func() {
log.Log("Changing work directory back to %s", cwd)
os.Chdir(cwd)
}()
ccmd := exec.Command("cd", curPath)
ccmd.Stdout = os.Stdout
ccmd.Stderr = os.Stderr
err = ccmd.Run()
if err != nil {
com.ColorLog("[ERRO] change current directory error %v\n", err)
return err
log.Error("", "Fail to change work directory")
log.Fatal("", err.Error())
}
oldGoPath := os.Getenv("GOPATH")
com.ColorLog("[TRAC] set GOPATH from %v to %v\n", oldGoPath, gopath)
log.Log("Setting GOPATH to %s", gopath)
err = os.Setenv("GOPATH", gopath)
if err != nil {
com.ColorLog("[ERRO] %v\n", err)
return err
log.Error("", "Fail to setting GOPATH")
log.Fatal("", err.Error())
}
defer os.Setenv("GOPATH", oldGoPath)
defer func() {
log.Log("Setting GOPATH back to %s", oldGoPath)
os.Setenv("GOPATH", oldGoPath)
}()
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
log.Log("===== application outputs start =====\n")
err = cmd.Run()
fmt.Println()
log.Log("====== application outputs end ======")
return err
}
func genNewGoPath(ctx *cli.Context) {

47
cmd/install.go

@ -16,36 +16,45 @@ package cmd
import (
"github.com/Unknwon/com"
"github.com/codegangsta/cli"
"github.com/gpmgo/gopm/doc"
"github.com/gpmgo/gopm/log"
)
var CmdInstall = &Command{
UsageLine: "install",
Short: "install according a gopmfile",
Long: `
install just like go install
`,
var CmdInstall = cli.Command{
Name: "install",
Usage: "link dependencies and go install",
Description: `Command install links dependencies according to gopmfile,
and execute 'go install'
gopm install`,
Action: runInstall,
}
func init() {
CmdInstall.Run = runInstall
CmdInstall.Flags = map[string]bool{}
func runInstall(ctx *cli.Context) {
if !com.IsFile(".gopmfile") {
log.Fatal("Install", "No gopmfile exist in work directory")
}
func printInstallPrompt(flag string) {
gf := doc.NewGopmfile(".")
target := gf.MustValue("target", "path")
if len(target) == 0 {
log.Fatal("Install", "Cannot find target in gopmfile")
}
func runInstall(cmd *Command, args []string) {
//genNewGoPath()
genNewGoPath(ctx)
com.ColorLog("[INFO] installing ...\n")
log.Trace("Installing...")
cmds := []string{"go", "install"}
cmds = append(cmds, args...)
err := execCmd(newGoPath, newCurPath, cmds...)
cmdArgs := []string{"go", "install"}
cmdArgs = append(cmdArgs, ctx.Args()...)
cmdArgs = append(cmdArgs, target)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
com.ColorLog("[ERRO] install failed: %v\n", err)
return
log.Error("Install", "Fail to install program")
log.Fatal("", err.Error())
}
com.ColorLog("[SUCC] install successfully!\n")
log.Success("SUCC", "Install", "Command execute successfully!")
}

5
cmd/run.go

@ -28,9 +28,10 @@ import (
var CmdRun = cli.Command{
Name: "run",
Usage: "link dependencies and go run",
Description: `Command run links dependencies according to gopmfile
Description: `Command run links dependencies according to gopmfile,
and execute 'go run'
gopm run <file names>`,
gopm run <go run commands>`,
Action: runRun,
}

7
gopm.go

@ -29,12 +29,9 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true
const APP_VER = "0.5.4.1110"
const APP_VER = "0.5.5.1111"
// //cmd.CmdSearch,
// cmd.CmdBuild,
// cmd.CmdInstall,
// cmdClean,
// cmdDoc,
// cmdEnv,
@ -58,6 +55,8 @@ func main() {
cmd.CmdGet,
cmd.CmdGen,
cmd.CmdRun,
cmd.CmdBuild,
cmd.CmdInstall,
}
app.Run(os.Args)
}

Loading…
Cancel
Save