Skip to content
This repository was archived by the owner on Aug 25, 2018. It is now read-only.

Commit 08f6d11

Browse files
committed
added_makefile_explicit_inclusion
1 parent 1f87bb3 commit 08f6d11

7 files changed

Lines changed: 46 additions & 10 deletions

File tree

fetch.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
insecure bool // Allow the use of insecure protocols
2222
tests bool
2323
all bool
24+
makefiles bool
2425
)
2526

2627
func addFetchFlags(fs *flag.FlagSet) {
@@ -31,6 +32,7 @@ func addFetchFlags(fs *flag.FlagSet) {
3132
fs.BoolVar(&insecure, "precaire", false, "allow the use of insecure protocols")
3233
fs.BoolVar(&tests, "t", false, "fetch _test.go files and testdata")
3334
fs.BoolVar(&all, "a", false, "fetch all files and subfolders")
35+
fs.BoolVar(&makefiles, "m", true, "fetch all makefiles extentions -- enabled by default")
3436
}
3537

3638
var cmdFetch = &Command{
@@ -50,6 +52,8 @@ from private repositories that cannot be probed.
5052
Flags:
5153
-t
5254
fetch also _test.go files and testdata.
55+
-m
56+
fetch also *.mak files (makefiles)
5357
-a
5458
fetch all files and subfolders, ignoring ONLY .git, .hg and .bzr.
5559
-branch branch
@@ -196,6 +200,7 @@ func fetchRecursive(m *vendor.Manifest, fullPath string, level int) error {
196200
Path: extra,
197201
NoTests: !tests,
198202
AllFiles: all,
203+
Makefiles: makefiles,
199204
}
200205

201206
if err := m.AddDependency(dep); err != nil {
@@ -207,7 +212,7 @@ func fetchRecursive(m *vendor.Manifest, fullPath string, level int) error {
207212
dst := filepath.Join(vendorDir, dep.Importpath)
208213
src := filepath.Join(wc.Dir(), dep.Path)
209214

210-
if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles); err != nil {
215+
if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles, dep.Makefiles); err != nil {
211216
return err
212217
}
213218

@@ -230,7 +235,7 @@ func fetchRecursive(m *vendor.Manifest, fullPath string, level int) error {
230235
return fmt.Errorf("unable to derive the root repo import path")
231236
}
232237
rootRepoPath := strings.TrimRight(strings.TrimSuffix(dep.Importpath, dep.Path), "/")
233-
deps, err := vendor.ParseImports(src, wc.Dir(), rootRepoPath, tests, all)
238+
deps, err := vendor.ParseImports(src, wc.Dir(), rootRepoPath, tests, all, makefiles)
234239
if err != nil {
235240
return fmt.Errorf("failed to parse imports: %s", err)
236241
}

fileutils/fileutils.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var licenseFiles = []string{
2626
"LICENSE", "LICENCE", "UNLICENSE", "COPYING", "COPYRIGHT",
2727
}
2828

29-
func ShouldSkip(path string, info os.FileInfo, tests, all bool) bool {
29+
func ShouldSkip(path string, info os.FileInfo, tests, all, makefiles bool) bool {
3030
name := filepath.Base(path)
3131

3232
relevantFile := false
@@ -49,6 +49,10 @@ func ShouldSkip(path string, info os.FileInfo, tests, all bool) bool {
4949
case all && !(name == ".git" && info.IsDir()) && name != ".bzr" && name != ".hg":
5050
skip = false
5151

52+
// Include all makefiles
53+
case makefiles && strings.HasSuffix(name, ".mak"):
54+
skip = false
55+
5256
// Include all files in a testdata folder
5357
case tests && testdata:
5458
skip = false
@@ -75,13 +79,13 @@ func ShouldSkip(path string, info os.FileInfo, tests, all bool) bool {
7579

7680
// Copypath copies the contents of src to dst, excluding any file that is not
7781
// relevant to the Go compiler.
78-
func Copypath(dst string, src string, tests, all bool) error {
82+
func Copypath(dst string, src string, tests, all, makefiles bool) error {
7983
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
8084
if err != nil {
8185
return err
8286
}
8387

84-
skip := ShouldSkip(path, info, tests, all)
88+
skip := ShouldSkip(path, info, tests, all, makefiles)
8589

8690
if skip {
8791
if info.IsDir() {

fileutils/fileutils_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestCopypathSymlinks(t *testing.T) {
1515
dst := mktemp(t)
1616
defer RemoveAll(dst)
1717
src := filepath.Join("_testdata", "copyfile")
18-
if err := Copypath(dst, src, true, false); err != nil {
18+
if err := Copypath(dst, src, true, false, false); err != nil {
1919
t.Fatalf("copypath(%s, %s): %v", dst, src, err)
2020
}
2121
res, err := os.Readlink(filepath.Join(dst, "a", "rick"))
@@ -34,3 +34,27 @@ func mktemp(t *testing.T) string {
3434
}
3535
return s
3636
}
37+
38+
func TestShouldSkip(t *testing.T) {
39+
_, filename, _, _ := runtime.Caller(1)
40+
stat, _ := os.Stat(filename)
41+
42+
expectations := [][]interface{}{
43+
[]interface{}{"a.go", stat, false, false, false, false}, // default: go files are ok
44+
[]interface{}{"a_test.go", stat, false, false, false, true}, // default: test files are not ok
45+
[]interface{}{"a.mak", stat, false, false, false, true}, // default: makefiles are not ok
46+
[]interface{}{"a.rand", stat, false, false, false, true}, // default: all files are not ok
47+
48+
[]interface{}{"a_test.go", stat, true, false, false, false}, // Allow test files
49+
[]interface{}{"a.mak", stat, false, false, true, false}, // Allow makefiles
50+
[]interface{}{"a.rand", stat, false, true, false, false}, // Allow all files
51+
}
52+
53+
for _, e := range expectations {
54+
result := ShouldSkip(e[0].(string), e[1].(os.FileInfo), e[2].(bool), e[3].(bool), e[4].(bool))
55+
56+
if result != e[5].(bool) {
57+
t.Fatalf("wrong result expected(%v) got(%v)", e[5].(bool), result)
58+
}
59+
}
60+
}

gbvendor/imports.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import (
1919
// ParseImports parses Go packages from a specific root returning a set of import paths.
2020
// vendorRoot is how deep to go looking for vendor folders, usually the repo root.
2121
// vendorPrefix is the vendorRoot import path.
22-
func ParseImports(root, vendorRoot, vendorPrefix string, tests, all bool) (map[string]bool, error) {
22+
func ParseImports(root, vendorRoot, vendorPrefix string, tests, all, makefiles bool) (map[string]bool, error) {
2323
pkgs := make(map[string]bool)
2424

2525
var walkFn = func(p string, info os.FileInfo, err error) error {
2626
if err != nil {
2727
return err
2828
}
2929

30-
if fileutils.ShouldSkip(p, info, tests, all) {
30+
if fileutils.ShouldSkip(p, info, tests, all, makefiles) {
3131
if info.IsDir() {
3232
return filepath.SkipDir
3333
}

gbvendor/manifest.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ type Dependency struct {
117117

118118
// AllFiles indicates that no files were ignored.
119119
AllFiles bool `json:"allfiles,omitempty"`
120+
121+
// Makefiles indicates that makefiles would be included.
122+
Makefiles bool `json:"makefiles,omitempty"`
120123
}
121124

122125
// WriteManifest writes a Manifest to the path. If the manifest does

restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func downloadDependency(dep vendor.Dependency, errors *uint32, vendorDir string,
123123
}
124124
}
125125

126-
if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles); err != nil {
126+
if err := fileutils.Copypath(dst, src, !dep.NoTests, dep.AllFiles, dep.Makefiles); err != nil {
127127
return err
128128
}
129129

update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Flags:
109109
dst := filepath.Join(vendorDir, filepath.FromSlash(dep.Importpath))
110110
src := filepath.Join(wc.Dir(), dep.Path)
111111

112-
if err := fileutils.Copypath(dst, src, !d.NoTests, d.AllFiles); err != nil {
112+
if err := fileutils.Copypath(dst, src, !d.NoTests, d.AllFiles, d.Makefiles); err != nil {
113113
return err
114114
}
115115

0 commit comments

Comments
 (0)