From 4d1fc7c8b0f7ad0bcceffb131006e24e6c1b9376 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Sun, 19 Jan 2025 14:19:20 -0500 Subject: [PATCH] feat(generator/rust): full rename of module path We will need to generate some well-known types in the `gcp-sdk-wkt` crate. In this crate, only the root module contains all the message types. Meanwhile, the types we want to generate, for example, `google.protobuf.Type` reference each other *and* the existing well-known types. --- generator/internal/language/rust.go | 4 ++-- generator/internal/language/rust_test.go | 4 ++-- generator/internal/sidekick/sidekick_test.go | 2 +- .../testdata/rust/protobuf/golden/module/rpc/.sidekick.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/generator/internal/language/rust.go b/generator/internal/language/rust.go index f0249310a..5da5e13c7 100644 --- a/generator/internal/language/rust.go +++ b/generator/internal/language/rust.go @@ -73,7 +73,7 @@ func newRustCodec(options map[string]string) (*rustCodec, error) { year, _, _ := time.Now().Date() codec := &rustCodec{ generationYear: fmt.Sprintf("%04d", year), - modulePath: "model", + modulePath: "crate::model", deserializeWithdDefaults: true, extraPackages: []*rustPackage{}, packageMapping: map[string]*rustPackage{}, @@ -606,7 +606,7 @@ func rustMessageName(m *api.Message) string { func rustMessageScopeName(m *api.Message, childPackageName, modulePath, sourceSpecificationPackageName string, packageMapping map[string]*rustPackage) string { rustPkg := func(packageName string) string { if packageName == sourceSpecificationPackageName { - return "crate::" + modulePath + return modulePath } mapped, ok := rustMapPackage(packageName, packageMapping) if !ok { diff --git a/generator/internal/language/rust_test.go b/generator/internal/language/rust_test.go index 4acce9519..ce62f9740 100644 --- a/generator/internal/language/rust_test.go +++ b/generator/internal/language/rust_test.go @@ -33,7 +33,7 @@ func createRustCodec() *rustCodec { } return &rustCodec{ - modulePath: "model", + modulePath: "crate::model", extraPackages: []*rustPackage{wkt}, packageMapping: map[string]*rustPackage{ "google.protobuf": wkt, @@ -1377,7 +1377,7 @@ func TestRust_FormatDocCommentsCrossLinks(t *testing.T) { path: "src/generated/iam/v1", } c := &rustCodec{ - modulePath: "model", + modulePath: "crate::model", extraPackages: []*rustPackage{wkt, iam}, packageMapping: map[string]*rustPackage{ "google.protobuf": wkt, diff --git a/generator/internal/sidekick/sidekick_test.go b/generator/internal/sidekick/sidekick_test.go index 4da1d2b42..6cec5f842 100644 --- a/generator/internal/sidekick/sidekick_test.go +++ b/generator/internal/sidekick/sidekick_test.go @@ -159,7 +159,7 @@ func TestRustModuleFromProtobuf(t *testing.T) { ServiceConfig: "google/rpc/rpc_publish.yaml", Name: "rpc", ExtraOptions: map[string]string{ - "module-path": "error::rpc::generated", + "module-path": "crate::error::rpc::generated", "deserialize-with-defaults": "false", "package:wkt": "package=gcp-sdk-wkt,path=src/wkt,source=google.protobuf", }, diff --git a/generator/testdata/rust/protobuf/golden/module/rpc/.sidekick.toml b/generator/testdata/rust/protobuf/golden/module/rpc/.sidekick.toml index e77a06fd8..8a07ce1a9 100644 --- a/generator/testdata/rust/protobuf/golden/module/rpc/.sidekick.toml +++ b/generator/testdata/rust/protobuf/golden/module/rpc/.sidekick.toml @@ -25,5 +25,5 @@ googleapis-root = 'testdata/googleapis' copyright-year = '2024' deserialize-with-defaults = 'false' generate-module = 'true' -module-path = 'error::rpc::generated' +module-path = 'crate::error::rpc::generated' 'package:wkt' = 'package=gcp-sdk-wkt,path=src/wkt,source=google.protobuf'