all: only copy files relevant to the Go compiler
diff --git a/fetch.go b/fetch.go
index 410e321..434274e 100644
--- a/fetch.go
+++ b/fetch.go
@@ -121,7 +121,7 @@
dst := filepath.Join(vendorDir(), dep.Importpath)
src := filepath.Join(wc.Dir(), dep.Path)
- if err := fileutils.Copypath(dst, src); err != nil {
+ if err := fileutils.Copypath(dst, src, true); err != nil {
return err
}
diff --git a/fileutils/fileutils.go b/fileutils/fileutils.go
index 7a3ead3..a4033ba 100644
--- a/fileutils/fileutils.go
+++ b/fileutils/fileutils.go
@@ -10,18 +10,32 @@
"strings"
)
-const debugCopypath = false
-const debugCopyfile = false
+// https://golang.org/cmd/go/#hdr-File_types
+var goFileTypes = []string{
+ ".go",
+ ".c", ".h",
+ ".cc", ".cpp", ".cxx", ".hh", ".hpp", ".hxx",
+ ".m",
+ ".s", ".S",
+ ".swig", ".swigcxx",
+ ".syso",
+}
-// Copypath copies the contents of src to dst, excluding any file or
-// directory that starts with a period.
-func Copypath(dst string, src string) error {
+// Copypath copies the contents of src to dst, excluding any file that is not
+// relevant to the Go compiler.
+func Copypath(dst string, src string, tests bool) error {
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
- if strings.HasPrefix(filepath.Base(path), ".") {
+ // https://golang.org/cmd/go/#hdr-Description_of_package_lists
+ name := filepath.Base(path)
+ if strings.HasPrefix(name, ".") ||
+ (strings.HasPrefix(name, "_") && name != "_testdata") ||
+ (!tests && name == "_testdata") ||
+ (!tests && name == "testdata") ||
+ (!tests && strings.HasSuffix(name, "_test.go")) {
if info.IsDir() {
return filepath.SkipDir
}
@@ -32,6 +46,17 @@
return nil
}
+ relevantFile := false
+ for _, ext := range goFileTypes {
+ if strings.HasSuffix(name, ext) {
+ relevantFile = true
+ break
+ }
+ }
+ if !relevantFile {
+ return nil
+ }
+
dst := filepath.Join(dst, path[len(src):])
if info.Mode()&os.ModeSymlink != 0 {
@@ -62,9 +87,6 @@
return fmt.Errorf("copyfile: create(%q): %v", dst, err)
}
defer w.Close()
- if debugCopyfile {
- fmt.Printf("copyfile(dst: %v, src: %v)\n", dst, src)
- }
_, err = io.Copy(w, r)
return err
}
@@ -80,9 +102,6 @@
if err := os.Symlink(target, dst); err != nil {
return fmt.Errorf("copylink: symlink: %v", err)
}
- if debugCopyfile {
- fmt.Printf("copylink(dst: %v, src: %v, tgt: %s)\n", dst, src, target)
- }
return nil
}
diff --git a/restore.go b/restore.go
index 2765e5f..81d338d 100644
--- a/restore.go
+++ b/restore.go
@@ -116,7 +116,7 @@
}
}
- if err := fileutils.Copypath(dst, src); err != nil {
+ if err := fileutils.Copypath(dst, src, true); err != nil {
return err
}
diff --git a/update.go b/update.go
index 5c13134..e1f261d 100644
--- a/update.go
+++ b/update.go
@@ -106,7 +106,7 @@
dst := filepath.Join(vendorDir(), filepath.FromSlash(dep.Importpath))
src := filepath.Join(wc.Dir(), dep.Path)
- if err := fileutils.Copypath(dst, src); err != nil {
+ if err := fileutils.Copypath(dst, src, true); err != nil {
return err
}