magehelper

package module
v0.0.0-...-7ac4d75 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 12 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 BasePackage

func BasePackage() (string, error)

BasePackage returns the full name of the package being tested. It reads go.mod, which means this is intended to be used on tests being run in situ from the project directory, not tests compiled and copied elsewhere to run.

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 LoadDependencies

func LoadDependencies(context.Context) error

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

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.

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.

Directories

Path Synopsis
Package tools offers Mage dependencies and commands to help install tools for use during a build, such as linters and code generators.
Package tools offers Mage dependencies and commands to help install tools for use during a build, such as linters and code generators.

Jump to

Keyboard shortcuts

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