shared

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdentNil    = "nil"
	IdentTrue   = "true"
	IdentFalse  = "false"
	IdentIgnore = "_"
)
View Source
const (
	TempBuildDir    = ".otel-build"
	VendorDir       = "vendor"
	BuildModeVendor = "-mod=vendor"
	BuildModeMod    = "-mod=mod"
	BuildConfFile   = "build_conf.json"
)
View Source
const (
	GoBuildIgnoreComment = "//go:build ignore"
	GoModFile            = "go.mod"
	GoSumFile            = "go.sum"
	GoWorkSumFile        = "go.work.sum"
	DebugLogFile         = "debug.log"
	TInstrument          = "instrument"
	TPreprocess          = "preprocess"
)

Variables

View Source
var TheName = "otelbuild"
View Source
var TheVersion = "1.0.0"

This is the version of the tool, which will be printed when the -version flag is passed. This value is specified by the build system.

Functions

func AddImport

func AddImport(root *dst.File, path string)

func AddImportForcely

func AddImportForcely(root *dst.File, path string)

func AddStructField

func AddStructField(decl dst.Decl, name string, typ string)

func AddressOf

func AddressOf(expr dst.Expr) *dst.UnaryExpr

AST Construction

func ArrayType

func ArrayType(elem dst.Expr) *dst.ArrayType

func AssignStmt

func AssignStmt(lhs, rhs dst.Expr) *dst.AssignStmt

func Block

func Block(stmt dst.Stmt) *dst.BlockStmt

func BlockStmts

func BlockStmts(stmts ...dst.Stmt) *dst.BlockStmt

func BoolFalse

func BoolFalse() *dst.BasicLit

func BoolTrue

func BoolTrue() *dst.BasicLit

func CallTo

func CallTo(name string, args []dst.Expr) *dst.CallExpr

func DeferStmt

func DeferStmt(call *dst.CallExpr) *dst.DeferStmt

func DefineStmts

func DefineStmts(lhs, rhs []dst.Expr) *dst.AssignStmt

func DereferenceOf

func DereferenceOf(expr dst.Expr) dst.Expr

func EmptyStmt

func EmptyStmt() *dst.EmptyStmt

func ExprStmt

func ExprStmt(expr dst.Expr) *dst.ExprStmt

func Exprs

func Exprs(exprs ...dst.Expr) []dst.Expr

func ExtractVersion

func ExtractVersion(path string) string

func FindFuncDecl

func FindFuncDecl(root *dst.File, name string) *dst.FuncDecl

func GetGoModDir

func GetGoModDir() (string, error)

GetGoModDir returns the directory of go.mod file.

func GetGoModPath

func GetGoModPath() (string, error)

GetGoModPath returns the absolute path of go.mod file, if any.

func GetInstrumentLogPath

func GetInstrumentLogPath(name string) string

func GetLogPath

func GetLogPath(name string) string

func GetPreprocessLogPath

func GetPreprocessLogPath(name string) string

func GetProjRootDir

func GetProjRootDir() (string, error)

GetProjRootDir returns the root directory of the project. It's an alias of GetGoModDir in the current implementation.

func GetTempBuildDir

func GetTempBuildDir() string

func GetVarNameOfFunc

func GetVarNameOfFunc(fn string) string

func GuaranteeInInstrument

func GuaranteeInInstrument()

func GuaranteeInPreprocess

func GuaranteeInPreprocess()

func HasGoBuildComment

func HasGoBuildComment(text string) bool

func HasReceiver

func HasReceiver(fn *dst.FuncDecl) bool

func HashStruct

func HashStruct(st interface{}) (uint64, error)

func Ident

func Ident(name string) *dst.Ident

func IfNotNilStmt

func IfNotNilStmt(cond dst.Expr, body, elseBody *dst.BlockStmt) *dst.IfStmt

func IfStmt

func IfStmt(init dst.Stmt, cond dst.Expr,
	body, elseBody *dst.BlockStmt) *dst.IfStmt

func InInstrument

func InInstrument() bool

func InPreprocess

func InPreprocess() bool

func IndexExpr

func IndexExpr(x dst.Expr, index dst.Expr) *dst.IndexExpr

func InitConfig

func InitConfig() (err error)

func IntLit

func IntLit(value int) *dst.BasicLit

func InterfaceType

func InterfaceType() *dst.InterfaceType

func IsCompileCommand

func IsCompileCommand(line string) bool

func IsEllipsis

func IsEllipsis(typ dst.Expr) bool

func IsExistGoMod

func IsExistGoMod() (bool, error)

func IsGoFile

func IsGoFile(path string) bool

func IsGoModFile

func IsGoModFile(path string) bool

func IsGoSumFile

func IsGoSumFile(path string) bool

func IsGoTestFile

func IsGoTestFile(path string) bool

func IsInterfaceType

func IsInterfaceType(typ dst.Expr) bool

func IsModPath

func IsModPath(path string) bool

IsModPath checks if the provided module path is valid.

func IsStringLit

func IsStringLit(expr dst.Expr, val string) bool

func IsUnusedIdent

func IsUnusedIdent(ident *dst.Ident) bool

func MakePublic

func MakePublic(name string) string

func MakeUnusedIdent

func MakeUnusedIdent(ident *dst.Ident) *dst.Ident

func MatchFuncDecl

func MatchFuncDecl(decl dst.Decl, function string, receiverType string) bool

func MatchStructDecl

func MatchStructDecl(decl dst.Decl, structType string) bool

func MatchVersion

func MatchVersion(version string, ruleVersion string) (bool, error)

MatchVersion checks if the version string matches the version range in the rule. The version range is in format [start, end), where start is inclusive and end is exclusive. If the rule version string is empty, it always matches.

func NewField

func NewField(name string, typ dst.Expr) *dst.Field

func NewVarDecl

func NewVarDecl(name string, paramTypes *dst.FieldList) *dst.GenDecl

func ParenExpr

func ParenExpr(x dst.Expr) *dst.ParenExpr

func ParseAstFromFile

func ParseAstFromFile(filePath string) (*dst.File, error)

ParseAstFromFile parses the AST from complete source file.

func ParseAstFromFileFast

func ParseAstFromFileFast(filePath string) (*dst.File, error)

func ParseAstFromFileOnlyPackage

func ParseAstFromFileOnlyPackage(filePath string) (*dst.File, error)

func ParseAstFromSnippet

func ParseAstFromSnippet(codeSnippnet string) ([]dst.Stmt, error)

ParseAstFromSnippet parses the AST from incomplete source code snippet.

func ParseAstFromSource

func ParseAstFromSource(source string) (*dst.File, error)

ParseAstFromSource parses the AST from complete source code.

func RemoveGoBuildComment

func RemoveGoBuildComment(text string) string

func RemoveImport

func RemoveImport(root *dst.File, path string) *dst.ImportSpec

func RenamePackage

func RenamePackage(source, newPkgName string) string

func ReturnStmt

func ReturnStmt(results []dst.Expr) *dst.ReturnStmt

func SelectorExpr

func SelectorExpr(x dst.Expr, sel string) *dst.SelectorExpr

func SplitCmds

func SplitCmds(input string) []string

SplitCmds splits the command line by space, but keep the quoted part as a whole. For example, "a b" c will be split into ["a b", "c"].

func Stmts

func Stmts(stmts ...dst.Stmt) []dst.Stmt

func StringLit

func StringLit(value string) *dst.BasicLit

func SwitchCase

func SwitchCase(list []dst.Expr, stmts []dst.Stmt) *dst.CaseClause

func TypeAssertExpr

func TypeAssertExpr(x dst.Expr, typ dst.Expr) *dst.TypeAssertExpr

func WriteAstToFile

func WriteAstToFile(astRoot *dst.File, filePath string) (string, error)

WriteAstToFile writes the AST to source file.

Types

type BuildConfig

type BuildConfig struct {
	// RuleJsonFiles is the name of the rule file. It is used to tell instrument
	// tool where to find the instrument rules. Multiple rules are separated by
	// comma. e.g. -rule=rule1.json,rule2.json. By default, new rules are appended
	// to default rules, i.e. -rule=rule1.json,rule2.json is exactly equivalent to
	// -rule=default.json,rule1.json,rule2.json. But if you do want to replace the
	// default rules, you can add a "+" prefix to the rule file name, e.g.
	// -rule=+rule1.json,rule2.json. In this case, the default rules will be replaced
	// by rule1.json, and then rule2.json will be appended to the rules.
	RuleJsonFiles string

	// InToolexec true means this tool is being invoked in the go build process.
	// This flag **SHOULD NOT** be set manually by users.
	InToolexec bool

	// DebugLog true means debug log is enabled.
	DebugLog bool

	// Verbose true means print verbose log.
	Verbose bool

	// Debug true means debug mode.
	Debug bool

	// Restore true means restore all instrumentations.
	Restore bool

	// BuildArgs are the arguments to pass to the go build command.
	BuildArgs []string

	// PrintVersion true means print version.
	PrintVersion bool
	// contains filtered or unexported fields
}

func GetConf

func GetConf() *BuildConfig

func (*BuildConfig) IsDisableDefaultRules

func (bc *BuildConfig) IsDisableDefaultRules() bool

Jump to

Keyboard shortcuts

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