From 9a1e6d15a31ec667b2ff9cf20e43b1daca61e004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 9 Sep 2020 16:51:13 +0200 Subject: modules: Make ignoreVendor a glob pattern Fixes #7642 --- modules/client.go | 9 +++++++-- modules/client_test.go | 6 +++++- modules/collect.go | 5 +++-- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/client.go b/modules/client.go index c66311d05..914d06a4e 100644 --- a/modules/client.go +++ b/modules/client.go @@ -605,8 +605,9 @@ type ClientConfig struct { // etc. HookBeforeFinalize func(m *ModulesConfig) error - // Ignore any _vendor directory. - IgnoreVendor bool + // Ignore any _vendor directory for module paths matching the given pattern. + // This can be nil. + IgnoreVendor glob.Glob // Absolute path to the project dir. WorkingDir string @@ -618,6 +619,10 @@ type ClientConfig struct { ModuleConfig Config } +func (c ClientConfig) shouldIgnoreVendor(path string) bool { + return c.IgnoreVendor != nil && c.IgnoreVendor.Match(path) +} + type goBinaryStatus int type goModule struct { diff --git a/modules/client_test.go b/modules/client_test.go index 07b71c409..d5da621d1 100644 --- a/modules/client_test.go +++ b/modules/client_test.go @@ -17,6 +17,8 @@ import ( "bytes" "testing" + "github.com/gohugoio/hugo/hugofs/glob" + "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/htesting" @@ -89,7 +91,7 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor Fs: hugofs.Os, WorkingDir: workingDir, ModuleConfig: modConfig, - IgnoreVendor: true, + IgnoreVendor: globAll, }) graphb.Reset() @@ -101,6 +103,8 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor } +var globAll, _ = glob.GetGlob("**") + func TestGetModlineSplitter(t *testing.T) { c := qt.New(t) diff --git a/modules/collect.go b/modules/collect.go index 0ac766fb9..f87ed2484 100644 --- a/modules/collect.go +++ b/modules/collect.go @@ -196,7 +196,8 @@ func (c *collector) initModules() error { gomods: goModules{}, } - if !c.ccfg.IgnoreVendor && c.isVendored(c.ccfg.WorkingDir) { + // If both these are true, we don't even need Go installed to build. + if c.ccfg.IgnoreVendor == nil && c.isVendored(c.ccfg.WorkingDir) { return nil } @@ -229,7 +230,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool modulePath := moduleImport.Path var realOwner Module = owner - if !c.ccfg.IgnoreVendor { + if !c.ccfg.shouldIgnoreVendor(modulePath) { if err := c.collectModulesTXT(owner); err != nil { return nil, err } -- cgit v1.2.3