magehelper

package module
v0.0.0-...-eb63631 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 15 Imported by: 0

README

Mage helper

Go Reference

The magehelper package provides package information for use in a Magefile build.

  • It defines a rule for installing tool programs during the build.
  • It reads dependency information from the current project to help determine prerequisites between build targets.
  • It defines a rule for running the Revive linter on the code.

Usage

go get github.com/rkennedy/magehelper

See this project's own magefile for example usage.

Documentation

Overview

Package magehelper helps Mage projects determine a project's files and used packages.

Index

Constants

This section is empty.

Variables

View Source
var Packages = map[string]Package{}

Packages holds the results of the LoadDependencies function. This variable is only valid after that function runs. Use mg.Deps or similar to make sure dependencies are loaded before referring to this variable.

Functions

func Build

func Build(ctx context.Context, exe string, tags []string) error

Build builds the current package with the given tags and writes the result to the given binary location.

func BuildTest

func BuildTest(ctx context.Context, pkg string, tags ...string) error

BuildTest builds the specified package's test.

func BuildTestDep

func BuildTestDep(pkg string, tags ...string) mg.Fn

BuildTestDep returns a mg.Fn that will build the tests for the given package, subject to any given build tags.

func BuildTests

func BuildTests(ctx context.Context, tags ...string) error

BuildTests build all the tests.

func BuildTestsDep

func BuildTestsDep(tags ...string) mg.Fn

BuildTestsDep returns a mg.Fn that will build all the tests using the given build tags.

func GetDependencies

func GetDependencies(
	baseMod string,
	files func(pkg Package) []string,
	imports func(pkg Package) []string,
) (result []string)

GetDependencies returns a list of files that the given base module depends on. The files callback should return a list of source files for a given package, and the imports callback should return a list of modules that the package imports. Use functions like Package.SourceFiles and Package.SourceImportPackages.

func InstallTool

func InstallTool(bin, module string) error

InstallTool installs the given module at the given location if the file at that location either doesn't exist or doesn't have the same version as the version of the module configured in go.mod.

func LoadDependencies

func LoadDependencies(context.Context) error

LoadDependencies populates the global Packages variable. It's suitable for use with mg.Deps or mg.CtxDeps.

func Revive

func Revive(ctx context.Context, reviveBin string, config string) error

Revive runs the given revive binary and uses the given configuration file to lint all the files in the current project. If revive is not installed, it will be installed using the version configured in go.mod.

func ReviveDep

func ReviveDep(bin, config string) mg.Fn

ReviveDep returns a mg.Fn object suitable for using with mg.Deps and similar. When resolved, the object will run the given revive binary and uses the given configuration file to lint all the files in the current project. If revive is not installed, it will be installed using the version configured in go.mod.

func RunTest

func RunTest(ctx context.Context, pkg string, tags ...string) error

RunTest runs the specified package's tests.

func RunTestDep

func RunTestDep(pkg string, tags ...string) mg.Fn

RunTestDep returns a mg.Fn that will run the tests for the given package, subject to the given build tags.

func Test

func Test(ctx context.Context, tags ...string) error

Test runs unit tests.

func ToolDep

func ToolDep(bin, module string) mg.Fn

ToolDep returns a mg.Fn object suitable for using with mg.Deps and similar. When resolved, the object will install the given module to the given binary location, just like InstallTool.

Types

type Package

type Package struct {
	Dir        string
	ImportPath string
	Name       string
	Target     string

	GoFiles        []string
	IgnoredGoFiles []string
	TestGoFiles    []string
	XTestGoFiles   []string

	EmbedFiles      []string
	TestEmbedFiles  []string
	XTestEmbedFiles []string

	Imports      []string
	TestImports  []string
	XTestImports []string
}

Package represents the output from go list -json. It's based on the internal package defined in cmd/go and on go/build.Package.

func (Package) IndirectGoFiles

func (pkg Package) IndirectGoFiles() []string

IndirectGoFiles returns the files that aren't automatically selected as being part of the package proper. Contract with github.com/mgechev/dots.Resolve, which will return the files that are direct members of the package, but it will not include other files from the same directory that belong to different packages, such as main or the _test package.

func (Package) SourceFiles

func (pkg Package) SourceFiles() []string

SourceFiles returns the files that contribute to an ordinary build; these are the dependencies to check to determine whether the package needs to be rebuilt.

func (Package) SourceImportPackages

func (pkg Package) SourceImportPackages() []string

SourceImportPackages returns the names of other packages imported by the package.

func (Package) TestFiles

func (pkg Package) TestFiles() []string

TestFiles returns the files that contribute to the tests; these are the dependencies to check to determine whether the tests need to be rebuilt.

func (Package) TestImportPackages

func (pkg Package) TestImportPackages() []string

TestImportPackages returns the names of other packages imported by this package's tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL