show debug flag
This commit is contained in:
parent
3115bead40
commit
346530150c
12
cmd/build.go
12
cmd/build.go
@ -43,14 +43,18 @@ goc build -- -o /to/this/path
|
||||
goc build -- -ldflags "-extldflags -static" -tags="embed kodo"
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
gocbuild := build.NewBuild(buildFlags, packages, buildOutput)
|
||||
gocBuild := build.NewBuild(buildFlags, packages, buildOutput)
|
||||
// remove temporary directory if needed
|
||||
defer gocbuild.RemoveTmpDir()
|
||||
defer func() {
|
||||
if !debugGoc {
|
||||
gocBuild.Clean()
|
||||
}
|
||||
}()
|
||||
// doCover with original buildFlags, with new GOPATH( tmp:original )
|
||||
// in the tmp directory
|
||||
doCover(buildFlags, gocbuild.NewGOPATH, gocbuild.TmpDir)
|
||||
doCover(buildFlags, gocBuild.NewGOPATH, gocBuild.TmpDir)
|
||||
// do install in the temporary directory
|
||||
gocbuild.Build()
|
||||
gocBuild.Build()
|
||||
return
|
||||
},
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var installCmd = &cobra.Command{
|
||||
Long: `
|
||||
First of all, this install command will copy the project code and its necessary dependencies to a temporary directory, then do cover for the target in this temporary directory, finally go install command will be executed and binaries generated to their original place.
|
||||
|
||||
To pass origial go build flags to goc command, place them after "--", see examples below for reference.
|
||||
To pass original go build flags to goc command, place them after "--", see examples below for reference.
|
||||
`,
|
||||
Example: `
|
||||
# Install all binaries with cover variables injected. The binary will be installed in $GOPATH/bin or $HOME/go/bin if directory existed.
|
||||
@ -40,14 +40,18 @@ goc install --center=http://127.0.0.1:7777
|
||||
goc build --buildflags="-ldflags '-extldflags -static' -tags='embed kodo'"
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
gocbuild := build.NewInstall(buildFlags, packages)
|
||||
gocBuild := build.NewInstall(buildFlags, packages)
|
||||
// remove temporary directory if needed
|
||||
defer gocbuild.RemoveTmpDir()
|
||||
defer func() {
|
||||
if !debugGoc {
|
||||
gocBuild.Clean()
|
||||
}
|
||||
}()
|
||||
// doCover with original buildFlags, with new GOPATH( tmp:original )
|
||||
// in the tmp directory
|
||||
doCover(buildFlags, gocbuild.NewGOPATH, gocbuild.TmpDir)
|
||||
doCover(buildFlags, gocBuild.NewGOPATH, gocBuild.TmpDir)
|
||||
// do install in the temporary directory
|
||||
gocbuild.Install()
|
||||
gocBuild.Install()
|
||||
},
|
||||
}
|
||||
|
||||
|
10
cmd/root.go
10
cmd/root.go
@ -17,13 +17,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
@ -54,8 +55,7 @@ Find more information at:
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVar(&debugGoc, "debuggoc", false, "turn goc into debug mode")
|
||||
rootCmd.PersistentFlags().MarkHidden("debuggoc")
|
||||
rootCmd.PersistentFlags().BoolVar(&debugGoc, "debug", false, "run goc in debug mode")
|
||||
viper.BindPFlags(rootCmd.PersistentFlags())
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ func (b *Build) determineOutputDir(outputDir string) string {
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot get current working directory, the err: %v.", err)
|
||||
}
|
||||
// if
|
||||
|
||||
if outputDir == "" {
|
||||
_, last := filepath.Split(curWorkingDir)
|
||||
if b.IsMod {
|
||||
|
@ -19,12 +19,12 @@ package build
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/qiniu/goc/pkg/cover"
|
||||
)
|
||||
|
||||
@ -57,7 +57,7 @@ func (b *Build) MvProjectsToTmp() {
|
||||
func (b *Build) mvProjectsToTmp() {
|
||||
path, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot get current working directoy, the error is: %v", err)
|
||||
log.Fatalf("Cannot get current working directory, the error is: %v", err)
|
||||
}
|
||||
b.TmpDir = filepath.Join(os.TempDir(), TmpFolderName(path))
|
||||
|
||||
@ -70,7 +70,7 @@ func (b *Build) mvProjectsToTmp() {
|
||||
}
|
||||
log.Printf("Tmp project generated in: %v", b.TmpDir)
|
||||
|
||||
// set Build.IsMod flag, so we dont have to call checkIfLegacyProject another time
|
||||
// set Build.IsMod flag, so we don't have to call checkIfLegacyProject another time
|
||||
if b.checkIfLegacyProject() {
|
||||
b.cpLegacyProject()
|
||||
} else {
|
||||
@ -154,11 +154,7 @@ func (b *Build) findWhereToInstall() string {
|
||||
return filepath.Join(os.Getenv("HOME"), "go", "bin")
|
||||
}
|
||||
|
||||
func (b *Build) RemoveTmpDir() {
|
||||
debuggoc := viper.GetBool("debuggoc")
|
||||
if debuggoc == false {
|
||||
if b.TmpDir != "" {
|
||||
os.RemoveAll(b.TmpDir)
|
||||
}
|
||||
}
|
||||
// Clean clears up the temporary workspace
|
||||
func (b *Build) Clean() error {
|
||||
return os.RemoveAll(b.TmpDir)
|
||||
}
|
||||
|
@ -20,11 +20,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/qiniu/goc/pkg/build"
|
||||
@ -55,7 +54,7 @@ var _ = Describe("E2E", func() {
|
||||
|
||||
By("goc build")
|
||||
testProjDir := filepath.Join(TESTS_ROOT, "samples/simple_project")
|
||||
cmd := exec.Command("goc", "build", "--debuggoc")
|
||||
cmd := exec.Command("goc", "build", "--debug")
|
||||
cmd.Dir = testProjDir
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
@ -63,7 +62,7 @@ var _ = Describe("E2E", func() {
|
||||
|
||||
By("goc install")
|
||||
testProjDir = filepath.Join(TESTS_ROOT, "samples/simple_project")
|
||||
cmd = exec.Command("goc", "install", "--debuggoc")
|
||||
cmd = exec.Command("goc", "install", "--debug")
|
||||
cmd.Dir = testProjDir
|
||||
|
||||
out, err = cmd.CombinedOutput()
|
||||
@ -114,7 +113,7 @@ var _ = Describe("E2E", func() {
|
||||
GOPATH = testProjDir
|
||||
|
||||
By("goc build")
|
||||
cmd := exec.Command("goc", "build", "--debuggoc")
|
||||
cmd := exec.Command("goc", "build", "--debug")
|
||||
cmd.Dir = oriWorkingDir
|
||||
// use GOPATH mode to compile project
|
||||
cmd.Env = append(os.Environ(), fmt.Sprintf("GOPATH=%v", GOPATH), "GO111MODULE=off")
|
||||
@ -125,7 +124,7 @@ var _ = Describe("E2E", func() {
|
||||
|
||||
By("goc install")
|
||||
testProjDir = filepath.Join(TESTS_ROOT, "samples/simple_gopath_project")
|
||||
cmd = exec.Command("goc", "install", "--debuggoc")
|
||||
cmd = exec.Command("goc", "install", "--debug")
|
||||
cmd.Dir = filepath.Join(testProjDir, "src/qiniu.com/simple_gopath_project")
|
||||
// use GOPATH mode to compile project
|
||||
cmd.Env = append(os.Environ(), fmt.Sprintf("GOPATH=%v", testProjDir), "GO111MODULE=off")
|
||||
@ -157,7 +156,7 @@ var _ = Describe("E2E", func() {
|
||||
Expect(err).To(BeNil(), "the binary cannot be disassembled")
|
||||
|
||||
cnt := strings.Count(string(out), "GoCover")
|
||||
Expect(cnt).To(BeNumerically(">", 0), "GoCover varibale should be in the binary")
|
||||
Expect(cnt).To(BeNumerically(">", 0), "GoCover variable should be in the binary")
|
||||
|
||||
cnt = strings.Count(string(out), "main.registerSelf")
|
||||
Expect(cnt).To(BeNumerically(">", 0), "main.registerSelf function should be in the binary")
|
||||
|
Loading…
Reference in New Issue
Block a user