Merge pull request #29 from vulcanize/fix
Fix for Travis issue at https://github.com/vulcanize/mcd_transformers/pull/6
This commit is contained in:
@@ -29,7 +29,6 @@ type Plugin struct {
|
||||
FileName string
|
||||
Save bool
|
||||
Home string
|
||||
Clone bool
|
||||
}
|
||||
|
||||
type Transformer struct {
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/config"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/plugin/helpers"
|
||||
@@ -61,15 +60,15 @@ func (b *builder) BuildPlugin() error {
|
||||
}
|
||||
|
||||
// setup env to build plugin
|
||||
err = b.setupBuildEnv()
|
||||
if err != nil {
|
||||
return err
|
||||
setupErr := b.setupBuildEnv()
|
||||
if setupErr != nil {
|
||||
return setupErr
|
||||
}
|
||||
|
||||
// Build the .go file into a .so plugin
|
||||
err = exec.Command("go", "build", "-buildmode=plugin", "-o", soFile, b.goFile).Run()
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("unable to build .so file: %s", err.Error()))
|
||||
execErr := exec.Command("go", "build", "-buildmode=plugin", "-o", soFile, b.goFile).Run()
|
||||
if execErr != nil {
|
||||
return errors.New(fmt.Sprintf("unable to build .so file: %s", execErr.Error()))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -87,37 +86,24 @@ func (b *builder) setupBuildEnv() error {
|
||||
|
||||
// Import transformer dependencies so that we can build our plugin
|
||||
for importPath := range repoPaths {
|
||||
dstPath := filepath.Join(vendorPath, importPath)
|
||||
// When testing on Travis we need to clone the libs
|
||||
if b.GenConfig.Clone {
|
||||
// And if we want to be able to work with a private repo we need to use ssh instead of https
|
||||
// and upload a permissioned ssh key to travis before deploying tests there
|
||||
index := strings.Index(importPath, "/")
|
||||
gitPath := importPath[:index] + ":" + importPath[index+1:]
|
||||
importURL := "git@" + gitPath + ".git"
|
||||
err = exec.Command("git", "clone", importURL, dstPath).Run()
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("unable to clone transformer dependency from %s to %s: %s", importPath, dstPath, err.Error()))
|
||||
}
|
||||
} else { // If not on Travis we can work with libs at $GOPATH
|
||||
srcDir, err := helpers.CleanPath(filepath.Join("$GOPATH/src", importPath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sp := strings.Split(dstPath, "/")
|
||||
spj := strings.Join(sp[:len(sp)-1], "/")
|
||||
err = exec.Command("rsync", "-a", srcDir, spj).Run()
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("unable to copy transformer dependency from %s to %s: %s", srcDir, dstPath, err.Error()))
|
||||
}
|
||||
dst := filepath.Join(vendorPath, importPath)
|
||||
src, cleanErr := helpers.CleanPath(filepath.Join("$GOPATH/src", importPath))
|
||||
if cleanErr != nil {
|
||||
return cleanErr
|
||||
}
|
||||
|
||||
copyErr := helpers.CopyDir(src, dst, "vendor")
|
||||
if copyErr != nil {
|
||||
return errors.New(fmt.Sprintf("unable to copy transformer dependency from %s to %s: %v", src, dst, copyErr))
|
||||
}
|
||||
|
||||
// Have to clear out the copied over vendor lib or plugin won't build (see issue above)
|
||||
err := os.RemoveAll(filepath.Join(dstPath, "vendor"))
|
||||
if err != nil {
|
||||
return err
|
||||
removeErr := os.RemoveAll(filepath.Join(dst, "vendor"))
|
||||
if removeErr != nil {
|
||||
return removeErr
|
||||
}
|
||||
// Keep track of this vendor directory to clear later
|
||||
b.tmpVenDirs = append(b.tmpVenDirs, dstPath)
|
||||
b.tmpVenDirs = append(b.tmpVenDirs, dst)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -18,6 +18,7 @@ package helpers
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -62,16 +63,54 @@ func CopyFile(src, dst string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
out, err := os.OpenFile(dst, syscall.O_CREAT|syscall.O_EXCL|os.O_WRONLY, os.FileMode(0666)) // Doesn't overwrite files
|
||||
if err != nil {
|
||||
in.Close()
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, in)
|
||||
in.Close()
|
||||
out.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
func CopyDir(src string, dst string, excludeRecursiveDir string) error {
|
||||
var err error
|
||||
var fds []os.FileInfo
|
||||
var srcinfo os.FileInfo
|
||||
|
||||
srcinfo, err = os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Close()
|
||||
|
||||
mkErr := os.MkdirAll(dst, srcinfo.Mode())
|
||||
if mkErr != nil {
|
||||
return mkErr
|
||||
}
|
||||
|
||||
fds, readErr := ioutil.ReadDir(src)
|
||||
if err != readErr {
|
||||
return readErr
|
||||
}
|
||||
for _, fd := range fds {
|
||||
srcfp := filepath.Join(src, fd.Name())
|
||||
dstfp := filepath.Join(dst, fd.Name())
|
||||
|
||||
if fd.IsDir() {
|
||||
if fd.Name() != excludeRecursiveDir {
|
||||
dirErr := CopyDir(srcfp, dstfp, "")
|
||||
if dirErr != nil {
|
||||
return dirErr
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fileErr := CopyFile(srcfp, dstfp)
|
||||
if fileErr != nil {
|
||||
return fileErr
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user