util

package
v0.0.0-...-0a43815 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// TaskDelimiter separates a package name from a task name in a task id
	TaskDelimiter = "#"
	// RootPkgName is the reserved name that specifies the root package
	RootPkgName = "//"
)

Variables

View Source
var TaskOutputModeStrings = []string{
	fullTaskOutputString,
	noTaskOutputString,
	hashTaskOutputString,
	newTaskOutputString,
	errorTaskOutputString,
}

TaskOutputModeStrings is an array containing the string representations for task output modes

Functions

func CloseAndIgnoreError

func CloseAndIgnoreError(closer interface{ Close() error })

CloseAndIgnoreError is a utility to tell our linter that we explicitly deem it okay to not check a particular error on closing of a resource.

We use `errcheck` as a linter, which is super-opinionated about checking errors, even in places where we don't necessarily care to check the error.

`golangci-lint` has a default ignore list for this lint problem (EXC0001) which can be used to sidestep this problem but it's possibly a little too-heavy-handed in exclusion. At the expense of discoverability, this utility function forces opt-in to ignoring errors on closing of things that can be `Close`d.

func Fprintf

func Fprintf(writer io.Writer, format string, args ...interface{})

func GetPackageTaskFromId

func GetPackageTaskFromId(taskId string) (packageName string, task string)

GetPackageTaskFromId returns a tuple of the package name and target task

func GetTaskId

func GetTaskId(pkgName interface{}, target string) string

GetTaskId returns a package-task identifier (e.g @feed/thing#build).

func HelpForCobraCmd

func HelpForCobraCmd(cmd *cobra.Command) string

HelpForCobraCmd returns the help string for a given command Note that this overwrites the output for the command

func InitPrintf

func InitPrintf()

initPrintf sets up the replacements used by printf.

func IsPackageTask

func IsPackageTask(task string) bool

IsPackageTask returns true if input is a package-specific task whose name has a length greater than 0.

Accepted: myapp#build Rejected: #build, build

func IsTaskInPackage

func IsTaskInPackage(task string, packageName string) bool

IsTaskInPackage returns true if the task does not belong to a different package note that this means unscoped tasks will always return true

func ParseConcurrency

func ParseConcurrency(concurrencyRaw string) (int, error)

ParseConcurrency parses a concurrency value, which can be a number (e.g. 2) or a percentage (e.g. 50%).

func PositiveMod

func PositiveMod(x, d int) int

PostitiveMod returns a modulo operator like JavaScripts

func Printf

func Printf(format string, args ...interface{})

func RootTaskID

func RootTaskID(target string) string

RootTaskID returns the task id for running the given task in the root package

func RootTaskTaskName

func RootTaskTaskName(taskID string) string

RootTaskTaskName returns the task portion of a root task taskID

func Sprintf

func Sprintf(format string, args ...interface{}) string

printf is used throughout this package to print something to stderr with some replacements for pseudo-shell variables for ANSI formatting codes.

func StripPackageName

func StripPackageName(taskID string) string

StripPackageName removes the package portion of a taskID if it is a package task. Non-package tasks are returned unmodified

func ToTaskOutputModeString

func ToTaskOutputModeString(value TaskOutputMode) (string, error)

ToTaskOutputModeString converts a task output mode enum value into the string representation

func ValidateGraph

func ValidateGraph(graph *dag.AcyclicGraph) error

ValidateGraph checks that a given DAG has no cycles and no self-referential edges. We differ from the underlying DAG Validate method in that we allow multiple roots.

Types

type CacheDisabledError

type CacheDisabledError struct {
	Status  CachingStatus
	Message string
}

CacheDisabledError is an error used to indicate that remote caching is not available.

func (*CacheDisabledError) Error

func (cd *CacheDisabledError) Error() string

type CachingStatus

type CachingStatus int

CachingStatus represents the api server's perspective on whether remote caching should be allowed

const (
	// CachingStatusDisabled indicates that the server will not accept or serve artifacts
	CachingStatusDisabled CachingStatus = iota
	// CachingStatusEnabled indicates that the server will accept and serve artifacts
	CachingStatusEnabled
	// CachingStatusOverLimit indicates that a usage limit has been hit and the
	// server will temporarily not accept or serve artifacts
	CachingStatusOverLimit
	// CachingStatusPaused indicates that a customer's spending has been paused and the
	// server will temporarily not accept or serve artifacts
	CachingStatusPaused
)

func CachingStatusFromString

func CachingStatusFromString(raw string) (CachingStatus, error)

CachingStatusFromString parses a raw string to a caching status enum value

type EnvMode

type EnvMode string

EnvMode specifies if we will be using strict env vars

const (
	// Infer - infer environment variable constraints from turbo.json
	Infer EnvMode = "Infer"
	// Loose - environment variables are unconstrained
	Loose EnvMode = "Loose"
	// Strict - environment variables are limited
	Strict EnvMode = "Strict"
)

func (EnvMode) MarshalText

func (s EnvMode) MarshalText() (text []byte, err error)

MarshalText implements TextMarshaler for the struct.

type ExitCodeError

type ExitCodeError struct {
	ExitCode int
}

ExitCodeError is a specific error that is returned by the command to specify the exit code

func (*ExitCodeError) Error

func (e *ExitCodeError) Error() string

type Hashable

type Hashable interface {
	Hashcode() interface{}
}

Hashable is the interface used by set to get the hash code of a value. If this isn't given, then the value of the item being added to the set itself is used as the comparison value.

type RunOpts

type RunOpts struct {
	// Force execution to be serially one-at-a-time
	Concurrency int
	// Whether to execute in parallel (defaults to false)
	Parallel bool

	EnvMode EnvMode
	// Whether or not to infer the framework for each workspace.
	FrameworkInference bool
	// The filename to write a perf profile.
	Profile string
	// If true, continue task executions even if a task fails.
	ContinueOnError bool
	PassThroughArgs []string
	// Restrict execution to only the listed task names. Default false
	Only bool
	// Dry run flags
	DryRun     bool
	DryRunJSON bool
	// Graph flags
	GraphDot      bool
	GraphFile     string
	Daemon        bool
	NoDaemon      bool
	SinglePackage bool

	// logPrefix controls whether we should print a prefix in task logs
	LogPrefix string

	// The order of the logs, either 'grouped' or 'stream'
	LogOrder string

	// Whether turbo should create a run summary
	Summarize bool

	ExperimentalSpaceID string

	// Whether this run is in Github Actions
	IsGithubActions bool
}

RunOpts holds the options that control the execution of a turbo run

type Semaphore

type Semaphore chan struct{}

Semaphore is a wrapper around a channel to provide utility methods to clarify that we are treating the channel as a semaphore

func NewSemaphore

func NewSemaphore(n int) Semaphore

NewSemaphore creates a semaphore that allows up to a given limit of simultaneous acquisitions

func (Semaphore) Acquire

func (s Semaphore) Acquire()

Acquire is used to acquire an available slot. Blocks until available.

func (Semaphore) Release

func (s Semaphore) Release()

Release is used to return a slot. Acquire must be called as a pre-condition.

func (Semaphore) TryAcquire

func (s Semaphore) TryAcquire() bool

TryAcquire is used to do a non-blocking acquire. Returns a bool indicating success

type Set

type Set map[interface{}]interface{}

Set is a set data structure.

func SetFromStrings

func SetFromStrings(sl []string) Set

SetFromStrings creates a Set containing the strings from the given slice

func (Set) Add

func (s Set) Add(v interface{})

Add adds an item to the set

func (Set) Copy

func (s Set) Copy() Set

Copy returns a shallow copy of the set.

func (Set) Delete

func (s Set) Delete(v interface{})

Delete removes an item from the set.

func (Set) Difference

func (s Set) Difference(other Set) Set

Difference returns a set with the elements that s has but other doesn't.

func (Set) Filter

func (s Set) Filter(cb func(interface{}) bool) Set

Filter returns a set that contains the elements from the receiver where the given callback returns true.

func (Set) Includes

func (s Set) Includes(v interface{}) bool

Includes returns true/false of whether a value is in the set.

func (Set) Intersection

func (s Set) Intersection(other Set) Set

Intersection computes the set intersection with other.

func (Set) Len

func (s Set) Len() int

Len is the number of items in the set.

func (Set) List

func (s Set) List() []interface{}

List returns the list of set elements.

func (Set) Some

func (s Set) Some(cb func(interface{}) bool) bool

Some tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.

func (Set) UnsafeListOfStrings

func (s Set) UnsafeListOfStrings() []string

UnsafeListOfStrings dangerously casts list to a string

type TaskOutputMode

type TaskOutputMode int

TaskOutputMode defines the ways turbo can display task output during a run

const (
	// FullTaskOutput will show all task output
	FullTaskOutput TaskOutputMode = iota
	// NoTaskOutput will hide all task output
	NoTaskOutput
	// HashTaskOutput will display turbo-computed task hashes
	HashTaskOutput
	// NewTaskOutput will show all new task output and turbo-computed task hashes for cached output
	NewTaskOutput
	// ErrorTaskOutput will show task output for failures only; no cache miss/hit messages are emitted
	ErrorTaskOutput
)

func FromTaskOutputModeString

func FromTaskOutputModeString(value string) (TaskOutputMode, error)

FromTaskOutputModeString converts a task output mode's string representation into the enum value

func (TaskOutputMode) MarshalJSON

func (c TaskOutputMode) MarshalJSON() ([]byte, error)

MarshalJSON converts a task output mode to its string representation

func (*TaskOutputMode) UnmarshalJSON

func (c *TaskOutputMode) UnmarshalJSON(data []byte) error

UnmarshalJSON converts a task output mode string representation into an enum

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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