Documentation
¶
Overview ¶
Package imports provides handling of claw.mod, local.replace and global.replace files.
Index ¶
- func AppendImports(ctx context.Context, pkgPath string) context.Context
- func FindClawFile(fs fs.ReadDirFS, path string) (string, error)
- func ValidModuleName(module string) error
- type ACL
- type ClawImports
- type Config
- func (c *Config) Abs(p string) (string, error)
- func (c *Config) GetImports() map[string]*idl.File
- func (c *Config) InRootRepo(pkgPath string) bool
- func (c *Config) Read(ctx context.Context, clawFilePath string) error
- func (c *Config) RootDir() string
- func (c *Config) ShouldWriteFile(pkgPath string) bool
- func (c *Config) TransformImportPath(pkgPath string) string
- func (c Config) Validate(f *idl.File) error
- type ConfigProvider
- type Directive
- type ImportFlow
- type LocalReplace
- func (l *LocalReplace) FindNext(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (l *LocalReplace) ParseReplace(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (l *LocalReplace) ReplaceMe(path string) Replace
- func (l *LocalReplace) SkipLinesWithComments(p *halfpike.Parser)
- func (l *LocalReplace) Start(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (l *LocalReplace) Validate() error
- type Module
- func (m *Module) FindNext(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (m *Module) ParseACLs(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (m *Module) ParseModule(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (m *Module) ParseReplace(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (m *Module) ParseRequire(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (m *Module) SkipLinesWithComments(p *halfpike.Parser)
- func (m *Module) Start(ctx context.Context, p *halfpike.Parser) halfpike.ParseFn
- func (m *Module) Validate() error
- type Replace
- type Require
- type VendoredConfig
- func (vc *VendoredConfig) Abs(p string) (string, error)
- func (vc *VendoredConfig) GetImports() map[string]*idl.File
- func (vc *VendoredConfig) InRootRepo(pkgPath string) bool
- func (vc *VendoredConfig) Read(ctx context.Context, clawFilePath string) error
- func (vc *VendoredConfig) ShouldWriteFile(pkgPath string) bool
- type Version
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendImports ¶
AppendImports extracts the ImportFlow in the Context and appends pkgPath to it and returns the new Context.
func FindClawFile ¶
FindClawFile will return the absolute path of the .claw file at path.
func ValidModuleName ¶
ValidModuleName determines if a module name is valid.
Types ¶
type ClawImports ¶
type ClawImports struct {
// Directive informs where to put all external repository imports.
Directive Directive
}
ClawImports represents a claw.imports file and includes halfpike methods to decode the file. A claw.imports file looks like the following:
directive {
path: "claw/external/imports"
}
func (*ClawImports) ParseDirective ¶
func (*ClawImports) SkipLinesWithComments ¶
func (c *ClawImports) SkipLinesWithComments(p *halfpike.Parser)
func (*ClawImports) Validate ¶
func (c *ClawImports) Validate() error
type Config ¶
type Config struct {
Root *idl.File
// Imports is a mapping of all package paths to their IDL. If the idl.File == nil but
// there is a key, then there is a replacement, check the LocalReplace.
Imports map[string]*idl.File
Module *Module
LocalReplace LocalReplace
GlobalReplace map[string]Replace
// VendorRepo is the repo path from claw.work (e.g., "github.com/bearlytools/claw").
// Empty if not using vendoring.
VendorRepo string
// VendorDir is the vendor directory name from claw.work (e.g., "claw_vendor").
// Empty if not using vendoring.
VendorDir string
// contains filtered or unexported fields
}
Config just holds the overall union of claw.mod, local.replace and global.replace.
func (*Config) GetImports ¶
GetImports returns the imports map for the base Config.
func (*Config) InRootRepo ¶
InRootRepo will determine if pkgPath is in the root file's repo.
func (*Config) Read ¶
Read reads the .claw file at clawFilePath, any claw.mod files found, any local.replace file, and uses it to build up our Config with all the files that are imported and that they import until we error or have all the files needed to begin building our Claw language files.
func (*Config) ShouldWriteFile ¶
ShouldWriteFile determines if a file should be written for the given package path. For Config (non-vendored), this is the same as InRootRepo.
func (*Config) TransformImportPath ¶
TransformImportPath transforms a package path to its proper import path. For vendored packages, this prepends the vendor repo and directory. For local packages (within VendorRepo), returns the path unchanged.
type ConfigProvider ¶
type ConfigProvider interface {
InRootRepo(pkgPath string) bool
ShouldWriteFile(pkgPath string) bool
Abs(p string) (string, error)
GetImports() map[string]*idl.File
}
ConfigProvider is an interface that provides configuration for compilation.
type Directive ¶
type Directive struct {
// Path is the path to the location in the git repo to store the imports.
Path string
}
Directive is a directive on where to store our external package renders.
type ImportFlow ¶
type ImportFlow []string
ImportFlow is a list of imports that have been imported in this import path. It is used when going down the tree of imports to make sure we do not see ourselves already in the path, which would indicate a cyclic import.
func ExtractImports ¶
func ExtractImports(ctx context.Context) ImportFlow
ExtractImports extracts a list of packages that have been imported in this import chain from the Context object. A nil return indicates you are at the first file.
func (ImportFlow) String ¶
func (i ImportFlow) String() string
type LocalReplace ¶
type LocalReplace struct {
Replace []Replace
// contains filtered or unexported fields
}
LocalReplace represents the local.replace file and includes halfpike methods to decode the file.
func NewLocalReplace ¶
func NewLocalReplace(fs neededFS, f *idl.File) LocalReplace
func (*LocalReplace) ParseReplace ¶
func (*LocalReplace) ReplaceMe ¶
func (l *LocalReplace) ReplaceMe(path string) Replace
ReplaceMe returns the replacement for path. Use Replace.IsZero() to dermine if it was found or not.
func (*LocalReplace) SkipLinesWithComments ¶
func (l *LocalReplace) SkipLinesWithComments(p *halfpike.Parser)
func (*LocalReplace) Validate ¶
func (l *LocalReplace) Validate() error
type Module ¶
type Module struct {
// Path is the module path.
Path string
// Required is a list of specific versions of packages that must be imported.
Required []Require
// Replace is a list of packages that should be replaced with a different location.
Replace []Replace
// ACLs are a list of ACLs that are provided. If it is set to acls = public, then
// the first and only ACL will be *.
ACLs []ACL
}
Module represents a claw.mod file and includes halpike methods to decode the file.
func (*Module) FindNext ¶
FindNext is used to scan lines until we find the next thing to parse and direct to the halfpike.ParseFn responsible.
func (*Module) ParseModule ¶
func (*Module) ParseReplace ¶
func (*Module) ParseRequire ¶
func (*Module) SkipLinesWithComments ¶
type VendoredConfig ¶
type VendoredConfig struct {
*Config
// contains filtered or unexported fields
}
VendoredConfig is a Config that uses vendored dependencies instead of fetching them.
func NewVendoredConfig ¶
func NewVendoredConfig(vendorDirPath, repoPath, vendorDirName string) *VendoredConfig
NewVendoredConfig creates a new VendoredConfig that uses vendored dependencies. vendorDirPath is the full filesystem path to the vendor directory. repoPath is the repo path from claw.work (e.g., "github.com/bearlytools/claw"). vendorDirName is the vendor directory name from claw.work (e.g., "claw_vendor").
func (*VendoredConfig) Abs ¶
func (vc *VendoredConfig) Abs(p string) (string, error)
Abs returns the appropriate path for a package - either vendor or original location. For local packages (within current git repository), returns their original source path. For external packages, returns the path within the vendor directory.
func (*VendoredConfig) GetImports ¶
func (vc *VendoredConfig) GetImports() map[string]*idl.File
GetImports returns the imports map for the VendoredConfig.
func (*VendoredConfig) InRootRepo ¶
func (vc *VendoredConfig) InRootRepo(pkgPath string) bool
InRootRepo returns true for local packages and true for vendored external packages. This prevents the writer from trying to do go get operations on either type.
func (*VendoredConfig) Read ¶
func (vc *VendoredConfig) Read(ctx context.Context, clawFilePath string) error
Read reads the .claw file and uses vendored dependencies instead of fetching them.
func (*VendoredConfig) ShouldWriteFile ¶
func (vc *VendoredConfig) ShouldWriteFile(pkgPath string) bool
ShouldWriteFile determines if a file should be written for the given package path. For VendoredConfig, always returns true - we want to write .go files for both local packages and vendored packages.