MCPcopy Create free account
hub / github.com/bufbuild/buf / newModule

Function newModule

private/bufpkg/bufmodule/module.go:252–335  ·  view source on GitHub ↗

must set ModuleReadBucket after constructor via setModuleReadBucket

(
	ctx context.Context,
	// This function must already be filtered to include only module files and must be sync.OnceValues wrapped!
	syncOnceValuesGetBucketWithStorageMatcherApplied func() (storage.ReadBucket, error),
	bucketID string,
	description string,
	moduleFullName bufparse.FullName,
	commitID uuid.UUID,
	isTarget bool,
	isLocal bool,
	getV1BufYAMLObjectData func() (ObjectData, error),
	getV1BufLockObjectData func() (ObjectData, error),
	getDepModuleKeysB5 func() ([]ModuleKey, error),
	targetPaths []string,
	targetExcludePaths []string,
	protoFileTargetPath string,
	includePackageFiles bool,
)

Source from the content-addressed store, hash-verified

250
251// must set ModuleReadBucket after constructor via setModuleReadBucket
252func newModule(
253 ctx context.Context,
254 // This function must already be filtered to include only module files and must be sync.OnceValues wrapped!
255 syncOnceValuesGetBucketWithStorageMatcherApplied func() (storage.ReadBucket, error),
256 bucketID string,
257 description string,
258 moduleFullName bufparse.FullName,
259 commitID uuid.UUID,
260 isTarget bool,
261 isLocal bool,
262 getV1BufYAMLObjectData func() (ObjectData, error),
263 getV1BufLockObjectData func() (ObjectData, error),
264 getDepModuleKeysB5 func() ([]ModuleKey, error),
265 targetPaths []string,
266 targetExcludePaths []string,
267 protoFileTargetPath string,
268 includePackageFiles bool,
269) (*module, error) {
270 // TODO FUTURE: get these validations into a common place
271 if protoFileTargetPath != "" && (len(targetPaths) > 0 || len(targetExcludePaths) > 0) {
272 return nil, syserror.Newf("cannot set both protoFileTargetPath %q and either targetPaths %v or targetExcludePaths %v", protoFileTargetPath, targetPaths, targetExcludePaths)
273 }
274 if protoFileTargetPath != "" && normalpath.Ext(protoFileTargetPath) != ".proto" {
275 return nil, syserror.Newf("protoFileTargetPath %q is not a .proto file", protoFileTargetPath)
276 }
277 if bucketID == "" && moduleFullName == nil {
278 return nil, syserror.New("bucketID was empty and moduleFullName was nil when constructing a Module, one of these must be set")
279 }
280 if !isLocal && moduleFullName == nil {
281 return nil, syserror.New("moduleFullName not present when constructing a remote Module")
282 }
283 if moduleFullName == nil && commitID != uuid.Nil {
284 return nil, syserror.New("moduleFullName not present and commitID present when constructing a remote Module")
285 }
286
287 normalizeAndValidateIfNotEmpty := func(path string) (string, error) {
288 if path == "" {
289 return path, nil
290 }
291 return normalpath.NormalizeAndValidate(path)
292 }
293 targetPaths, err := xslices.MapError(targetPaths, normalizeAndValidateIfNotEmpty)
294 if err != nil {
295 return nil, syserror.Wrap(err)
296 }
297 targetExcludePaths, err = xslices.MapError(targetExcludePaths, normalizeAndValidateIfNotEmpty)
298 if err != nil {
299 return nil, syserror.Wrap(err)
300 }
301 protoFileTargetPath, err = normalizeAndValidateIfNotEmpty(protoFileTargetPath)
302 if err != nil {
303 return nil, syserror.Wrap(err)
304 }
305
306 module := &module{
307 ctx: ctx,
308 getBucket: syncOnceValuesGetBucketWithStorageMatcherApplied,
309 bucketID: bucketID,

Callers 2

AddLocalModuleMethod · 0.85
ToModuleMethod · 0.85

Calls 8

NewfFunction · 0.92
ExtFunction · 0.92
NewFunction · 0.92
NormalizeAndValidateFunction · 0.92
WrapFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…