Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy missing go version to the generated Beats #17105

Merged
merged 4 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,16 @@ jobs:
stage: test

# Generators
# https://github.com/elastic/beats/issues/16951
#- os: linux
# before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0
# env: TARGETS="-C generator/_templates/metricbeat test test-package"
# go: $TRAVIS_GO_VERSION
# stage: test
#- os: linux
# before_install: .ci/scripts/travis_has_changes.sh generator libbeat || travis_terminate 0
# env: TARGETS="-C generator/_templates/beat test test-package"
# go: $TRAVIS_GO_VERSION
# stage: test
- os: linux
before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0
env: TARGETS="-C generator/_templates/metricbeat test test-package"
go: $TRAVIS_GO_VERSION
stage: test
- os: linux
before_install: .ci/scripts/travis_has_changes.sh generator libbeat || travis_terminate 0
env: TARGETS="-C generator/_templates/beat test test-package"
go: $TRAVIS_GO_VERSION
stage: test

- os: osx
before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0
Expand Down
64 changes: 36 additions & 28 deletions dev-tools/mage/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ import (
"github.com/elastic/beats/v7/dev-tools/mage/gotool"
)

// copyModule contains a module name and the list of files or directories
// CopyModule contains a module name and the list of files or directories
// to copy recursively.
type copyModule struct {
name string
filesToCopy []string
type CopyModule struct {
Name string
FilesToCopy []string
}

var (
copyAll = []copyModule{
copyModule{
name: "github.com/godror/godror",
filesToCopy: []string{
"odpi",
copyAll = []CopyModule{
CopyModule{
Name: "github.com/tsg/go-daemon",
FilesToCopy: []string{
"src",
},
},
copyModule{
name: "github.com/tsg/go-daemon",
filesToCopy: []string{
"src",
CopyModule{
Name: "github.com/godror/godror",
FilesToCopy: []string{
"odpi",
},
},
}
filesToRemove = []string{
filepath.Join("vendor", "github.com", "yuin", "gopher-lua", "parse", "Makefile"),
filepath.Join("github.com", "yuin", "gopher-lua", "parse", "Makefile"),
}
)

Expand All @@ -74,32 +74,40 @@ func Vendor() error {
if err != nil {
return err
}

vendorFolder := filepath.Join(repo.RootDir, "vendor")
err = CopyFilesToVendor(vendorFolder, copyAll)
if err != nil {
return err
}

for _, p := range filesToRemove {
p = filepath.Join(vendorFolder, p)
err = os.RemoveAll(p)
if err != nil {
return err
kvch marked this conversation as resolved.
Show resolved Hide resolved
}
}
return nil
}

// copy packages which require the whole tree
for _, p := range copyAll {
path, err := gotool.ListModuleCacheDir(p.name)
// CopyFilesToVendor copies packages which require the whole tree
func CopyFilesToVendor(vendorFolder string, modulesToCopy []CopyModule) error {
for _, p := range modulesToCopy {
path, err := gotool.ListModuleCacheDir(p.Name)
if err != nil {
return err
}

for _, f := range p.filesToCopy {
for _, f := range p.FilesToCopy {
from := filepath.Join(path, f)
to := filepath.Join(vendorFolder, p.name, f)
copyTask := &CopyTask{Source: from, Dest: to, DirMode: os.ModeDir | 0750}
to := filepath.Join(vendorFolder, p.Name, f)
copyTask := &CopyTask{Source: from, Dest: to, Mode: 0640, DirMode: os.ModeDir | 0750}
err = copyTask.Execute()
if err != nil {
return err
}
}
}

for _, p := range filesToRemove {
p = filepath.Join(repo.RootDir, p)
err = os.RemoveAll(p)
if err != nil {
return err
}
}
return nil
}
1 change: 1 addition & 0 deletions generator/_templates/beat/{beat}/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tools

import (
_ "github.com/pierrre/gotestcover"
_ "github.com/tsg/go-daemon"
_ "golang.org/x/tools/cmd/goimports"

_ "github.com/mitchellh/gox"
Expand Down
1 change: 1 addition & 0 deletions generator/_templates/metricbeat/{beat}/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tools

import (
_ "github.com/pierrre/gotestcover"
_ "github.com/tsg/go-daemon"
_ "golang.org/x/tools/cmd/goimports"

_ "github.com/mitchellh/gox"
Expand Down
43 changes: 22 additions & 21 deletions generator/common/beatgen/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ import (
"github.com/elastic/beats/v7/dev-tools/mage/gotool"
)

var (
makefileDeps = []string{
"dev-tools",
"libbeat",
"licenses",
"metricbeat",
"script",
}
)

func InitModule() error {
err := gotool.Mod.Init()
if err != nil {
Expand Down Expand Up @@ -112,21 +102,32 @@ func CopyVendor() error {
return err
}

path, err := gotool.ListModuleCacheDir("github.com/elastic/beats/v7")
err = devtools.CopyFilesToVendor(
"./vendor",
[]devtools.CopyModule{
devtools.CopyModule{
Name: "github.com/elastic/beats/v7",
FilesToCopy: []string{
"dev-tools",
"libbeat",
"licenses",
"metricbeat",
"script",
".go-version",
},
},
devtools.CopyModule{
Name: "github.com/tsg/go-daemon",
FilesToCopy: []string{
"src",
},
},
},
)
if err != nil {
return err
}

vendorPath := "./vendor/github.com/elastic/beats/v7"
for _, d := range makefileDeps {
from := filepath.Join(path, d)
to := filepath.Join(vendorPath, d)
copyTask := &devtools.CopyTask{Source: from, Dest: to, Mode: 0640, DirMode: os.ModeDir | 0750}
err = copyTask.Execute()
if err != nil {
return err
}
}
return nil
}

Expand Down