Documentation ¶
Overview ¶
compilerutil package defines utility methods.
Index ¶
- Constants
- Variables
- func DCHECK(checker checkFn, failMessage string, args ...interface{})
- func DetectGoroutineLeak(t *testing.T, grCount int)
- func DownloadURLToFileWithProgress(url *url.URL, filePath string, callback ProgressCallback) error
- func IsId(possibleId string) bool
- func LatestSemanticVersion(availableVersions []string) (string, bool)
- func LogMessageToConsole(prefixColor *color.Color, prefixText string, ...)
- func LogToConsole(level ConsoleLogLevel, sourceRange compilercommon.SourceRange, message string, ...)
- func NewUniqueId() string
- func NextSemanticVersion(currentVersionString string, option NextVersionOption) (string, error)
- func ParseFloat(strValue string) float64
- func Queue() *orderedWorkQueue
- func SemanticUpdateVersion(currentVersionString string, availableVersions []string, ...) (string, error)
- func WalkSourcePath(path string, handler PathHandler, skipDirectories ...string) (uint, error)
- type CancelFunction
- type CancelationHandle
- type ConsoleLogLevel
- type Element
- type ImmutableMap
- type IntRange
- type LockMap
- type NextVersionOption
- type PathHandler
- type ProgressCallback
- type RangeMapTree
- type RangeMapTreeCalculator
- type Stack
- type UpdateVersionOption
Constants ¶
const INDENTATION = " "
const RECURSIVE_PATTERN = "/..."
RECURSIVE_PATTERN defines the pattern for recursively searching for files.
Variables ¶
var ( InfoColor = color.New(color.FgBlue, color.Bold) SuccessColor = color.New(color.FgGreen, color.Bold) WarningColor = color.New(color.FgYellow, color.Bold) ErrorColor = color.New(color.FgRed, color.Bold) BoldWhiteColor = color.New(color.FgWhite, color.Bold) FaintWhiteColor = color.New(color.FgWhite, color.Faint) MessageColor = color.New(color.FgHiWhite) )
var RunningUnderTest = false
Functions ¶
func DCHECK ¶
func DCHECK(checker checkFn, failMessage string, args ...interface{})
DCHECK executes the checker function only if the DEBUG environment variable is set. If the function returns false, the compiler will panic with the formatted message.
func DetectGoroutineLeak ¶ added in v0.3.1
DetectGoroutineLeak detects if there is a leak of goroutines over the life of a test.
func DownloadURLToFileWithProgress ¶ added in v0.3.0
func DownloadURLToFileWithProgress(url *url.URL, filePath string, callback ProgressCallback) error
DownloadURLToFileWithProgress downloads the contents of the given URL to the given file path on disk, invoking the callback function to report progress.
func LatestSemanticVersion ¶
LatestSemanticVersion returns the latest non-patch semantic version found in the list of available versions, if any.
func LogMessageToConsole ¶ added in v0.2.0
func LogMessageToConsole(prefixColor *color.Color, prefixText string, sourceRange compilercommon.SourceRange, message string, args ...interface{})
LogMessageToConsole logs a message to the console, with the given level and range.
func LogToConsole ¶
func LogToConsole(level ConsoleLogLevel, sourceRange compilercommon.SourceRange, message string, args ...interface{})
LogToConsole logs a message to the console, with the given level and range.
func NextSemanticVersion ¶ added in v0.2.0
func NextSemanticVersion(currentVersionString string, option NextVersionOption) (string, error)
NextSemanticVersion returns the next logic semantic version from the current version, given the update option.
func ParseFloat ¶
ParseFloat parses the given string value into a float64, panicing on failure.
func SemanticUpdateVersion ¶
func SemanticUpdateVersion(currentVersionString string, availableVersions []string, option UpdateVersionOption) (string, error)
SemanticUpdateVersion finds the semver in the available versions list that is newer than the current version.
func WalkSourcePath ¶
func WalkSourcePath(path string, handler PathHandler, skipDirectories ...string) (uint, error)
WalkSourcePath walks the given source path, invoking the given handler for each file found. Returns the number of files walked and the error that occurred, if any.
Types ¶
type CancelFunction ¶ added in v0.3.0
type CancelFunction func()
CancelFunction is a function that can be invoked to cancel the operation.
type CancelationHandle ¶ added in v0.3.0
type CancelationHandle interface { // Cancel marks the operation as canceled. Cancel() // WasCanceled returns whether the operation was canceled. WasCanceled() bool }
CancelationHandle defines a handle for the cancelation of operations.
func GetCancelationHandle ¶ added in v0.3.0
func GetCancelationHandle(existing CancelationHandle) CancelationHandle
GetCancelationHandle returns either the existing cancelation handle (if not nil) or a new no-op handle.
func NewCancelationHandle ¶ added in v0.3.0
func NewCancelationHandle() CancelationHandle
NewCancelationHandle returns a new handle for canceling an operation.
func NoopCancelationHandle ¶ added in v0.3.0
func NoopCancelationHandle() CancelationHandle
NoopCancelationHandle returns a cancelation handle that cannot be canceled.
type ConsoleLogLevel ¶
type ConsoleLogLevel int
const ( InfoLogLevel ConsoleLogLevel = iota SuccessLogLevel WarningLogLevel ErrorLogLevel )
type ImmutableMap ¶ added in v0.1.0
type ImmutableMap interface { // Get returns the value found at the given key, if any. Get(key string) (interface{}, bool) // Set returns a new ImmutableMap which is a copy of this map, but with the given key set // to the given value. Set(key string, value interface{}) ImmutableMap }
ImmutableMap defines an immutable map struct, where Set-ing a new key returns a new ImmutableMap.
func NewImmutableMap ¶ added in v0.1.0
func NewImmutableMap() ImmutableMap
NewImmutableMap creates a new, empty immutable map.
type LockMap ¶
type LockMap struct {
// contains filtered or unexported fields
}
LockMap defines a concurrent-safe map that returns a sync Mutex for each key. This is useful when multiple resources are being loaded concurrently and locking is needed, but only on a per-resource basis.
type NextVersionOption ¶ added in v0.2.0
type NextVersionOption string
NextVersionOption defines the options for the NextSemanticVersion method.
const ( // NextMajorVersion indicates that the major version field should be incremented. NextMajorVersion NextVersionOption = "major" // NextMinorVersion indicates that the minor version field should be incremented. NextMinorVersion NextVersionOption = "minor" // NextPatchVersion indicates that the patch version field should be incremented. NextPatchVersion NextVersionOption = "patch" )
type PathHandler ¶
PathHandler defines a handler to be invoked for every file found. Implementations should return false if the file should be skipped.
type ProgressCallback ¶ added in v0.3.0
ProgressCallback is a callback for the progress of a file download operation.
type RangeMapTree ¶
type RangeMapTree struct {
// contains filtered or unexported fields
}
RangeMapTree defines a helper struct for cached, faster lookup of an int range to an associated piece of data, under a specific key (such as a source file path). Note that the ranges for the data must be explicitly *non-overlapping* under each key, or this data structure will fail to work as intended. Ranges *within* other ranges, on the other hand, are allowed.
This data structure is safe for multi-threaded access.
func NewRangeMapTree ¶
func NewRangeMapTree(calculator RangeMapTreeCalculator) *RangeMapTree
NewRangeMapTree creates a new range map tree.
func (*RangeMapTree) Get ¶
func (rmt *RangeMapTree) Get(key string, current IntRange) interface{}
Get returns the data associated with the given key and range. If the data for that range has not yet been calculated, the calculator method is called to do so lazily.
type RangeMapTreeCalculator ¶
RangeMapTreeCalculator returns the calculated value for the given key and range. The range returned should encompass the entire range of the returned value. If no valid value is found for the position and key, the range returned should be the range requested.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
func (*Stack) Peek ¶
func (s *Stack) Peek() interface{}
Peek returns the element on the top of the list, if any. If the stack is empty, return nil
func (*Stack) PeekSecond ¶
func (s *Stack) PeekSecond() interface{}
PeekSecond returns the element second to the top of the list, if any. If the stack contains less than two elemeents, return nil
type UpdateVersionOption ¶
type UpdateVersionOption string
UpdateVersionOption defines the options for the SemanticUpdateVersion method.
const ( // UpdateVersionMinor indicates that only minor version updates are allowed. UpdateVersionMinor UpdateVersionOption = "minor" // UpdateVersionMajor indicates the both minor and major version updates are allowed. UpdateVersionMajor UpdateVersionOption = "major" )