Documentation ¶
Overview ¶
Package swift provides utility functions for generating Bazel declarations for Swift source files.
Index ¶
- Constants
- func BazelLabelFromTarget(repoName string, target *swiftpkg.Target) *label.Label
- func BzlmodStanzas(di *DependencyIndex, moduleDir string, diPath string) (string, error)
- func CodeDirForLocalPackage(pkgDir string, localPkgPath string) string
- func CodeDirForRemotePackage(buildDir string, url string) string
- func FilterFiles(paths []string) []string
- func Imports(rules []*rule.Rule) []any
- func IsBuiltInFramework(name string) bool
- func IsBuiltInSwiftModule(name string) bool
- func IsSwiftRuleKind(ruleKind string) bool
- func ModuleDir(configModPaths []string, path string) string
- func ModuleName(r *rule.Rule) string
- func ModulemapBazelLabelFromTargetLabel(lbl *label.Label) *label.Label
- func NewLabel(lblStr LabelStr) (*label.Label, error)
- func NewPatchesFromYAML(b []byte) (map[string]*Patch, error)
- func RepoNameFromIdentity(id string) string
- func RepoRuleFromBazelRepo(bzlRepo *BazelRepo, diRel string, pkgDir string, repoDir string, patch *Patch) (*rule.Rule, error)
- func RulesFromProtos(args language.GenerateArgs, generateProtoLibraries bool, ...) []*rule.Rule
- func RulesFromSrcs(args language.GenerateArgs, srcs []string, defaultName string, ...) []*rule.Rule
- func UseRepoNames(di *DependencyIndex) (string, error)
- type BazelRepo
- type DependencyIndex
- func (di DependencyIndex) AddDirectDependency(identities ...string)
- func (di *DependencyIndex) AddModule(modules ...*Module)
- func (di *DependencyIndex) AddPackage(packages ...*Package)
- func (di *DependencyIndex) AddProduct(products ...*Product)
- func (di DependencyIndex) DirectDepIdentities() []string
- func (di *DependencyIndex) DirectDepPackages() []*Package
- func (di *DependencyIndex) FindModules(moduleName string, pkgIdentities []string) Modules
- func (di *DependencyIndex) GetPackage(identity string) *Package
- func (di *DependencyIndex) IndexBazelRepo(bzlRepo *BazelRepo) error
- func (di *DependencyIndex) IndexRepoRule(r *rule.Rule, repoRoot string) error
- func (di *DependencyIndex) JSON() ([]byte, error)
- func (di *DependencyIndex) MarshalJSON() ([]byte, error)
- func (di *DependencyIndex) Packages() []*Package
- func (di *DependencyIndex) ResolveModulesToProducts(moduleNames []string, pkgIdentities []string) *ModuleResolutionResult
- func (di *DependencyIndex) UnmarshalJSON(b []byte) error
- type HTTPArchive
- type LabelStr
- type LabelStrs
- type LocalPackage
- type Module
- func NewModule(name, c99name string, srcType swiftpkg.SourceType, bzlLabel *label.Label, ...) *Module
- func NewModuleFromLabelStruct(name, c99name string, srcType swiftpkg.SourceType, bzlLabel label.Label, ...) *Module
- func NewModuleFromTarget(repoName, pkgIdentity string, t *swiftpkg.Target) (*Module, error)
- type ModuleIndex
- type ModuleResolutionResult
- type ModuleToProductsIndex
- type ModuleType
- type Modules
- type Package
- type PackageIndex
- type Patch
- type Product
- type ProductIndex
- type ProductIndexKey
- type ProductIndexKeys
- type ProductMembershipsIndex
- type ProductType
- type Products
- type RemotePackage
Constants ¶
const ( UnknownProductTypeStr = "unknown" LibraryProductTypeStr = "library" ExecutableProductTypeStr = "executable" PluginProductTypeStr = "plugin" )
const ( LibraryRuleKind = "swift_library" ProtoLibraryRuleKind = "swift_proto_library" GRPCLibraryRuleKind = "swift_grpc_library" BinaryRuleKind = "swift_binary" TestRuleKind = "swift_test" // Repository Rule SwiftPkgRuleKind = "swift_package" LocalSwiftPkgRuleKind = "local_swift_package" HTTPArchiveRuleKind = "http_archive" AliasRuleKind = "alias" )
const HTTPArchivePkgIdentity = "__http_archive__"
const (
ModuleNameAttrName = "module_name"
)
const ( // SwiftProtoModuleNameKey is the key for the module name private // attribute for swift_proto_library and swift_grpc_library targets. SwiftProtoModuleNameKey = "_swift_proto_module_name" )
Variables ¶
This section is empty.
Functions ¶
func BazelLabelFromTarget ¶
BazelLabelFromTarget creates a Bazel label from a Swift target. The logic in this function must stay in sync with pkginfo_targets.bazel_label_name_from_parts() in the Starlark code.
func BzlmodStanzas ¶
func BzlmodStanzas(di *DependencyIndex, moduleDir string, diPath string) (string, error)
func CodeDirForLocalPackage ¶
CodeDirForLocalPackage returns the path to the dependency's code. For local packages, it is the path to the local package.
func CodeDirForRemotePackage ¶
CodeDirForRemotePackage returns the path to the dependency's code. For source control dependencies, it is the checkout directory.
func FilterFiles ¶
FilterFiles returns a list of Swift source files excluding `Package.swift`.
func IsBuiltInFramework ¶ added in v0.22.0
IsBuiltInFramework determines if the module is built into the Swift standard library.
func IsBuiltInSwiftModule ¶ added in v0.22.0
IsBuiltInSwiftModule determines if the module is built into the Swift standard library.
func IsSwiftRuleKind ¶
IsSwiftRuleKind determines whether to provided rule kind is a Swift rule.
func ModuleDir ¶
ModuleDir returns the module root directory. The configModPaths is a list of relative paths to module directories defined by swift_default_module_name directives.
func ModuleName ¶
ModuleName returns the module name from a Swift rule declaration.
func ModulemapBazelLabelFromTargetLabel ¶ added in v0.6.0
ModulemapBazelLabelFromTargetLabel creates a Bazel label for a modulemap target from the corresponding target label.
func NewPatchesFromYAML ¶ added in v0.5.0
NewPatchesFromYAML reads the provided YAML returning a map of patches organized by Swift package identity.
func RepoNameFromIdentity ¶
RepoNameFromIdentity returns a Bazel repository name from a Swift package identity/name. The value produced by this function will not have the `@` character appended. This is handled by label.Label.
func RepoRuleFromBazelRepo ¶
func RepoRuleFromBazelRepo( bzlRepo *BazelRepo, diRel string, pkgDir string, repoDir string, patch *Patch, ) (*rule.Rule, error)
RepoRuleFromBazelRepo returns a repository rule declaration for a Swift Bazel repository. The pkgDir is the path to the Swift package that is referencing this Bazel repository.
func RulesFromProtos ¶ added in v0.8.0
func RulesFromProtos( args language.GenerateArgs, generateProtoLibraries bool, generateGRPCLibraryFlavors []string, ) []*rule.Rule
RulesFromProtos returns the Bazel build rule declarations for the provided source files.
func RulesFromSrcs ¶
func RulesFromSrcs( args language.GenerateArgs, srcs []string, defaultName string, defaultModuleName string, swiftLibraryTags []string, ) []*rule.Rule
RulesFromSrcs returns the Bazel build rule declarations for the provided source files.
func UseRepoNames ¶
func UseRepoNames(di *DependencyIndex) (string, error)
Types ¶
type BazelRepo ¶
A BazelRepo represents a Swift package as a Bazel repository for an external dependency.
func NewBazelRepo ¶
func NewBazelRepo( identity string, pkgInfo *swiftpkg.PackageInfo, pin *spreso.Pin, ) (*BazelRepo, error)
NewBazelRepo returns a Bazel repo for a Swift package.
type DependencyIndex ¶
type DependencyIndex struct {
// contains filtered or unexported fields
}
A DependencyIndex encapsulates the indexes used to lookup Swift modules and products.
func NewDependencyIndex ¶
func NewDependencyIndex() *DependencyIndex
NewDependencyIndex creates an empty dependency index.
func NewDependencyIndexFromJSON ¶
func NewDependencyIndexFromJSON(data []byte) (*DependencyIndex, error)
NewDependencyIndexFromJSON creates a dependency index from JSON.
func (DependencyIndex) AddDirectDependency ¶
func (di DependencyIndex) AddDirectDependency(identities ...string)
func (*DependencyIndex) AddModule ¶
func (di *DependencyIndex) AddModule(modules ...*Module)
AddModule adds one or more modules to the underlying indexes.
func (*DependencyIndex) AddPackage ¶
func (di *DependencyIndex) AddPackage(packages ...*Package)
func (*DependencyIndex) AddProduct ¶
func (di *DependencyIndex) AddProduct(products ...*Product)
AddProduct adds one or more products to the underlying indexes.
func (DependencyIndex) DirectDepIdentities ¶
func (di DependencyIndex) DirectDepIdentities() []string
func (*DependencyIndex) DirectDepPackages ¶
func (di *DependencyIndex) DirectDepPackages() []*Package
func (*DependencyIndex) FindModules ¶
func (di *DependencyIndex) FindModules(moduleName string, pkgIdentities []string) Modules
func (*DependencyIndex) GetPackage ¶
func (di *DependencyIndex) GetPackage(identity string) *Package
func (*DependencyIndex) IndexBazelRepo ¶
func (di *DependencyIndex) IndexBazelRepo(bzlRepo *BazelRepo) error
IndexBazelRepo indexes the modules and products for a Bazel repository.
func (*DependencyIndex) IndexRepoRule ¶
func (di *DependencyIndex) IndexRepoRule(r *rule.Rule, repoRoot string) error
IndexRepoRule indexes any repository rules that are not already included in the module index generated by update-repos. In other words, the swift_package repo rules are not indexed here because their contents are already included in the module index JSON file.
func (*DependencyIndex) JSON ¶
func (di *DependencyIndex) JSON() ([]byte, error)
JSON returns the pretty, JSON representation for the dependency index that is written to disk.
func (*DependencyIndex) MarshalJSON ¶
func (di *DependencyIndex) MarshalJSON() ([]byte, error)
func (*DependencyIndex) Packages ¶ added in v0.14.0
func (di *DependencyIndex) Packages() []*Package
func (*DependencyIndex) ResolveModulesToProducts ¶
func (di *DependencyIndex) ResolveModulesToProducts( moduleNames []string, pkgIdentities []string, ) *ModuleResolutionResult
ResolveModulesToProducts finds the best set of products to satisfy the list of modules restricted to a set of packages.
func (*DependencyIndex) UnmarshalJSON ¶
func (di *DependencyIndex) UnmarshalJSON(b []byte) error
type HTTPArchive ¶
A HTTPArchive represents Swift module information found in a Bazel `http_archive` declaration.
func NewHTTPArchive ¶
func NewHTTPArchive(name string, modules []*Module) *HTTPArchive
func NewHTTPArchiveFromRule ¶
func NewHTTPArchiveFromRule(r *rule.Rule, repoRoot string) (*HTTPArchive, error)
NewHTTPArchiveFromRule returns an HTTPArchive from a repository rule. If the repository does not provide any Swift modules, it returns nil.
type LocalPackage ¶
type LocalPackage struct {
Path string `json:"path"`
}
type Module ¶
type Module struct { Name string C99name string SrcType swiftpkg.SourceType Label *label.Label ModulemapLabel *label.Label PkgIdentity string ProductMemberships []string }
Module represents a Swift module mapped to a Bazel target.
func NewModule ¶
func NewModule( name, c99name string, srcType swiftpkg.SourceType, bzlLabel *label.Label, modulemapLabel *label.Label, pkgIdentity string, pms []string, ) *Module
NewModule creates a new module.
func NewModuleFromLabelStruct ¶
func NewModuleFromLabelStruct( name, c99name string, srcType swiftpkg.SourceType, bzlLabel label.Label, pkgIdentity string, pms []string, ) *Module
NewModuleFromLabelStruct is a convenience function because label.New returns a struct, not a pointer.
func NewModuleFromTarget ¶
NewModuleFromTarget returns a module from the specified Swift target.
func (*Module) MarshalJSON ¶
MarshalJSON customizes the marshalling of a module to JSON.
func (*Module) UnmarshalJSON ¶
UnmarshalJSON customizes the unmarshalling of a module from JSON.
type ModuleIndex ¶
A ModuleIndex represents an index organized by module name.
func NewModuleIndex ¶
func NewModuleIndex(modules ...*Module) ModuleIndex
NewModuleIndex creates a new module index populated with the provided modules.
func (ModuleIndex) Add ¶
func (mi ModuleIndex) Add(modules ...*Module)
Add indexes the provided modules.
func (ModuleIndex) Modules ¶
func (mi ModuleIndex) Modules() Modules
Modules returns a unique list of modules.
func (ModuleIndex) Resolve ¶
func (mi ModuleIndex) Resolve(repoName, moduleName string) *Module
Resolve finds the module given the Bazel repo name and the Swift module name.
type ModuleResolutionResult ¶
type ModuleToProductsIndex ¶
type ModuleToProductsIndex map[string][]ProductIndexKey
A ModuleToProductsIndex maps a module name to the products to which it belongs (i.e., has membership).
func (ModuleToProductsIndex) Add ¶
func (mpi ModuleToProductsIndex) Add(moduleName string, newKeys ...ProductIndexKey)
func (ModuleToProductsIndex) IndexModule ¶
func (mpi ModuleToProductsIndex) IndexModule(m *Module)
type ModuleType ¶
type ModuleType int
A ModuleType is an enum for the type of Swift module.
const ( UnknownModuleType ModuleType = iota LibraryModuleType BinaryModuleType TestModuleType )
type Package ¶
type Package struct { Name string `json:"name"` Identity string `json:"identity"` Local *LocalPackage `json:"local,omitempty"` Remote *RemotePackage `json:"remote,omitempty"` CLanguageStandard string `json:"cLanguageStandard,omitempty"` CxxLanguageStandard string `json:"cxxLanguageStandard,omitempty"` }
type PackageIndex ¶
func NewPackageIndex ¶
func NewPackageIndex(packages ...*Package) PackageIndex
func (PackageIndex) Add ¶
func (pi PackageIndex) Add(packages ...*Package)
func (PackageIndex) Packages ¶
func (pi PackageIndex) Packages() []*Package
type Patch ¶ added in v0.5.0
type Patch struct { Files []string `json:"files" yaml:"files"` Args []string `json:"args,omitempty" yaml:"args,omitempty"` Cmds []string `json:"cmds,omitempty" yaml:"cmds,omitempty"` WinCmds []string `json:"win_cmds,omitempty" yaml:"win_cmds,omitempty"` Tool string `json:"tool,omitempty" yaml:"tool,omitempty"` }
Patch represents the parameters needed to patch a Swift package.
type Product ¶
type Product struct { Identity string Name string Type ProductType TargetLabels []*label.Label }
A Product represents a Swift package product.
func NewProduct ¶
func NewProduct(identity, name string, ptype ProductType, targetLabels []*label.Label) *Product
func NewProductFromPkgInfoProduct ¶
NewProductFromPkgInfoProduct returns a Swift product based upon a Swift manifest product.
func (*Product) IndexKey ¶
func (p *Product) IndexKey() ProductIndexKey
IndexKey returns a unique key for the product.
func (*Product) MarshalJSON ¶
func (*Product) UnmarshalJSON ¶
type ProductIndex ¶
type ProductIndex map[ProductIndexKey]*Product
A ProductIndex represents products organized by a unique key.
func NewProductIndex ¶
func NewProductIndex(products ...*Product) ProductIndex
NewProductIndex creates a product index populated with the provided products.
func (ProductIndex) Add ¶
func (pi ProductIndex) Add(products ...*Product)
Add indexes the provided products.
func (ProductIndex) Products ¶
func (pi ProductIndex) Products() []*Product
Products returns the products in the index.
func (ProductIndex) Resolve ¶
func (pi ProductIndex) Resolve(identity, name string) *Product
Resolve finds the product based upon identity and product name.
type ProductIndexKey ¶
type ProductIndexKey string
A ProductIndexKey represents the key used to index products.
func NewProductIndexKey ¶
func NewProductIndexKey(identity, name string) ProductIndexKey
NewProductIndexKey creates a product index key from a package identity and product name.
func (ProductIndexKey) Identity ¶
func (pik ProductIndexKey) Identity() string
type ProductIndexKeys ¶
type ProductIndexKeys []ProductIndexKey
func (ProductIndexKeys) Len ¶
func (piks ProductIndexKeys) Len() int
func (ProductIndexKeys) Less ¶
func (piks ProductIndexKeys) Less(i, j int) bool
func (ProductIndexKeys) Swap ¶
func (piks ProductIndexKeys) Swap(i, j int)
type ProductMembershipsIndex ¶
type ProductMembershipsIndex map[ProductIndexKey]mapset.Set[string]
func (ProductMembershipsIndex) Add ¶
func (pmi ProductMembershipsIndex) Add(prdIndexKey ProductIndexKey, moduleNames ...string)
func (ProductMembershipsIndex) IndexModule ¶
func (pmi ProductMembershipsIndex) IndexModule(m *Module)
type ProductType ¶
type ProductType int
A ProductType is an enum for a Swift product type.
const ( UnknownProductType ProductType = iota LibraryProductType ExecutableProductType PluginProductType )
Source Files ¶
- bazel_label.go
- bazel_repo.go
- bazel_repo_name.go
- builtin_modules.go
- bzlmod.go
- code_dir.go
- constants.go
- dependency_index.go
- doc.go
- files.go
- find_rules.go
- http_archive.go
- imports.go
- is_builtin_module.go
- label_str.go
- module.go
- module_dir.go
- module_index.go
- module_name.go
- module_to_products_index.go
- module_type.go
- package.go
- package_index.go
- patch.go
- product.go
- product_index.go
- product_memberships_index.go
- repo_rule_from_bazel_repo.go
- rule_attr_string_dict.go
- rule_kinds.go
- rules_common.go
- rules_from_protos.go
- rules_from_srcs.go
- test_rules_common.go