fix gofmt
This commit is contained in:
parent
fe93aca1a6
commit
5a2a6cd199
@ -18,8 +18,8 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
@ -19,8 +19,8 @@ package cmd
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/qiniu/goc/pkg/cover"
|
||||
|
@ -18,12 +18,13 @@ package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/qiniu/goc/pkg/cover"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/qiniu/goc/pkg/cover"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Build is to describe the building/installing process of a goc build/install
|
||||
@ -51,8 +52,8 @@ func NewBuild(buildflags string, packages string, outputDir string) *Build {
|
||||
if false == b.validatePackageForBuild() {
|
||||
log.Fatalln("packages only support \".\"")
|
||||
}
|
||||
b.Target = b.determineOutputDir(outputDir)
|
||||
b.MvProjectsToTmp()
|
||||
b.Target = b.determineOutputDir(outputDir)
|
||||
return b
|
||||
}
|
||||
|
||||
@ -79,6 +80,9 @@ func (b *Build) Build() {
|
||||
// determineOutputDir, as we only allow . as package name,
|
||||
// the binary name is always same as the directory name of current directory
|
||||
func (b *Build) determineOutputDir(outputDir string) string {
|
||||
if b.TmpDir == "" {
|
||||
log.Fatalln("Can only be called after Build.MvProjectsToTmp().")
|
||||
}
|
||||
curWorkingDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot get current working directory, the err: %v.", err)
|
||||
@ -86,8 +90,11 @@ func (b *Build) determineOutputDir(outputDir string) string {
|
||||
// if
|
||||
if outputDir == "" {
|
||||
_, last := filepath.Split(curWorkingDir)
|
||||
// replace "_" with "-" in the import path
|
||||
last = strings.ReplaceAll(last, "_", "-")
|
||||
if b.IsMod {
|
||||
// in mod, special rule
|
||||
// replace "_" with "-" in the import path
|
||||
last = strings.ReplaceAll(last, "_", "-")
|
||||
}
|
||||
return filepath.Join(curWorkingDir, last)
|
||||
}
|
||||
abs, err := filepath.Abs(outputDir)
|
||||
|
@ -19,7 +19,6 @@ package build
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
|
||||
"github.com/otiai10/copy"
|
||||
)
|
||||
|
||||
|
@ -48,7 +48,7 @@ func (b *Build) cpLegacyProject() {
|
||||
|
||||
// only cp dependency in root(current gopath),
|
||||
// skip deps in other GOPATHs
|
||||
func (b *Build) cpDepPackages( pkg *cover.Package, visited map[string]bool) {
|
||||
func (b *Build) cpDepPackages(pkg *cover.Package, visited map[string]bool) {
|
||||
/*
|
||||
oriGOPATH := os.Getenv("GOPATH")
|
||||
if oriGOPATH == "" {
|
||||
|
@ -19,9 +19,9 @@ package cover
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -55,7 +55,7 @@ var _ = Describe("E2E", func() {
|
||||
|
||||
By("goc build")
|
||||
testProjDir := filepath.Join(TESTS_ROOT, "samples/simple_project")
|
||||
cmd := exec.Command("goc", "build")
|
||||
cmd := exec.Command("goc", "build", "--debuggoc")
|
||||
cmd.Dir = testProjDir
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
@ -84,7 +84,7 @@ var _ = Describe("E2E", func() {
|
||||
obj := filepath.Join(dir, "simple-project")
|
||||
fInfo, err := os.Lstat(obj)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(startTime.Before(fInfo.ModTime())).To(Equal(true), "new binary should be generated, not the old one")
|
||||
Expect(startTime.Before(fInfo.ModTime())).To(Equal(true), obj+"new binary should be generated, not the old one")
|
||||
|
||||
cmd := exec.Command("go", "tool", "objdump", "simple-project")
|
||||
cmd.Dir = dir
|
||||
@ -114,12 +114,13 @@ var _ = Describe("E2E", func() {
|
||||
GOPATH = testProjDir
|
||||
|
||||
By("goc build")
|
||||
cmd := exec.Command("goc", "build")
|
||||
cmd := exec.Command("goc", "build", "--debuggoc")
|
||||
cmd.Dir = oriWorkingDir
|
||||
// use GOPATH mode to compile project
|
||||
cmd.Env = append(os.Environ(), fmt.Sprintf("GOPATH=%v", GOPATH), "GO111MODULE=off")
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
fmt.Println(string(out))
|
||||
Expect(err).To(BeNil(), "goc build on this project should be successful", string(out), cmd.Dir)
|
||||
|
||||
By("goc install")
|
||||
@ -145,7 +146,7 @@ var _ = Describe("E2E", func() {
|
||||
By("check generated binary")
|
||||
objects := []string{GOPATH + "/bin", oriWorkingDir}
|
||||
for _, dir := range objects {
|
||||
obj := filepath.Join(dir, "simple-gopath-project")
|
||||
obj := filepath.Join(dir, "simple_gopath_project")
|
||||
fInfo, err := os.Lstat(obj)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(startTime.Before(fInfo.ModTime())).To(Equal(true), "new binary should be generated, not the old one")
|
||||
|
Loading…
Reference in New Issue
Block a user