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

Cherry-pick #14162 to 7.5: Stop using mage:import in custom beats #14186

Merged
merged 1 commit into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The list below covers the major changes between 7.0.0-rc2 and master only.

==== Bugfixes

- Stop using `mage:import` in community beats. This was ignoring the vendorized beats directory for some mage targets, using the code available in GOPATH, this causes inconsistencies and compilation problems if the version of the code in the GOPATH is different to the vendored one. Use of `mage:import` will continue to be unsupported in custom beats till beats is migrated to go modules, or mage supports vendored dependencies. {issue}13998[13998] {pull}14162[14162]

==== Added

- Metricset generator generates beta modules by default now. {pull}10657[10657]
Expand Down
45 changes: 34 additions & 11 deletions generator/beat/{beat}/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@ import (
"github.com/magefile/mage/mg"

devtools "github.com/elastic/beats/dev-tools/mage"

// mage:import
_ "github.com/elastic/beats/dev-tools/mage/target/common"
// mage:import
"github.com/elastic/beats/dev-tools/mage/target/build"
// mage:import
"github.com/elastic/beats/dev-tools/mage/target/update"
// mage:import
_ "github.com/elastic/beats/dev-tools/mage/target/test"
// mage:import
_ "github.com/elastic/beats/dev-tools/mage/target/unittest"
// mage:import
"github.com/elastic/beats/dev-tools/mage/target/common"
"github.com/elastic/beats/dev-tools/mage/target/pkg"
"github.com/elastic/beats/dev-tools/mage/target/unittest"
"github.com/elastic/beats/dev-tools/mage/target/update"
)

func init() {
Expand Down Expand Up @@ -54,3 +46,34 @@ func Config() error {
func Fields() error {
return devtools.GenerateFieldsYAML()
}

// Clean cleans all generated files and build artifacts.
func Clean() error {
return devtools.Clean()
}

// Check formats code, updates generated content, check for common errors, and
// checks for any modified files.
func Check() {
common.Check()
}

// Fmt formats source code (.go and .py) and adds license headers.
func Fmt() {
common.Fmt()
}

// Test runs all available tests
func Test() {
mg.Deps(unittest.GoUnitTest)
}

// Build builds the Beat binary.
func Build() error {
return build.Build()
}

// CrossBuild cross-builds the beat for all target platforms.
func CrossBuild() error {
return build.CrossBuild()
}
55 changes: 40 additions & 15 deletions generator/metricbeat/{beat}/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,13 @@ import (
"github.com/magefile/mage/mg"

devtools "github.com/elastic/beats/dev-tools/mage"
metricbeat "github.com/elastic/beats/metricbeat/scripts/mage"

// mage:import
_ "github.com/elastic/beats/dev-tools/mage/target/common"
// mage:import
"github.com/elastic/beats/dev-tools/mage/target/build"
// mage:import
"github.com/elastic/beats/dev-tools/mage/target/pkg"
// mage:import
_ "github.com/elastic/beats/dev-tools/mage/target/test"
// mage:import
_ "github.com/elastic/beats/dev-tools/mage/target/unittest"
// mage:import
_ "github.com/elastic/beats/dev-tools/mage/target/integtest"
// mage:import
"github.com/elastic/beats/dev-tools/mage/target/collectors"
// mage:import
"github.com/elastic/beats/dev-tools/mage/target/common"
"github.com/elastic/beats/dev-tools/mage/target/pkg"
"github.com/elastic/beats/dev-tools/mage/target/unittest"
"github.com/elastic/beats/dev-tools/mage/target/update"
metricbeat "github.com/elastic/beats/metricbeat/scripts/mage"
)

func init() {
Expand Down Expand Up @@ -87,3 +76,39 @@ func configYML() error {
}
return devtools.Config(devtools.AllConfigTypes, customDeps, ".")
}

// Clean cleans all generated files and build artifacts.
func Clean() error {
return devtools.Clean()
}

// Check formats code, updates generated content, check for common errors, and
// checks for any modified files.
func Check() {
common.Check()
}

// Fmt formats source code (.go and .py) and adds license headers.
func Fmt() {
common.Fmt()
}

// Update updates the generated files (aka make update).
func Update() error {
return update.Update()
}

// Test runs all available tests
func Test() {
mg.Deps(unittest.GoUnitTest)
}

// Build builds the Beat binary.
func Build() error {
return build.Build()
}

// CrossBuild cross-builds the beat for all target platforms.
func CrossBuild() error {
return build.CrossBuild()
}