Browse Source

Done build and install

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

17
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. 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 # Requirement
@ -40,16 +40,19 @@ USAGE:
gopm [global options] command [command options] [arguments...] gopm [global options] command [command options] [arguments...]
VERSION: VERSION:
0.5.2.1109 0.5.5.1111
COMMANDS: COMMANDS:
get fetch remote package(s) and dependencies to local repository get fetch remote package(s) and dependencies to local repository
gen generate a gopmfile according current go project gen generate a gopmfile according current go project
help, h Shows a list of commands or help for one command 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: GLOBAL OPTIONS:
--version print the version --version print the version
--help, -h show help --help, -h show help
``` ```

42
cmd/build.go

@ -15,37 +15,33 @@
package cmd package cmd
import ( import (
"github.com/Unknwon/com" "github.com/codegangsta/cli"
)
var CmdBuild = &Command{ "github.com/gpmgo/gopm/log"
UsageLine: "build", )
Short: "build according a gopmfile",
Long: `
build just like go build
`,
}
func init() { var CmdBuild = cli.Command{
CmdBuild.Run = runBuild Name: "build",
CmdBuild.Flags = map[string]bool{} 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) { func runBuild(ctx *cli.Context) {
//genNewGoPath() genNewGoPath(ctx)
com.ColorLog("[INFO] building ...\n") log.Trace("Building...")
cmds := []string{"go", "build"} cmdArgs := []string{"go", "build"}
cmds = append(cmds, args...) cmdArgs = append(cmdArgs, ctx.Args()...)
err := execCmd(newGoPath, newCurPath, cmds...) err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil { if err != nil {
com.ColorLog("[ERRO] build failed: %v\n", err) log.Error("Build", "Fail to build program")
return 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 package cmd
import ( import (
"fmt"
"go/build" "go/build"
"os" "os"
"os/exec" "os/exec"
@ -110,44 +111,54 @@ var newGoPath string
func execCmd(gopath, curPath string, args ...string) error { func execCmd(gopath, curPath string, args ...string) error {
cwd, err := os.Getwd() cwd, err := os.Getwd()
if err != nil { 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) log.Log("Changing work directory to %s", curPath)
err = os.Chdir(filepath.Join(cwd, "vendor"))
if err != nil {
com.ColorLog("[ERRO] change current directory error %v\n", err)
return err
}
err = os.Chdir(curPath) err = os.Chdir(curPath)
if err != nil { if err != nil {
com.ColorLog("[ERRO] change current directory error %v\n", err) log.Error("", "Fail to change work directory")
return err 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 := exec.Command("cd", curPath)
ccmd.Stdout = os.Stdout ccmd.Stdout = os.Stdout
ccmd.Stderr = os.Stderr ccmd.Stderr = os.Stderr
err = ccmd.Run() err = ccmd.Run()
if err != nil { if err != nil {
com.ColorLog("[ERRO] change current directory error %v\n", err) log.Error("", "Fail to change work directory")
return err log.Fatal("", err.Error())
} }
oldGoPath := os.Getenv("GOPATH") 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) err = os.Setenv("GOPATH", gopath)
if err != nil { if err != nil {
com.ColorLog("[ERRO] %v\n", err) log.Error("", "Fail to setting GOPATH")
return err 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 := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr 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) { func genNewGoPath(ctx *cli.Context) {

51
cmd/install.go

@ -16,36 +16,45 @@ package cmd
import ( import (
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/codegangsta/cli"
"github.com/gpmgo/gopm/doc"
"github.com/gpmgo/gopm/log"
) )
var CmdInstall = &Command{ var CmdInstall = cli.Command{
UsageLine: "install", Name: "install",
Short: "install according a gopmfile", Usage: "link dependencies and go install",
Long: ` Description: `Command install links dependencies according to gopmfile,
install just like go install and execute 'go install'
`,
}
func init() { gopm install`,
CmdInstall.Run = runInstall Action: runInstall,
CmdInstall.Flags = map[string]bool{}
} }
func printInstallPrompt(flag string) { func runInstall(ctx *cli.Context) {
} if !com.IsFile(".gopmfile") {
log.Fatal("Install", "No gopmfile exist in work directory")
}
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(ctx)
//genNewGoPath()
com.ColorLog("[INFO] installing ...\n") log.Trace("Installing...")
cmds := []string{"go", "install"} cmdArgs := []string{"go", "install"}
cmds = append(cmds, args...) cmdArgs = append(cmdArgs, ctx.Args()...)
err := execCmd(newGoPath, newCurPath, cmds...) cmdArgs = append(cmdArgs, target)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil { if err != nil {
com.ColorLog("[ERRO] install failed: %v\n", err) log.Error("Install", "Fail to install program")
return 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{ var CmdRun = cli.Command{
Name: "run", Name: "run",
Usage: "link dependencies and go 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, 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. // Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true const go11tag = true
const APP_VER = "0.5.4.1110" const APP_VER = "0.5.5.1111"
// //cmd.CmdSearch, // //cmd.CmdSearch,
// cmd.CmdBuild,
// cmd.CmdInstall,
// cmdClean, // cmdClean,
// cmdDoc, // cmdDoc,
// cmdEnv, // cmdEnv,
@ -58,6 +55,8 @@ func main() {
cmd.CmdGet, cmd.CmdGet,
cmd.CmdGen, cmd.CmdGen,
cmd.CmdRun, cmd.CmdRun,
cmd.CmdBuild,
cmd.CmdInstall,
} }
app.Run(os.Args) app.Run(os.Args)
} }

Loading…
Cancel
Save