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