From bce5b5bde007394497ccb31259565fb24956f341 Mon Sep 17 00:00:00 2001 From: Edward McFarlane Date: Wed, 30 Oct 2024 12:57:47 -0400 Subject: [PATCH] Add bufparse package --- private/buf/bufcli/errors.go | 6 +- private/buf/bufctl/controller.go | 31 ++-- private/buf/buffetch/internal/internal.go | 5 +- private/buf/buffetch/internal/module_ref.go | 10 +- private/buf/buffetch/internal/reader.go | 3 +- private/buf/buffetch/ref_parser.go | 4 +- private/buf/buffetch/ref_parser_test.go | 6 +- private/buf/buflsp/file.go | 2 +- private/buf/buflsp/symbol.go | 2 +- private/buf/bufmigrate/migrate_builder.go | 15 +- private/buf/bufmigrate/migrator.go | 37 ++--- private/buf/bufprint/bufprint.go | 12 +- private/buf/bufworkspace/malformed_dep.go | 29 ++-- private/buf/bufworkspace/workspace.go | 13 +- .../buf/bufworkspace/workspace_dep_manager.go | 9 +- .../buf/bufworkspace/workspace_provider.go | 17 +-- .../buf/bufworkspace/workspace_targeting.go | 13 +- private/buf/bufworkspace/workspace_test.go | 4 +- .../command/config/configinit/configinit.go | 6 +- .../config/configlsmodules/configlsmodules.go | 4 +- .../cmd/buf/command/dep/depgraph/depgraph.go | 14 +- .../cmd/buf/command/dep/internal/internal.go | 17 +-- .../buf/cmd/buf/command/lsfiles/lsfiles.go | 2 +- .../cmd/buf/command/mod/modopen/modopen.go | 2 +- .../commit/commitaddlabel/commitaddlabel.go | 14 +- .../registry/commit/commitinfo/commitinfo.go | 8 +- .../registry/commit/commitlist/commitlist.go | 24 ++-- .../commit/commitresolve/commitresolve.go | 12 +- .../label/labelarchive/labelarchive.go | 6 +- .../registry/label/labelinfo/labelinfo.go | 6 +- .../registry/label/labellist/labellist.go | 6 +- .../label/labelunarchive/labelunarchive.go | 6 +- .../module/modulecreate/modulecreate.go | 4 +- .../module/moduledelete/moduledelete.go | 4 +- .../module/moduledeprecate/moduledeprecate.go | 4 +- .../registry/module/moduleinfo/moduleinfo.go | 4 +- .../moduleundeprecate/moduleundeprecate.go | 4 +- .../module/moduleupdate/moduleupdate.go | 4 +- .../command/registry/sdk/version/version.go | 14 +- private/buf/cmd/buf/imports_test.go | 9 +- private/buf/cmd/internal/internal.go | 2 +- .../internal/bufcheckserverutil/input_file.go | 4 +- private/bufpkg/bufconfig/buf_lock_file.go | 31 ++-- private/bufpkg/bufconfig/buf_yaml_file.go | 48 +++---- .../bufconfig/generate_managed_config.go | 60 ++++---- private/bufpkg/bufconfig/module_config.go | 16 +-- private/bufpkg/bufimage/bufimage.go | 21 +-- .../bufimagemodify/bufimagemodify_test.go | 37 ++--- .../bufimage/bufimagemodify/field_option.go | 4 +- .../bufimage/bufimagemodify/override.go | 10 +- .../bufimagetesting/bufimagetesting.go | 6 +- .../bufimage/bufimageutil/bufimageutil.go | 2 +- private/bufpkg/bufimage/build_image.go | 2 +- private/bufpkg/bufimage/image.go | 2 +- private/bufpkg/bufimage/image_file.go | 10 +- .../bufpkg/bufimage/module_image_file_info.go | 5 +- .../bufimage/parser_accessor_handler.go | 43 +++--- private/bufpkg/bufimage/util.go | 6 +- private/bufpkg/bufimage/util_test.go | 6 +- .../well_known_type_image_file_info.go | 4 +- private/bufpkg/bufmodule/added_module.go | 36 ++--- private/bufpkg/bufmodule/bufmodule_test.go | 17 +-- .../bufmodule/bufmoduleapi/commit_provider.go | 2 +- .../bufpkg/bufmodule/bufmoduleapi/convert.go | 17 +-- .../bufmoduleapi/module_data_provider.go | 9 +- .../module_key_for_universal_proto_commit.go | 9 +- .../bufmoduleapi/module_key_provider.go | 13 +- .../bufpkg/bufmodule/bufmoduleapi/registry.go | 17 +-- .../bufmoduleapi/universal_proto_commit.go | 3 +- .../bufpkg/bufmodule/bufmoduleapi/uploader.go | 34 ++--- .../bufmodulecache/bufmodulecache_test.go | 21 +-- .../bufmodule/bufmodulestore/commit_store.go | 7 +- .../bufmodulestore/module_data_store.go | 17 +-- .../bufmodulestore/module_data_store_test.go | 13 +- .../bufpkg/bufmodule/bufmodulestore/util.go | 2 +- .../bufmoduletesting/bufmoduletesting.go | 25 ++-- private/bufpkg/bufmodule/commit.go | 4 +- private/bufpkg/bufmodule/errors.go | 7 +- private/bufpkg/bufmodule/file_info.go | 2 +- private/bufpkg/bufmodule/graph_provider.go | 2 +- private/bufpkg/bufmodule/module.go | 31 ++-- private/bufpkg/bufmodule/module_data.go | 2 +- .../bufpkg/bufmodule/module_data_provider.go | 2 +- private/bufpkg/bufmodule/module_key.go | 19 +-- .../bufpkg/bufmodule/module_key_provider.go | 6 +- private/bufpkg/bufmodule/module_set.go | 13 +- .../bufpkg/bufmodule/module_set_builder.go | 21 +-- .../bufpkg/bufmodule/registry_commit_id.go | 2 +- private/bufpkg/bufmodule/remote_dep.go | 24 ++-- private/bufpkg/bufparse/bufparse.go | 15 ++ private/bufpkg/bufparse/errors.go | 76 ++++++++++ .../full_name.go} | 96 ++++++------- .../bufpkg/{bufmodule => bufparse}/parse.go | 28 ++-- .../module_ref.go => bufparse/ref.go} | 46 +++--- private/bufpkg/bufparse/usage.gen.go | 19 +++ private/bufpkg/bufplugin/errors.go | 7 +- private/bufpkg/bufplugin/parse.go | 83 ----------- private/bufpkg/bufplugin/plugin_data.go | 2 +- .../bufpkg/bufplugin/plugin_data_provider.go | 2 +- private/bufpkg/bufplugin/plugin_full_name.go | 132 ------------------ private/bufpkg/bufplugin/plugin_key.go | 15 +- .../bufpkg/bufplugin/plugin_key_provider.go | 12 +- private/bufpkg/bufplugin/plugin_ref.go | 101 -------------- .../bufpkg/bufprotosource/bufprotosource.go | 10 +- 104 files changed, 783 insertions(+), 949 deletions(-) create mode 100644 private/bufpkg/bufparse/bufparse.go create mode 100644 private/bufpkg/bufparse/errors.go rename private/bufpkg/{bufmodule/module_full_name.go => bufparse/full_name.go} (50%) rename private/bufpkg/{bufmodule => bufparse}/parse.go (65%) rename private/bufpkg/{bufmodule/module_ref.go => bufparse/ref.go} (59%) create mode 100644 private/bufpkg/bufparse/usage.gen.go delete mode 100644 private/bufpkg/bufplugin/parse.go delete mode 100644 private/bufpkg/bufplugin/plugin_full_name.go delete mode 100644 private/bufpkg/bufplugin/plugin_ref.go diff --git a/private/buf/bufcli/errors.go b/private/buf/bufcli/errors.go index 7d57f4863a..689925d570 100644 --- a/private/buf/bufcli/errors.go +++ b/private/buf/bufcli/errors.go @@ -19,7 +19,7 @@ import ( "fmt" "connectrpc.com/connect" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" ) var ( @@ -73,12 +73,12 @@ func NewModuleNotFoundError(name string) error { } // NewModuleRefNotFoundError informs the user that a ModuleRef does not exist. -func NewModuleRefNotFoundError(moduleRef bufmodule.ModuleRef) error { +func NewModuleRefNotFoundError(moduleRef bufparse.Ref) error { return fmt.Errorf("%q does not exist", moduleRef) } // NewLabelNotFoundError informs the user that a ModuleRef does not exist as a label. -func NewLabelNotFoundError(moduleRef bufmodule.ModuleRef) error { +func NewLabelNotFoundError(moduleRef bufparse.Ref) error { return fmt.Errorf("label %q does not exist", moduleRef) } diff --git a/private/buf/bufctl/controller.go b/private/buf/bufctl/controller.go index 0e1322348a..e02ca8691c 100644 --- a/private/buf/bufctl/controller.go +++ b/private/buf/bufctl/controller.go @@ -33,6 +33,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufimage" "github.com/bufbuild/buf/private/bufpkg/bufimage/bufimageutil" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufreflect" "github.com/bufbuild/buf/private/gen/data/datawkt" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" @@ -1090,15 +1091,15 @@ func (c *controller) warnUnconfiguredTransitiveImports( if slicesext.Count(workspace.Modules(), bufmodule.Module.IsLocal) == 0 { return nil } - // Construct a struct map of all the ModuleFullName strings of the configured buf.yaml + // Construct a struct map of all the FullName strings of the configured buf.yaml // Module dependencies, and the local Modules. These are considered OK to depend on // for non-imports in the Image. - configuredModuleFullNameStrings, err := slicesext.MapError( + configuredFullNameStrings, err := slicesext.MapError( workspace.ConfiguredDepModuleRefs(), - func(moduleRef bufmodule.ModuleRef) (string, error) { - moduleFullName := moduleRef.ModuleFullName() + func(moduleRef bufparse.Ref) (string, error) { + moduleFullName := moduleRef.FullName() if moduleFullName == nil { - return "", syserror.New("ModuleFullName nil on ModuleRef") + return "", syserror.New("FullName nil on ModuleRef") } return moduleFullName.String(), nil }, @@ -1106,23 +1107,23 @@ func (c *controller) warnUnconfiguredTransitiveImports( if err != nil { return err } - configuredModuleFullNameStringMap := slicesext.ToStructMap(configuredModuleFullNameStrings) + configuredFullNameStringMap := slicesext.ToStructMap(configuredFullNameStrings) for _, localModule := range bufmodule.ModuleSetLocalModules(workspace) { - if moduleFullName := localModule.ModuleFullName(); moduleFullName != nil { - configuredModuleFullNameStringMap[moduleFullName.String()] = struct{}{} + if moduleFullName := localModule.FullName(); moduleFullName != nil { + configuredFullNameStringMap[moduleFullName.String()] = struct{}{} } } - // Construct a map from Image file path -> ModuleFullName string. + // Construct a map from Image file path -> FullName string. // - // If a given file in the Image did not have a ModuleFullName, it came from a local unnamed Module + // If a given file in the Image did not have a FullName, it came from a local unnamed Module // in the Workspace, and we're safe to ignore it with respect to calculating the undeclared // transitive imports. - pathToModuleFullNameString := make(map[string]string) + pathToFullNameString := make(map[string]string) for _, imageFile := range image.Files() { // If nil, this came from a local unnamed Module in the Workspace, and we're safe to ignore. - if moduleFullName := imageFile.ModuleFullName(); moduleFullName != nil { - pathToModuleFullNameString[imageFile.Path()] = moduleFullName.String() + if moduleFullName := imageFile.FullName(); moduleFullName != nil { + pathToFullNameString[imageFile.Path()] = moduleFullName.String() } } @@ -1132,12 +1133,12 @@ func (c *controller) warnUnconfiguredTransitiveImports( continue } for _, importPath := range imageFile.FileDescriptorProto().GetDependency() { - moduleFullNameString, ok := pathToModuleFullNameString[importPath] + moduleFullNameString, ok := pathToFullNameString[importPath] if !ok { // The import was from a local unnamed Module in the Workspace. continue } - if _, ok := configuredModuleFullNameStringMap[moduleFullNameString]; !ok { + if _, ok := configuredFullNameStringMap[moduleFullNameString]; !ok { c.logger.Warn(fmt.Sprintf( `File %q imports %q, which is not in your workspace or in the dependencies declared in your buf.yaml, but is found in transitive dependency %q. Declare %q in the deps key in your buf.yaml.`, diff --git a/private/buf/buffetch/internal/internal.go b/private/buf/buffetch/internal/internal.go index 3bd250ea9b..64e6bd0423 100644 --- a/private/buf/buffetch/internal/internal.go +++ b/private/buf/buffetch/internal/internal.go @@ -25,6 +25,7 @@ import ( "github.com/bufbuild/buf/private/buf/buftarget" "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app" "github.com/bufbuild/buf/private/pkg/git" "github.com/bufbuild/buf/private/pkg/httpauth" @@ -223,7 +224,7 @@ func NewGitRef( // ModuleRef is a module reference. type ModuleRef interface { Ref - ModuleRef() bufmodule.ModuleRef + ModuleRef() bufparse.Ref moduleRef() } @@ -375,7 +376,7 @@ type ParsedModuleRef interface { // This should only be used for testing. func NewDirectParsedModuleRef( format string, - moduleRef bufmodule.ModuleRef, + moduleRef bufparse.Ref, ) ParsedModuleRef { return newDirectModuleRef( format, diff --git a/private/buf/buffetch/internal/module_ref.go b/private/buf/buffetch/internal/module_ref.go index 9eb21e074d..eba42fb22d 100644 --- a/private/buf/buffetch/internal/module_ref.go +++ b/private/buf/buffetch/internal/module_ref.go @@ -17,7 +17,7 @@ package internal import ( "strings" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app" ) @@ -27,7 +27,7 @@ var ( type moduleRef struct { format string - iModuleRef bufmodule.ModuleRef + iModuleRef bufparse.Ref } func newModuleRef( @@ -46,7 +46,7 @@ func newModuleRef( if strings.Contains(path, "://") { return nil, NewInvalidPathError(format, path) } - moduleRef, err := bufmodule.ParseModuleRef(path) + moduleRef, err := bufparse.ParseRef(path) if err != nil { // TODO: this is dumb return nil, NewInvalidPathError(format, path) @@ -54,7 +54,7 @@ func newModuleRef( return newDirectModuleRef(format, moduleRef), nil } -func newDirectModuleRef(format string, iModuleRef bufmodule.ModuleRef) *moduleRef { +func newDirectModuleRef(format string, iModuleRef bufparse.Ref) *moduleRef { return &moduleRef{ format: format, iModuleRef: iModuleRef, @@ -65,7 +65,7 @@ func (r *moduleRef) Format() string { return r.format } -func (r *moduleRef) ModuleRef() bufmodule.ModuleRef { +func (r *moduleRef) ModuleRef() bufparse.Ref { return r.iModuleRef } diff --git a/private/buf/buffetch/internal/reader.go b/private/buf/buffetch/internal/reader.go index df9e4d5183..0a2e8356e6 100644 --- a/private/buf/buffetch/internal/reader.go +++ b/private/buf/buffetch/internal/reader.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/buf/buftarget" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app" "github.com/bufbuild/buf/private/pkg/git" "github.com/bufbuild/buf/private/pkg/httpauth" @@ -398,7 +399,7 @@ func (r *reader) getModuleKey( } moduleKeys, err := r.moduleKeyProvider.GetModuleKeysForModuleRefs( ctx, - []bufmodule.ModuleRef{moduleRef.ModuleRef()}, + []bufparse.Ref{moduleRef.ModuleRef()}, bufmodule.DigestTypeB5, ) if err != nil { diff --git a/private/buf/buffetch/ref_parser.go b/private/buf/buffetch/ref_parser.go index d43f700aa0..9969d99837 100644 --- a/private/buf/buffetch/ref_parser.go +++ b/private/buf/buffetch/ref_parser.go @@ -25,7 +25,7 @@ import ( "github.com/bufbuild/buf/private/buf/buffetch/internal" "github.com/bufbuild/buf/private/bufpkg/bufconfig" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app" "github.com/bufbuild/buf/private/pkg/syserror" ) @@ -837,7 +837,7 @@ func assumeModuleOrDir(path string) (string, error) { if path == "" { return "", errors.New("assumeModuleOrDir: no path given") } - if _, err := bufmodule.ParseModuleRef(path); err == nil { + if _, err := bufparse.ParseRef(path); err == nil { // this is possible to be a module, check if it is a directory though // OK to use os.Stat instead of os.Lstat here fileInfo, err := os.Stat(path) diff --git a/private/buf/buffetch/ref_parser_test.go b/private/buf/buffetch/ref_parser_test.go index 4072adb03f..0e552f2061 100644 --- a/private/buf/buffetch/ref_parser_test.go +++ b/private/buf/buffetch/ref_parser_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/bufbuild/buf/private/buf/buffetch/internal" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app" "github.com/bufbuild/buf/private/pkg/git" "github.com/bufbuild/buf/private/pkg/normalpath" @@ -1442,8 +1442,8 @@ func testNewModuleRef( owner string, name string, ref string, -) bufmodule.ModuleRef { - moduleRef, err := bufmodule.NewModuleRef(registry, owner, name, ref) +) bufparse.Ref { + moduleRef, err := bufparse.NewRef(registry, owner, name, ref) require.NoError(t, err) return moduleRef } diff --git a/private/buf/buflsp/file.go b/private/buf/buflsp/file.go index b17e61a105..bffaee6d17 100644 --- a/private/buf/buflsp/file.go +++ b/private/buf/buflsp/file.go @@ -575,7 +575,7 @@ func (f *file) RunLints(ctx context.Context) bool { return false } - f.lsp.logger.Debug(fmt.Sprintf("running lint for %q in %v", f.uri, module.ModuleFullName())) + f.lsp.logger.Debug(fmt.Sprintf("running lint for %q in %v", f.uri, module.FullName())) lintConfig := workspace.GetLintConfigForOpaqueID(module.OpaqueID()) err := f.lsp.checkClient.Lint( diff --git a/private/buf/buflsp/symbol.go b/private/buf/buflsp/symbol.go index 1d73107849..451f2e43fc 100644 --- a/private/buf/buflsp/symbol.go +++ b/private/buf/buflsp/symbol.go @@ -471,7 +471,7 @@ func (s *symbol) FormatDocs(ctx context.Context) string { if def.file.IsWKT() { bsrHost = "buf.build/protocolbuffers/wellknowntypes" } else if fileInfo, ok := def.file.objectInfo.(bufmodule.FileInfo); ok { - bsrHost = fileInfo.Module().ModuleFullName().String() + bsrHost = fileInfo.Module().FullName().String() } if hasAnchor { bsrTooltip = pkg + "." + strings.Join(path, ".") diff --git a/private/buf/bufmigrate/migrate_builder.go b/private/buf/bufmigrate/migrate_builder.go index 3166039f72..6969dbd5f2 100644 --- a/private/buf/bufmigrate/migrate_builder.go +++ b/private/buf/bufmigrate/migrate_builder.go @@ -23,6 +23,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/command" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" @@ -45,7 +46,7 @@ type migrateBuilder struct { addedModuleDirPaths map[string]struct{} moduleConfigs []bufconfig.ModuleConfig - configuredDepModuleRefs []bufmodule.ModuleRef + configuredDepModuleRefs []bufparse.Ref hasSeenBufLockFile bool depModuleKeys []bufmodule.ModuleKey pathToMigratedBufGenYAMLFile map[string]bufconfig.BufGenYAMLFile @@ -244,7 +245,7 @@ func (m *migrateBuilder) addModule(ctx context.Context, moduleDirPath string) (r return syserror.Newf("expect exactly 1 module config from buf yaml, got %d", len(bufYAMLFile.ModuleConfigs())) } moduleConfig := bufYAMLFile.ModuleConfigs()[0] - moduleFullName := moduleConfig.ModuleFullName() + moduleFullName := moduleConfig.FullName() // If a buf.yaml v1beta1 has a non-empty name and multiple roots, the // resulting buf.yaml v2 should have these roots as module directories, // but they should not share the same module name. Instead we just give @@ -314,7 +315,7 @@ func (m *migrateBuilder) addModule(ctx context.Context, moduleDirPath string) (r } moduleConfig, err = bufconfig.NewModuleConfig( moduleRootRelativeToDestination, - moduleConfig.ModuleFullName(), + moduleConfig.FullName(), // We do not need to handle paths in rootToIncludes, rootToExcludes, lint or breaking config specially, // because the paths are transformed correctly by readBufYAMLFile and writeBufYAMLFile. moduleConfig.RootToIncludes(), @@ -387,12 +388,12 @@ func (m *migrateBuilder) addModule(ctx context.Context, moduleDirPath string) (r func (m *migrateBuilder) appendModuleConfig(moduleConfig bufconfig.ModuleConfig, parentPath string) error { m.moduleConfigs = append(m.moduleConfigs, moduleConfig) - if moduleConfig.ModuleFullName() == nil { + if moduleConfig.FullName() == nil { return nil } - if file, ok := m.moduleFullNameStringToParentPath[moduleConfig.ModuleFullName().String()]; ok { - return fmt.Errorf("module %s is found in both %s and %s", moduleConfig.ModuleFullName(), file, parentPath) + if file, ok := m.moduleFullNameStringToParentPath[moduleConfig.FullName().String()]; ok { + return fmt.Errorf("module %s is found in both %s and %s", moduleConfig.FullName(), file, parentPath) } - m.moduleFullNameStringToParentPath[moduleConfig.ModuleFullName().String()] = parentPath + m.moduleFullNameStringToParentPath[moduleConfig.FullName().String()] = parentPath return nil } diff --git a/private/buf/bufmigrate/migrator.go b/private/buf/bufmigrate/migrator.go index 37d38bf5e9..6d7673fd0a 100644 --- a/private/buf/bufmigrate/migrator.go +++ b/private/buf/bufmigrate/migrator.go @@ -28,6 +28,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufcheck" "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/command" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" @@ -325,9 +326,9 @@ func (m *migrator) buildBufYAMLAndBufLockFiles( migrateBuilder *migrateBuilder, ) (bufconfig.BufYAMLFile, bufconfig.BufLockFile, error) { // module full name --> the list of declared dependencies that are this module. - depModuleToDeclaredRefs := make(map[string][]bufmodule.ModuleRef) + depModuleToDeclaredRefs := make(map[string][]bufparse.Ref) for _, declaredRef := range migrateBuilder.configuredDepModuleRefs { - moduleFullName := declaredRef.ModuleFullName().String() + moduleFullName := declaredRef.FullName().String() // If a declared dependency also shows up in the workspace, it's not a dependency. if _, ok := migrateBuilder.moduleFullNameStringToParentPath[moduleFullName]; ok { continue @@ -337,7 +338,7 @@ func (m *migrator) buildBufYAMLAndBufLockFiles( // module full name --> the list of lock entries that are this module. depModuleToLockEntries := make(map[string][]bufmodule.ModuleKey) for _, lockEntry := range migrateBuilder.depModuleKeys { - moduleFullName := lockEntry.ModuleFullName().String() + moduleFullName := lockEntry.FullName().String() // If a declared dependency also shows up in the workspace, it's not a dependency. // // We are only removing lock entries that are in the workspace. A lock entry @@ -350,7 +351,7 @@ func (m *migrator) buildBufYAMLAndBufLockFiles( // This will be set to false if the duplicate dependencies cannot be resolved locally. areDependenciesResolved := true for depModule, declaredRefs := range depModuleToDeclaredRefs { - refStringToRef := make(map[string]bufmodule.ModuleRef) + refStringToRef := make(map[string]bufparse.Ref) for _, ref := range declaredRefs { // Add ref even if ref.Ref() is empty. Therefore, slicesext.ToValuesMap is not used. refStringToRef[ref.Ref()] = ref @@ -378,7 +379,7 @@ func (m *migrator) buildBufYAMLAndBufLockFiles( } } if areDependenciesResolved { - resolvedDeclaredRefs := make([]bufmodule.ModuleRef, 0, len(depModuleToDeclaredRefs)) + resolvedDeclaredRefs := make([]bufparse.Ref, 0, len(depModuleToDeclaredRefs)) for _, depModuleRefs := range depModuleToDeclaredRefs { // depModuleRefs is guaranteed to have length 1, because areDependenciesResolved is true. resolvedDeclaredRefs = append(resolvedDeclaredRefs, depModuleRefs...) @@ -460,7 +461,7 @@ func (m *migrator) buildBufYAMLAndBufLockFiles( func (m *migrator) getModuleToRefToCommit( ctx context.Context, - moduleRefs []bufmodule.ModuleRef, + moduleRefs []bufparse.Ref, ) (map[string]map[string]bufmodule.Commit, error) { // The module refs that are collected by migrateBuilder is across all modules being // migrated, so there may be duplicates. ModuleKeyProvider errors on duplicate module @@ -468,7 +469,7 @@ func (m *migrator) getModuleToRefToCommit( // so we deduplicate the module refs we are passing here. moduleRefs = slicesext.DeduplicateAny( moduleRefs, - func(moduleRef bufmodule.ModuleRef) string { return moduleRef.String() }, + func(moduleRef bufparse.Ref) string { return moduleRef.String() }, ) moduleKeys, err := m.moduleKeyProvider.GetModuleKeysForModuleRefs(ctx, moduleRefs, bufmodule.DigestTypeB5) if err != nil { @@ -487,7 +488,7 @@ func (m *migrator) getModuleToRefToCommit( // of GetModuleKeysForModuleRefs and GetCommitsForModuleKeys. commit := commits[i] - moduleFullName := moduleRef.ModuleFullName() + moduleFullName := moduleRef.FullName() if moduleToRefToCommit[moduleFullName.String()] == nil { moduleToRefToCommit[moduleFullName.String()] = make(map[string]bufmodule.Commit) } @@ -548,7 +549,7 @@ func (m *migrator) upgradeModuleKeysToB5( b4IndexedModuleKeys, func(indexedModuleKey slicesext.Indexed[bufmodule.ModuleKey]) (bufmodule.CommitKey, error) { return bufmodule.NewCommitKey( - indexedModuleKey.Value.ModuleFullName().Registry(), + indexedModuleKey.Value.FullName().Registry(), indexedModuleKey.Value.CommitID(), bufmodule.DigestTypeB5, ) @@ -566,7 +567,7 @@ func (m *migrator) upgradeModuleKeysToB5( moduleKeyIndex := b4IndexedModuleKeys[i].Index existingModuleKey := moduleKeys[moduleKeyIndex] newModuleKey, err := bufmodule.NewModuleKey( - existingModuleKey.ModuleFullName(), + existingModuleKey.FullName(), existingModuleKey.CommitID(), commit.ModuleKey().Digest, ) @@ -581,10 +582,10 @@ func (m *migrator) upgradeModuleKeysToB5( func resolvedDeclaredAndLockedDependencies( moduleToRefToCommit map[string]map[string]bufmodule.Commit, commitIDToCommit map[uuid.UUID]bufmodule.Commit, - moduleFullNameToDeclaredRefs map[string][]bufmodule.ModuleRef, + moduleFullNameToDeclaredRefs map[string][]bufparse.Ref, moduleFullNameToLockKeys map[string][]bufmodule.ModuleKey, -) ([]bufmodule.ModuleRef, []bufmodule.ModuleKey, error) { - depModuleFullNameToResolvedRef := make(map[string]bufmodule.ModuleRef) +) ([]bufparse.Ref, []bufmodule.ModuleKey, error) { + depFullNameToResolvedRef := make(map[string]bufparse.Ref) for moduleFullName, refs := range moduleFullNameToDeclaredRefs { var errs []error // There are multiple pinned versions of the same dependency, we use the latest one. @@ -603,11 +604,11 @@ func resolvedDeclaredAndLockedDependencies( if len(errs) > 0 { return nil, nil, multierr.Combine(errs...) } - depModuleFullNameToResolvedRef[moduleFullName] = refs[0] + depFullNameToResolvedRef[moduleFullName] = refs[0] } resolvedDepModuleKeys := make([]bufmodule.ModuleKey, 0, len(moduleFullNameToLockKeys)) for moduleFullName, lockKeys := range moduleFullNameToLockKeys { - resolvedRef, ok := depModuleFullNameToResolvedRef[moduleFullName] + resolvedRef, ok := depFullNameToResolvedRef[moduleFullName] if ok && resolvedRef.Ref() != "" { // If we have already picked a pinned dependency ref for this dependency, // we use that as the lock entry as well. @@ -633,13 +634,13 @@ func resolvedDeclaredAndLockedDependencies( } resolvedDepModuleKeys = append(resolvedDepModuleKeys, lockKeys[0]) } - resolvedDeclaredDependencies := slicesext.MapValuesToSlice(depModuleFullNameToResolvedRef) + resolvedDeclaredDependencies := slicesext.MapValuesToSlice(depFullNameToResolvedRef) // Sort the resolved dependencies for deterministic results. sort.Slice(resolvedDeclaredDependencies, func(i, j int) bool { - return resolvedDeclaredDependencies[i].ModuleFullName().String() < resolvedDeclaredDependencies[j].ModuleFullName().String() + return resolvedDeclaredDependencies[i].FullName().String() < resolvedDeclaredDependencies[j].FullName().String() }) sort.Slice(resolvedDepModuleKeys, func(i, j int) bool { - return resolvedDepModuleKeys[i].ModuleFullName().String() < resolvedDepModuleKeys[j].ModuleFullName().String() + return resolvedDepModuleKeys[i].FullName().String() < resolvedDepModuleKeys[j].FullName().String() }) return resolvedDeclaredDependencies, resolvedDepModuleKeys, nil } diff --git a/private/buf/bufprint/bufprint.go b/private/buf/bufprint/bufprint.go index 1647a41f93..1853a07686 100644 --- a/private/buf/bufprint/bufprint.go +++ b/private/buf/bufprint/bufprint.go @@ -26,7 +26,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" ownerv1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/owner/v1" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" registryv1alpha1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/registry/v1alpha1" "github.com/bufbuild/buf/private/pkg/protoencoding" "github.com/bufbuild/buf/private/pkg/protostat" @@ -199,7 +199,7 @@ func PrintEntity(writer io.Writer, format Format, entity Entity) error { } // NewLabelEntity returns a new label entity to print. -func NewLabelEntity(label *modulev1.Label, moduleFullName bufmodule.ModuleFullName) Entity { +func NewLabelEntity(label *modulev1.Label, moduleFullName bufparse.FullName) Entity { var archiveTime *time.Time if label.ArchiveTime != nil { timeValue := label.ArchiveTime.AsTime() @@ -215,7 +215,7 @@ func NewLabelEntity(label *modulev1.Label, moduleFullName bufmodule.ModuleFullNa } // NewCommitEntity returns a new commit entity to print. -func NewCommitEntity(commit *modulev1.Commit, moduleFullName bufmodule.ModuleFullName) Entity { +func NewCommitEntity(commit *modulev1.Commit, moduleFullName bufparse.FullName) Entity { return outputCommit{ Commit: commit.Id, CreateTime: commit.CreateTime.AsTime(), @@ -224,7 +224,7 @@ func NewCommitEntity(commit *modulev1.Commit, moduleFullName bufmodule.ModuleFul } // NewModuleEntity returns a new module entity to print. -func NewModuleEntity(module *modulev1.Module, moduleFullName bufmodule.ModuleFullName) Entity { +func NewModuleEntity(module *modulev1.Module, moduleFullName bufparse.FullName) Entity { return outputModule{ ID: module.Id, Remote: moduleFullName.Registry(), @@ -412,7 +412,7 @@ type outputLabel struct { CreateTime time.Time `json:"create_time,omitempty" bufprint:"Create Time"` ArchiveTime *time.Time `json:"archive_time,omitempty" bufprint:"Archive Time,omitempty"` - moduleFullName bufmodule.ModuleFullName + moduleFullName bufparse.FullName } func (l outputLabel) fullName() string { @@ -423,7 +423,7 @@ type outputCommit struct { Commit string `json:"commit,omitempty" bufprint:"Commit"` CreateTime time.Time `json:"create_time,omitempty" bufprint:"Create Time"` - moduleFullName bufmodule.ModuleFullName + moduleFullName bufparse.FullName } func (c outputCommit) fullName() string { diff --git a/private/buf/bufworkspace/malformed_dep.go b/private/buf/bufworkspace/malformed_dep.go index 520d2d3db4..f343788396 100644 --- a/private/buf/bufworkspace/malformed_dep.go +++ b/private/buf/bufworkspace/malformed_dep.go @@ -18,6 +18,7 @@ import ( "sort" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" ) @@ -43,7 +44,7 @@ type MalformedDep interface { // ModuleRef is the module ref information of the malformed dep. // // Always present. - ModuleRef() bufmodule.ModuleRef + ModuleRef() bufparse.Ref // Type is why this dep was malformed. // // Always present. @@ -54,11 +55,11 @@ type MalformedDep interface { // MalformedDepsForWorkspace gets the MalformedDeps for the workspace. func MalformedDepsForWorkspace(workspace Workspace) ([]MalformedDep, error) { - localModuleFullNameStringMap := slicesext.ToStructMapOmitEmpty( + localFullNameStringMap := slicesext.ToStructMapOmitEmpty( slicesext.Map( bufmodule.ModuleSetLocalModules(workspace), func(module bufmodule.Module) string { - if moduleFullName := module.ModuleFullName(); moduleFullName != nil { + if moduleFullName := module.FullName(); moduleFullName != nil { return moduleFullName.String() } return "" @@ -72,9 +73,9 @@ func MalformedDepsForWorkspace(workspace Workspace) ([]MalformedDep, error) { moduleFullNameStringToRemoteDep, err := slicesext.ToUniqueValuesMapError( remoteDeps, func(remoteDep bufmodule.RemoteDep) (string, error) { - moduleFullName := remoteDep.ModuleFullName() + moduleFullName := remoteDep.FullName() if moduleFullName == nil { - return "", syserror.Newf("ModuleFullName nil on remote Module dependency %q", remoteDep.OpaqueID()) + return "", syserror.Newf("FullName nil on remote Module dependency %q", remoteDep.OpaqueID()) } return moduleFullName.String(), nil }, @@ -84,10 +85,10 @@ func MalformedDepsForWorkspace(workspace Workspace) ([]MalformedDep, error) { } moduleFullNameStringToConfiguredDepModuleRef, err := slicesext.ToUniqueValuesMapError( workspace.ConfiguredDepModuleRefs(), - func(moduleRef bufmodule.ModuleRef) (string, error) { - moduleFullName := moduleRef.ModuleFullName() + func(moduleRef bufparse.Ref) (string, error) { + moduleFullName := moduleRef.FullName() if moduleFullName == nil { - return "", syserror.New("ModuleFullName nil on ModuleRef") + return "", syserror.New("FullName nil on ModuleRef") } return moduleFullName.String(), nil }, @@ -97,7 +98,7 @@ func MalformedDepsForWorkspace(workspace Workspace) ([]MalformedDep, error) { } var malformedDeps []MalformedDep for moduleFullNameString, configuredDepModuleRef := range moduleFullNameStringToConfiguredDepModuleRef { - _, isLocalModule := localModuleFullNameStringMap[moduleFullNameString] + _, isLocalModule := localFullNameStringMap[moduleFullNameString] _, isRemoteDep := moduleFullNameStringToRemoteDep[moduleFullNameString] if !isRemoteDep && !isLocalModule { // The module was in buf.yaml deps, but was not in the remote dep list after @@ -115,8 +116,8 @@ func MalformedDepsForWorkspace(workspace Workspace) ([]MalformedDep, error) { sort.Slice( malformedDeps, func(i int, j int) bool { - return malformedDeps[i].ModuleRef().ModuleFullName().String() < - malformedDeps[j].ModuleRef().ModuleFullName().String() + return malformedDeps[i].ModuleRef().FullName().String() < + malformedDeps[j].ModuleRef().FullName().String() }, ) return malformedDeps, nil @@ -125,12 +126,12 @@ func MalformedDepsForWorkspace(workspace Workspace) ([]MalformedDep, error) { // *** PRIVATE *** type malformedDep struct { - moduleRef bufmodule.ModuleRef + moduleRef bufparse.Ref malformedDepType MalformedDepType } func newMalformedDep( - moduleRef bufmodule.ModuleRef, + moduleRef bufparse.Ref, malformedDepType MalformedDepType, ) *malformedDep { return &malformedDep{ @@ -139,7 +140,7 @@ func newMalformedDep( } } -func (m *malformedDep) ModuleRef() bufmodule.ModuleRef { +func (m *malformedDep) ModuleRef() bufparse.Ref { return m.moduleRef } diff --git a/private/buf/bufworkspace/workspace.go b/private/buf/bufworkspace/workspace.go index afa14b84ba..68ea77ac06 100644 --- a/private/buf/bufworkspace/workspace.go +++ b/private/buf/bufworkspace/workspace.go @@ -17,6 +17,7 @@ package bufworkspace import ( "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/slicesext" ) @@ -76,14 +77,14 @@ type Workspace interface { // // These come from buf.yaml files. // - // The ModuleRefs in this list will be unique by ModuleFullName. If there are two ModuleRefs - // in the buf.yaml with the same ModuleFullName but different Refs, an error will be given + // The ModuleRefs in this list will be unique by FullName. If there are two ModuleRefs + // in the buf.yaml with the same FullName but different Refs, an error will be given // at workspace constructions. For example, with v1 buf.yaml, this is a union of the deps in // the buf.yaml files in the workspace. If different buf.yamls had different refs, an error // will be returned - we have no way to resolve what the user intended. // // Sorted. - ConfiguredDepModuleRefs() []bufmodule.ModuleRef + ConfiguredDepModuleRefs() []bufparse.Ref // IsV2 signifies if this module was created from a v2 buf.yaml. // @@ -104,7 +105,7 @@ type workspace struct { opaqueIDToLintConfig map[string]bufconfig.LintConfig opaqueIDToBreakingConfig map[string]bufconfig.BreakingConfig pluginConfigs []bufconfig.PluginConfig - configuredDepModuleRefs []bufmodule.ModuleRef + configuredDepModuleRefs []bufparse.Ref // If true, the workspace was created from v2 buf.yamls. // If false, the workspace was created from defaults, or v1beta1/v1 buf.yamls. @@ -116,7 +117,7 @@ func newWorkspace( opaqueIDToLintConfig map[string]bufconfig.LintConfig, opaqueIDToBreakingConfig map[string]bufconfig.BreakingConfig, pluginConfigs []bufconfig.PluginConfig, - configuredDepModuleRefs []bufmodule.ModuleRef, + configuredDepModuleRefs []bufparse.Ref, isV2 bool, ) *workspace { return &workspace{ @@ -141,7 +142,7 @@ func (w *workspace) PluginConfigs() []bufconfig.PluginConfig { return slicesext.Copy(w.pluginConfigs) } -func (w *workspace) ConfiguredDepModuleRefs() []bufmodule.ModuleRef { +func (w *workspace) ConfiguredDepModuleRefs() []bufparse.Ref { return slicesext.Copy(w.configuredDepModuleRefs) } diff --git a/private/buf/bufworkspace/workspace_dep_manager.go b/private/buf/bufworkspace/workspace_dep_manager.go index ddf6901c2a..1b2f8f5239 100644 --- a/private/buf/bufworkspace/workspace_dep_manager.go +++ b/private/buf/bufworkspace/workspace_dep_manager.go @@ -21,6 +21,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/syserror" ) @@ -47,14 +48,14 @@ type WorkspaceDepManager interface { // // These come from buf.yaml files. // - // The ModuleRefs in this list will be unique by ModuleFullName. If there are two ModuleRefs - // in the buf.yaml with the same ModuleFullName but different Refs, an error will be given + // The ModuleRefs in this list will be unique by FullName. If there are two ModuleRefs + // in the buf.yaml with the same FullName but different Refs, an error will be given // at workspace constructions. For example, with v1 buf.yaml, this is a union of the deps in // the buf.yaml files in the workspace. If different buf.yamls had different refs, an error // will be returned - we have no way to resolve what the user intended. // // Sorted. - ConfiguredDepModuleRefs(ctx context.Context) ([]bufmodule.ModuleRef, error) + ConfiguredDepModuleRefs(ctx context.Context) ([]bufparse.Ref, error) isWorkspaceDepManager() } @@ -92,7 +93,7 @@ func newWorkspaceDepManager( } } -func (w *workspaceDepManager) ConfiguredDepModuleRefs(ctx context.Context) ([]bufmodule.ModuleRef, error) { +func (w *workspaceDepManager) ConfiguredDepModuleRefs(ctx context.Context) ([]bufparse.Ref, error) { bufYAMLFile, err := bufconfig.GetBufYAMLFileForPrefix(ctx, w.bucket, w.targetSubDirPath) if err != nil { if !errors.Is(err, fs.ErrNotExist) { diff --git a/private/buf/bufworkspace/workspace_provider.go b/private/buf/bufworkspace/workspace_provider.go index ca3f881afe..a9811072cf 100644 --- a/private/buf/bufworkspace/workspace_provider.go +++ b/private/buf/bufworkspace/workspace_provider.go @@ -24,6 +24,7 @@ import ( "github.com/bufbuild/buf/private/buf/buftarget" "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/slogext" @@ -158,13 +159,13 @@ func (w *workspaceProvider) GetWorkspaceForModuleKey( // If we have more than one ModuleConfig, find the ModuleConfig that matches the // name from the ModuleKey. If none is found, just fall back to the default (ie do nothing here). for _, moduleConfig := range moduleConfigs { - moduleFullName := moduleConfig.ModuleFullName() + moduleFullName := moduleConfig.FullName() if moduleFullName == nil { continue } - if bufmodule.ModuleFullNameEqual(moduleFullName, moduleKey.ModuleFullName()) { + if bufparse.FullNameEqual(moduleFullName, moduleKey.FullName()) { targetModuleConfig = moduleConfig - // We know that the ModuleConfigs are unique by ModuleFullName. + // We know that the ModuleConfigs are unique by FullName. break } } @@ -193,7 +194,7 @@ func (w *workspaceProvider) GetWorkspaceForModuleKey( opaqueIDToLintConfig := make(map[string]bufconfig.LintConfig) opaqueIDToBreakingConfig := make(map[string]bufconfig.BreakingConfig) for _, module := range moduleSet.Modules() { - if bufmodule.ModuleFullNameEqual(module.ModuleFullName(), moduleKey.ModuleFullName()) { + if bufparse.FullNameEqual(module.FullName(), moduleKey.FullName()) { // Set the lint and breaking config for the single targeted Module. opaqueIDToLintConfig[module.OpaqueID()] = targetModuleConfig.LintConfig() opaqueIDToBreakingConfig[module.OpaqueID()] = targetModuleConfig.BreakingConfig() @@ -330,7 +331,7 @@ func (w *workspaceProvider) getWorkspaceForBucketAndModuleDirPathsV1Beta1OrV1( mappedModuleBucket, moduleBucketAndTargeting.bucketID, moduleTargeting.isTargetModule, - bufmodule.LocalModuleWithModuleFullName(moduleConfig.ModuleFullName()), + bufmodule.LocalModuleWithFullName(moduleConfig.FullName()), bufmodule.LocalModuleWithTargetPaths( moduleTargeting.moduleTargetPaths, moduleTargeting.moduleTargetExcludePaths, @@ -434,7 +435,7 @@ func (w *workspaceProvider) getWorkspaceForBucketBufYAMLV2( mappedModuleBucket, moduleBucketAndTargeting.bucketID, moduleTargeting.isTargetModule, - bufmodule.LocalModuleWithModuleFullName(moduleConfig.ModuleFullName()), + bufmodule.LocalModuleWithFullName(moduleConfig.FullName()), bufmodule.LocalModuleWithTargetPaths( moduleTargeting.moduleTargetPaths, moduleTargeting.moduleTargetExcludePaths, @@ -464,8 +465,8 @@ func (w *workspaceProvider) getWorkspaceForBucketModuleSet( moduleSet bufmodule.ModuleSet, bucketIDToModuleConfig map[string]bufconfig.ModuleConfig, pluginConfigs []bufconfig.PluginConfig, - // Expected to already be unique by ModuleFullName. - configuredDepModuleRefs []bufmodule.ModuleRef, + // Expected to already be unique by FullName. + configuredDepModuleRefs []bufparse.Ref, isV2 bool, ) (*workspace, error) { opaqueIDToLintConfig := make(map[string]bufconfig.LintConfig) diff --git a/private/buf/bufworkspace/workspace_targeting.go b/private/buf/bufworkspace/workspace_targeting.go index a9b2b90ca9..ca6063316f 100644 --- a/private/buf/bufworkspace/workspace_targeting.go +++ b/private/buf/bufworkspace/workspace_targeting.go @@ -25,6 +25,7 @@ import ( "github.com/bufbuild/buf/private/buf/buftarget" "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" @@ -53,7 +54,7 @@ type workspaceTargeting struct { type v1Targeting struct { bucketIDToModuleConfig map[string]bufconfig.ModuleConfig moduleBucketsAndTargeting []*moduleBucketAndModuleTargeting - allConfiguredDepModuleRefs []bufmodule.ModuleRef + allConfiguredDepModuleRefs []bufparse.Ref } type v2Targeting struct { @@ -296,7 +297,7 @@ func v1WorkspaceTargeting( // directories, and this is a system error - this should be verified before we reach this function. var hadIsTentativelyTargetModule bool var hadIsTargetModule bool - var allConfiguredDepModuleRefs []bufmodule.ModuleRef + var allConfiguredDepModuleRefs []bufparse.Ref bucketIDToModuleConfig := make(map[string]bufconfig.ModuleConfig) // We use this to detect different refs across different files. moduleFullNameStringToConfiguredDepModuleRefString := make(map[string]string) @@ -312,15 +313,15 @@ func v1WorkspaceTargeting( return nil, err } for _, configuredDepModuleRef := range configuredDepModuleRefs { - moduleFullNameString := configuredDepModuleRef.ModuleFullName().String() + moduleFullNameString := configuredDepModuleRef.FullName().String() configuredDepModuleRefString := configuredDepModuleRef.String() existingConfiguredDepModuleRefString, ok := moduleFullNameStringToConfiguredDepModuleRefString[moduleFullNameString] if !ok { - // We haven't encountered a ModuleRef with this ModuleFullName yet, add it. + // We haven't encountered a ModuleRef with this FullName yet, add it. allConfiguredDepModuleRefs = append(allConfiguredDepModuleRefs, configuredDepModuleRef) moduleFullNameStringToConfiguredDepModuleRefString[moduleFullNameString] = configuredDepModuleRefString } else if configuredDepModuleRefString != existingConfiguredDepModuleRefString { - // We encountered the same ModuleRef by ModuleFullName, but with a different Ref. + // We encountered the same ModuleRef by FullName, but with a different Ref. return nil, fmt.Errorf("found different refs for the same module within buf.yaml deps in the workspace: %s %s", configuredDepModuleRefString, existingConfiguredDepModuleRefString) } } @@ -698,7 +699,7 @@ func getModuleConfigAndConfiguredDepModuleRefsV1Beta1OrV1( bucket storage.ReadBucket, moduleDirPath string, overrideBufYAMLFile bufconfig.BufYAMLFile, -) (bufconfig.ModuleConfig, []bufmodule.ModuleRef, error) { +) (bufconfig.ModuleConfig, []bufparse.Ref, error) { var bufYAMLFile bufconfig.BufYAMLFile var err error if overrideBufYAMLFile != nil { diff --git a/private/buf/bufworkspace/workspace_test.go b/private/buf/bufworkspace/workspace_test.go index 3cf3451deb..0006c48217 100644 --- a/private/buf/bufworkspace/workspace_test.go +++ b/private/buf/bufworkspace/workspace_test.go @@ -240,9 +240,9 @@ func TestUnusedDep(t *testing.T) { malformedDeps, err := MalformedDepsForWorkspace(workspace) require.NoError(t, err) require.Equal(t, 2, len(malformedDeps)) - require.Equal(t, "buf.testing/acme/date", malformedDeps[0].ModuleRef().ModuleFullName().String()) + require.Equal(t, "buf.testing/acme/date", malformedDeps[0].ModuleRef().FullName().String()) require.Equal(t, MalformedDepTypeUnused, malformedDeps[0].Type()) - require.Equal(t, "buf.testing/acme/extension", malformedDeps[1].ModuleRef().ModuleFullName().String()) + require.Equal(t, "buf.testing/acme/extension", malformedDeps[1].ModuleRef().FullName().String()) require.Equal(t, MalformedDepTypeUnused, malformedDeps[1].Type()) } diff --git a/private/buf/cmd/buf/command/config/configinit/configinit.go b/private/buf/cmd/buf/command/config/configinit/configinit.go index cc252df60e..9407552072 100644 --- a/private/buf/cmd/buf/command/config/configinit/configinit.go +++ b/private/buf/cmd/buf/command/config/configinit/configinit.go @@ -20,7 +20,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/bufpkg/bufconfig" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" "github.com/spf13/pflag" @@ -124,9 +124,9 @@ func run( } fileVersion := bufconfig.FileVersionV2 - var moduleFullName bufmodule.ModuleFullName + var moduleFullName bufparse.FullName if container.NumArgs() > 0 { - moduleFullName, err = bufmodule.ParseModuleFullName(container.Arg(0)) + moduleFullName, err = bufparse.ParseFullName(container.Arg(0)) if err != nil { return err } diff --git a/private/buf/cmd/buf/command/config/configlsmodules/configlsmodules.go b/private/buf/cmd/buf/command/config/configlsmodules/configlsmodules.go index fc2c04a93f..7ec7257c2f 100644 --- a/private/buf/cmd/buf/command/config/configlsmodules/configlsmodules.go +++ b/private/buf/cmd/buf/command/config/configlsmodules/configlsmodules.go @@ -193,7 +193,7 @@ func getExternalModulesForBufWorkYAMLFile( return nil, syserror.Newf("got BufYAMLFile at %q with FileVersion %v with ModuleConfig that had non-root DirPath %q", dirPath, bufYAMLFile.FileVersion(), moduleConfig.DirPath()) } var name string - if moduleFullName := moduleConfig.ModuleFullName(); moduleFullName != nil { + if moduleFullName := moduleConfig.FullName(); moduleFullName != nil { name = moduleFullName.String() } includes := slicesext.Map(moduleConfig.RootToIncludes()["."], func(include string) string { return normalpath.Join(dirPath, include) }) @@ -222,7 +222,7 @@ func getExternalModulesForBufYAMLFile( externalModules := make([]*externalModule, len(moduleConfigs)) for i, moduleConfig := range moduleConfigs { var name string - if moduleFullName := moduleConfig.ModuleFullName(); moduleFullName != nil { + if moduleFullName := moduleConfig.FullName(); moduleFullName != nil { name = moduleFullName.String() } dirPath := moduleConfig.DirPath() diff --git a/private/buf/cmd/buf/command/dep/depgraph/depgraph.go b/private/buf/cmd/buf/command/dep/depgraph/depgraph.go index 0fcdbede51..396aa0e4c4 100644 --- a/private/buf/cmd/buf/command/dep/depgraph/depgraph.go +++ b/private/buf/cmd/buf/command/dep/depgraph/depgraph.go @@ -204,7 +204,7 @@ func run( } func moduleToString(module bufmodule.Module) string { - if moduleFullName := module.ModuleFullName(); moduleFullName != nil { + if moduleFullName := module.FullName(); moduleFullName != nil { commitID := dashlessCommitIDStringForModule(module) if commitID != "" { return moduleFullName.String() + ":" + commitID @@ -214,10 +214,10 @@ func moduleToString(module bufmodule.Module) string { return module.OpaqueID() } -// moduleFullNameOrOpaqueID returns the ModuleFullName for a module if available, otherwise +// moduleFullNameOrOpaqueID returns the FullName for a module if available, otherwise // it returns the OpaqueID. func moduleFullNameOrOpaqueID(module bufmodule.Module) string { - if moduleFullName := module.ModuleFullName(); moduleFullName != nil { + if moduleFullName := module.FullName(); moduleFullName != nil { return moduleFullName.String() } return module.OpaqueID() @@ -233,7 +233,7 @@ func dashlessCommitIDStringForModule(module bufmodule.Module) string { } type externalModule struct { - // ModuleFullName if remote, OpaqueID if no ModuleFullName + // FullName if remote, OpaqueID if no FullName Name string `json:"name,omitempty" yaml:"name,omitempty"` // Dashless Commit string `json:"commit,omitempty" yaml:"commit,omitempty"` @@ -249,8 +249,8 @@ func (e *externalModule) addDeps( flags *flags, ) error { for _, dep := range deps { - depModuleFullNameOrOpaqueID := moduleFullNameOrOpaqueID(dep) - depExternalModule, ok := moduleFullNameOrOpaqueIDToExternalModule[depModuleFullNameOrOpaqueID] + depFullNameOrOpaqueID := moduleFullNameOrOpaqueID(dep) + depExternalModule, ok := moduleFullNameOrOpaqueIDToExternalModule[depFullNameOrOpaqueID] if ok { // If this dependency has already been seen, we can simply update our current module // and return early. @@ -271,7 +271,7 @@ func (e *externalModule) addDeps( if err := depExternalModule.addDeps(transitiveDeps, graph, moduleFullNameOrOpaqueIDToExternalModule, flags); err != nil { return err } - moduleFullNameOrOpaqueIDToExternalModule[depModuleFullNameOrOpaqueID] = depExternalModule + moduleFullNameOrOpaqueIDToExternalModule[depFullNameOrOpaqueID] = depExternalModule e.Deps = append(e.Deps, depExternalModule) } return nil diff --git a/private/buf/cmd/buf/command/dep/internal/internal.go b/private/buf/cmd/buf/command/dep/internal/internal.go index b68a2e0b62..d5d57cf584 100644 --- a/private/buf/cmd/buf/command/dep/internal/internal.go +++ b/private/buf/cmd/buf/command/dep/internal/internal.go @@ -23,6 +23,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufctl" "github.com/bufbuild/buf/private/buf/bufworkspace" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app/appext" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" @@ -33,7 +34,7 @@ import ( func ModuleKeysAndTransitiveDepModuleKeysForModuleRefs( ctx context.Context, container appext.Container, - moduleRefs []bufmodule.ModuleRef, + moduleRefs []bufparse.Ref, digestType bufmodule.DigestType, ) ([]bufmodule.ModuleKey, error) { moduleKeyProvider, err := bufcli.NewModuleKeyProvider(container) @@ -123,7 +124,7 @@ func LogUnusedConfiguredDepsForWorkspace( case bufworkspace.MalformedDepTypeUnused: logger.Warn(fmt.Sprintf( `Module %[1]s is declared in your buf.yaml deps but is unused. This command only modifies buf.lock files, not buf.yaml files. Please remove %[1]s from your buf.yaml deps if it is not needed.`, - malformedDep.ModuleRef().ModuleFullName(), + malformedDep.ModuleRef().FullName(), )) default: return fmt.Errorf("unknown MalformedDepType: %v", t) @@ -166,16 +167,16 @@ func moduleKeysAndTransitiveDepModuleKeysForModuleKeys( // // See comment on Prune. func validateModuleKeysContains(containingModuleKeys []bufmodule.ModuleKey, moduleKeys []bufmodule.ModuleKey) error { - containingModuleFullNameStringToModuleKey, err := getModuleFullNameStringToModuleKey(containingModuleKeys) + containingFullNameStringToModuleKey, err := getFullNameStringToModuleKey(containingModuleKeys) if err != nil { return syserror.Newf("validateModuleKeysContains: containingModuleKeys: %w", err) } - moduleFullNameStringToModuleKey, err := getModuleFullNameStringToModuleKey(moduleKeys) + moduleFullNameStringToModuleKey, err := getFullNameStringToModuleKey(moduleKeys) if err != nil { return syserror.Newf("validateModuleKeysContains: moduleKeys: %w", err) } for moduleFullNameString := range moduleFullNameStringToModuleKey { - if _, ok := containingModuleFullNameStringToModuleKey[moduleFullNameString]; !ok { + if _, ok := containingFullNameStringToModuleKey[moduleFullNameString]; !ok { return fmt.Errorf( `Module %s is detected to be a still-used dependency from your existing buf.lock, but is not a declared dependency in your buf.yaml deps, and is not a transitive dependency of any declared dependency. Add %s to your buf.yaml deps.`, moduleFullNameString, @@ -186,12 +187,12 @@ func validateModuleKeysContains(containingModuleKeys []bufmodule.ModuleKey, modu return nil } -// All ModuleKeys are expected to be unique by ModuleFullName. -func getModuleFullNameStringToModuleKey(moduleKeys []bufmodule.ModuleKey) (map[string]bufmodule.ModuleKey, error) { +// All ModuleKeys are expected to be unique by FullName. +func getFullNameStringToModuleKey(moduleKeys []bufmodule.ModuleKey) (map[string]bufmodule.ModuleKey, error) { return slicesext.ToUniqueValuesMap( moduleKeys, func(moduleKey bufmodule.ModuleKey) string { - return moduleKey.ModuleFullName().String() + return moduleKey.FullName().String() }, ) } diff --git a/private/buf/cmd/buf/command/lsfiles/lsfiles.go b/private/buf/cmd/buf/command/lsfiles/lsfiles.go index 663a4e62cf..aaba9ae531 100644 --- a/private/buf/cmd/buf/command/lsfiles/lsfiles.go +++ b/private/buf/cmd/buf/command/lsfiles/lsfiles.go @@ -262,7 +262,7 @@ type externalImageFileInfo struct { func newExternalImageFileInfo(imageFileInfo bufimage.ImageFileInfo) *externalImageFileInfo { var module string - if moduleFullName := imageFileInfo.ModuleFullName(); moduleFullName != nil { + if moduleFullName := imageFileInfo.FullName(); moduleFullName != nil { module = moduleFullName.String() } var commit string diff --git a/private/buf/cmd/buf/command/mod/modopen/modopen.go b/private/buf/cmd/buf/command/mod/modopen/modopen.go index 2f44fe4b8e..86f511c567 100644 --- a/private/buf/cmd/buf/command/mod/modopen/modopen.go +++ b/private/buf/cmd/buf/command/mod/modopen/modopen.go @@ -75,7 +75,7 @@ func run( if len(moduleConfigs) != 1 { return syserror.Newf("got %d ModuleConfigs for a v1beta1/v1 buf.yaml", len(moduleConfigs)) } - moduleFullName := moduleConfigs[0].ModuleFullName() + moduleFullName := moduleConfigs[0].FullName() if moduleFullName == nil { return fmt.Errorf("%s/buf.yaml has no module name", dirPath) } diff --git a/private/buf/cmd/buf/command/registry/commit/commitaddlabel/commitaddlabel.go b/private/buf/cmd/buf/command/registry/commit/commitaddlabel/commitaddlabel.go index 685a2ce6c7..54f430fa7a 100644 --- a/private/buf/cmd/buf/command/registry/commit/commitaddlabel/commitaddlabel.go +++ b/private/buf/cmd/buf/command/registry/commit/commitaddlabel/commitaddlabel.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -84,7 +84,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -108,14 +108,14 @@ func run( return err } moduleClientProvider := bufregistryapimodule.NewClientProvider(clientConfig) - labelServiceClient := moduleClientProvider.V1LabelServiceClient(moduleRef.ModuleFullName().Registry()) + labelServiceClient := moduleClientProvider.V1LabelServiceClient(moduleRef.FullName().Registry()) requestValues := slicesext.Map(labels, func(label string) *modulev1.CreateOrUpdateLabelsRequest_Value { return &modulev1.CreateOrUpdateLabelsRequest_Value{ LabelRef: &modulev1.LabelRef{ Value: &modulev1.LabelRef_Name_{ Name: &modulev1.LabelRef_Name{ - Owner: moduleRef.ModuleFullName().Owner(), - Module: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Module: moduleRef.FullName().Name(), Label: label, }, }, @@ -138,7 +138,7 @@ func run( } if format == bufprint.FormatText { for _, label := range resp.Msg.Labels { - fmt.Fprintf(container.Stdout(), "%s:%s\n", moduleRef.ModuleFullName(), label.Name) + fmt.Fprintf(container.Stdout(), "%s:%s\n", moduleRef.FullName(), label.Name) } return nil } @@ -146,7 +146,7 @@ func run( container.Stdout(), format, slicesext.Map(resp.Msg.Labels, func(label *modulev1.Label) bufprint.Entity { - return bufprint.NewLabelEntity(label, moduleRef.ModuleFullName()) + return bufprint.NewLabelEntity(label, moduleRef.FullName()) })..., ) } diff --git a/private/buf/cmd/buf/command/registry/commit/commitinfo/commitinfo.go b/private/buf/cmd/buf/command/registry/commit/commitinfo/commitinfo.go index 3a79745df1..eda3a1f192 100644 --- a/private/buf/cmd/buf/command/registry/commit/commitinfo/commitinfo.go +++ b/private/buf/cmd/buf/command/registry/commit/commitinfo/commitinfo.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -74,7 +74,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -94,7 +94,7 @@ func run( if err != nil { return err } - commitServiceClient := bufregistryapimodule.NewClientProvider(clientConfig).V1CommitServiceClient(moduleRef.ModuleFullName().Registry()) + commitServiceClient := bufregistryapimodule.NewClientProvider(clientConfig).V1CommitServiceClient(moduleRef.FullName().Registry()) resp, err := commitServiceClient.GetCommits( ctx, connect.NewRequest( @@ -122,6 +122,6 @@ func run( return bufprint.PrintEntity( container.Stdout(), format, - bufprint.NewCommitEntity(commits[0], moduleRef.ModuleFullName()), + bufprint.NewCommitEntity(commits[0], moduleRef.FullName()), ) } diff --git a/private/buf/cmd/buf/command/registry/commit/commitlist/commitlist.go b/private/buf/cmd/buf/command/registry/commit/commitlist/commitlist.go index 292ccc8208..d31bff7151 100644 --- a/private/buf/cmd/buf/command/registry/commit/commitlist/commitlist.go +++ b/private/buf/cmd/buf/command/registry/commit/commitlist/commitlist.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -104,7 +104,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -116,7 +116,7 @@ func run( if err != nil { return err } - registry := moduleRef.ModuleFullName().Registry() + registry := moduleRef.FullName().Registry() moduleClientProvider := bufregistryapimodule.NewClientProvider(clientConfig) commitServiceClient := moduleClientProvider.V1CommitServiceClient(registry) labelServiceClient := moduleClientProvider.V1LabelServiceClient(registry) @@ -129,8 +129,8 @@ func run( { Value: &modulev1.ResourceRef_Name_{ Name: &modulev1.ResourceRef_Name{ - Owner: moduleRef.ModuleFullName().Owner(), - Module: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Module: moduleRef.FullName().Name(), Child: &modulev1.ResourceRef_Name_Ref{ Ref: moduleRef.Ref(), }, @@ -159,7 +159,7 @@ func run( format, "", "", - []bufprint.Entity{bufprint.NewCommitEntity(commit, moduleRef.ModuleFullName())}, + []bufprint.Entity{bufprint.NewCommitEntity(commit, moduleRef.FullName())}, ) } if resource.GetModule() != nil { @@ -177,8 +177,8 @@ func run( ResourceRef: &modulev1.ResourceRef{ Value: &modulev1.ResourceRef_Name_{ Name: &modulev1.ResourceRef_Name{ - Owner: moduleRef.ModuleFullName().Owner(), - Module: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Module: moduleRef.FullName().Name(), }, }, }, @@ -198,7 +198,7 @@ func run( resp.Msg.NextPageToken, nextPageCommand(container, flags, resp.Msg.NextPageToken), slicesext.Map(resp.Msg.Commits, func(commit *modulev1.Commit) bufprint.Entity { - return bufprint.NewCommitEntity(commit, moduleRef.ModuleFullName()) + return bufprint.NewCommitEntity(commit, moduleRef.FullName()) }), ) } @@ -221,8 +221,8 @@ func run( LabelRef: &modulev1.LabelRef{ Value: &modulev1.LabelRef_Name_{ Name: &modulev1.LabelRef_Name{ - Owner: moduleRef.ModuleFullName().Owner(), - Module: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Module: moduleRef.FullName().Name(), Label: moduleRef.Ref(), }, }, @@ -250,7 +250,7 @@ func run( resp.Msg.NextPageToken, nextPageCommand(container, flags, resp.Msg.NextPageToken), slicesext.Map(commits, func(commit *modulev1.Commit) bufprint.Entity { - return bufprint.NewCommitEntity(commit, moduleRef.ModuleFullName()) + return bufprint.NewCommitEntity(commit, moduleRef.FullName()) }), ) } diff --git a/private/buf/cmd/buf/command/registry/commit/commitresolve/commitresolve.go b/private/buf/cmd/buf/command/registry/commit/commitresolve/commitresolve.go index fccfc7e597..36137b6225 100644 --- a/private/buf/cmd/buf/command/registry/commit/commitresolve/commitresolve.go +++ b/private/buf/cmd/buf/command/registry/commit/commitresolve/commitresolve.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -73,7 +73,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -86,7 +86,7 @@ func run( if err != nil { return err } - commitServiceClient := bufregistryapimodule.NewClientProvider(clientConfig).V1CommitServiceClient(moduleRef.ModuleFullName().Registry()) + commitServiceClient := bufregistryapimodule.NewClientProvider(clientConfig).V1CommitServiceClient(moduleRef.FullName().Registry()) resp, err := commitServiceClient.GetCommits( ctx, connect.NewRequest( @@ -95,8 +95,8 @@ func run( { Value: &modulev1.ResourceRef_Name_{ Name: &modulev1.ResourceRef_Name{ - Owner: moduleRef.ModuleFullName().Owner(), - Module: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Module: moduleRef.FullName().Name(), Child: &modulev1.ResourceRef_Name_Ref{ Ref: moduleRef.Ref(), }, @@ -121,6 +121,6 @@ func run( return bufprint.PrintNames( container.Stdout(), format, - bufprint.NewCommitEntity(commit, moduleRef.ModuleFullName()), + bufprint.NewCommitEntity(commit, moduleRef.FullName()), ) } diff --git a/private/buf/cmd/buf/command/registry/label/labelarchive/labelarchive.go b/private/buf/cmd/buf/command/registry/label/labelarchive/labelarchive.go index 12e2e2fb98..1f55b21f25 100644 --- a/private/buf/cmd/buf/command/registry/label/labelarchive/labelarchive.go +++ b/private/buf/cmd/buf/command/registry/label/labelarchive/labelarchive.go @@ -21,7 +21,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -62,7 +62,7 @@ func run( container appext.Container, _ *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -74,7 +74,7 @@ func run( if err != nil { return err } - moduleFullName := moduleRef.ModuleFullName() + moduleFullName := moduleRef.FullName() labelServiceClient := bufregistryapimodule.NewClientProvider(clientConfig).V1LabelServiceClient(moduleFullName.Registry()) // ArchiveLabelsResponse is empty. if _, err := labelServiceClient.ArchiveLabels( diff --git a/private/buf/cmd/buf/command/registry/label/labelinfo/labelinfo.go b/private/buf/cmd/buf/command/registry/label/labelinfo/labelinfo.go index 857d010a32..1c8186fa8a 100644 --- a/private/buf/cmd/buf/command/registry/label/labelinfo/labelinfo.go +++ b/private/buf/cmd/buf/command/registry/label/labelinfo/labelinfo.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -73,7 +73,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -90,7 +90,7 @@ func run( return err } moduleClientProvider := bufregistryapimodule.NewClientProvider(clientConfig) - moduleFullName := moduleRef.ModuleFullName() + moduleFullName := moduleRef.FullName() labelServiceClient := moduleClientProvider.V1LabelServiceClient(moduleFullName.Registry()) resp, err := labelServiceClient.GetLabels( ctx, diff --git a/private/buf/cmd/buf/command/registry/label/labellist/labellist.go b/private/buf/cmd/buf/command/registry/label/labellist/labellist.go index 5b15eddbcc..fb142708d2 100644 --- a/private/buf/cmd/buf/command/registry/label/labellist/labellist.go +++ b/private/buf/cmd/buf/command/registry/label/labellist/labellist.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -104,7 +104,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -121,7 +121,7 @@ func run( return err } moduleClientProvider := bufregistryapimodule.NewClientProvider(clientConfig) - moduleFullName := moduleRef.ModuleFullName() + moduleFullName := moduleRef.FullName() labelServiceClient := moduleClientProvider.V1LabelServiceClient(moduleFullName.Registry()) order := modulev1.ListLabelsRequest_ORDER_UPDATE_TIME_DESC if flags.Reverse { diff --git a/private/buf/cmd/buf/command/registry/label/labelunarchive/labelunarchive.go b/private/buf/cmd/buf/command/registry/label/labelunarchive/labelunarchive.go index c104833dad..d2d034fbb9 100644 --- a/private/buf/cmd/buf/command/registry/label/labelunarchive/labelunarchive.go +++ b/private/buf/cmd/buf/command/registry/label/labelunarchive/labelunarchive.go @@ -21,7 +21,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -62,7 +62,7 @@ func run( container appext.Container, _ *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(container.Arg(0)) + moduleRef, err := bufparse.ParseRef(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -74,7 +74,7 @@ func run( if err != nil { return err } - moduleFullName := moduleRef.ModuleFullName() + moduleFullName := moduleRef.FullName() labelServiceClient := bufregistryapimodule.NewClientProvider(clientConfig).V1LabelServiceClient(moduleFullName.Registry()) // UnarchiveLabelsResponse is empty. if _, err := labelServiceClient.UnarchiveLabels( diff --git a/private/buf/cmd/buf/command/registry/module/modulecreate/modulecreate.go b/private/buf/cmd/buf/command/registry/module/modulecreate/modulecreate.go index 4b274514e2..4d9fbdeb18 100644 --- a/private/buf/cmd/buf/command/registry/module/modulecreate/modulecreate.go +++ b/private/buf/cmd/buf/command/registry/module/modulecreate/modulecreate.go @@ -23,7 +23,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -89,7 +89,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleFullName, err := bufmodule.ParseModuleFullName(container.Arg(0)) + moduleFullName, err := bufparse.ParseFullName(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } diff --git a/private/buf/cmd/buf/command/registry/module/moduledelete/moduledelete.go b/private/buf/cmd/buf/command/registry/module/moduledelete/moduledelete.go index 37b72d307e..669af923b1 100644 --- a/private/buf/cmd/buf/command/registry/module/moduledelete/moduledelete.go +++ b/private/buf/cmd/buf/command/registry/module/moduledelete/moduledelete.go @@ -21,7 +21,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -72,7 +72,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleFullName, err := bufmodule.ParseModuleFullName(container.Arg(0)) + moduleFullName, err := bufparse.ParseFullName(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } diff --git a/private/buf/cmd/buf/command/registry/module/moduledeprecate/moduledeprecate.go b/private/buf/cmd/buf/command/registry/module/moduledeprecate/moduledeprecate.go index 4ebfd44ea4..7742b81c7e 100644 --- a/private/buf/cmd/buf/command/registry/module/moduledeprecate/moduledeprecate.go +++ b/private/buf/cmd/buf/command/registry/module/moduledeprecate/moduledeprecate.go @@ -21,7 +21,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -54,7 +54,7 @@ func newFlags() *flags { func (f *flags) Bind(flagSet *pflag.FlagSet) {} func run(ctx context.Context, container appext.Container, flags *flags) error { - moduleFullName, err := bufmodule.ParseModuleFullName(container.Arg(0)) + moduleFullName, err := bufparse.ParseFullName(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } diff --git a/private/buf/cmd/buf/command/registry/module/moduleinfo/moduleinfo.go b/private/buf/cmd/buf/command/registry/module/moduleinfo/moduleinfo.go index 19ae1d19db..9ad9c838cb 100644 --- a/private/buf/cmd/buf/command/registry/module/moduleinfo/moduleinfo.go +++ b/private/buf/cmd/buf/command/registry/module/moduleinfo/moduleinfo.go @@ -22,7 +22,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" "github.com/bufbuild/buf/private/buf/bufprint" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -73,7 +73,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleFullName, err := bufmodule.ParseModuleFullName(container.Arg(0)) + moduleFullName, err := bufparse.ParseFullName(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } diff --git a/private/buf/cmd/buf/command/registry/module/moduleundeprecate/moduleundeprecate.go b/private/buf/cmd/buf/command/registry/module/moduleundeprecate/moduleundeprecate.go index 8bca106626..e8d31627c3 100644 --- a/private/buf/cmd/buf/command/registry/module/moduleundeprecate/moduleundeprecate.go +++ b/private/buf/cmd/buf/command/registry/module/moduleundeprecate/moduleundeprecate.go @@ -21,7 +21,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -39,7 +39,7 @@ func NewCommand(name string, builder appext.SubCommandBuilder) *appcmd.Command { } func run(ctx context.Context, container appext.Container) error { - moduleFullName, err := bufmodule.ParseModuleFullName(container.Arg(0)) + moduleFullName, err := bufparse.ParseFullName(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } diff --git a/private/buf/cmd/buf/command/registry/module/moduleupdate/moduleupdate.go b/private/buf/cmd/buf/command/registry/module/moduleupdate/moduleupdate.go index 6e67806e70..f4c66ab26c 100644 --- a/private/buf/cmd/buf/command/registry/module/moduleupdate/moduleupdate.go +++ b/private/buf/cmd/buf/command/registry/module/moduleupdate/moduleupdate.go @@ -21,7 +21,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appext" @@ -90,7 +90,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleFullName, err := bufmodule.ParseModuleFullName(container.Arg(0)) + moduleFullName, err := bufparse.ParseFullName(container.Arg(0)) if err != nil { return appcmd.WrapInvalidArgumentError(err) } diff --git a/private/buf/cmd/buf/command/registry/sdk/version/version.go b/private/buf/cmd/buf/command/registry/sdk/version/version.go index cb96d3d61f..7c01c93786 100644 --- a/private/buf/cmd/buf/command/registry/sdk/version/version.go +++ b/private/buf/cmd/buf/command/registry/sdk/version/version.go @@ -20,7 +20,7 @@ import ( "connectrpc.com/connect" "github.com/bufbuild/buf/private/buf/bufcli" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufremoteplugin/bufremotepluginref" "github.com/bufbuild/buf/private/gen/proto/connect/buf/alpha/registry/v1alpha1/registryv1alpha1connect" registryv1alpha1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/registry/v1alpha1" @@ -89,7 +89,7 @@ func run( container appext.Container, flags *flags, ) error { - moduleRef, err := bufmodule.ParseModuleRef(flags.Module) + moduleRef, err := bufparse.ParseRef(flags.Module) if err != nil { return appcmd.WrapInvalidArgumentError(err) } @@ -97,7 +97,7 @@ func run( if err != nil { return appcmd.WrapInvalidArgumentError(err) } - if pluginIdentity.Remote() != moduleRef.ModuleFullName().Registry() { + if pluginIdentity.Remote() != moduleRef.FullName().Registry() { return appcmd.NewInvalidArgumentError("module and plugin must be from the same BSR instance") } @@ -107,12 +107,12 @@ func run( } pluginCurationServiceClient := connectclient.Make( clientConfig, - moduleRef.ModuleFullName().Registry(), + moduleRef.FullName().Registry(), registryv1alpha1connect.NewPluginCurationServiceClient, ) resolveServiceClient := connectclient.Make( clientConfig, - moduleRef.ModuleFullName().Registry(), + moduleRef.FullName().Registry(), registryv1alpha1connect.NewResolveServiceClient, ) getLatestCuratedPluginResponse, err := pluginCurationServiceClient.GetLatestCuratedPlugin( @@ -133,8 +133,8 @@ func run( return fmt.Errorf("plugin %q is not associated with a package ecosystem", flags.Plugin) } moduleReference := ®istryv1alpha1.LocalModuleReference{ - Owner: moduleRef.ModuleFullName().Owner(), - Repository: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Repository: moduleRef.FullName().Name(), Reference: moduleRef.Ref(), } pluginReference := ®istryv1alpha1.GetRemotePackageVersionPlugin{ diff --git a/private/buf/cmd/buf/imports_test.go b/private/buf/cmd/buf/imports_test.go index d80ae08491..7a9fe1f43a 100644 --- a/private/buf/cmd/buf/imports_test.go +++ b/private/buf/cmd/buf/imports_test.go @@ -22,6 +22,7 @@ import ( "github.com/bufbuild/buf/private/buf/bufctl" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/app/appcmd" "github.com/bufbuild/buf/private/pkg/app/appcmd/appcmdtesting" "github.com/bufbuild/buf/private/pkg/uuidutil" @@ -51,7 +52,7 @@ func TestValidImportFromCache(t *testing.T) { func TestValidImportFromCorruptedCacheFile(t *testing.T) { t.Parallel() - moduleFullName, err := bufmodule.NewModuleFullName("bufbuild.test", "bufbot", "people") + moduleFullName, err := bufparse.NewFullName("bufbuild.test", "bufbot", "people") require.NoError(t, err) commitID, err := uuidutil.FromDashless("fc7d540124fd42db92511c19a60a1d98") require.NoError(t, err) @@ -60,7 +61,7 @@ func TestValidImportFromCorruptedCacheFile(t *testing.T) { actualDigest, err := bufmodule.ParseDigest("b5:87403abcc5ec8403180536840a46bef8751df78caa8ad4b46939f4673d8bd58663d0f593668651bb2cd23049fedac4989e8b28c7e0e36b9b524f58ab09bf1053") require.NoError(t, err) digestMismatchError := &bufmodule.DigestMismatchError{ - ModuleFullName: moduleFullName, + FullName: moduleFullName, CommitID: commitID, ExpectedDigest: expectedDigest, ActualDigest: actualDigest, @@ -85,7 +86,7 @@ func TestValidImportFromCorruptedCacheFile(t *testing.T) { func TestValidImportFromCorruptedCacheDep(t *testing.T) { t.Parallel() - moduleFullName, err := bufmodule.NewModuleFullName("bufbuild.test", "bufbot", "students") + moduleFullName, err := bufparse.NewFullName("bufbuild.test", "bufbot", "students") require.NoError(t, err) commitID, err := uuidutil.FromDashless("6c776ed5bee54462b06d31fb7f7c16b8") require.NoError(t, err) @@ -94,7 +95,7 @@ func TestValidImportFromCorruptedCacheDep(t *testing.T) { actualDigest, err := bufmodule.ParseDigest("b5:975dad3641303843fb6a06eedf038b0e6ff41da82b8a483920afb36011e0b0a24f720a2407f5e0783389530486ff410b7e132f219add69a5c7324d54f6f89a6c") require.NoError(t, err) digestMismatchError := &bufmodule.DigestMismatchError{ - ModuleFullName: moduleFullName, + FullName: moduleFullName, CommitID: commitID, ExpectedDigest: expectedDigest, ActualDigest: actualDigest, diff --git a/private/buf/cmd/internal/internal.go b/private/buf/cmd/internal/internal.go index 2c06b85599..d81895f8da 100644 --- a/private/buf/cmd/internal/internal.go +++ b/private/buf/cmd/internal/internal.go @@ -58,7 +58,7 @@ func GetModuleConfigForProtocPlugin( // // If we have a v2 buf.yaml, users have to provide a module path or full name, otherwise // we can't deduce what ModuleConfig to use. - if fullName := moduleConfig.ModuleFullName(); fullName != nil && fullName.String() == module { + if fullName := moduleConfig.FullName(); fullName != nil && fullName.String() == module { // Can return here because BufYAMLFile guarantees that module full names are unique across // its module configs. return moduleConfig, nil diff --git a/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go b/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go index d1f15093ee..086b1b639d 100644 --- a/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go +++ b/private/bufpkg/bufcheck/bufcheckserver/internal/bufcheckserverutil/input_file.go @@ -16,7 +16,7 @@ package bufcheckserverutil import ( "buf.build/go/bufplugin/descriptor" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/google/uuid" ) @@ -38,7 +38,7 @@ func (i *inputFile) ExternalPath() string { return i.Path() } -func (i *inputFile) ModuleFullName() bufmodule.ModuleFullName { +func (i *inputFile) FullName() bufparse.FullName { return nil } diff --git a/private/bufpkg/bufconfig/buf_lock_file.go b/private/bufpkg/bufconfig/buf_lock_file.go index ace54fd8e5..3eee9d2fb6 100644 --- a/private/bufpkg/bufconfig/buf_lock_file.go +++ b/private/bufpkg/bufconfig/buf_lock_file.go @@ -24,6 +24,7 @@ import ( "time" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/encoding" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" @@ -65,8 +66,8 @@ type BufLockFile interface { // DepModuleKeys returns the ModuleKeys representing the dependencies as specified in the buf.lock file. // - // All ModuleKeys will have unique ModuleFullNames. - // ModuleKeys are sorted by ModuleFullName. + // All ModuleKeys will have unique FullNames. + // ModuleKeys are sorted by FullName. // // Files with FileVersionV1Beta1 or FileVersionV1 will only have ModuleKeys with Digests of DigestTypeB4, // while Files with FileVersionV2 will only have ModuleKeys with Digests of DigestTypeB5. @@ -190,7 +191,7 @@ func newBufLockFile( objectData ObjectData, depModuleKeys []bufmodule.ModuleKey, ) (*bufLockFile, error) { - if err := validateNoDuplicateModuleKeysByModuleFullName(depModuleKeys); err != nil { + if err := validateNoDuplicateModuleKeysByFullName(depModuleKeys); err != nil { return nil, err } switch fileVersion { @@ -210,7 +211,7 @@ func newBufLockFile( sort.Slice( depModuleKeys, func(i int, j int) bool { - return depModuleKeys[i].ModuleFullName().String() < depModuleKeys[j].ModuleFullName().String() + return depModuleKeys[i].FullName().String() < depModuleKeys[j].FullName().String() }, ) bufLockFile := &bufLockFile{ @@ -278,7 +279,7 @@ func readBufLockFile( if dep.Repository == "" { return nil, errors.New("repository missing") } - moduleFullName, err := bufmodule.NewModuleFullName( + moduleFullName, err := bufparse.NewFullName( dep.Remote, dep.Owner, dep.Repository, @@ -326,7 +327,7 @@ func readBufLockFile( if dep.Name == "" { return nil, errors.New("no module name specified") } - moduleFullName, err := bufmodule.ParseModuleFullName(dep.Name) + moduleFullName, err := bufparse.ParseFullName(dep.Name) if err != nil { return nil, fmt.Errorf("invalid module name: %w", err) } @@ -383,14 +384,14 @@ func writeBufLockFile( return err } externalBufLockFile.Deps[i] = externalBufLockFileDepV1Beta1V1{ - Remote: depModuleKey.ModuleFullName().Registry(), - Owner: depModuleKey.ModuleFullName().Owner(), - Repository: depModuleKey.ModuleFullName().Name(), + Remote: depModuleKey.FullName().Registry(), + Owner: depModuleKey.FullName().Owner(), + Repository: depModuleKey.FullName().Name(), Commit: uuidutil.ToDashless(depModuleKey.CommitID()), Digest: digest.String(), } } - // No need to sort - depModuleKeys is already sorted by ModuleFullName + // No need to sort - depModuleKeys is already sorted by FullName data, err := encoding.MarshalYAML(&externalBufLockFile) if err != nil { return err @@ -409,12 +410,12 @@ func writeBufLockFile( return err } externalBufLockFile.Deps[i] = externalBufLockFileDepV2{ - Name: depModuleKey.ModuleFullName().String(), + Name: depModuleKey.FullName().String(), Commit: uuidutil.ToDashless(depModuleKey.CommitID()), Digest: digest.String(), } } - // No need to sort - depModuleKeys is already sorted by ModuleFullName + // No need to sort - depModuleKeys is already sorted by FullName data, err := encoding.MarshalYAML(&externalBufLockFile) if err != nil { return err @@ -441,10 +442,10 @@ func getDeprecatedDigestTypeForExternalDigest(externalDigest string) string { return "" } -func validateNoDuplicateModuleKeysByModuleFullName(moduleKeys []bufmodule.ModuleKey) error { +func validateNoDuplicateModuleKeysByFullName(moduleKeys []bufmodule.ModuleKey) error { moduleFullNameStringMap := make(map[string]struct{}) for _, moduleKey := range moduleKeys { - moduleFullNameString := moduleKey.ModuleFullName().String() + moduleFullNameString := moduleKey.FullName().String() if _, ok := moduleFullNameStringMap[moduleFullNameString]; ok { return fmt.Errorf("duplicate module %q attempted to be added to lock file", moduleFullNameString) } @@ -462,7 +463,7 @@ func validateV1AndV1Beta1DepsHaveCommits(bufLockFile BufLockFile) error { return syserror.Newf( "%s lock files require commits, however we did not have a commit for module %q", fileVersion.String(), - depModuleKey.ModuleFullName().String(), + depModuleKey.FullName().String(), ) } } diff --git a/private/bufpkg/bufconfig/buf_yaml_file.go b/private/bufpkg/bufconfig/buf_yaml_file.go index dc3472929f..ebe5abb6be 100644 --- a/private/bufpkg/bufconfig/buf_yaml_file.go +++ b/private/bufpkg/bufconfig/buf_yaml_file.go @@ -25,7 +25,7 @@ import ( "path/filepath" "sort" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/encoding" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" @@ -71,7 +71,7 @@ type BufYAMLFile interface { // For v1 buf.yaml, this will only have a single ModuleConfig. // // This will always be non-empty. - // All ModuleConfigs will have unique ModuleFullNames, but not necessarily + // All ModuleConfigs will have unique FullNames, but not necessarily // unique DirPaths. // // The module configs are sorted by DirPath. If two module configs have the @@ -108,9 +108,9 @@ type BufYAMLFile interface { // // These come from buf.yaml files. // - // The ModuleRefs in this list will be unique by ModuleFullName. - // Sorted by ModuleFullName. - ConfiguredDepModuleRefs() []bufmodule.ModuleRef + // The ModuleRefs in this list will be unique by FullName. + // Sorted by FullName. + ConfiguredDepModuleRefs() []bufparse.Ref //IncludeDocsLink specifies whether a top-level comment with a link to our public docs // should be included at the top of the buf.yaml file. IncludeDocsLink() bool @@ -125,7 +125,7 @@ func NewBufYAMLFile( fileVersion FileVersion, moduleConfigs []ModuleConfig, pluginConfigs []PluginConfig, - configuredDepModuleRefs []bufmodule.ModuleRef, + configuredDepModuleRefs []bufparse.Ref, options ...BufYAMLFileOption, ) (BufYAMLFile, error) { bufYAMLFileOptions := newBufYAMLFileOptions() @@ -253,7 +253,7 @@ type bufYAMLFile struct { topLevelLintConfig LintConfig topLevelBreakingConfig BreakingConfig pluginConfigs []PluginConfig - configuredDepModuleRefs []bufmodule.ModuleRef + configuredDepModuleRefs []bufparse.Ref includeDocsLink bool } @@ -264,7 +264,7 @@ func newBufYAMLFile( topLevelLintConfig LintConfig, topLevelBreakingConfig BreakingConfig, pluginConfigs []PluginConfig, - configuredDepModuleRefs []bufmodule.ModuleRef, + configuredDepModuleRefs []bufparse.Ref, includeDocsLink bool, ) (*bufYAMLFile, error) { if (fileVersion == FileVersionV1Beta1 || fileVersion == FileVersionV1) && len(moduleConfigs) > 1 { @@ -290,10 +290,10 @@ func newBufYAMLFile( } } // Zero values are not added to duplicates. - if _, err := bufmodule.ModuleFullNameStringToUniqueValue(moduleConfigs); err != nil { + if _, err := bufparse.FullNameStringToUniqueValue(moduleConfigs); err != nil { return nil, err } - if _, err := bufmodule.ModuleFullNameStringToUniqueValue(configuredDepModuleRefs); err != nil { + if _, err := bufparse.FullNameStringToUniqueValue(configuredDepModuleRefs); err != nil { return nil, err } // Since multiple module configs with the same DirPath are allowed in v2, we need a stable sort @@ -308,8 +308,8 @@ func newBufYAMLFile( sort.Slice( configuredDepModuleRefs, func(i int, j int) bool { - return configuredDepModuleRefs[i].ModuleFullName().String() < - configuredDepModuleRefs[j].ModuleFullName().String() + return configuredDepModuleRefs[i].FullName().String() < + configuredDepModuleRefs[j].FullName().String() }, ) return &bufYAMLFile{ @@ -352,7 +352,7 @@ func (c *bufYAMLFile) PluginConfigs() []PluginConfig { return c.pluginConfigs } -func (c *bufYAMLFile) ConfiguredDepModuleRefs() []bufmodule.ModuleRef { +func (c *bufYAMLFile) ConfiguredDepModuleRefs() []bufparse.Ref { return slicesext.Copy(c.configuredDepModuleRefs) } @@ -394,9 +394,9 @@ func readBufYAMLFile( if fileVersion == FileVersionV1 && len(externalBufYAMLFile.Build.Roots) > 0 { return nil, fmt.Errorf("build.roots cannot be set on version %v: %v", fileVersion, externalBufYAMLFile.Build.Roots) } - var moduleFullName bufmodule.ModuleFullName + var moduleFullName bufparse.FullName if externalBufYAMLFile.Name != "" { - moduleFullName, err = bufmodule.ParseModuleFullName(externalBufYAMLFile.Name) + moduleFullName, err = bufparse.ParseFullName(externalBufYAMLFile.Name) if err != nil { return nil, err } @@ -486,9 +486,9 @@ func readBufYAMLFile( if err != nil { return nil, fmt.Errorf("invalid module path: %w", err) } - var moduleFullName bufmodule.ModuleFullName + var moduleFullName bufparse.FullName if externalModule.Name != "" { - moduleFullName, err = bufmodule.ParseModuleFullName(externalModule.Name) + moduleFullName, err = bufparse.ParseFullName(externalModule.Name) if err != nil { return nil, err } @@ -689,11 +689,11 @@ func writeBufYAMLFile(writer io.Writer, bufYAMLFile BufYAMLFile) error { // Already sorted. externalBufYAMLFile.Deps = slicesext.Map( bufYAMLFile.ConfiguredDepModuleRefs(), - func(moduleRef bufmodule.ModuleRef) string { + func(moduleRef bufparse.Ref) string { return moduleRef.String() }, ) - if moduleFullName := moduleConfig.ModuleFullName(); moduleFullName != nil { + if moduleFullName := moduleConfig.FullName(); moduleFullName != nil { externalBufYAMLFile.Name = moduleFullName.String() } rootToExcludes := moduleConfig.RootToExcludes() @@ -761,7 +761,7 @@ func writeBufYAMLFile(writer io.Writer, bufYAMLFile BufYAMLFile) error { // Already sorted. externalBufYAMLFile.Deps = slicesext.Map( bufYAMLFile.ConfiguredDepModuleRefs(), - func(moduleRef bufmodule.ModuleRef) string { + func(moduleRef bufparse.Ref) string { return moduleRef.String() }, ) @@ -791,7 +791,7 @@ func writeBufYAMLFile(writer io.Writer, bufYAMLFile BufYAMLFile) error { externalModule := externalBufYAMLFileModuleV2{ Path: moduleDirPath, } - if moduleFullName := moduleConfig.ModuleFullName(); moduleFullName != nil { + if moduleFullName := moduleConfig.FullName(); moduleFullName != nil { externalModule.Name = moduleFullName.String() } rootToIncludes := moduleConfig.RootToIncludes() @@ -963,10 +963,10 @@ func getRootToExcludes(roots []string, fullExcludes []string) (map[string][]stri func getConfiguredDepModuleRefsForExternalDeps( externalDeps []string, -) ([]bufmodule.ModuleRef, error) { - configuredDepModuleRefs := make([]bufmodule.ModuleRef, len(externalDeps)) +) ([]bufparse.Ref, error) { + configuredDepModuleRefs := make([]bufparse.Ref, len(externalDeps)) for i, externalDep := range externalDeps { - moduleRef, err := bufmodule.ParseModuleRef(externalDep) + moduleRef, err := bufparse.ParseRef(externalDep) if err != nil { return nil, fmt.Errorf("invalid dep: %w", err) } diff --git a/private/bufpkg/bufconfig/generate_managed_config.go b/private/bufpkg/bufconfig/generate_managed_config.go index 567d7da5ab..8ec74b86ca 100644 --- a/private/bufpkg/bufconfig/generate_managed_config.go +++ b/private/bufpkg/bufconfig/generate_managed_config.go @@ -20,7 +20,7 @@ import ( "strconv" "strings" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" ) @@ -58,16 +58,16 @@ func NewGenerateManagedConfig( // it means for all files/fields the specified options are not modified. // // A ManagedDisableRule is guaranteed to specify at least one of the two aspects. -// i.e. At least one of Path, ModuleFullName, FieldName, FileOption and +// i.e. At least one of Path, FullName, FieldName, FileOption and // FieldOption is not empty. A rule can disable all options for certain files/fields, // disable certains options for all files/fields, or disable certain options for // certain files/fields. To disable all options for all files/fields, turn off managed mode. type ManagedDisableRule interface { // Path returns the file path, relative to its module, to disable managed mode for. Path() string - // ModuleFullName returns the full name string of the module to disable + // FullName returns the full name string of the module to disable // managed mode for. - ModuleFullName() string + FullName() string // FieldName returns the fully qualified name for the field to disable managed // mode for. This is guaranteed to be empty if FileOption is not empty. FieldName() string @@ -101,16 +101,16 @@ func NewManagedDisableRule( // // - The options to modify. Exactly one of FileOption and FieldOption is not empty. // - The value to modify these options with. -// - The files/fields for which the options are modified. If all of Path, ModuleFullName +// - The files/fields for which the options are modified. If all of Path, FullName // - or FieldName are empty, all files/fields are modified. Otherwise, only -// file/fields that match the specified Path, ModuleFullName and FieldName +// file/fields that match the specified Path, FullName and FieldName // is modified. type ManagedOverrideRule interface { // Path is the file path, relative to its module, to disable managed mode for. Path() string - // ModuleFullName is the full name string of the module to disable + // FullName is the full name string of the module to disable // managed mode for. - ModuleFullName() string + FullName() string // FieldName is the fully qualified name for the field to disable managed // mode for. This is guaranteed to be empty is FileOption is not empty. FieldName() string @@ -531,7 +531,7 @@ func newManagedDisableRule( } } if moduleFullName != "" { - if _, err := bufmodule.ParseModuleFullName(moduleFullName); err != nil { + if _, err := bufparse.ParseFullName(moduleFullName); err != nil { return nil, err } } @@ -548,7 +548,7 @@ func (m *managedDisableRule) Path() string { return m.path } -func (m *managedDisableRule) ModuleFullName() string { +func (m *managedDisableRule) FullName() string { return m.moduleFullName } @@ -594,7 +594,7 @@ func newFileOptionManagedOverrideRule( return nil, fmt.Errorf("invalid value %v for %v: %w", value, fileOption, err) } if moduleFullName != "" { - if _, err := bufmodule.ParseModuleFullName(moduleFullName); err != nil { + if _, err := bufparse.ParseFullName(moduleFullName); err != nil { return nil, fmt.Errorf("invalid module name for %v override: %w", fileOption, err) } } @@ -631,7 +631,7 @@ func newFieldOptionManagedOverrideRule( return nil, fmt.Errorf("invalid value %v for %v: %w", value, fieldOption, err) } if moduleFullName != "" { - if _, err := bufmodule.ParseModuleFullName(moduleFullName); err != nil { + if _, err := bufparse.ParseFullName(moduleFullName); err != nil { return nil, fmt.Errorf("invalid module name for %v override: %w", fieldOption, err) } } @@ -653,7 +653,7 @@ func (m *managedOverrideRule) Path() string { return m.path } -func (m *managedOverrideRule) ModuleFullName() string { +func (m *managedOverrideRule) FullName() string { return m.moduleFullName } @@ -677,7 +677,7 @@ func (m *managedOverrideRule) isManagedOverrideRule() {} func disablesAndOverridesFromExceptAndOverrideV1( exceptFileOption FileOption, - exceptModuleFullNames []string, + exceptFullNames []string, overrideFileOption FileOption, moduleFullNameToOverride map[string]string, ) ([]ManagedDisableRule, []ManagedOverrideRule, error) { @@ -685,18 +685,18 @@ func disablesAndOverridesFromExceptAndOverrideV1( disables []ManagedDisableRule overrides []ManagedOverrideRule ) - seenExceptModuleFullNames := make(map[string]struct{}, len(exceptModuleFullNames)) - for _, exceptModuleFullName := range exceptModuleFullNames { - if _, err := bufmodule.ParseModuleFullName(exceptModuleFullName); err != nil { + seenExceptFullNames := make(map[string]struct{}, len(exceptFullNames)) + for _, exceptFullName := range exceptFullNames { + if _, err := bufparse.ParseFullName(exceptFullName); err != nil { return nil, nil, err } - if _, ok := seenExceptModuleFullNames[exceptModuleFullName]; ok { - return nil, nil, fmt.Errorf("%q is defined multiple times in except", exceptModuleFullName) + if _, ok := seenExceptFullNames[exceptFullName]; ok { + return nil, nil, fmt.Errorf("%q is defined multiple times in except", exceptFullName) } - seenExceptModuleFullNames[exceptModuleFullName] = struct{}{} + seenExceptFullNames[exceptFullName] = struct{}{} disable, err := newManagedDisableRule( "", - exceptModuleFullName, + exceptFullName, "", exceptFileOption, FieldOptionUnspecified, @@ -707,19 +707,19 @@ func disablesAndOverridesFromExceptAndOverrideV1( disables = append(disables, disable) } // Sort by keys for deterministic order. - sortedModuleFullNames := slicesext.MapKeysToSortedSlice(moduleFullNameToOverride) - for _, overrideModuleFullName := range sortedModuleFullNames { - if _, err := bufmodule.ParseModuleFullName(overrideModuleFullName); err != nil { + sortedFullNames := slicesext.MapKeysToSortedSlice(moduleFullNameToOverride) + for _, overrideFullName := range sortedFullNames { + if _, err := bufparse.ParseFullName(overrideFullName); err != nil { return nil, nil, err } - if _, ok := seenExceptModuleFullNames[overrideModuleFullName]; ok { - return nil, nil, fmt.Errorf("override %q is already defined as an except", overrideModuleFullName) + if _, ok := seenExceptFullNames[overrideFullName]; ok { + return nil, nil, fmt.Errorf("override %q is already defined as an except", overrideFullName) } override, err := NewManagedOverrideRuleForFileOption( "", - overrideModuleFullName, + overrideFullName, overrideFileOption, - moduleFullNameToOverride[overrideModuleFullName], + moduleFullNameToOverride[overrideFullName], ) if err != nil { return nil, nil, err @@ -791,7 +791,7 @@ func newExternalManagedConfigV2FromGenerateManagedConfig( externalManagedDisableConfigV2{ FileOption: fileOptionName, FieldOption: fieldOptionName, - Module: disable.ModuleFullName(), + Module: disable.FullName(), Path: disable.Path(), Field: disable.FieldName(), }, @@ -816,7 +816,7 @@ func newExternalManagedConfigV2FromGenerateManagedConfig( externalManagedOverrideConfigV2{ FileOption: fileOptionName, FieldOption: fieldOptionName, - Module: override.ModuleFullName(), + Module: override.FullName(), Path: override.Path(), Field: override.FieldName(), Value: value, diff --git a/private/bufpkg/bufconfig/module_config.go b/private/bufpkg/bufconfig/module_config.go index f808ff4e62..3b7f3d6313 100644 --- a/private/bufpkg/bufconfig/module_config.go +++ b/private/bufpkg/bufconfig/module_config.go @@ -18,7 +18,7 @@ import ( "errors" "fmt" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" ) @@ -68,7 +68,7 @@ func init() { // ModuleConfig is configuration for a specific Module. // // ModuleConfigs do not expose BucketID or OpaqueID, however DirPath is effectively BucketID, -// and ModuleFullName -> fallback to DirPath effectively is OpaqueID. Given that it is up to +// and FullName -> fallback to DirPath effectively is OpaqueID. Given that it is up to // the user of this package to decide what to do with these fields, we do not name DirPath as // BucketID, and we do not expose OpaqueID. type ModuleConfig interface { @@ -80,10 +80,10 @@ type ModuleConfig interface { // to the Workspace constructor to come up with a BucketID (likely the directory name // within buf.work.yaml). DirPath() string - // ModuleFullName returns the ModuleFullName for the Module, if available. + // FullName returns the FullName for the Module, if available. // // This may be nil. - ModuleFullName() bufmodule.ModuleFullName + FullName() bufparse.FullName // RootToIncludes contains a map from root to the directories to include for that root. // The keys in RootToIncludes are always the same as those in RooToExcludes. // @@ -152,7 +152,7 @@ type ModuleConfig interface { // NewModuleConfig returns a new ModuleConfig. func NewModuleConfig( dirPath string, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, rootToIncludes map[string][]string, rootToExcludes map[string][]string, lintConfig LintConfig, @@ -172,7 +172,7 @@ func NewModuleConfig( type moduleConfig struct { dirPath string - moduleFullName bufmodule.ModuleFullName + moduleFullName bufparse.FullName rootToIncludes map[string][]string rootToExcludes map[string][]string lintConfig LintConfig @@ -182,7 +182,7 @@ type moduleConfig struct { // All validations are syserrors as we only ever read ModuleConfigs. func newModuleConfig( dirPath string, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, rootToIncludes map[string][]string, rootToExcludes map[string][]string, lintConfig LintConfig, @@ -252,7 +252,7 @@ func (m *moduleConfig) DirPath() string { return m.dirPath } -func (m *moduleConfig) ModuleFullName() bufmodule.ModuleFullName { +func (m *moduleConfig) FullName() bufparse.FullName { return m.moduleFullName } diff --git a/private/bufpkg/bufimage/bufimage.go b/private/bufpkg/bufimage/bufimage.go index 3f3ba08558..18299cb723 100644 --- a/private/bufpkg/bufimage/bufimage.go +++ b/private/bufpkg/bufimage/bufimage.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/gen/data/datawkt" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" "github.com/bufbuild/buf/private/pkg/normalpath" @@ -47,18 +48,18 @@ import ( type ImageFileInfo interface { storage.ObjectInfo - // ModuleFullName returns the full name of the Module that this ImageFile came from, + // FullName returns the full name of the Module that this ImageFile came from, // if the ImageFile came from a Module (as opposed to a serialized Protobuf message), - // and if the ModuleFullName was known. + // and if the FullName was known. // // May be nil. Callers should not rely on this value being present. - ModuleFullName() bufmodule.ModuleFullName + FullName() bufparse.FullName // CommitID returns the BSR ID of the Commit of the Module that this ImageFile came from. // if the ImageFile came from a Module (as opposed to a serialized Protobuf message), and // if the CommitID was known.. // // May be empty, that is CommitID() == uuid.Nil may be true. Callers should not rely on this - // value being present. If ModuleFullName is nil, this will always be empty. + // value being present. If FullName is nil, this will always be empty. CommitID() uuid.UUID // Imports returns the imports for this ImageFile. Imports() ([]string, error) @@ -182,7 +183,7 @@ type ImageFile interface { // TODO FUTURE: moduleFullName and commitID should be options since they are optional. func NewImageFile( fileDescriptor protodescriptor.FileDescriptor, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, externalPath string, localPath string, @@ -214,7 +215,7 @@ func ImageFileWithIsImport(imageFile ImageFile, isImport bool) ImageFile { // No need to validate as ImageFile is already validated. return newImageFileNoValidate( imageFile.FileDescriptorProto(), - imageFile.ModuleFullName(), + imageFile.FullName(), imageFile.CommitID(), imageFile.ExternalPath(), imageFile.LocalPath(), @@ -231,7 +232,7 @@ type Image interface { // This contains all files, including imports if available. // The returned files are in correct DAG order. // - // All files that have the same ModuleFullName will also have the same commit, or no commit. + // All files that have the same FullName will also have the same commit, or no commit. // This is enforced at construction time. Files() []ImageFile // GetFile gets the file for the root relative file path. @@ -337,7 +338,7 @@ func CloneImageFile(imageFile ImageFile) (ImageFile, error) { // The other attributes are already immutable, so we don't need to copy them. return NewImageFile( clonedDescriptor, - imageFile.ModuleFullName(), + imageFile.FullName(), imageFile.CommitID(), imageFile.ExternalPath(), imageFile.LocalPath(), @@ -377,7 +378,7 @@ func NewImageForProto(protoImage *imagev1.Image, options ...NewImageForProtoOpti var isImport bool var isSyntaxUnspecified bool var unusedDependencyIndexes []int32 - var moduleFullName bufmodule.ModuleFullName + var moduleFullName bufparse.FullName var commitID uuid.UUID var err error if protoImageFileExtension := protoImageFile.GetBufExtension(); protoImageFileExtension != nil { @@ -386,7 +387,7 @@ func NewImageForProto(protoImage *imagev1.Image, options ...NewImageForProtoOpti unusedDependencyIndexes = protoImageFileExtension.GetUnusedDependency() if protoModuleInfo := protoImageFileExtension.GetModuleInfo(); protoModuleInfo != nil { if protoModuleName := protoModuleInfo.GetName(); protoModuleName != nil { - moduleFullName, err = bufmodule.NewModuleFullName( + moduleFullName, err = bufparse.NewFullName( protoModuleName.GetRemote(), protoModuleName.GetOwner(), protoModuleName.GetRepository(), diff --git a/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go b/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go index 9bfb1d6ac8..d842395f5f 100644 --- a/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go +++ b/private/bufpkg/bufimage/bufimagemodify/bufimagemodify_test.go @@ -25,6 +25,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufimage/bufimagetesting" "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduletesting" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/slogtestext" "github.com/google/go-cmp/cmp" "github.com/google/uuid" @@ -38,13 +39,13 @@ func TestModifyImage(t *testing.T) { t.Parallel() testcases := []struct { description string - dirPathToModuleFullName map[string]string + dirPathToFullName map[string]string config bufconfig.GenerateManagedConfig filePathToExpectedOptions map[string]*descriptorpb.FileOptions }{ { description: "nil_config", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -74,7 +75,7 @@ func TestModifyImage(t *testing.T) { }, { description: "empty_config", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -154,7 +155,7 @@ func TestModifyImage(t *testing.T) { includeSourceInfo := includeSourceInfo t.Run(testcase.description, func(t *testing.T) { t.Parallel() - image := testGetImageFromDirs(t, testcase.dirPathToModuleFullName, includeSourceInfo) + image := testGetImageFromDirs(t, testcase.dirPathToFullName, includeSourceInfo) err := Modify( image, testcase.config, @@ -180,7 +181,7 @@ func TestModifyImageFile( t.Parallel() testcases := []struct { description string - dirPathToModuleFullName map[string]string + dirPathToFullName map[string]string config bufconfig.GenerateManagedConfig modifyFunc func(internal.MarkSweeper, bufimage.ImageFile, bufconfig.GenerateManagedConfig, ...ModifyOption) error filePathToExpectedOptions map[string]*descriptorpb.FileOptions @@ -188,7 +189,7 @@ func TestModifyImageFile( }{ { description: "cc_enable_arena", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -212,7 +213,7 @@ func TestModifyImageFile( }, { description: "csharp_namespace", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -249,7 +250,7 @@ func TestModifyImageFile( }, { description: "go_package", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -289,7 +290,7 @@ func TestModifyImageFile( }, { description: "java_package_prefix", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -383,7 +384,7 @@ func TestModifyImageFile( }, { description: "java_package_suffix", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -437,7 +438,7 @@ func TestModifyImageFile( }, { description: "java_package", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -490,7 +491,7 @@ func TestModifyImageFile( }, { description: "objc_class_prefix", - dirPathToModuleFullName: map[string]string{ + dirPathToFullName: map[string]string{ filepath.Join("testdata", "foo"): "buf.build/acme/foo", filepath.Join("testdata", "bar"): "buf.build/acme/bar", }, @@ -555,7 +556,7 @@ func TestModifyImageFile( includeSourceInfo := includeSourceInfo t.Run(testcase.description, func(t *testing.T) { t.Parallel() - image := testGetImageFromDirs(t, testcase.dirPathToModuleFullName, includeSourceInfo) + image := testGetImageFromDirs(t, testcase.dirPathToFullName, includeSourceInfo) sweeper := internal.NewMarkSweeper(image) // TODO FUTURE: check include source code info for filePath, expectedOptions := range testcase.filePathToExpectedOptions { @@ -770,7 +771,7 @@ func testGetImageFile( path string, moduleFullName string, ) bufimage.ImageFile { - parsedModuleFullName, err := bufmodule.ParseModuleFullName(moduleFullName) + parsedFullName, err := bufparse.ParseFullName(moduleFullName) require.NoError(t, err) return bufimagetesting.NewImageFile( t, @@ -778,7 +779,7 @@ func testGetImageFile( Name: proto.String(path), Syntax: proto.String("proto3"), }, - parsedModuleFullName, + parsedFullName, uuid.Nil, path, "", @@ -790,11 +791,11 @@ func testGetImageFile( func testGetImageFromDirs( t *testing.T, - dirPathToModuleFullName map[string]string, + dirPathToFullName map[string]string, includeSourceInfo bool, ) bufimage.Image { - moduleDatas := make([]bufmoduletesting.ModuleData, 0, len(dirPathToModuleFullName)) - for dirPath, moduleFullName := range dirPathToModuleFullName { + moduleDatas := make([]bufmoduletesting.ModuleData, 0, len(dirPathToFullName)) + for dirPath, moduleFullName := range dirPathToFullName { moduleDatas = append( moduleDatas, bufmoduletesting.ModuleData{ diff --git a/private/bufpkg/bufimage/bufimagemodify/field_option.go b/private/bufpkg/bufimage/bufimagemodify/field_option.go index b4dcd64e1e..d19e1d8222 100644 --- a/private/bufpkg/bufimage/bufimagemodify/field_option.go +++ b/private/bufpkg/bufimage/bufimagemodify/field_option.go @@ -47,7 +47,7 @@ func modifyJsType( config.Overrides(), func(override bufconfig.ManagedOverrideRule) bool { return override.FieldOption() == bufconfig.FieldOptionJSType && - fileMatchConfig(imageFile, override.Path(), override.ModuleFullName()) + fileMatchConfig(imageFile, override.Path(), override.FullName()) }, ) // Unless specified, js type is not modified. @@ -60,7 +60,7 @@ func modifyJsType( return (disable.FieldOption() == bufconfig.FieldOptionJSType || (disable.FieldOption() == bufconfig.FieldOptionUnspecified && disable.FileOption() == bufconfig.FileOptionUnspecified)) && - fileMatchConfig(imageFile, disable.Path(), disable.ModuleFullName()) + fileMatchConfig(imageFile, disable.Path(), disable.FullName()) }, ) // If the entire file is disabled, skip. diff --git a/private/bufpkg/bufimage/bufimagemodify/override.go b/private/bufpkg/bufimage/bufimagemodify/override.go index 1b0e9d41d8..b819d856fd 100644 --- a/private/bufpkg/bufimage/bufimagemodify/override.go +++ b/private/bufpkg/bufimage/bufimagemodify/override.go @@ -157,7 +157,7 @@ func stringOverrideFromConfig( overrideOptions.suffix = "" } for _, overrideRule := range config.Overrides() { - if !fileMatchConfig(imageFile, overrideRule.Path(), overrideRule.ModuleFullName()) { + if !fileMatchConfig(imageFile, overrideRule.Path(), overrideRule.FullName()) { continue } switch overrideRule.FileOption() { @@ -210,7 +210,7 @@ func overrideFromConfig[T bool | descriptorpb.FileOptions_OptimizeMode]( ) (*T, error) { var override *T for _, overrideRule := range config.Overrides() { - if !fileMatchConfig(imageFile, overrideRule.Path(), overrideRule.ModuleFullName()) { + if !fileMatchConfig(imageFile, overrideRule.Path(), overrideRule.FullName()) { continue } if overrideRule.FileOption() != fileOption { @@ -238,7 +238,7 @@ func isFileOptionDisabledForFile( if disableRule.FieldOption() != bufconfig.FieldOptionUnspecified { continue // FieldOption specified, not a matching rule. } - if !fileMatchConfig(imageFile, disableRule.Path(), disableRule.ModuleFullName()) { + if !fileMatchConfig(imageFile, disableRule.Path(), disableRule.FullName()) { continue } return true @@ -249,12 +249,12 @@ func isFileOptionDisabledForFile( func fileMatchConfig( imageFile bufimage.ImageFile, requiredPath string, - requiredModuleFullName string, + requiredFullName string, ) bool { if requiredPath != "" && !normalpath.EqualsOrContainsPath(requiredPath, imageFile.Path(), normalpath.Relative) { return false } - if requiredModuleFullName != "" && (imageFile.ModuleFullName() == nil || imageFile.ModuleFullName().String() != requiredModuleFullName) { + if requiredFullName != "" && (imageFile.FullName() == nil || imageFile.FullName().String() != requiredFullName) { return false } return true diff --git a/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go b/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go index f18e740e72..a6f23420d0 100644 --- a/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go +++ b/private/bufpkg/bufimage/bufimagetesting/bufimagetesting.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/bufbuild/buf/private/bufpkg/bufimage" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" "github.com/bufbuild/buf/private/pkg/protodescriptor" "github.com/google/uuid" @@ -33,7 +33,7 @@ import ( func NewImageFile( t testing.TB, fileDescriptor protodescriptor.FileDescriptor, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, commit uuid.UUID, externalPath string, localPath string, @@ -108,7 +108,7 @@ func normalizeImageFiles(t testing.TB, imageFiles []bufimage.ImageFile) []bufima imageFile.FileDescriptorProto().GetName(), imageFile.FileDescriptorProto().GetDependency()..., ), - imageFile.ModuleFullName(), + imageFile.FullName(), imageFile.CommitID(), imageFile.ExternalPath(), imageFile.LocalPath(), diff --git a/private/bufpkg/bufimage/bufimageutil/bufimageutil.go b/private/bufpkg/bufimage/bufimageutil/bufimageutil.go index 152eecd89b..414dbb7ef2 100644 --- a/private/bufpkg/bufimage/bufimageutil/bufimageutil.go +++ b/private/bufpkg/bufimage/bufimageutil/bufimageutil.go @@ -991,7 +991,7 @@ func stripSourceRetentionOptionsFromFile(imageFile bufimage.ImageFile) (bufimage } return bufimage.NewImageFile( updatedFileDescriptor, - imageFile.ModuleFullName(), + imageFile.FullName(), imageFile.CommitID(), imageFile.ExternalPath(), imageFile.LocalPath(), diff --git a/private/bufpkg/bufimage/build_image.go b/private/bufpkg/bufimage/build_image.go index a29555014e..136d88b09f 100644 --- a/private/bufpkg/bufimage/build_image.go +++ b/private/bufpkg/bufimage/build_image.go @@ -346,7 +346,7 @@ func getImageFilesRec( _, syntaxUnspecified := syntaxUnspecifiedFilenames[path] imageFile, err := NewImageFile( fileDescriptorProto, - parserAccessorHandler.ModuleFullName(path), + parserAccessorHandler.FullName(path), parserAccessorHandler.CommitID(path), // if empty, defaults to path parserAccessorHandler.ExternalPath(path), diff --git a/private/bufpkg/bufimage/image.go b/private/bufpkg/bufimage/image.go index 0de02f1378..a35343b30b 100644 --- a/private/bufpkg/bufimage/image.go +++ b/private/bufpkg/bufimage/image.go @@ -48,7 +48,7 @@ func newImage(files []ImageFile, reorder bool, resolver protoencoding.Resolver) return nil, fmt.Errorf("duplicate file: %s", path) } pathToImageFile[path] = file - if moduleFullName := file.ModuleFullName(); moduleFullName != nil { + if moduleFullName := file.FullName(); moduleFullName != nil { moduleFullNameString := moduleFullName.String() existing, ok := moduleFullNameStringToCommitIDAndFilePath[moduleFullNameString] if ok { diff --git a/private/bufpkg/bufimage/image_file.go b/private/bufpkg/bufimage/image_file.go index 32aacd85e4..9830ce8745 100644 --- a/private/bufpkg/bufimage/image_file.go +++ b/private/bufpkg/bufimage/image_file.go @@ -15,7 +15,7 @@ package bufimage import ( - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/protodescriptor" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/google/uuid" @@ -26,7 +26,7 @@ var _ ImageFile = &imageFile{} type imageFile struct { fileDescriptorProto *descriptorpb.FileDescriptorProto - moduleFullName bufmodule.ModuleFullName + moduleFullName bufparse.FullName commitID uuid.UUID externalPath string localPath string @@ -37,7 +37,7 @@ type imageFile struct { func newImageFile( fileDescriptor protodescriptor.FileDescriptor, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, externalPath string, localPath string, @@ -62,7 +62,7 @@ func newImageFile( func newImageFileNoValidate( fileDescriptor protodescriptor.FileDescriptor, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, externalPath string, localPath string, @@ -103,7 +103,7 @@ func (f *imageFile) LocalPath() string { return f.localPath } -func (f *imageFile) ModuleFullName() bufmodule.ModuleFullName { +func (f *imageFile) FullName() bufparse.FullName { return f.moduleFullName } diff --git a/private/bufpkg/bufimage/module_image_file_info.go b/private/bufpkg/bufimage/module_image_file_info.go index a4905e2858..0f5b88baad 100644 --- a/private/bufpkg/bufimage/module_image_file_info.go +++ b/private/bufpkg/bufimage/module_image_file_info.go @@ -16,6 +16,7 @@ package bufimage import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/google/uuid" ) @@ -29,8 +30,8 @@ func newModuleImageFileInfo(fileInfo bufmodule.FileInfo) *moduleImageFileInfo { } } -func (p *moduleImageFileInfo) ModuleFullName() bufmodule.ModuleFullName { - return p.FileInfo.Module().ModuleFullName() +func (p *moduleImageFileInfo) FullName() bufparse.FullName { + return p.FileInfo.Module().FullName() } func (p *moduleImageFileInfo) CommitID() uuid.UUID { diff --git a/private/bufpkg/bufimage/parser_accessor_handler.go b/private/bufpkg/bufimage/parser_accessor_handler.go index 496f781689..313180b8b5 100644 --- a/private/bufpkg/bufimage/parser_accessor_handler.go +++ b/private/bufpkg/bufimage/parser_accessor_handler.go @@ -23,20 +23,21 @@ import ( "sync" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/gen/data/datawkt" "github.com/google/uuid" "go.uber.org/multierr" ) type parserAccessorHandler struct { - ctx context.Context - moduleReadBucket bufmodule.ModuleReadBucket - pathToExternalPath map[string]string - pathToLocalPath map[string]string - nonImportPaths map[string]struct{} - pathToModuleFullName map[string]bufmodule.ModuleFullName - pathToCommitID map[string]uuid.UUID - lock sync.RWMutex + ctx context.Context + moduleReadBucket bufmodule.ModuleReadBucket + pathToExternalPath map[string]string + pathToLocalPath map[string]string + nonImportPaths map[string]struct{} + pathToFullName map[string]bufparse.FullName + pathToCommitID map[string]uuid.UUID + lock sync.RWMutex } func newParserAccessorHandler( @@ -44,13 +45,13 @@ func newParserAccessorHandler( moduleReadBucket bufmodule.ModuleReadBucket, ) *parserAccessorHandler { return &parserAccessorHandler{ - ctx: ctx, - moduleReadBucket: moduleReadBucket, - pathToExternalPath: make(map[string]string), - pathToLocalPath: make(map[string]string), - nonImportPaths: make(map[string]struct{}), - pathToModuleFullName: make(map[string]bufmodule.ModuleFullName), - pathToCommitID: make(map[string]uuid.UUID), + ctx: ctx, + moduleReadBucket: moduleReadBucket, + pathToExternalPath: make(map[string]string), + pathToLocalPath: make(map[string]string), + nonImportPaths: make(map[string]struct{}), + pathToFullName: make(map[string]bufparse.FullName), + pathToCommitID: make(map[string]uuid.UUID), } } @@ -88,7 +89,7 @@ func (p *parserAccessorHandler) Open(path string) (_ io.ReadCloser, retErr error path, moduleFile.ExternalPath(), moduleFile.LocalPath(), - moduleFile.Module().ModuleFullName(), + moduleFile.Module().FullName(), moduleFile.Module().CommitID(), ); err != nil { return nil, err @@ -115,11 +116,11 @@ func (p *parserAccessorHandler) LocalPath(path string) string { return p.pathToLocalPath[path] } -// ModuleFullName returns nil if not available. -func (p *parserAccessorHandler) ModuleFullName(path string) bufmodule.ModuleFullName { +// FullName returns nil if not available. +func (p *parserAccessorHandler) FullName(path string) bufparse.FullName { p.lock.RLock() defer p.lock.RUnlock() - return p.pathToModuleFullName[path] // nil is a valid value. + return p.pathToFullName[path] // nil is a valid value. } // CommitID returns empty if not available. @@ -133,7 +134,7 @@ func (p *parserAccessorHandler) addPath( path string, externalPath string, localPath string, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, ) error { p.lock.Lock() @@ -157,7 +158,7 @@ func (p *parserAccessorHandler) addPath( } } if moduleFullName != nil { - p.pathToModuleFullName[path] = moduleFullName + p.pathToFullName[path] = moduleFullName } if commitID != uuid.Nil { p.pathToCommitID[path] = commitID diff --git a/private/bufpkg/bufimage/util.go b/private/bufpkg/bufimage/util.go index a6eb391652..20df2a4507 100644 --- a/private/bufpkg/bufimage/util.go +++ b/private/bufpkg/bufimage/util.go @@ -18,7 +18,7 @@ import ( "errors" "fmt" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/gen/data/datawkt" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" "github.com/bufbuild/buf/private/pkg/normalpath" @@ -311,7 +311,7 @@ func imageFileToProtoImageFile(imageFile ImageFile) (*imagev1.ImageFile, error) imageFile.IsImport(), imageFile.IsSyntaxUnspecified(), imageFile.UnusedDependencyIndexes(), - imageFile.ModuleFullName(), + imageFile.FullName(), protoCommitID, ), nil } @@ -321,7 +321,7 @@ func fileDescriptorProtoToProtoImageFile( isImport bool, isSyntaxUnspecified bool, unusedDependencyIndexes []int32, - moduleFullName bufmodule.ModuleFullName, + moduleFullName bufparse.FullName, // Dashless moduleProtoCommitID string, ) *imagev1.ImageFile { diff --git a/private/bufpkg/bufimage/util_test.go b/private/bufpkg/bufimage/util_test.go index 46a8e8da7b..82259447a1 100644 --- a/private/bufpkg/bufimage/util_test.go +++ b/private/bufpkg/bufimage/util_test.go @@ -18,7 +18,7 @@ import ( "bytes" "testing" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1" "github.com/bufbuild/buf/private/pkg/protoencoding" "github.com/bufbuild/buf/private/pkg/uuidutil" @@ -143,7 +143,7 @@ func TestImageToProtoPreservesUnrecognizedFields(t *testing.T) { otherData = protowire.AppendFixed32(otherData, 23456) fileDescriptor.ProtoReflect().SetUnknown(otherData) - moduleFullName, err := bufmodule.ParseModuleFullName("buf.build/foo/bar") + moduleFullName, err := bufparse.ParseFullName("buf.build/foo/bar") require.NoError(t, err) commitID, err := uuidutil.New() require.NoError(t, err) @@ -176,7 +176,7 @@ func TestImageToProtoPreservesUnrecognizedFields(t *testing.T) { // if we go back through an image file, we should strip out the // buf extension unknown bytes but preserve the rest - moduleFullName, err = bufmodule.ParseModuleFullName("buf.build/abc/def") + moduleFullName, err = bufparse.ParseFullName("buf.build/abc/def") require.NoError(t, err) // NB: intentionally different metadata commitID2, err := uuidutil.New() diff --git a/private/bufpkg/bufimage/well_known_type_image_file_info.go b/private/bufpkg/bufimage/well_known_type_image_file_info.go index d6a4c0007c..be2d127f06 100644 --- a/private/bufpkg/bufimage/well_known_type_image_file_info.go +++ b/private/bufpkg/bufimage/well_known_type_image_file_info.go @@ -15,7 +15,7 @@ package bufimage import ( - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/storage" "github.com/google/uuid" ) @@ -38,7 +38,7 @@ func newWellKnownTypeImageFileInfo( } } -func (p *wellKnownTypeImageFileInfo) ModuleFullName() bufmodule.ModuleFullName { +func (p *wellKnownTypeImageFileInfo) FullName() bufparse.FullName { return nil } diff --git a/private/bufpkg/bufmodule/added_module.go b/private/bufpkg/bufmodule/added_module.go index 7e54692309..611fa9a333 100644 --- a/private/bufpkg/bufmodule/added_module.go +++ b/private/bufpkg/bufmodule/added_module.go @@ -89,7 +89,7 @@ func (a *addedModule) IsTarget() bool { // OpaqueID returns the OpaqueID of the addedModule. func (a *addedModule) OpaqueID() string { if a.remoteModuleKey != nil { - return a.remoteModuleKey.ModuleFullName().String() + return a.remoteModuleKey.FullName().String() } return a.localModule.OpaqueID() } @@ -121,14 +121,14 @@ func (a *addedModule) ToModule( return nil, syserror.Newf("expected 1 ModuleData, got %d", len(moduleDatas)) } moduleData := moduleDatas[0] - if moduleData.ModuleKey().ModuleFullName() == nil { - return nil, syserror.New("got nil ModuleFullName for a ModuleKey returned from a ModuleDataProvider") + if moduleData.ModuleKey().FullName() == nil { + return nil, syserror.New("got nil FullName for a ModuleKey returned from a ModuleDataProvider") } - if a.remoteModuleKey.ModuleFullName().String() != moduleData.ModuleKey().ModuleFullName().String() { + if a.remoteModuleKey.FullName().String() != moduleData.ModuleKey().FullName().String() { return nil, syserror.Newf( - "mismatched ModuleFullName from ModuleDataProvider: input %q, output %q", - a.remoteModuleKey.ModuleFullName().String(), - moduleData.ModuleKey().ModuleFullName().String(), + "mismatched FullName from ModuleDataProvider: input %q, output %q", + a.remoteModuleKey.FullName().String(), + moduleData.ModuleKey().FullName().String(), ) } return moduleData, nil @@ -255,7 +255,7 @@ func (a *addedModule) ToModule( // To accomplish this, we need to take the dependencies of the declared ModuleKeys (ie what // the Module actually says is in its buf.lock). This function enables us to do that for // digest calculations. Within the Module, we say that if we get a remote Module, use the - // declared ModuleKeys instead of whatever Module we have resolved to for a given ModuleFullName. + // declared ModuleKeys instead of whatever Module we have resolved to for a given FullName. getDeclaredDepModuleKeysB5 := func() ([]ModuleKey, error) { moduleData, err := getModuleData() if err != nil { @@ -288,7 +288,7 @@ func (a *addedModule) ToModule( // from B4 to B5 by using the commit provider. commitKeysToFetch := make([]CommitKey, len(declaredDepModuleKeys)) for i, declaredDepModuleKey := range declaredDepModuleKeys { - commitKey, err := NewCommitKey(declaredDepModuleKey.ModuleFullName().Registry(), declaredDepModuleKey.CommitID(), DigestTypeB5) + commitKey, err := NewCommitKey(declaredDepModuleKey.FullName().Registry(), declaredDepModuleKey.CommitID(), DigestTypeB5) if err != nil { return nil, err } @@ -316,7 +316,7 @@ func (a *addedModule) ToModule( getBucket, "", "", - a.remoteModuleKey.ModuleFullName(), + a.remoteModuleKey.FullName(), a.remoteModuleKey.CommitID(), a.isTarget, false, @@ -343,9 +343,9 @@ func (a *addedModule) ToModule( // // When returned, all modules have unique opaqueIDs and Digests. // -// Note: Modules with the same ModuleFullName will automatically have the same commit and Digest after this, -// as there will be exactly one Module with a given ModuleFullName, given that an OpaqueID will be equal -// for Modules with equal ModuleFullNames. +// Note: Modules with the same FullName will automatically have the same commit and Digest after this, +// as there will be exactly one Module with a given FullName, given that an OpaqueID will be equal +// for Modules with equal FullNames. func getUniqueSortedAddedModulesByOpaqueID( ctx context.Context, commitProvider CommitProvider, @@ -430,9 +430,9 @@ func selectAddedModuleForOpaqueIDIgnoreTargeting( // has already been taken into account. // // All addedModules are assumed to have the same OpaqueID, and therefore the same -// ModuleFullName, since they are remote Modules. We validate this. +// FullName, since they are remote Modules. We validate this. // -// Note that there may be straight duplicates, ie two modules with the same ModuleFullName and CommitID! This +// Note that there may be straight duplicates, ie two modules with the same FullName and CommitID! This // function deduplicates these. // // The ModuleKey with the latest create time is used. @@ -456,13 +456,13 @@ func selectRemoteAddedModuleForOpaqueIDIgnoreTargeting( if moduleFullNameStrings := slicesext.ToUniqueSorted( slicesext.Map( addedModules, - func(addedModule *addedModule) string { return addedModule.remoteModuleKey.ModuleFullName().String() }, + func(addedModule *addedModule) string { return addedModule.remoteModuleKey.FullName().String() }, ), ); len(moduleFullNameStrings) > 1 { - return nil, syserror.Newf("multiple ModuleFullNames detected in selectRemoteAddedModuleForOpaqueIDIgnoreTargeting: %s", strings.Join(moduleFullNameStrings, ", ")) + return nil, syserror.Newf("multiple FullNames detected in selectRemoteAddedModuleForOpaqueIDIgnoreTargeting: %s", strings.Join(moduleFullNameStrings, ", ")) } - // We now know that we have >1 addedModules, and all of them have a remoteModuleKey, and all the remoteModuleKeys have the same ModuleFullName. + // We now know that we have >1 addedModules, and all of them have a remoteModuleKey, and all the remoteModuleKeys have the same FullName. // Now, we deduplicate by commit ID. If we end up with a single Module, we return that, otherwise we select exactly one Module // based on the create time of the corresponding commit ID. diff --git a/private/bufpkg/bufmodule/bufmodule_test.go b/private/bufpkg/bufmodule/bufmodule_test.go index 9efcec6f8e..fedb29d74d 100644 --- a/private/bufpkg/bufmodule/bufmodule_test.go +++ b/private/bufpkg/bufmodule/bufmodule_test.go @@ -21,6 +21,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduletesting" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/dag/dagtest" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/slogtestext" @@ -92,19 +93,19 @@ func TestBasic(t *testing.T) { // // Remember, the bsrProvider is just acting like a BSR; if we actually want to // say dependencies are part of our workspace, we need to add them! We do so now. - moduleRefExtdep1, err := bufmodule.NewModuleRef("buf.build", "foo", "extdep1", "") + moduleRefExtdep1, err := bufparse.NewRef("buf.build", "foo", "extdep1", "") require.NoError(t, err) - moduleRefExtdep2, err := bufmodule.NewModuleRef("buf.build", "foo", "extdep2", "") + moduleRefExtdep2, err := bufparse.NewRef("buf.build", "foo", "extdep2", "") require.NoError(t, err) - moduleRefExtdep3, err := bufmodule.NewModuleRef("buf.build", "foo", "extdep3", "") + moduleRefExtdep3, err := bufparse.NewRef("buf.build", "foo", "extdep3", "") require.NoError(t, err) - moduleRefExtdep4, err := bufmodule.NewModuleRef("buf.build", "foo", "extdep4", "") + moduleRefExtdep4, err := bufparse.NewRef("buf.build", "foo", "extdep4", "") require.NoError(t, err) - moduleRefModule2, err := bufmodule.NewModuleRef("buf.build", "bar", "module2", "") + moduleRefModule2, err := bufparse.NewRef("buf.build", "bar", "module2", "") require.NoError(t, err) moduleKeys, err := bsrProvider.GetModuleKeysForModuleRefs( ctx, - []bufmodule.ModuleRef{ + []bufparse.Ref{ moduleRefExtdep1, moduleRefExtdep2, moduleRefExtdep3, @@ -138,7 +139,7 @@ func TestBasic(t *testing.T) { // // This module is also in the BSR, but we'll prefer the local sources when // we do ModuleSetBuilder.Build(). - moduleFullName, err := bufmodule.NewModuleFullName("buf.build", "bar", "module2") + moduleFullName, err := bufparse.NewFullName("buf.build", "bar", "module2") require.NoError(t, err) moduleSetBuilder.AddLocalModule( testNewBucketForPathToData( @@ -157,7 +158,7 @@ func TestBasic(t *testing.T) { ), "path/to/module2", true, - bufmodule.LocalModuleWithModuleFullName(moduleFullName), + bufmodule.LocalModuleWithFullName(moduleFullName), // We're going to exclude the files in the foo directory from targeting, // ie foo/module2_excluded.proto. This file will still be in the module, // but will not be marked as a target. diff --git a/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go b/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go index d710cec37b..465dfe3145 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/commit_provider.go @@ -84,7 +84,7 @@ func (a *commitProvider) GetCommitsForModuleKeys( registryToIndexedModuleKeys := slicesext.ToIndexedValuesMap( moduleKeys, func(moduleKey bufmodule.ModuleKey) string { - return moduleKey.ModuleFullName().Registry() + return moduleKey.FullName().Registry() }, ) indexedCommits := make([]slicesext.Indexed[bufmodule.Commit], 0, len(moduleKeys)) diff --git a/private/bufpkg/bufmodule/bufmoduleapi/convert.go b/private/bufpkg/bufmodule/bufmoduleapi/convert.go index 30906500cb..6daa5bfb94 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/convert.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/convert.go @@ -23,6 +23,7 @@ import ( modulev1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1beta1" "github.com/bufbuild/buf/private/bufpkg/bufcas" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" "github.com/bufbuild/buf/private/pkg/uuidutil" @@ -211,12 +212,12 @@ func commitIDsToV1Beta1ProtoResourceRefs(commitIDs []uuid.UUID) []*modulev1beta1 return slicesext.Map(commitIDs, commitIDToV1Beta1ProtoResourceRef) } -func moduleRefToV1ProtoResourceRef(moduleRef bufmodule.ModuleRef) *modulev1.ResourceRef { +func moduleRefToV1ProtoResourceRef(moduleRef bufparse.Ref) *modulev1.ResourceRef { return &modulev1.ResourceRef{ Value: &modulev1.ResourceRef_Name_{ Name: &modulev1.ResourceRef_Name{ - Owner: moduleRef.ModuleFullName().Owner(), - Module: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Module: moduleRef.FullName().Name(), Child: &modulev1.ResourceRef_Name_Ref{ Ref: moduleRef.Ref(), }, @@ -225,16 +226,16 @@ func moduleRefToV1ProtoResourceRef(moduleRef bufmodule.ModuleRef) *modulev1.Reso } } -func moduleRefsToV1ProtoResourceRefs(moduleRefs []bufmodule.ModuleRef) []*modulev1.ResourceRef { +func moduleRefsToV1ProtoResourceRefs(moduleRefs []bufparse.Ref) []*modulev1.ResourceRef { return slicesext.Map(moduleRefs, moduleRefToV1ProtoResourceRef) } -func moduleRefToV1Beta1ProtoResourceRef(moduleRef bufmodule.ModuleRef) *modulev1beta1.ResourceRef { +func moduleRefToV1Beta1ProtoResourceRef(moduleRef bufparse.Ref) *modulev1beta1.ResourceRef { return &modulev1beta1.ResourceRef{ Value: &modulev1beta1.ResourceRef_Name_{ Name: &modulev1beta1.ResourceRef_Name{ - Owner: moduleRef.ModuleFullName().Owner(), - Module: moduleRef.ModuleFullName().Name(), + Owner: moduleRef.FullName().Owner(), + Module: moduleRef.FullName().Name(), Child: &modulev1beta1.ResourceRef_Name_Ref{ Ref: moduleRef.Ref(), }, @@ -243,7 +244,7 @@ func moduleRefToV1Beta1ProtoResourceRef(moduleRef bufmodule.ModuleRef) *modulev1 } } -func moduleRefsToV1Beta1ProtoResourceRefs(moduleRefs []bufmodule.ModuleRef) []*modulev1beta1.ResourceRef { +func moduleRefsToV1Beta1ProtoResourceRefs(moduleRefs []bufparse.Ref) []*modulev1beta1.ResourceRef { return slicesext.Map(moduleRefs, moduleRefToV1Beta1ProtoResourceRef) } diff --git a/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go b/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go index c97c4f7f59..13bdaab04d 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/module_data_provider.go @@ -22,6 +22,7 @@ import ( modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" @@ -84,7 +85,7 @@ func (a *moduleDataProvider) GetModuleDatasForModuleKeys( if err != nil { return nil, err } - if _, err := bufmodule.ModuleFullNameStringToUniqueValue(moduleKeys); err != nil { + if _, err := bufparse.FullNameStringToUniqueValue(moduleKeys); err != nil { return nil, err } @@ -95,7 +96,7 @@ func (a *moduleDataProvider) GetModuleDatasForModuleKeys( registryToIndexedModuleKeys := slicesext.ToIndexedValuesMap( moduleKeys, func(moduleKey bufmodule.ModuleKey) string { - return moduleKey.ModuleFullName().Registry() + return moduleKey.FullName().Registry() }, ) indexedModuleDatas := make([]slicesext.Indexed[bufmodule.ModuleData], 0, len(moduleKeys)) @@ -168,7 +169,7 @@ func (a *moduleDataProvider) getIndexedModuleDatasForRegistryAndIndexedModuleKey sort.Slice( depModuleKeys, func(i int, j int) bool { - return depModuleKeys[i].ModuleFullName().String() < depModuleKeys[j].ModuleFullName().String() + return depModuleKeys[i].FullName().String() < depModuleKeys[j].FullName().String() }, ) @@ -276,7 +277,7 @@ func (a *moduleDataProvider) warnIfDeprecated( return err } if v1ProtoModule.State == modulev1.ModuleState_MODULE_STATE_DEPRECATED { - a.logger.Warn(fmt.Sprintf("%s is deprecated", moduleKey.ModuleFullName().String())) + a.logger.Warn(fmt.Sprintf("%s is deprecated", moduleKey.FullName().String())) } return nil } diff --git a/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_universal_proto_commit.go b/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_universal_proto_commit.go index d38a020cea..8a13cb555d 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_universal_proto_commit.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/module_key_for_universal_proto_commit.go @@ -19,6 +19,7 @@ import ( "fmt" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/uuidutil" ) @@ -29,7 +30,7 @@ func getModuleKeyForUniversalProtoCommit( registry string, universalProtoCommit *universalProtoCommit, ) (bufmodule.ModuleKey, error) { - moduleFullName, err := getModuleFullNameForRegistryProtoOwnerIDProtoModuleID( + moduleFullName, err := getFullNameForRegistryProtoOwnerIDProtoModuleID( ctx, v1ProtoModuleProvider, v1ProtoOwnerProvider, @@ -53,7 +54,7 @@ func getModuleKeyForUniversalProtoCommit( ) } -func getModuleFullNameForRegistryProtoOwnerIDProtoModuleID( +func getFullNameForRegistryProtoOwnerIDProtoModuleID( ctx context.Context, v1ProtoModuleProvider *v1ProtoModuleProvider, v1ProtoOwnerProvider *v1ProtoOwnerProvider, @@ -62,7 +63,7 @@ func getModuleFullNameForRegistryProtoOwnerIDProtoModuleID( protoOwnerID string, // Dashless protoModuleID string, -) (bufmodule.ModuleFullName, error) { +) (bufparse.FullName, error) { v1ProtoModule, err := v1ProtoModuleProvider.getV1ProtoModuleForProtoModuleID( ctx, registry, @@ -88,7 +89,7 @@ func getModuleFullNameForRegistryProtoOwnerIDProtoModuleID( default: return nil, fmt.Errorf("proto Owner did not have a User or Organization: %v", v1ProtoOwner) } - return bufmodule.NewModuleFullName( + return bufparse.NewFullName( registry, ownerName, v1ProtoModule.Name, diff --git a/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go b/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go index c1c576ec35..7051a21358 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/module_key_provider.go @@ -19,6 +19,7 @@ import ( "log/slog" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/uuidutil" @@ -60,13 +61,13 @@ func newModuleKeyProvider( func (a *moduleKeyProvider) GetModuleKeysForModuleRefs( ctx context.Context, - moduleRefs []bufmodule.ModuleRef, + moduleRefs []bufparse.Ref, digestType bufmodule.DigestType, ) ([]bufmodule.ModuleKey, error) { // Check unique. if _, err := slicesext.ToUniqueValuesMapError( moduleRefs, - func(moduleRef bufmodule.ModuleRef) (string, error) { + func(moduleRef bufparse.Ref) (string, error) { return moduleRef.String(), nil }, ); err != nil { @@ -75,8 +76,8 @@ func (a *moduleKeyProvider) GetModuleKeysForModuleRefs( registryToIndexedModuleRefs := slicesext.ToIndexedValuesMap( moduleRefs, - func(moduleRef bufmodule.ModuleRef) string { - return moduleRef.ModuleFullName().Registry() + func(moduleRef bufparse.Ref) string { + return moduleRef.FullName().Registry() }, ) indexedModuleKeys := make([]slicesext.Indexed[bufmodule.ModuleKey], 0, len(moduleRefs)) @@ -98,7 +99,7 @@ func (a *moduleKeyProvider) GetModuleKeysForModuleRefs( func (a *moduleKeyProvider) getIndexedModuleKeysForRegistryAndIndexedModuleRefs( ctx context.Context, registry string, - indexedModuleRefs []slicesext.Indexed[bufmodule.ModuleRef], + indexedModuleRefs []slicesext.Indexed[bufparse.Ref], digestType bufmodule.DigestType, ) ([]slicesext.Indexed[bufmodule.ModuleKey], error) { universalProtoCommits, err := getUniversalProtoCommitsForRegistryAndModuleRefs(ctx, a.moduleClientProvider, registry, slicesext.IndexedToValues(indexedModuleRefs), digestType) @@ -114,7 +115,7 @@ func (a *moduleKeyProvider) getIndexedModuleKeysForRegistryAndIndexedModuleRefs( } moduleKey, err := bufmodule.NewModuleKey( // Note we don't have to resolve owner_name and module_name since we already have them. - indexedModuleRefs[i].Value.ModuleFullName(), + indexedModuleRefs[i].Value.FullName(), commitID, func() (bufmodule.Digest, error) { // Do not call getModuleKeyForProtoCommit, we already have the owner and module names. diff --git a/private/bufpkg/bufmodule/bufmoduleapi/registry.go b/private/bufpkg/bufmodule/bufmoduleapi/registry.go index 894cb146f7..bcb289047d 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/registry.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/registry.go @@ -19,6 +19,7 @@ import ( "strings" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/gen/data/datalegacyfederation" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" @@ -28,8 +29,8 @@ import ( // we have way bigger problems than this hardcoded variable. const defaultPublicRegistry = "buf.build" -type hasModuleFullName interface { - ModuleFullName() bufmodule.ModuleFullName +type hasFullName interface { + FullName() bufparse.FullName } // getPrimarySecondaryRegistry returns the primary and secondary registry for a call that supports @@ -45,7 +46,7 @@ type hasModuleFullName interface { // beyond a non-public registry depending on buf.build. // // This is used to support legacy federation. -func getPrimarySecondaryRegistry[T hasModuleFullName](s []T, publicRegistry string) (string, string, error) { +func getPrimarySecondaryRegistry[T hasFullName](s []T, publicRegistry string) (string, string, error) { if len(s) == 0 { return "", "", syserror.New("must have at least one value in getPrimarySecondaryRegistry") } @@ -71,7 +72,7 @@ func getPrimarySecondaryRegistry[T hasModuleFullName](s []T, publicRegistry stri } } -func isLegacyFederationAllowed[T hasModuleFullName](s []T, additionalLegacyFederationRegistry string) (bool, error) { +func isLegacyFederationAllowed[T hasFullName](s []T, additionalLegacyFederationRegistry string) (bool, error) { registries, err := getRegistries(s) if err != nil { return false, err @@ -93,13 +94,13 @@ func isLegacyFederationAllowed[T hasModuleFullName](s []T, additionalLegacyFeder return false, nil } -func getRegistries[T hasModuleFullName](s []T) ([]string, error) { +func getRegistries[T hasFullName](s []T) ([]string, error) { registryMap, err := slicesext.ToValuesMapError( s, func(e T) (string, error) { - moduleFullName := e.ModuleFullName() + moduleFullName := e.FullName() if moduleFullName == nil { - return "", syserror.Newf("no ModuleFullName for %v", e) + return "", syserror.Newf("no FullName for %v", e) } registry := moduleFullName.Registry() if registry == "" { @@ -123,7 +124,7 @@ func getSingleRegistryForContentModules(contentModules []bufmodule.Module) (stri } var registry string for _, module := range contentModules { - moduleFullName := module.ModuleFullName() + moduleFullName := module.FullName() if moduleFullName == nil { return "", syserror.Newf("expected module name for %s", module.Description()) } diff --git a/private/bufpkg/bufmodule/bufmoduleapi/universal_proto_commit.go b/private/bufpkg/bufmodule/bufmoduleapi/universal_proto_commit.go index f2cc9f2555..5ac5740009 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/universal_proto_commit.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/universal_proto_commit.go @@ -23,6 +23,7 @@ import ( modulev1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1beta1" "connectrpc.com/connect" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/bufpkg/bufregistryapi/bufregistryapimodule" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" @@ -123,7 +124,7 @@ func getUniversalProtoCommitsForRegistryAndModuleRefs( bufregistryapimodule.V1Beta1CommitServiceClientProvider }, registry string, - moduleRefs []bufmodule.ModuleRef, + moduleRefs []bufparse.Ref, digestType bufmodule.DigestType, ) ([]*universalProtoCommit, error) { switch digestType { diff --git a/private/bufpkg/bufmodule/bufmoduleapi/uploader.go b/private/bufpkg/bufmodule/bufmoduleapi/uploader.go index ff78d879b4..fef54b8b02 100644 --- a/private/bufpkg/bufmodule/bufmoduleapi/uploader.go +++ b/private/bufpkg/bufmodule/bufmoduleapi/uploader.go @@ -111,7 +111,7 @@ func (a *uploader) Upload( // Only push named modules to the registry. Any dependencies for named modules must have a name. // Local unnamed modules can be excluded if the UploadWithExcludeUnnamed option is set. contentModules, err = slicesext.FilterError(contentModules, func(module bufmodule.Module) (bool, error) { - moduleName := module.ModuleFullName() + moduleName := module.FullName() if moduleName == nil { moduleDescription := module.Description() if uploadOptions.ExcludeUnnamed() { @@ -125,7 +125,7 @@ func (a *uploader) Upload( return false, err } if allDepModuleDescriptions := slicesext.Reduce(deps, func(allDepModuleDescriptions []string, dep bufmodule.ModuleDep) []string { - if moduleName := dep.ModuleFullName(); moduleName == nil { + if moduleName := dep.FullName(); moduleName == nil { return append(allDepModuleDescriptions, dep.Description()) } return allDepModuleDescriptions @@ -202,7 +202,7 @@ func (a *uploader) Upload( strings.Join(slicesext.Map( contentModules, func(module bufmodule.Module) string { - return module.ModuleFullName().String() + return module.FullName().String() }, ), ", "), strings.Join(contentModuleSortedDefaultLabels, ", "), @@ -268,8 +268,8 @@ func (a *uploader) Upload( slicesext.ToValuesMap( remoteDeps, func(remoteDep bufmodule.RemoteDep) string { - // We've already validated two or three times that ModuleFullName is present here. - return remoteDep.ModuleFullName().Registry() + // We've already validated two or three times that FullName is present here. + return remoteDep.FullName().Registry() }, ), ) @@ -336,11 +336,11 @@ func (a *uploader) Upload( commits := make([]bufmodule.Commit, len(universalProtoCommits)) for i, universalProtoCommit := range universalProtoCommits { universalProtoCommit := universalProtoCommit - // This is how we get the ModuleFullName without calling the ModuleService or OwnerService. + // This is how we get the FullName without calling the ModuleService or OwnerService. // // We've maintained ordering throughout this function, so we can do this. // The API returns Commits in the same order as the Contents. - moduleFullName := contentModules[i].ModuleFullName() + moduleFullName := contentModules[i].FullName() commitID, err := uuidutil.FromDashless(universalProtoCommit.ID) if err != nil { return nil, err @@ -384,10 +384,10 @@ func (a *uploader) createContentModuleIfNotExist( { OwnerRef: &ownerv1.OwnerRef{ Value: &ownerv1.OwnerRef_Name{ - Name: contentModule.ModuleFullName().Owner(), + Name: contentModule.FullName().Owner(), }, }, - Name: contentModule.ModuleFullName().Name(), + Name: contentModule.FullName().Name(), Visibility: v1ProtoCreateModuleVisibility, DefaultLabelName: createDefaultLabel, }, @@ -431,8 +431,8 @@ func (a *uploader) validateContentModulesExist( return &modulev1.ModuleRef{ Value: &modulev1.ModuleRef_Name_{ Name: &modulev1.ModuleRef_Name{ - Owner: module.ModuleFullName().Owner(), - Module: module.ModuleFullName().Name(), + Owner: module.FullName().Owner(), + Module: module.FullName().Name(), }, }, } @@ -457,10 +457,10 @@ func getV1Beta1ProtoUploadRequestContent( if !module.IsLocal() { return nil, syserror.New("expected local Module in getProtoLegacyFederationUploadRequestContent") } - if module.ModuleFullName() == nil { + if module.FullName() == nil { return nil, syserror.Newf("expected module name for local module: %s", module.Description()) } - if module.ModuleFullName().Registry() != primaryRegistry { + if module.FullName().Registry() != primaryRegistry { // This should never happen - the upload Modules should already be verified above to come from one registry. return nil, syserror.Newf("attempting to upload content for registry other than %s in getProtoLegacyFederationUploadRequestContent", primaryRegistry) } @@ -474,8 +474,8 @@ func getV1Beta1ProtoUploadRequestContent( ModuleRef: &modulev1beta1.ModuleRef{ Value: &modulev1beta1.ModuleRef_Name_{ Name: &modulev1beta1.ModuleRef_Name{ - Owner: module.ModuleFullName().Owner(), - Module: module.ModuleFullName().Name(), + Owner: module.FullName().Owner(), + Module: module.FullName().Name(), }, }, }, @@ -491,7 +491,7 @@ func getV1Beta1ProtoUploadRequestContent( func remoteDepToV1Beta1ProtoUploadRequestDepRef( remoteDep bufmodule.RemoteDep, ) (*modulev1beta1.UploadRequest_DepRef, error) { - if remoteDep.ModuleFullName() == nil { + if remoteDep.FullName() == nil { return nil, syserror.Newf("expected module name for remote module dependency %q", remoteDep.OpaqueID()) } depCommitID := remoteDep.CommitID() @@ -500,6 +500,6 @@ func remoteDepToV1Beta1ProtoUploadRequestDepRef( } return &modulev1beta1.UploadRequest_DepRef{ CommitId: uuidutil.ToDashless(depCommitID), - Registry: remoteDep.ModuleFullName().Registry(), + Registry: remoteDep.FullName().Registry(), }, nil } diff --git a/private/bufpkg/bufmodule/bufmodulecache/bufmodulecache_test.go b/private/bufpkg/bufmodule/bufmodulecache/bufmodulecache_test.go index d5213a80b1..81a21225c3 100644 --- a/private/bufpkg/bufmodule/bufmodulecache/bufmodulecache_test.go +++ b/private/bufpkg/bufmodule/bufmodulecache/bufmodulecache_test.go @@ -24,6 +24,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmodulestore" "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduletesting" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/filelock" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/slogtestext" @@ -67,7 +68,7 @@ func TestCommitProviderForModuleKeyBasic(t *testing.T) { slicesext.Map( commits, func(commit bufmodule.Commit) string { - return commit.ModuleKey().ModuleFullName().String() + return commit.ModuleKey().FullName().String() }, ), ) @@ -90,7 +91,7 @@ func TestCommitProviderForModuleKeyBasic(t *testing.T) { slicesext.Map( commits, func(commit bufmodule.Commit) string { - return commit.ModuleKey().ModuleFullName().String() + return commit.ModuleKey().FullName().String() }, ), ) @@ -132,7 +133,7 @@ func TestCommitProviderForCommitKeyBasic(t *testing.T) { slicesext.Map( commits, func(commit bufmodule.Commit) string { - return commit.ModuleKey().ModuleFullName().String() + return commit.ModuleKey().FullName().String() }, ), ) @@ -155,7 +156,7 @@ func TestCommitProviderForCommitKeyBasic(t *testing.T) { slicesext.Map( commits, func(commit bufmodule.Commit) string { - return commit.ModuleKey().ModuleFullName().String() + return commit.ModuleKey().FullName().String() }, ), ) @@ -195,7 +196,7 @@ func TestModuleDataProviderBasic(t *testing.T) { slicesext.Map( moduleDatas, func(moduleData bufmodule.ModuleData) string { - return moduleData.ModuleKey().ModuleFullName().String() + return moduleData.ModuleKey().FullName().String() }, ), ) @@ -218,7 +219,7 @@ func TestModuleDataProviderBasic(t *testing.T) { slicesext.Map( moduleDatas, func(moduleData bufmodule.ModuleData) string { - return moduleData.ModuleKey().ModuleFullName().String() + return moduleData.ModuleKey().FullName().String() }, ), ) @@ -312,15 +313,15 @@ func testGetBSRProviderAndModuleKeys(t *testing.T, ctx context.Context) (bufmodu }, ) require.NoError(t, err) - moduleRefMod1, err := bufmodule.NewModuleRef("buf.build", "foo", "mod1", "") + moduleRefMod1, err := bufparse.NewRef("buf.build", "foo", "mod1", "") require.NoError(t, err) - moduleRefMod2, err := bufmodule.NewModuleRef("buf.build", "foo", "mod2", "") + moduleRefMod2, err := bufparse.NewRef("buf.build", "foo", "mod2", "") require.NoError(t, err) - moduleRefMod3, err := bufmodule.NewModuleRef("buf.build", "foo", "mod3", "") + moduleRefMod3, err := bufparse.NewRef("buf.build", "foo", "mod3", "") require.NoError(t, err) moduleKeys, err := bsrProvider.GetModuleKeysForModuleRefs( ctx, - []bufmodule.ModuleRef{ + []bufparse.Ref{ moduleRefMod1, // Switching order on purpose. moduleRefMod3, diff --git a/private/bufpkg/bufmodule/bufmodulestore/commit_store.go b/private/bufpkg/bufmodule/bufmodulestore/commit_store.go index 057d39b155..f08527c984 100644 --- a/private/bufpkg/bufmodule/bufmodulestore/commit_store.go +++ b/private/bufpkg/bufmodule/bufmodulestore/commit_store.go @@ -24,6 +24,7 @@ import ( "time" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slogext" "github.com/bufbuild/buf/private/pkg/storage" @@ -189,7 +190,7 @@ func (p *commitStore) getCommitForCommitKey( invalidReason = "mismatched digest type" return nil, err } - moduleFullName, err := bufmodule.NewModuleFullName( + moduleFullName, err := bufparse.NewFullName( commitKey.Registry(), externalCommit.Owner, externalCommit.Module, @@ -239,8 +240,8 @@ func (p *commitStore) putCommit( path := getCommitStoreFilePath(commitKey) externalCommit := externalCommit{ Version: externalCommitVersion, - Owner: moduleKey.ModuleFullName().Owner(), - Module: moduleKey.ModuleFullName().Name(), + Owner: moduleKey.FullName().Owner(), + Module: moduleKey.FullName().Name(), CreateTime: createTime, Digest: digest.String(), } diff --git a/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go b/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go index bfd953e0af..978c8062e5 100644 --- a/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go +++ b/private/bufpkg/bufmodule/bufmodulestore/module_data_store.go @@ -22,6 +22,7 @@ import ( "log/slog" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/encoding" "github.com/bufbuild/buf/private/pkg/filelock" "github.com/bufbuild/buf/private/pkg/normalpath" @@ -476,7 +477,7 @@ func (p *moduleDataStore) putModuleData( return err } externalModuleData.Deps[i] = externalModuleDataDep{ - Name: depModuleKey.ModuleFullName().String(), + Name: depModuleKey.FullName().String(), Commit: uuidutil.ToDashless(depModuleKey.CommitID()), Digest: digest.String(), } @@ -627,9 +628,9 @@ func getModuleDataStoreDirPath(moduleKey bufmodule.ModuleKey) (string, error) { } return normalpath.Join( digest.Type().String(), - moduleKey.ModuleFullName().Registry(), - moduleKey.ModuleFullName().Owner(), - moduleKey.ModuleFullName().Name(), + moduleKey.FullName().Registry(), + moduleKey.FullName().Owner(), + moduleKey.FullName().Name(), uuidutil.ToDashless(moduleKey.CommitID()), ), nil } @@ -646,9 +647,9 @@ func getModuleDataStoreTarPath(moduleKey bufmodule.ModuleKey) (string, error) { } return normalpath.Join( digest.Type().String(), - moduleKey.ModuleFullName().Registry(), - moduleKey.ModuleFullName().Owner(), - moduleKey.ModuleFullName().Name(), + moduleKey.FullName().Registry(), + moduleKey.FullName().Owner(), + moduleKey.FullName().Name(), uuidutil.ToDashless(moduleKey.CommitID())+".tar", ), nil } @@ -657,7 +658,7 @@ func getDeclaredDepModuleKeyForExternalModuleDataDep(dep externalModuleDataDep) if dep.Name == "" { return nil, errors.New("no module name specified") } - moduleFullName, err := bufmodule.ParseModuleFullName(dep.Name) + moduleFullName, err := bufparse.ParseFullName(dep.Name) if err != nil { return nil, fmt.Errorf("invalid module name: %w", err) } diff --git a/private/bufpkg/bufmodule/bufmodulestore/module_data_store_test.go b/private/bufpkg/bufmodule/bufmodulestore/module_data_store_test.go index 27ce8a2463..47dc87b613 100644 --- a/private/bufpkg/bufmodule/bufmodulestore/module_data_store_test.go +++ b/private/bufpkg/bufmodule/bufmodulestore/module_data_store_test.go @@ -20,6 +20,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufmodule" "github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduletesting" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/filelock" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" @@ -181,15 +182,15 @@ func testGetModuleKeysAndModuleDatas(t *testing.T, ctx context.Context) ([]bufmo }, ) require.NoError(t, err) - moduleRefMod1, err := bufmodule.NewModuleRef("buf.build", "foo", "mod1", "") + moduleRefMod1, err := bufparse.NewRef("buf.build", "foo", "mod1", "") require.NoError(t, err) - moduleRefMod2, err := bufmodule.NewModuleRef("buf.build", "foo", "mod2", "") + moduleRefMod2, err := bufparse.NewRef("buf.build", "foo", "mod2", "") require.NoError(t, err) - moduleRefMod3, err := bufmodule.NewModuleRef("buf.build", "foo", "mod3", "") + moduleRefMod3, err := bufparse.NewRef("buf.build", "foo", "mod3", "") require.NoError(t, err) moduleKeys, err := bsrProvider.GetModuleKeysForModuleRefs( ctx, - []bufmodule.ModuleRef{ + []bufparse.Ref{ moduleRefMod1, // Switching order on purpose. moduleRefMod3, @@ -234,7 +235,7 @@ func testRequireModuleKeyNamesEqual(t *testing.T, expected []string, actual []bu slicesext.Map( actual, func(value bufmodule.ModuleKey) string { - return value.ModuleFullName().String() + return value.FullName().String() }, ), ) @@ -251,7 +252,7 @@ func testRequireModuleDataNamesEqual(t *testing.T, expected []string, actual []b slicesext.Map( actual, func(value bufmodule.ModuleData) string { - return value.ModuleKey().ModuleFullName().String() + return value.ModuleKey().FullName().String() }, ), ) diff --git a/private/bufpkg/bufmodule/bufmodulestore/util.go b/private/bufpkg/bufmodule/bufmodulestore/util.go index c4d6265904..004132481e 100644 --- a/private/bufpkg/bufmodule/bufmodulestore/util.go +++ b/private/bufpkg/bufmodule/bufmodulestore/util.go @@ -28,7 +28,7 @@ func logDebugModuleKey(ctx context.Context, logger *slog.Logger, moduleKey bufmo message, append( []any{ - slog.String("moduleFullName", moduleKey.ModuleFullName().String()), + slog.String("moduleFullName", moduleKey.FullName().String()), slog.String("commitID", uuidutil.ToDashless(moduleKey.CommitID())), }, fields..., diff --git a/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go b/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go index 8233e9cf7c..bf649eca9f 100644 --- a/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go +++ b/private/bufpkg/bufmodule/bufmoduletesting/bufmoduletesting.go @@ -23,6 +23,7 @@ import ( "github.com/bufbuild/buf/private/bufpkg/bufconfig" "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/dag" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/slogext" @@ -42,7 +43,7 @@ var ( // // Exactly one of PathToData, Bucket, DirPath must be set. // -// Name is the ModuleFullName string. When creating an OmniProvider, Name is required. +// Name is the FullName string. When creating an OmniProvider, Name is required. // // CommitID is optional, but it must be unique across all ModuleDatas. If CommitID is not set, // a mock commitID is created if Name is set. @@ -87,7 +88,7 @@ func NewOmniProvider( // NewModuleSet returns a new ModuleSet. // // This can be used in cases where ModuleKeyProviders and ModuleDataProviders are not needed, -// and when ModuleFullNames do not matter. +// and when FullNames do not matter. // // Note the ModuleDatas must be self-contained, that is they only import from each other. func NewModuleSet( @@ -99,7 +100,7 @@ func NewModuleSet( // NewModuleSetForDirPath returns a new ModuleSet for the directory path. // // This can be used in cases where ModuleKeyProviders and ModuleDataProviders are not needed, -// and when ModuleFullNames do not matter. +// and when FullNames do not matter. // // Note that this Module cannot have any dependencies. func NewModuleSetForDirPath( @@ -115,7 +116,7 @@ func NewModuleSetForDirPath( // NewModuleSetForPathToData returns a new ModuleSet for the path to data map. // // This can be used in cases where ModuleKeyProviders and ModuleDataProviders are not needed, -// and when ModuleFullNames do not matter. +// and when FullNames do not matter. // // Note that this Module cannot have any dependencies. func NewModuleSetForPathToData( @@ -131,7 +132,7 @@ func NewModuleSetForPathToData( // NewModuleSetForBucket returns a new ModuleSet for the Bucket. // // This can be used in cases where ModuleKeyProviders and ModuleDataProviders are not needed, -// and when ModuleFullNames do not matter. +// and when FullNames do not matter. // // Note that this Module cannot have any dependencies. func NewModuleSetForBucket( @@ -167,12 +168,12 @@ func newOmniProvider( func (o *omniProvider) GetModuleKeysForModuleRefs( ctx context.Context, - moduleRefs []bufmodule.ModuleRef, + moduleRefs []bufparse.Ref, digestType bufmodule.DigestType, ) ([]bufmodule.ModuleKey, error) { moduleKeys := make([]bufmodule.ModuleKey, len(moduleRefs)) for i, moduleRef := range moduleRefs { - module := o.GetModuleForModuleFullName(moduleRef.ModuleFullName()) + module := o.GetModuleForFullName(moduleRef.FullName()) if module == nil { return nil, &fs.PathError{Op: "read", Path: moduleRef.String(), Err: fs.ErrNotExist} } @@ -195,7 +196,7 @@ func (o *omniProvider) GetModuleDatasForModuleKeys( if _, err := bufmodule.UniqueDigestTypeForModuleKeys(moduleKeys); err != nil { return nil, err } - if _, err := bufmodule.ModuleFullNameStringToUniqueValue(moduleKeys); err != nil { + if _, err := bufparse.FullNameStringToUniqueValue(moduleKeys); err != nil { return nil, err } return slicesext.MapError( @@ -280,7 +281,7 @@ func (o *omniProvider) GetGraphForModuleKeys( } modules := make([]bufmodule.Module, len(moduleKeys)) for i, moduleKey := range moduleKeys { - module := o.GetModuleForModuleFullName(moduleKey.ModuleFullName()) + module := o.GetModuleForFullName(moduleKey.FullName()) if module == nil { return nil, &fs.PathError{Op: "read", Path: moduleKey.String(), Err: fs.ErrNotExist} } @@ -298,7 +299,7 @@ func (o *omniProvider) getModuleDataForModuleKey( ctx context.Context, moduleKey bufmodule.ModuleKey, ) (bufmodule.ModuleData, error) { - module := o.GetModuleForModuleFullName(moduleKey.ModuleFullName()) + module := o.GetModuleForFullName(moduleKey.FullName()) if module == nil { return nil, &fs.PathError{Op: "read", Path: moduleKey.String(), Err: fs.ErrNotExist} } @@ -415,7 +416,7 @@ func addModuleDataToModuleSetBuilder( } var localModuleOptions []bufmodule.LocalModuleOption if moduleData.Name != "" { - moduleFullName, err := bufmodule.ParseModuleFullName(moduleData.Name) + moduleFullName, err := bufparse.ParseFullName(moduleData.Name) if err != nil { return err } @@ -434,7 +435,7 @@ func addModuleDataToModuleSetBuilder( commitIDToCreateTime[commitID] = createTime } localModuleOptions = []bufmodule.LocalModuleOption{ - bufmodule.LocalModuleWithModuleFullNameAndCommitID(moduleFullName, commitID), + bufmodule.LocalModuleWithFullNameAndCommitID(moduleFullName, commitID), } } else if requireName { return errors.New("ModuleData.Name was required in this context") diff --git a/private/bufpkg/bufmodule/commit.go b/private/bufpkg/bufmodule/commit.go index b10f279a57..91a4c90282 100644 --- a/private/bufpkg/bufmodule/commit.go +++ b/private/bufpkg/bufmodule/commit.go @@ -80,7 +80,7 @@ func newCommit( // and call that, but we make a variable to reference the original ModuleKey just for constency. originalModuleKey := moduleKey moduleKey = newModuleKeyNoValidate( - originalModuleKey.ModuleFullName(), + originalModuleKey.FullName(), originalModuleKey.CommitID(), func() (Digest, error) { moduleKeyDigest, err := originalModuleKey.Digest() @@ -89,7 +89,7 @@ func newCommit( } if !DigestEqual(commitOptions.expectedDigest, moduleKeyDigest) { return nil, &DigestMismatchError{ - ModuleFullName: originalModuleKey.ModuleFullName(), + FullName: originalModuleKey.FullName(), CommitID: originalModuleKey.CommitID(), ExpectedDigest: commitOptions.expectedDigest, ActualDigest: moduleKeyDigest, diff --git a/private/bufpkg/bufmodule/errors.go b/private/bufpkg/bufmodule/errors.go index 50653225fb..d20658428d 100644 --- a/private/bufpkg/bufmodule/errors.go +++ b/private/bufpkg/bufmodule/errors.go @@ -19,6 +19,7 @@ import ( "io/fs" "strings" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/uuidutil" "github.com/google/uuid" ) @@ -222,7 +223,7 @@ func (n *NoProtoFilesError) Error() string { // DigestMismatchError is the error returned if the Digest of a downloaded Module or Commit // does not match the expected digest in a buf.lock file. type DigestMismatchError struct { - ModuleFullName ModuleFullName + FullName bufparse.FullName CommitID uuid.UUID ExpectedDigest Digest ActualDigest Digest @@ -235,9 +236,9 @@ func (m *DigestMismatchError) Error() string { } var builder strings.Builder _, _ = builder.WriteString(`*** Digest verification failed`) - if m.ModuleFullName != nil { + if m.FullName != nil { _, _ = builder.WriteString(` for "`) - _, _ = builder.WriteString(m.ModuleFullName.String()) + _, _ = builder.WriteString(m.FullName.String()) if m.CommitID != uuid.Nil { _, _ = builder.WriteString(`:`) _, _ = builder.WriteString(uuidutil.ToDashless(m.CommitID)) diff --git a/private/bufpkg/bufmodule/file_info.go b/private/bufpkg/bufmodule/file_info.go index fdb66d34bd..4dbbfb3100 100644 --- a/private/bufpkg/bufmodule/file_info.go +++ b/private/bufpkg/bufmodule/file_info.go @@ -24,7 +24,7 @@ import ( // FileInfo is the file info for a Module file. // // It comprises the typical storage.ObjectInfo, along with a pointer back to the Module. -// This allows callers to figure out i.e. the ModuleFullName, Commit, as well as any other +// This allows callers to figure out i.e. the FullName, Commit, as well as any other // data it may need. type FileInfo interface { storage.ObjectInfo diff --git a/private/bufpkg/bufmodule/graph_provider.go b/private/bufpkg/bufmodule/graph_provider.go index 4052bcb8b6..1fd25501a3 100644 --- a/private/bufpkg/bufmodule/graph_provider.go +++ b/private/bufpkg/bufmodule/graph_provider.go @@ -32,7 +32,7 @@ type GraphProvider interface { // // The key will be the ModuleKey.CommitID(). // - // The input ModuleKeys are expected to be unique by ModuleFullName. The implementation + // The input ModuleKeys are expected to be unique by FullName. The implementation // may error if this is not the case. // // The input ModuleKeys are expected to have the same DigestType. The implementation diff --git a/private/bufpkg/bufmodule/module.go b/private/bufpkg/bufmodule/module.go index 408dad2b54..6928a26807 100644 --- a/private/bufpkg/bufmodule/module.go +++ b/private/bufpkg/bufmodule/module.go @@ -18,6 +18,7 @@ import ( "context" "sync" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/storage" @@ -55,7 +56,7 @@ type Module interface { // It's uniqueness property only applies to the lifetime of the Module, and only within // Modules commonly built from a ModuleSetBuilder. // - // If two Modules have the same ModuleFullName, they will have the same OpaqueID. + // If two Modules have the same FullName, they will have the same OpaqueID. OpaqueID() string // BucketID is an unstructured ID that represents the Bucket that this Module was constructed // with via ModuleSetProvider. @@ -71,14 +72,14 @@ type Module interface { // // May be empty if a Module was not constructed with a Bucket via a ModuleSetProvider. BucketID() string - // ModuleFullName returns the full name of the Module. + // FullName returns the full name of the Module. // // May be nil. Callers should not rely on this value being present. // However, this is always present for remote Modules. // - // At least one of ModuleFullName and BucketID will always be present. Use OpaqueID + // At least one of FullName and BucketID will always be present. Use OpaqueID // as an always-present identifier. - ModuleFullName() ModuleFullName + FullName() bufparse.FullName // CommitID returns the BSR ID of the Commit. // // It is up to the caller to convert this to a dashless ID when necessary. @@ -86,7 +87,7 @@ type Module interface { // May be empty, that is CommitID() == uuid.Nil may be true. // Callers should not rely on this value being present. // - // If ModuleFullName is nil, this will always be empty. + // If FullName is nil, this will always be empty. CommitID() uuid.UUID // Description returns a human-readable description of the Module. // @@ -121,7 +122,7 @@ type Module interface { // This list is pruned - only Modules that this Module actually depends on (either directly or transitively) // via import statements within its .proto files will be returned. // - // Dependencies with the same ModuleFullName will always have the same Commits and Digests. + // Dependencies with the same FullName will always have the same Commits and Digests. // // Sorted by OpaqueID. ModuleDeps() ([]ModuleDep, error) @@ -159,7 +160,7 @@ type Module interface { // dependencies specified in a buf.lock (with no correspoding Module in the Workspace), // or a DepNode in a CreateCommitRequest with no corresponding ModuleNode. // - // Remote Modules will always have ModuleFullNames. + // Remote Modules will always have FullNames. IsLocal() bool // V1Beta1OrV1BufYAMLObjectData returns the original source buf.yaml associated with this Module, if the @@ -199,10 +200,10 @@ type Module interface { // ModuleToModuleKey returns a new ModuleKey for the given Module. // -// The given Module must have a ModuleFullName and CommitID, otherwise this will return error. +// The given Module must have a FullName and CommitID, otherwise this will return error. func ModuleToModuleKey(module Module, digestType DigestType) (ModuleKey, error) { return newModuleKey( - module.ModuleFullName(), + module.FullName(), module.CommitID(), func() (Digest, error) { return module.Digest(digestType) @@ -233,7 +234,7 @@ type module struct { getBucket func() (storage.ReadBucket, error) bucketID string description string - moduleFullName ModuleFullName + moduleFullName bufparse.FullName commitID uuid.UUID isTarget bool isLocal bool @@ -254,7 +255,7 @@ func newModule( syncOnceValuesGetBucketWithStorageMatcherApplied func() (storage.ReadBucket, error), bucketID string, description string, - moduleFullName ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, isTarget bool, isLocal bool, @@ -336,7 +337,7 @@ func newModule( func (m *module) OpaqueID() string { // We know that one of bucketID and moduleFullName are present via construction. // - // Prefer moduleFullName since modules with the same ModuleFullName should have the same OpaqueID. + // Prefer moduleFullName since modules with the same FullName should have the same OpaqueID. if m.moduleFullName != nil { return m.moduleFullName.String() } @@ -347,7 +348,7 @@ func (m *module) BucketID() string { return m.bucketID } -func (m *module) ModuleFullName() ModuleFullName { +func (m *module) FullName() bufparse.FullName { return m.moduleFullName } @@ -465,7 +466,7 @@ func newGetDigestFuncForModuleAndDigestType(module *module, digestType DigestTyp } moduleDepFullNames := make(map[string]struct{}, len(moduleDeps)) for _, dep := range moduleDeps { - fullName := dep.ModuleFullName() + fullName := dep.FullName() if fullName == nil { return nil, syserror.Newf("remote module dependencies should have full names") } @@ -473,7 +474,7 @@ func newGetDigestFuncForModuleAndDigestType(module *module, digestType DigestTyp } prunedDepModuleKeys := make([]ModuleKey, 0, len(declaredDepModuleKeys)) for _, dep := range declaredDepModuleKeys { - if _, ok := moduleDepFullNames[dep.ModuleFullName().String()]; ok { + if _, ok := moduleDepFullNames[dep.FullName().String()]; ok { prunedDepModuleKeys = append(prunedDepModuleKeys, dep) } } diff --git a/private/bufpkg/bufmodule/module_data.go b/private/bufpkg/bufmodule/module_data.go index 28bbc5d593..2d9e76e69f 100644 --- a/private/bufpkg/bufmodule/module_data.go +++ b/private/bufpkg/bufmodule/module_data.go @@ -164,7 +164,7 @@ func newModuleData( } if !DigestEqual(expectedDigest, actualDigest) { return &DigestMismatchError{ - ModuleFullName: moduleKey.ModuleFullName(), + FullName: moduleKey.FullName(), CommitID: moduleKey.CommitID(), ExpectedDigest: expectedDigest, ActualDigest: actualDigest, diff --git a/private/bufpkg/bufmodule/module_data_provider.go b/private/bufpkg/bufmodule/module_data_provider.go index 8648fe3ba0..1a149f27b4 100644 --- a/private/bufpkg/bufmodule/module_data_provider.go +++ b/private/bufpkg/bufmodule/module_data_provider.go @@ -30,7 +30,7 @@ type ModuleDataProvider interface { // // Returned ModuleDatas will be in the same order as the input ModuleKeys. // - // The input ModuleKeys are expected to be unique by ModuleFullName. The implementation + // The input ModuleKeys are expected to be unique by FullName. The implementation // may error if this is not the case. // // The input ModuleKeys are expected to have the same DigestType. The implementation diff --git a/private/bufpkg/bufmodule/module_key.go b/private/bufpkg/bufmodule/module_key.go index 73241bb9e1..a0679e747c 100644 --- a/private/bufpkg/bufmodule/module_key.go +++ b/private/bufpkg/bufmodule/module_key.go @@ -20,6 +20,7 @@ import ( "strings" "sync" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/syserror" "github.com/bufbuild/buf/private/pkg/uuidutil" @@ -35,10 +36,10 @@ type ModuleKey interface { // String returns "registry/owner/name:dashlessCommitID". fmt.Stringer - // ModuleFullName returns the full name of the Module. + // FullName returns the full name of the Module. // // Always present. - ModuleFullName() ModuleFullName + FullName() bufparse.FullName // CommitID returns the ID of the Commit. // // It is up to the caller to convert this to a dashless ID when necessary. @@ -61,7 +62,7 @@ type ModuleKey interface { // *not* validate the digest. If you need to validate the digest, call Digest() and evaluate // the returned error. func NewModuleKey( - moduleFullName ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, getDigest func() (Digest, error), ) (ModuleKey, error) { @@ -107,25 +108,25 @@ func ModuleKeyToCommitKey(moduleKey ModuleKey) (CommitKey, error) { if err != nil { return nil, err } - return newCommitKey(moduleKey.ModuleFullName().Registry(), moduleKey.CommitID(), digest.Type()) + return newCommitKey(moduleKey.FullName().Registry(), moduleKey.CommitID(), digest.Type()) } // *** PRIVATE *** type moduleKey struct { - moduleFullName ModuleFullName + moduleFullName bufparse.FullName commitID uuid.UUID getDigest func() (Digest, error) } func newModuleKey( - moduleFullName ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, getDigest func() (Digest, error), ) (*moduleKey, error) { if moduleFullName == nil { - return nil, errors.New("nil ModuleFullName when constructing ModuleKey") + return nil, errors.New("nil FullName when constructing ModuleKey") } if commitID == uuid.Nil { return nil, errors.New("empty commitID when constructing ModuleKey") @@ -134,7 +135,7 @@ func newModuleKey( } func newModuleKeyNoValidate( - moduleFullName ModuleFullName, + moduleFullName bufparse.FullName, commitID uuid.UUID, getDigest func() (Digest, error), ) *moduleKey { @@ -145,7 +146,7 @@ func newModuleKeyNoValidate( } } -func (m *moduleKey) ModuleFullName() ModuleFullName { +func (m *moduleKey) FullName() bufparse.FullName { return m.moduleFullName } diff --git a/private/bufpkg/bufmodule/module_key_provider.go b/private/bufpkg/bufmodule/module_key_provider.go index 369f2be43c..096e521a08 100644 --- a/private/bufpkg/bufmodule/module_key_provider.go +++ b/private/bufpkg/bufmodule/module_key_provider.go @@ -16,6 +16,8 @@ package bufmodule import ( "context" + + "github.com/bufbuild/buf/private/bufpkg/bufparse" ) // ModuleKeyProvider provides ModuleKeys for ModuleRefs. @@ -24,11 +26,11 @@ type ModuleKeyProvider interface { // // Returned ModuleKeys will be in the same order as the input ModuleRefs. // - // The input ModuleRefs are expected to be unique by ModuleFullName. The implementation + // The input ModuleRefs are expected to be unique by FullName. The implementation // may error if this is not the case. // // If there is no error, the length of the ModuleKeys returned will match the length of the ModuleRefs. // If there is an error, no ModuleKeys will be returned. // If any ModuleRef is not found, an error with fs.ErrNotExist will be returned. - GetModuleKeysForModuleRefs(context.Context, []ModuleRef, DigestType) ([]ModuleKey, error) + GetModuleKeysForModuleRefs(context.Context, []bufparse.Ref, DigestType) ([]ModuleKey, error) } diff --git a/private/bufpkg/bufmodule/module_set.go b/private/bufpkg/bufmodule/module_set.go index cd3cd0d1ba..a89fa00d03 100644 --- a/private/bufpkg/bufmodule/module_set.go +++ b/private/bufpkg/bufmodule/module_set.go @@ -20,6 +20,7 @@ import ( "io/fs" "sort" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/cache" "github.com/bufbuild/buf/private/pkg/dag" "github.com/bufbuild/buf/private/pkg/slicesext" @@ -45,10 +46,10 @@ type ModuleSet interface { // These will be sorted by OpaqueID. Modules() []Module - // GetModuleForModuleFullName gets the Module for the ModuleFullName, if it exists. + // GetModuleForFullName gets the Module for the FullName, if it exists. // - // Returns nil if there is no Module with the given ModuleFullName. - GetModuleForModuleFullName(moduleFullName ModuleFullName) Module + // Returns nil if there is no Module with the given FullName. + GetModuleForFullName(moduleFullName bufparse.FullName) Module // GetModuleForOpaqueID gets the Module for the OpaqueID, if it exists. // // Returns nil if there is no Module with the given OpaqueID. However, as long @@ -267,11 +268,11 @@ func newModuleSet( bucketIDToModule := make(map[string]Module, len(modules)) commitIDToModule := make(map[uuid.UUID]Module, len(modules)) for _, module := range modules { - if moduleFullName := module.ModuleFullName(); moduleFullName != nil { + if moduleFullName := module.FullName(); moduleFullName != nil { moduleFullNameString := moduleFullName.String() if _, ok := moduleFullNameStringToModule[moduleFullNameString]; ok { // This should never happen. - return nil, syserror.Newf("duplicate ModuleFullName %q when constructing ModuleSet", moduleFullNameString) + return nil, syserror.Newf("duplicate FullName %q when constructing ModuleSet", moduleFullNameString) } moduleFullNameStringToModule[moduleFullNameString] = module } @@ -323,7 +324,7 @@ func (m *moduleSet) Modules() []Module { return c } -func (m *moduleSet) GetModuleForModuleFullName(moduleFullName ModuleFullName) Module { +func (m *moduleSet) GetModuleForFullName(moduleFullName bufparse.FullName) Module { return m.moduleFullNameStringToModule[moduleFullName.String()] } diff --git a/private/bufpkg/bufmodule/module_set_builder.go b/private/bufpkg/bufmodule/module_set_builder.go index 3eb81d74d9..00529532a9 100644 --- a/private/bufpkg/bufmodule/module_set_builder.go +++ b/private/bufpkg/bufmodule/module_set_builder.go @@ -19,6 +19,7 @@ import ( "log/slog" "sync/atomic" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/slicesext" "github.com/bufbuild/buf/private/pkg/slogext" @@ -57,8 +58,8 @@ type ModuleSetBuilder interface { // The Bucket used to construct the module will only be read for .proto files, // license file(s), and documentation file(s). // - // The BucketID is required. If LocalModuleWithModuleFullName.* is used, the OpaqueID will - // use this ModuleFullName, otherwise the OpaqueID will be the BucketID. + // The BucketID is required. If LocalModuleWithFullName.* is used, the OpaqueID will + // use this FullName, otherwise the OpaqueID will be the BucketID. // // The dependencies of the Module are unknown, since bufmodule does not parse configuration, // and therefore the dependencies of the Module are *not* automatically added to the ModuleSet. @@ -78,7 +79,7 @@ type ModuleSetBuilder interface { // The ModuleDataProvider given to the ModuleSetBuilder at construction time will be used to // retrieve this Module. // - // The resulting Module will not have a BucketID but will always have a ModuleFullName. + // The resulting Module will not have a BucketID but will always have a FullName. // // The dependencies of the Module will are *not* automatically added to the ModuleSet. // It is the caller's responsibility to add transitive dependencies. @@ -158,18 +159,18 @@ func NewModuleSetForRemoteModule( // LocalModuleOption is an option for AddLocalModule. type LocalModuleOption func(*localModuleOptions) -// LocalModuleWithModuleFullName returns a new LocalModuleOption that adds the given ModuleFullName to the result Module. +// LocalModuleWithFullName returns a new LocalModuleOption that adds the given FullName to the result Module. // -// Use LocalModuleWithModuleFullNameAndCommitID if you'd also like to add a CommitID. -func LocalModuleWithModuleFullName(moduleFullName ModuleFullName) LocalModuleOption { +// Use LocalModuleWithFullNameAndCommitID if you'd also like to add a CommitID. +func LocalModuleWithFullName(moduleFullName bufparse.FullName) LocalModuleOption { return func(localModuleOptions *localModuleOptions) { localModuleOptions.moduleFullName = moduleFullName } } -// LocalModuleWithModuleFullName returns a new LocalModuleOption that adds the given ModuleFullName and CommitID +// LocalModuleWithFullName returns a new LocalModuleOption that adds the given FullName and CommitID // to the result Module. -func LocalModuleWithModuleFullNameAndCommitID(moduleFullName ModuleFullName, commitID uuid.UUID) LocalModuleOption { +func LocalModuleWithFullNameAndCommitID(moduleFullName bufparse.FullName, commitID uuid.UUID) LocalModuleOption { return func(localModuleOptions *localModuleOptions) { localModuleOptions.moduleFullName = moduleFullName localModuleOptions.commitID = commitID @@ -320,7 +321,7 @@ func (b *moduleSetBuilder) AddLocalModule( option(localModuleOptions) } if localModuleOptions.moduleFullName == nil && localModuleOptions.commitID != uuid.Nil { - return b.addError(syserror.New("cannot set commitID without ModuleFullName when calling AddLocalModule")) + return b.addError(syserror.New("cannot set commitID without FullName when calling AddLocalModule")) } if !isTarget && (len(localModuleOptions.targetPaths) > 0 || len(localModuleOptions.targetExcludePaths) > 0) { return b.addError(syserror.Newf("cannot set TargetPaths for a non-target Module when calling AddLocalModule, bucketID=%q, targetPaths=%v, targetExcludePaths=%v", bucketID, localModuleOptions.targetPaths, localModuleOptions.targetExcludePaths)) @@ -447,7 +448,7 @@ func (b *moduleSetBuilder) addError(err error) *moduleSetBuilder { func (*moduleSetBuilder) isModuleSetBuilder() {} type localModuleOptions struct { - moduleFullName ModuleFullName + moduleFullName bufparse.FullName commitID uuid.UUID description string targetPaths []string diff --git a/private/bufpkg/bufmodule/registry_commit_id.go b/private/bufpkg/bufmodule/registry_commit_id.go index b6d3fa548c..be53a59f9d 100644 --- a/private/bufpkg/bufmodule/registry_commit_id.go +++ b/private/bufpkg/bufmodule/registry_commit_id.go @@ -35,7 +35,7 @@ func NewRegistryCommitID(registry string, commitID uuid.UUID) RegistryCommitID { // ModuleKeyToRegistryCommitID converts the ModuleKey to a RegistryCommitID. func ModuleKeyToRegistryCommitID(moduleKey ModuleKey) RegistryCommitID { return NewRegistryCommitID( - moduleKey.ModuleFullName().Registry(), + moduleKey.FullName().Registry(), moduleKey.CommitID(), ) } diff --git a/private/bufpkg/bufmodule/remote_dep.go b/private/bufpkg/bufmodule/remote_dep.go index 365f2a89c3..0ec236067b 100644 --- a/private/bufpkg/bufmodule/remote_dep.go +++ b/private/bufpkg/bufmodule/remote_dep.go @@ -28,7 +28,7 @@ import ( // We don't care about targeting here - we want to know the remote dependencies for // purposes such as figuring out what dependencies are unused and can be pruned. type RemoteDep interface { - // All RemoteDeps will have a ModuleFullName, as they are remote. + // All RemoteDeps will have a FullName, as they are remote. Module // IsDirect returns true if the remote dependency is a direct dependency of a Module in the ModuleSet. @@ -39,7 +39,7 @@ type RemoteDep interface { // RemoteDepsForModuleSet returns the remote dependencies of the local Modules in the ModuleSet. // -// Sorted by ModuleFullName. +// Sorted by FullName. // // TODO FUTURE: This needs a LOT of testing. func RemoteDepsForModuleSet(moduleSet ModuleSet) ([]RemoteDep, error) { @@ -48,7 +48,7 @@ func RemoteDepsForModuleSet(moduleSet ModuleSet) ([]RemoteDep, error) { // RemoteDepsForModules returns the remote dependencies of the local Modules. // -// Sorted by ModuleFullName. +// Sorted by FullName. // // This is used in situations where we have already filtered a ModuleSet down to a specific // set of modules, such as in the Uploader. Generally, you want to use RemoteDepsForModuleSet. @@ -59,7 +59,7 @@ func RemoteDepsForModuleSet(moduleSet ModuleSet) ([]RemoteDep, error) { // TODO FUTURE: This needs a LOT of testing. func RemoteDepsForModules(modules []Module) ([]RemoteDep, error) { visitedOpaqueIDs := make(map[string]struct{}) - remoteDepModuleFullNameStringsThatAreDirectDepsOfLocal := make(map[string]struct{}) + remoteDepFullNameStringsThatAreDirectDepsOfLocal := make(map[string]struct{}) var remoteDepModules []Module for _, module := range modules { if !module.IsLocal() { @@ -73,13 +73,13 @@ func RemoteDepsForModules(modules []Module) ([]RemoteDep, error) { if moduleDep.IsLocal() { continue } - moduleDepFullName := moduleDep.ModuleFullName() + moduleDepFullName := moduleDep.FullName() if moduleDepFullName == nil { // Just a sanity check. - return nil, syserror.New("remote module did not have a ModuleFullName") + return nil, syserror.New("remote module did not have a FullName") } if moduleDep.IsDirect() { - remoteDepModuleFullNameStringsThatAreDirectDepsOfLocal[moduleDepFullName.String()] = struct{}{} + remoteDepFullNameStringsThatAreDirectDepsOfLocal[moduleDepFullName.String()] = struct{}{} } iRemoteDepModules, err := remoteDepsForModuleSetRec( moduleDep, @@ -93,12 +93,12 @@ func RemoteDepsForModules(modules []Module) ([]RemoteDep, error) { } remoteDeps := make([]RemoteDep, len(remoteDepModules)) for i, remoteDepModule := range remoteDepModules { - moduleFullName := remoteDepModule.ModuleFullName() + moduleFullName := remoteDepModule.FullName() if moduleFullName == nil { // Just a sanity check. - return nil, syserror.New("remote module did not have a ModuleFullName") + return nil, syserror.New("remote module did not have a FullName") } - _, isDirect := remoteDepModuleFullNameStringsThatAreDirectDepsOfLocal[moduleFullName.String()] + _, isDirect := remoteDepFullNameStringsThatAreDirectDepsOfLocal[moduleFullName.String()] remoteDeps[i] = newRemoteDep(remoteDepModule, isDirect) } sort.Slice( @@ -138,9 +138,9 @@ func remoteDepsForModuleSetRec( if remoteModule.IsLocal() { return nil, syserror.New("only pass remote modules to remoteDepsForModuleSetRec") } - if remoteModule.ModuleFullName() == nil { + if remoteModule.FullName() == nil { // Just a sanity check. - return nil, syserror.New("ModuleFullName is nil for a remote Module") + return nil, syserror.New("FullName is nil for a remote Module") } opaqueID := remoteModule.OpaqueID() if _, ok := visitedOpaqueIDs[opaqueID]; ok { diff --git a/private/bufpkg/bufparse/bufparse.go b/private/bufpkg/bufparse/bufparse.go new file mode 100644 index 0000000000..bd0d7468b5 --- /dev/null +++ b/private/bufpkg/bufparse/bufparse.go @@ -0,0 +1,15 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bufparse diff --git a/private/bufpkg/bufparse/errors.go b/private/bufpkg/bufparse/errors.go new file mode 100644 index 0000000000..3c139f00c6 --- /dev/null +++ b/private/bufpkg/bufparse/errors.go @@ -0,0 +1,76 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bufparse + +import "strings" + +// ParseError is an error that occurred during parsing. +// +// This is returned by all Parse.* functions in this package. +type ParseError struct { + // typeString is the user-consumable string representing of the type that was attempted to be parsed. + // + // Users cannot rely on this data being structured. + // Examples: "digest", "digest type". + typeString string + // input is the input string that was attempted to be parsed. + input string + // err is the underlying error. + // + // Err may be a *ParseError itself. + // + // This is an error we may give back to the user, use pretty strings that should + // be read. + err error +} + +// Error implements the error interface. +func (p *ParseError) Error() string { + if p == nil { + return "" + } + var builder strings.Builder + _, _ = builder.WriteString(`could not parse`) + if p.typeString != "" { + _, _ = builder.WriteString(` `) + _, _ = builder.WriteString(p.typeString) + } + if p.input != "" { + _, _ = builder.WriteString(` "`) + _, _ = builder.WriteString(p.input) + _, _ = builder.WriteString(`"`) + } + if p.err != nil { + _, _ = builder.WriteString(`: `) + _, _ = builder.WriteString(p.err.Error()) + } + return builder.String() +} + +// Unwrap returns the underlying error. +func (p *ParseError) Unwrap() error { + if p == nil { + return nil + } + return p.err +} + +// Input returns the input string that was attempted to be parsed. +func (p *ParseError) Input() string { + if p == nil { + return "" + } + return p.input +} diff --git a/private/bufpkg/bufmodule/module_full_name.go b/private/bufpkg/bufparse/full_name.go similarity index 50% rename from private/bufpkg/bufmodule/module_full_name.go rename to private/bufpkg/bufparse/full_name.go index 03b00fd4bd..9a7475521a 100644 --- a/private/bufpkg/bufmodule/module_full_name.go +++ b/private/bufpkg/bufparse/full_name.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package bufmodule +package bufparse import ( "errors" @@ -22,54 +22,54 @@ import ( "github.com/bufbuild/buf/private/pkg/netext" ) -// ModuleFullName represents the full name of the Module, including its registry, owner, and name. -type ModuleFullName interface { +// FullName represents the full name of the entity, including its registry, owner, and name. +type FullName interface { // String returns "registry/owner/name". fmt.Stringer - // Registry returns the hostname of the BSR instance that this Module is contained within. + // Registry returns the hostname of the BSR instance that this is contained within. Registry() string - // Owner returns the name of the user or organization that owns this Module. + // Owner returns the name of the user or organization that owns this . Owner() string - // Name returns the name of the Module. + // Name returns the name of the . Name() string - isModuleFullName() + isFullName() } -// NewModuleFullName returns a new ModuleFullName for the given components. -func NewModuleFullName( +// NewFullName returns a new FullName for the given components. +func NewFullName( registry string, owner string, name string, -) (ModuleFullName, error) { - return newModuleFullName( +) (FullName, error) { + return newFullName( registry, owner, name, ) } -// ParseModuleFullName parses a ModuleFullName from a string in the form "registry/owner/name". -func ParseModuleFullName(moduleFullNameString string) (ModuleFullName, error) { - // parseModuleFullNameComponents returns ParseErrors. - registry, owner, name, err := parseModuleFullNameComponents(moduleFullNameString) +// ParseFullName parses a FullName from a string in the form "registry/owner/name". +func ParseFullName(fullNameString string) (FullName, error) { + // parseFullNameComponents returns ParseErrors. + registry, owner, name, err := parseFullNameComponents(fullNameString) if err != nil { return nil, err } - if err := validateModuleFullNameParameters(registry, owner, name); err != nil { + if err := validateFullNameParameters(registry, owner, name); err != nil { return nil, &ParseError{ - typeString: "module name", - input: moduleFullNameString, + typeString: "full name", + input: fullNameString, err: err, } } // We don't rely on constructors for ParseErrors. - return NewModuleFullName(registry, owner, name) + return NewFullName(registry, owner, name) } -// ModuleFullNameEqual returns true if the ModuleFullNames are equal. -func ModuleFullNameEqual(one ModuleFullName, two ModuleFullName) bool { +// FullNameEqual returns true if the FullNames are equal. +func FullNameEqual(one FullName, two FullName) bool { if (one == nil) != (two == nil) { return false } @@ -79,84 +79,84 @@ func ModuleFullNameEqual(one ModuleFullName, two ModuleFullName) bool { return one.String() == two.String() } -// HasModuleFullName is any type that has a ModuleFullName() function. -type HasModuleFullName interface { - // ModuleFullName returns the ModuleullName. +// HasFullName is any type that has a FullName() function. +type HasFullName interface { + // FullName returns the ullName. // // May be empty. - ModuleFullName() ModuleFullName + FullName() FullName } -// ModuleFullNameStringToValue maps the values that implement HasModuleFullName to a map -// from ModuleFullName string to the unique value that has this ModuleFullName. +// FullNameStringToValue maps the values that implement HasFullName to a map +// from FullName string to the unique value that has this FullName. // -// If any value has a nil ModuleFullName, this value is not added to the map. Therefore, -// for types that potentially have a nil ModuleFullName, you cannot reply on this function +// If any value has a nil FullName, this value is not added to the map. Therefore, +// for types that potentially have a nil FullName, you cannot reply on this function // returning a map of the same length as the input values. // -// Returns error if there are values with duplicate ModuleFullNames. -func ModuleFullNameStringToUniqueValue[T HasModuleFullName, S ~[]T](values S) (map[string]T, error) { +// Returns error if there are values with duplicate FullNames. +func FullNameStringToUniqueValue[T HasFullName, S ~[]T](values S) (map[string]T, error) { m := make(map[string]T, len(values)) for _, value := range values { - moduleFullName := value.ModuleFullName() - if moduleFullName == nil { + fullName := value.FullName() + if fullName == nil { continue } - existingValue, ok := m[moduleFullName.String()] + existingValue, ok := m[fullName.String()] if ok { return nil, fmt.Errorf( "duplicate module names in input: %q, %q", - existingValue.ModuleFullName().String(), - moduleFullName.String(), + existingValue.FullName().String(), + fullName.String(), ) } - m[moduleFullName.String()] = value + m[fullName.String()] = value } return m, nil } // *** PRIVATE *** -type moduleFullName struct { +type fullName struct { registry string owner string name string } -func newModuleFullName( +func newFullName( registry string, owner string, name string, -) (*moduleFullName, error) { - if err := validateModuleFullNameParameters(registry, owner, name); err != nil { +) (*fullName, error) { + if err := validateFullNameParameters(registry, owner, name); err != nil { return nil, err } - return &moduleFullName{ + return &fullName{ registry: registry, owner: owner, name: name, }, nil } -func (m *moduleFullName) Registry() string { +func (m *fullName) Registry() string { return m.registry } -func (m *moduleFullName) Owner() string { +func (m *fullName) Owner() string { return m.owner } -func (m *moduleFullName) Name() string { +func (m *fullName) Name() string { return m.name } -func (m *moduleFullName) String() string { +func (m *fullName) String() string { return m.registry + "/" + m.owner + "/" + m.name } -func (*moduleFullName) isModuleFullName() {} +func (*fullName) isFullName() {} -func validateModuleFullNameParameters( +func validateFullNameParameters( registry string, owner string, name string, diff --git a/private/bufpkg/bufmodule/parse.go b/private/bufpkg/bufparse/parse.go similarity index 65% rename from private/bufpkg/bufmodule/parse.go rename to private/bufpkg/bufparse/parse.go index 50052983cb..f0c18e5405 100644 --- a/private/bufpkg/bufmodule/parse.go +++ b/private/bufpkg/bufparse/parse.go @@ -12,38 +12,38 @@ // See the License for the specific language governing permissions and // limitations under the License. -package bufmodule +package bufparse import ( "errors" "strings" ) -func parseModuleFullNameComponents(path string) (registry string, owner string, name string, err error) { +func parseFullNameComponents(path string) (registry string, owner string, name string, err error) { slashSplit := strings.Split(path, "/") if len(slashSplit) != 3 { - return "", "", "", newInvalidModuleFullNameStringError(path) + return "", "", "", newInvalidFullNameStringError(path) } registry = strings.TrimSpace(slashSplit[0]) if registry == "" { - return "", "", "", newInvalidModuleFullNameStringError(path) + return "", "", "", newInvalidFullNameStringError(path) } owner = strings.TrimSpace(slashSplit[1]) if owner == "" { - return "", "", "", newInvalidModuleFullNameStringError(path) + return "", "", "", newInvalidFullNameStringError(path) } name = strings.TrimSpace(slashSplit[2]) if name == "" { - return "", "", "", newInvalidModuleFullNameStringError(path) + return "", "", "", newInvalidFullNameStringError(path) } return registry, owner, name, nil } -func parseModuleRefComponents(path string) (registry string, owner string, name string, ref string, err error) { +func parseRefComponents(path string) (registry string, owner string, name string, ref string, err error) { // split by the first "/" to separate the registry and remaining part slashSplit := strings.SplitN(path, "/", 2) if len(slashSplit) != 2 { - return "", "", "", "", newInvalidModuleRefStringError(path) + return "", "", "", "", newInvalidRefStringError(path) } registry, rest := slashSplit[0], slashSplit[1] // split the remaining part by ":" to separate the reference @@ -54,19 +54,19 @@ func parseModuleRefComponents(path string) (registry string, owner string, name case 2: ref = strings.TrimSpace(colonSplit[1]) if ref == "" { - return "", "", "", "", newInvalidModuleRefStringError(path) + return "", "", "", "", newInvalidRefStringError(path) } default: - return "", "", "", "", newInvalidModuleRefStringError(path) + return "", "", "", "", newInvalidRefStringError(path) } - registry, owner, name, err = parseModuleFullNameComponents(registry + "/" + colonSplit[0]) + registry, owner, name, err = parseFullNameComponents(registry + "/" + colonSplit[0]) if err != nil { - return "", "", "", "", newInvalidModuleRefStringError(path) + return "", "", "", "", newInvalidRefStringError(path) } return registry, owner, name, ref, nil } -func newInvalidModuleFullNameStringError(s string) error { +func newInvalidFullNameStringError(s string) error { return &ParseError{ typeString: "module name", input: s, @@ -74,7 +74,7 @@ func newInvalidModuleFullNameStringError(s string) error { } } -func newInvalidModuleRefStringError(s string) error { +func newInvalidRefStringError(s string) error { return &ParseError{ typeString: "module reference", input: s, diff --git a/private/bufpkg/bufmodule/module_ref.go b/private/bufpkg/bufparse/ref.go similarity index 59% rename from private/bufpkg/bufmodule/module_ref.go rename to private/bufpkg/bufparse/ref.go index 8ef19f4824..617d8fff9c 100644 --- a/private/bufpkg/bufmodule/module_ref.go +++ b/private/bufpkg/bufparse/ref.go @@ -12,70 +12,70 @@ // See the License for the specific language governing permissions and // limitations under the License. -package bufmodule +package bufparse import ( "errors" "fmt" ) -// ModuleRef is an unresolved reference to a Module. -type ModuleRef interface { +// Ref is an unresolved reference to a . +type Ref interface { // String returns "registry/owner/name[:ref]". fmt.Stringer - // ModuleFullName returns the full name of the Module. + // FullName returns the full name of the . // // Always present. - ModuleFullName() ModuleFullName - // Ref returns the reference within the Module. + FullName() FullName + // Ref returns the reference within the . // // May be a label or dashless commitID. // - // May be empty, in which case this references the commit of the default label of the Module. + // May be empty, in which case this references the commit of the default label of the . Ref() string - isModuleRef() + isRef() } -// NewModuleRef returns a new ModuleRef for the given compoonents. -func NewModuleRef( +// NewRef returns a new Ref for the given compoonents. +func NewRef( registry string, owner string, name string, ref string, -) (ModuleRef, error) { - moduleFullName, err := NewModuleFullName(registry, owner, name) +) (Ref, error) { + moduleFullName, err := NewFullName(registry, owner, name) if err != nil { return nil, err } - return newModuleRef(moduleFullName, ref) + return newRef(moduleFullName, ref) } -// ParseModuleRef parses a ModuleRef from a string in the form "registry/owner/name[:ref]". -func ParseModuleRef(moduleRefString string) (ModuleRef, error) { +// ParseRef parses a Ref from a string in the form "registry/owner/name[:ref]". +func ParseRef(moduleRefString string) (Ref, error) { // Returns ParseErrors. - registry, owner, name, ref, err := parseModuleRefComponents(moduleRefString) + registry, owner, name, ref, err := parseRefComponents(moduleRefString) if err != nil { return nil, err } // We don't rely on constructors for ParseErrors. - return NewModuleRef(registry, owner, name, ref) + return NewRef(registry, owner, name, ref) } // *** PRIVATE *** type moduleRef struct { - moduleFullName ModuleFullName + moduleFullName FullName ref string } -func newModuleRef( - moduleFullName ModuleFullName, +func newRef( + moduleFullName FullName, ref string, ) (*moduleRef, error) { if moduleFullName == nil { - return nil, errors.New("nil ModuleFullName when constructing ModuleRef") + return nil, errors.New("nil FullName when constructing Ref") } return &moduleRef{ moduleFullName: moduleFullName, @@ -83,7 +83,7 @@ func newModuleRef( }, nil } -func (m *moduleRef) ModuleFullName() ModuleFullName { +func (m *moduleRef) FullName() FullName { return m.moduleFullName } @@ -98,4 +98,4 @@ func (m *moduleRef) String() string { return m.moduleFullName.String() + ":" + m.ref } -func (*moduleRef) isModuleRef() {} +func (*moduleRef) isRef() {} diff --git a/private/bufpkg/bufparse/usage.gen.go b/private/bufpkg/bufparse/usage.gen.go new file mode 100644 index 0000000000..f0a3423dc8 --- /dev/null +++ b/private/bufpkg/bufparse/usage.gen.go @@ -0,0 +1,19 @@ +// Copyright 2020-2024 Buf Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generated. DO NOT EDIT. + +package bufparse + +import _ "github.com/bufbuild/buf/private/usage" diff --git a/private/bufpkg/bufplugin/errors.go b/private/bufpkg/bufplugin/errors.go index d01f996e46..fdf0637aec 100644 --- a/private/bufpkg/bufplugin/errors.go +++ b/private/bufpkg/bufplugin/errors.go @@ -17,6 +17,7 @@ package bufplugin import ( "strings" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/uuidutil" "github.com/google/uuid" ) @@ -83,7 +84,7 @@ func (p *ParseError) Input() string { // DigestMismatchError is the error returned if the Digest of a downloaded Plugin or Commit // does not match the expected digest in a buf.lock file. type DigestMismatchError struct { - PluginFullName PluginFullName + FullName bufparse.FullName CommitID uuid.UUID ExpectedDigest Digest ActualDigest Digest @@ -96,9 +97,9 @@ func (m *DigestMismatchError) Error() string { } var builder strings.Builder _, _ = builder.WriteString(`*** Digest verification failed`) - if m.PluginFullName != nil { + if m.FullName != nil { _, _ = builder.WriteString(` for "`) - _, _ = builder.WriteString(m.PluginFullName.String()) + _, _ = builder.WriteString(m.FullName.String()) if m.CommitID != uuid.Nil { _, _ = builder.WriteString(`:`) _, _ = builder.WriteString(uuidutil.ToDashless(m.CommitID)) diff --git a/private/bufpkg/bufplugin/parse.go b/private/bufpkg/bufplugin/parse.go deleted file mode 100644 index f8557d7996..0000000000 --- a/private/bufpkg/bufplugin/parse.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2020-2024 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package bufplugin - -import ( - "errors" - "strings" -) - -func parsePluginFullNameComponents(path string) (registry string, owner string, name string, err error) { - slashSplit := strings.Split(path, "/") - if len(slashSplit) != 3 { - return "", "", "", newInvalidPluginFullNameStringError(path) - } - registry = strings.TrimSpace(slashSplit[0]) - if registry == "" { - return "", "", "", newInvalidPluginFullNameStringError(path) - } - owner = strings.TrimSpace(slashSplit[1]) - if owner == "" { - return "", "", "", newInvalidPluginFullNameStringError(path) - } - name = strings.TrimSpace(slashSplit[2]) - if name == "" { - return "", "", "", newInvalidPluginFullNameStringError(path) - } - return registry, owner, name, nil -} - -func parsePluginRefComponents(path string) (registry string, owner string, name string, ref string, err error) { - // split by the first "/" to separate the registry and remaining part - slashSplit := strings.SplitN(path, "/", 2) - if len(slashSplit) != 2 { - return "", "", "", "", newInvalidPluginRefStringError(path) - } - registry, rest := slashSplit[0], slashSplit[1] - // split the remaining part by ":" to separate the reference - colonSplit := strings.Split(rest, ":") - switch len(colonSplit) { - case 1: - // path excluding registry has no colon, no need to handle its ref - case 2: - ref = strings.TrimSpace(colonSplit[1]) - if ref == "" { - return "", "", "", "", newInvalidPluginRefStringError(path) - } - default: - return "", "", "", "", newInvalidPluginRefStringError(path) - } - registry, owner, name, err = parsePluginFullNameComponents(registry + "/" + colonSplit[0]) - if err != nil { - return "", "", "", "", newInvalidPluginRefStringError(path) - } - return registry, owner, name, ref, nil -} - -func newInvalidPluginFullNameStringError(s string) error { - return &ParseError{ - typeString: "plugin name", - input: s, - err: errors.New("must be in the form registry/owner/name"), - } -} - -func newInvalidPluginRefStringError(s string) error { - return &ParseError{ - typeString: "plugin reference", - input: s, - err: errors.New("must be in the form registry/owner/name[:ref]"), - } -} diff --git a/private/bufpkg/bufplugin/plugin_data.go b/private/bufpkg/bufplugin/plugin_data.go index bd6d2cd6ed..330c252b2e 100644 --- a/private/bufpkg/bufplugin/plugin_data.go +++ b/private/bufpkg/bufplugin/plugin_data.go @@ -96,7 +96,7 @@ func newPluginData( } if !DigestEqual(actualDigest, expectedDigest) { return &DigestMismatchError{ - PluginFullName: pluginKey.PluginFullName(), + FullName: pluginKey.FullName(), CommitID: pluginKey.CommitID(), ExpectedDigest: expectedDigest, ActualDigest: actualDigest, diff --git a/private/bufpkg/bufplugin/plugin_data_provider.go b/private/bufpkg/bufplugin/plugin_data_provider.go index a12b50a2a3..e8786cb128 100644 --- a/private/bufpkg/bufplugin/plugin_data_provider.go +++ b/private/bufpkg/bufplugin/plugin_data_provider.go @@ -30,7 +30,7 @@ type PluginDataProvider interface { // // Returned PluginDatas will be in the same order as the input PluginKeys. // - // The input PluginKeys are expected to be unique by PluginFullName. The implementation + // The input PluginKeys are expected to be unique by FullName. The implementation // may error if this is not the case. // // The input PluginKeys are expected to have the same DigestType. The implementation diff --git a/private/bufpkg/bufplugin/plugin_full_name.go b/private/bufpkg/bufplugin/plugin_full_name.go deleted file mode 100644 index 172a257859..0000000000 --- a/private/bufpkg/bufplugin/plugin_full_name.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2020-2024 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package bufplugin - -import ( - "errors" - "fmt" - "strings" - - "github.com/bufbuild/buf/private/pkg/netext" -) - -// PluginFullName represents the full name of the Plugin, including its registry, owner, and name. -type PluginFullName interface { - // String returns "registry/owner/name". - fmt.Stringer - - // Registry returns the hostname of the BSR instance that this Plugin is contained within. - Registry() string - // Owner returns the name of the user or organization that owns this Plugin. - Owner() string - // Name returns the name of the Plugin. - Name() string - - isPluginFullName() -} - -// NewPluginFullName returns a new PluginFullName for the given components. -func NewPluginFullName( - registry string, - owner string, - name string, -) (PluginFullName, error) { - return newPluginFullName(registry, owner, name) -} - -// ParsePluginFullName parses a PluginFullName from a string in the form "registry/owner/name". -func ParsePluginFullName(pluginFullNameString string) (PluginFullName, error) { - // parsePluginFullNameComponents returns ParseErrors. - registry, owner, name, err := parsePluginFullNameComponents(pluginFullNameString) - if err != nil { - return nil, err - } - if err := validatePluginFullNameParameters(registry, owner, name); err != nil { - return nil, &ParseError{ - typeString: "plugin name", - input: pluginFullNameString, - err: err, - } - } - // We don't rely on constructors for ParseErrors. - return newPluginFullName(registry, owner, name) -} - -// *** PRIVATE *** - -type pluginFullName struct { - registry string - owner string - name string -} - -func newPluginFullName( - registry string, - owner string, - name string, -) (*pluginFullName, error) { - if err := validatePluginFullNameParameters(registry, owner, name); err != nil { - return nil, err - } - return &pluginFullName{ - registry: registry, - owner: owner, - name: name, - }, nil -} - -func (p *pluginFullName) Registry() string { - return p.registry -} - -func (p *pluginFullName) Owner() string { - return p.owner -} - -func (p *pluginFullName) Name() string { - return p.name -} - -func (p *pluginFullName) String() string { - return p.registry + "/" + p.owner + "/" + p.name -} - -func (*pluginFullName) isPluginFullName() {} - -func validatePluginFullNameParameters( - registry string, - owner string, - name string, -) error { - if registry == "" { - return errors.New("registry is empty") - } - if _, err := netext.ValidateHostname(registry); err != nil { - return fmt.Errorf("registry %q is not a valid hostname: %w", registry, err) - } - if owner == "" { - return errors.New("owner is empty") - } - if strings.Contains(owner, "/") { - return fmt.Errorf("owner %q cannot contain slashes", owner) - } - if name == "" { - return errors.New("name is empty") - } - if strings.Contains(name, "/") { - return fmt.Errorf("name %q cannot contain slashes", name) - } - return nil -} diff --git a/private/bufpkg/bufplugin/plugin_key.go b/private/bufpkg/bufplugin/plugin_key.go index fe8046589b..d78f140584 100644 --- a/private/bufpkg/bufplugin/plugin_key.go +++ b/private/bufpkg/bufplugin/plugin_key.go @@ -19,6 +19,7 @@ import ( "fmt" "sync" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/uuidutil" "github.com/google/uuid" ) @@ -32,10 +33,10 @@ type PluginKey interface { // String returns "registry/owner/name:dashlessCommitID". fmt.Stringer - // PluginFullName returns the full name of the Plugin. + // FullName returns the full name of the Plugin. // // Always present. - PluginFullName() PluginFullName + FullName() bufparse.FullName // CommitID returns the ID of the Commit. // // It is up to the caller to convert this to a dashless ID when necessary. @@ -59,7 +60,7 @@ type PluginKey interface { // *not* validate the digest. If you need to validate the digset, call Digest() and evaluate // the returned error. func NewPluginKey( - pluginFullName PluginFullName, + pluginFullName bufparse.FullName, commitID uuid.UUID, getDigest func() (Digest, error), ) (PluginKey, error) { @@ -73,19 +74,19 @@ func NewPluginKey( // ** PRIVATE ** type pluginKey struct { - pluginFullName PluginFullName + pluginFullName bufparse.FullName commitID uuid.UUID getDigest func() (Digest, error) } func newPluginKey( - pluginFullName PluginFullName, + pluginFullName bufparse.FullName, commitID uuid.UUID, getDigest func() (Digest, error), ) (*pluginKey, error) { if pluginFullName == nil { - return nil, errors.New("nil PluginFullName when constructing PluginKey") + return nil, errors.New("nil FullName when constructing PluginKey") } if commitID == uuid.Nil { return nil, errors.New("empty commitID when constructing PluginKey") @@ -97,7 +98,7 @@ func newPluginKey( }, nil } -func (p *pluginKey) PluginFullName() PluginFullName { +func (p *pluginKey) FullName() bufparse.FullName { return p.pluginFullName } diff --git a/private/bufpkg/bufplugin/plugin_key_provider.go b/private/bufpkg/bufplugin/plugin_key_provider.go index 57e1050471..fcde880280 100644 --- a/private/bufpkg/bufplugin/plugin_key_provider.go +++ b/private/bufpkg/bufplugin/plugin_key_provider.go @@ -17,6 +17,8 @@ package bufplugin import ( "context" "io/fs" + + "github.com/bufbuild/buf/private/bufpkg/bufparse" ) var ( @@ -24,19 +26,19 @@ var ( NopPluginKeyProvider PluginKeyProvider = nopPluginKeyProvider{} ) -// PluginKeyProvider provides PluginKeys for PluginRefs. +// PluginKeyProvider provides PluginKeys for bufparse.Refs. type PluginKeyProvider interface { // GetPluginKeysForPluginRefs gets the PluginKets for the given PluginRefs. // // Returned PluginKeys will be in the same order as the input PluginRefs. // - // The input PluginRefs are expected to be unique by PluginFullName. The implementation + // The input PluginRefs are expected to be unique by FullName. The implementation // may error if this is not the case. // - // If there is no error, the length of the PluginKeys returned will match the length of the PluginRefs. + // If there is no error, the length of the PluginKeys returned will match the length of the Refs. // If there is an error, no PluginKeys will be returned. // If any PluginRef is not found, an error with fs.ErrNotExist will be returned. - GetPluginKeysForPluginRefs(context.Context, []PluginRef, DigestType) ([]PluginKey, error) + GetPluginKeysForPluginRefs(context.Context, []bufparse.Ref, DigestType) ([]PluginKey, error) } // *** PRIVATE *** @@ -45,7 +47,7 @@ type nopPluginKeyProvider struct{} func (nopPluginKeyProvider) GetPluginKeysForPluginRefs( context.Context, - []PluginRef, + []bufparse.Ref, DigestType, ) ([]PluginKey, error) { return nil, fs.ErrNotExist diff --git a/private/bufpkg/bufplugin/plugin_ref.go b/private/bufpkg/bufplugin/plugin_ref.go deleted file mode 100644 index 329296226f..0000000000 --- a/private/bufpkg/bufplugin/plugin_ref.go +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2020-2024 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package bufplugin - -import ( - "errors" - "fmt" -) - -// PluginRef is an unresolved reference to a Plugin. -type PluginRef interface { - // String returns "registry/owner/name[:ref]". - fmt.Stringer - - // PluginFullName returns the full name of the Plugin. - // - // Always present. - PluginFullName() PluginFullName - // Ref returns the reference within the Plugin. - // - // May be a label or dashless commitID. - // - // May be empty, in which case this references the commit of the default label of the Plugin. - Ref() string - - isPluginRef() -} - -// NewPluginRef returns a new PluginRef for the given compoonents. -func NewPluginRef( - registry string, - owner string, - name string, - ref string, -) (PluginRef, error) { - pluginFullName, err := NewPluginFullName(registry, owner, name) - if err != nil { - return nil, err - } - return newPluginRef(pluginFullName, ref) -} - -// ParsePluginRef parses a PluginRef from a string in the form "registry/owner/name[:ref]". -func ParsePluginRef(pluginRefString string) (PluginRef, error) { - // Returns ParseErrors. - registry, owner, name, ref, err := parsePluginRefComponents(pluginRefString) - if err != nil { - return nil, err - } - // We don't rely on constructors for ParseErrors. - return NewPluginRef(registry, owner, name, ref) -} - -// *** PRIVATE *** - -type pluginRef struct { - pluginFullName PluginFullName - ref string -} - -func newPluginRef( - pluginFullName PluginFullName, - ref string, -) (*pluginRef, error) { - if pluginFullName == nil { - return nil, errors.New("nil PluginFullName when constructing PluginRef") - } - return &pluginRef{ - pluginFullName: pluginFullName, - ref: ref, - }, nil -} - -func (m *pluginRef) PluginFullName() PluginFullName { - return m.pluginFullName -} - -func (m *pluginRef) Ref() string { - return m.ref -} - -func (m *pluginRef) String() string { - if m.ref == "" { - return m.pluginFullName.String() - } - return m.pluginFullName.String() + ":" + m.ref -} - -func (*pluginRef) isPluginRef() {} diff --git a/private/bufpkg/bufprotosource/bufprotosource.go b/private/bufpkg/bufprotosource/bufprotosource.go index 664225812e..4c3be081b1 100644 --- a/private/bufpkg/bufprotosource/bufprotosource.go +++ b/private/bufpkg/bufprotosource/bufprotosource.go @@ -29,7 +29,7 @@ import ( "sort" "strconv" - "github.com/bufbuild/buf/private/bufpkg/bufmodule" + "github.com/bufbuild/buf/private/bufpkg/bufparse" "github.com/bufbuild/buf/private/pkg/normalpath" "github.com/bufbuild/buf/private/pkg/protodescriptor" "github.com/google/uuid" @@ -247,16 +247,16 @@ type FileInfo interface { // RootDirPath: proto // ExternalPath: /foo/bar/proto/one/one.proto ExternalPath() string - // ModuleFullName is the module that this file came from. + // FullName is the module that this file came from. // // Note this *can* be nil if we did not build from a named module. // All code must assume this can be nil. // Note that nil checking should work since the backing type is always a pointer. - ModuleFullName() bufmodule.ModuleFullName + FullName() bufparse.FullName // CommitID is the commit for the module that this file came from. // - // This will only be set if ModuleFullName is set, but may not be set - // even if ModuleFullName is set, that is commit is optional information + // This will only be set if FullName is set, but may not be set + // even if FullName is set, that is commit is optional information // even if we know what module this file came from. CommitID() uuid.UUID // IsImport returns true if this file is an import.