Documentation ¶
Overview ¶
Package bufwork defines the primitives used to enable workspaces.
If a buf.work.yaml file exists in a parent directory (up to the root of the filesystem), the directory containing the file is used as the root of one or more modules. With this, modules can import from one another, and a variety of commands work on multiple modules rather than one. For example, if `buf lint` is run for an input that contains a buf.work.yaml, each of the modules contained within the workspace will be linted. Other commands, such as `buf build`, will merge workspace modules into one (i.e. a "supermodule") so that all of the files contained are consolidated into a single image.
In the following example, the workspace consists of two modules: the module defined in the petapis directory can import definitions from the paymentapis module without vendoring the definitions under a common root. To be clear, `import "acme/payment/v2/payment.proto";` from the acme/pet/v1/pet.proto file will suffice as long as the buf.work.yaml file exists.
// buf.work.yaml version: v1 directories: - paymentapis - petapis $ tree . ├── buf.work.yaml ├── paymentapis │ ├── acme │ │ └── payment │ │ └── v2 │ │ └── payment.proto │ └── buf.yaml └── petapis ├── acme │ └── pet │ └── v1 │ └── pet.proto └── buf.yaml
Note that inputs MUST NOT overlap with any of the directories defined in the buf.work.yaml file. For example, it's not possible to build input "paymentapis/acme" since the image would otherwise include the content defined in paymentapis/acme/payment/v2/payment.proto as acme/payment/v2/payment.proto and payment/v2/payment.proto.
Index ¶
- Constants
- Variables
- func BuildOptionsForWorkspaceDirectory(ctx context.Context, workspaceConfig *Config, moduleConfig *bufconfig.Config, ...) ([]bufmodulebuild.BuildOption, error)
- func ExistingConfigFilePath(ctx context.Context, readBucket storage.ReadBucket) (string, error)
- type Config
- type ExternalConfigV1
- type Provider
- type WorkspaceBuilder
Constants ¶
const ( // ExternalConfigV1FilePath is the default configuration file path for v1. ExternalConfigV1FilePath = "buf.work.yaml" // V1Version is the version string used to indicate the v1 version of the buf.work.yaml file. V1Version = "v1" // BackupExternalConfigV1FilePath is another acceptable configuration file path for v1. // // Originally we thought we were going to use buf.work, and had this around for // a while, but then moved to buf.work.yaml. We still need to support buf.work as // we released with it, however. BackupExternalConfigV1FilePath = "buf.work" )
Variables ¶
var ( // AllConfigFilePaths are all acceptable config file paths without overrides. // // These are in the order we should check. AllConfigFilePaths = []string{ ExternalConfigV1FilePath, BackupExternalConfigV1FilePath, } )
Functions ¶
func BuildOptionsForWorkspaceDirectory ¶
func BuildOptionsForWorkspaceDirectory( ctx context.Context, workspaceConfig *Config, moduleConfig *bufconfig.Config, relativeRootPath string, subDirPath string, externalDirOrFilePaths []string, externalDirOrFilePathsAllowNotExist bool, ) ([]bufmodulebuild.BuildOption, error)
BuildOptionsForWorkspaceDirectory returns the bufmodulebuild.BuildOptions required for the given subDirPath based on the workspace configuration.
func ExistingConfigFilePath ¶
ExistingConfigFilePath checks if a configuration file exists, and if so, returns the path within the ReadBucket of this configuration file.
Returns empty string and no error if no configuration file exists.
Types ¶
type Config ¶
type Config struct { // Directories are normalized and validated. Directories []string }
Config is the workspace config.
type ExternalConfigV1 ¶
type ExternalConfigV1 struct { Version string `json:"version,omitempty" yaml:"version,omitempty"` Directories []string `json:"directories,omitempty" yaml:"directories,omitempty"` }
ExternalConfigV1 represents the on-disk representation of the workspace configuration at version v1.
type Provider ¶
type Provider interface { // GetConfig gets the Config for the YAML data at ConfigFilePath. // // If the data is of length 0, returns the default config. GetConfig(ctx context.Context, readBucket storage.ReadBucket, relativeRootPath string) (*Config, error) // GetConfig gets the Config for the given JSON or YAML data. // // If the data is of length 0, returns the default config. GetConfigForData(ctx context.Context, data []byte) (*Config, error) }
Provider provides workspace configurations.
func NewProvider ¶
NewProvider returns a new Provider.
type WorkspaceBuilder ¶ added in v1.0.0
type WorkspaceBuilder interface { // BuildWorkspace builds a bufmodule.Workspace for the given targetSubDirPath. BuildWorkspace( ctx context.Context, workspaceConfig *Config, readBucket storage.ReadBucket, relativeRootPath string, targetSubDirPath string, configOverride string, externalDirOrFilePaths []string, externalDirOrFilePathsAllowNotExist bool, ) (bufmodule.Workspace, error) // GetModuleConfig returns the bufmodule.Module and *bufconfig.Config, associated with the given // targetSubDirPath, if it exists. GetModuleConfig(targetSubDirPath string) (bufmodule.Module, *bufconfig.Config, bool) }
WorkspaceBuilder builds workspaces. A single WorkspaceBuilder should NOT be persisted acorss calls because the WorkspaceBuilder caches the modules used in each workspace.
func NewWorkspaceBuilder ¶ added in v1.0.0
func NewWorkspaceBuilder( configProvider bufconfig.Provider, moduleBucketBuilder bufmodulebuild.ModuleBucketBuilder, ) WorkspaceBuilder
NewWorkspaceBuilder returns a new WorkspaceBuilder.