generators

package
v0.0.0-...-8ff35f7 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package generator includes a set of default generators for cipkg actions:

  • CIPDExport
  • EmbeddedFiles
  • ImportTargets
  • FetchURLs

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknowDependencyType = errors.New("unknown dependency type")
)

Functions

This section is empty.

Types

type CIPDExport

type CIPDExport struct {
	Name     string
	Metadata *core.Action_Metadata

	Ensure   ensure.File
	Expander template.Expander

	ConfigFile          string
	CacheDir            string
	HTTPUserAgentPrefix string
	MaxThreads          int
	ParallelDownloads   int
	ServiceURL          string
}

CIPDExport is used for downloading CIPD packages. It behaves similar to `cipd export` for the provided ensure file and use ${out} as the cipd root path. TODO(crbug/1323147): Replace direct call cipd binary with cipd sdk when it's available.

func (*CIPDExport) Generate

func (c *CIPDExport) Generate(ctx context.Context, plats Platforms) (*core.Action, error)

type Dependency

type Dependency struct {
	Generator Generator
	Type      DependencyType
	Runtime   bool
}

Dependency provide function for generating the corresponding action with platform from the dependency type for cross-compilation.

func (*Dependency) Generate

func (dep *Dependency) Generate(ctx context.Context, plats Platforms) (*core.Action, error)

Generate the corresponding action with platform from the dependency type for cross-compilation.

type DependencyType

type DependencyType int

DependencyType includes the different dependency types are used to calculate dependency's cross-compile platform from the dependent's.

const (
	DepsUnknown DependencyType = iota
	DepsBuildBuild
	DepsBuildHost
	DepsBuildTarget
	DepsHostHost
	DepsHostTarget
	DepsTargetTarget
	DepsMaxNum
)

func (DependencyType) String

func (t DependencyType) String() string

type EmbeddedFiles

type EmbeddedFiles struct {
	// contains filtered or unexported fields
}

func InitEmbeddedFS

func InitEmbeddedFS(name string, e embed.FS) *EmbeddedFiles

InitEmbeddedFS registers the embed.FS to copy executor and returns the corresponding generator. It should only be used in init() or on global variables e.g. //go:embed something var somethingEmbed embed.FS var somethingGen = InitEmbeddedFS("derivationName", somethingEmbed)

func (*EmbeddedFiles) Generate

func (e *EmbeddedFiles) Generate(ctx context.Context, plats Platforms) (*core.Action, error)

func (*EmbeddedFiles) SubDir

func (e *EmbeddedFiles) SubDir(dir string) *EmbeddedFiles

SubDir returns a generator copies files in the sub directory of the source.

func (*EmbeddedFiles) WithModeOverride

func (e *EmbeddedFiles) WithModeOverride(f func(name string) (fs.FileMode, error)) *EmbeddedFiles

WithModeOverride overrides file modes while copying.

type FetchURL

type FetchURL struct {
	URL           string
	Mode          fs.FileMode
	HashAlgorithm core.HashAlgorithm
	HashValue     string
}

type FetchURLs

type FetchURLs struct {
	Name     string
	Metadata *core.Action_Metadata
	URLs     map[string]FetchURL
}

FetchURLs downloads files from servers based on the path-url pairs of URLs.

func (*FetchURLs) Generate

func (f *FetchURLs) Generate(ctx context.Context, plats Platforms) (*core.Action, error)

type FindBinaryFunc

type FindBinaryFunc func(bin string) (path string, err error)

FindBinaryFunc returns a slash separated path for the provided binary name.

type Generator

type Generator interface {
	Generate(ctx context.Context, plats Platforms) (*core.Action, error)
}

Generator is the interface for generating actions.

type ImportTarget

type ImportTarget struct {
	Source  string
	Version string
	Mode    fs.FileMode

	FollowSymlinks bool

	// Tf true, the import target will be considered different if source path
	// changed. Otherwise only Version will be take into account.
	SourcePathDependent bool

	GenerateBatShim bool // Generate bat shim instead of symlink source file.
	MinGWSymlink    bool // Create MinGW's symlink instead of os symlink.
}

type ImportTargets

type ImportTargets struct {
	Name     string
	Metadata *core.Action_Metadata
	Targets  map[string]ImportTarget
}

ImportTargets is used to import file/directory from host environment. The builder itself won't detect the change of the imported file/directory. A version string should be generated to indicate the change if it matters. By default, target will be symlinked. When Mode in target is set to anything other than symlink, a hash version will be generated if there is no version provided.

func FromPathBatch

func FromPathBatch(name string, finder FindBinaryFunc, bins ...string) (*ImportTargets, error)

FromPathBatch is a wrapper for builtins.Import generator. It finds binaries using finder func and caches the result based on the name. if finder is nil, binaries will be searched from the PATH environment.

func (*ImportTargets) Generate

func (i *ImportTargets) Generate(ctx context.Context, plats Platforms) (*core.Action, error)

type Platform

type Platform struct {
	// contains filtered or unexported fields
}

Platform defines the environment outside the build system, which can't be identified in the environment variables or commands, but will affect the outputs. Platform must includes operating system and architecture, but also support any attributes that may affect the results (e.g. glibcABI).

func CurrentPlatform

func CurrentPlatform() Platform

CurrentPlatform returns a Platform with os and arch set to runtime.GOOS and runtime.GOARCH.

func NewPlatform

func NewPlatform(os, arch string) Platform

NewPlatform returns a Platform with os and arch set.

func PlatformFromCIPD

func PlatformFromCIPD(cipdPlat string) Platform

PlatformFromCIPD converts cipd platform to Platform.

func (Platform) Arch

func (p Platform) Arch() string

func (Platform) Get

func (p Platform) Get(key string) string

Get will return the value of the attribute

func (Platform) OS

func (p Platform) OS() string

func (Platform) Set

func (p Platform) Set(key, val string)

Set will set the attribute.

func (Platform) String

func (p Platform) String() string

type Platforms

type Platforms struct {
	Build  Platform
	Host   Platform
	Target Platform
}

Platforms is the cross-compile platform tuple.

Jump to

Keyboard shortcuts

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