Skip to content

Commit 0ecb537

Browse files
authored
chore(tool/cmd/migrate): parse extra dependencies for ruby migration (#6921)
Update the Ruby migration tool to extract the `ruby-cloud-extra-dependencies` parameter from `BUILD.bazel` rules in googleapis and set the `extra_dependencies` configuration for Ruby APIs. This adds the `extra_dependencies` field to RubyAPI in internal/config and updates the config schema documentation. For #6632
1 parent 5558a02 commit 0ecb537

6 files changed

Lines changed: 84 additions & 4 deletions

File tree

doc/config-schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ This document describes the schema for the librarian.yaml.
488488
| Field | Type | Description |
489489
| :--- | :--- | :--- |
490490
| `env_prefix` | string | Is the environment variable prefix. |
491+
| `extra_dependencies` | string | Contains extra runtime dependencies to the .gemspec file. |
491492

492493
## RubyPackage Configuration
493494

internal/config/language.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,4 +851,7 @@ type RubyPackage struct {
851851
type RubyAPI struct {
852852
// EnvPrefix is the environment variable prefix.
853853
EnvPrefix string `yaml:"env_prefix,omitempty"`
854+
855+
// ExtraDependencies contains extra runtime dependencies to the .gemspec file.
856+
ExtraDependencies string `yaml:"extra_dependencies,omitempty"`
854857
}

tool/cmd/migrate/ruby.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"path/filepath"
2525
"regexp"
2626
"slices"
27-
"sort"
2827
"strings"
2928

3029
"github.com/googleapis/librarian/internal/config"
@@ -49,6 +48,7 @@ type owlbotSrc struct {
4948
// VersionedBuild represents build configuration parsed from BUILD.bazel for a Ruby API version.
5049
type VersionedBuild struct {
5150
EnvPrefix string
51+
ExtraDeps string
5252
}
5353

5454
func runRubyMigration(ctx context.Context, repoPath string) error {
@@ -133,7 +133,8 @@ func findRubyLibraries(googleapisPath, repoPath string) ([]*config.Library, erro
133133
}
134134
if vb != nil {
135135
lib.APIs[0].Ruby = &config.RubyAPI{
136-
EnvPrefix: vb.EnvPrefix,
136+
EnvPrefix: vb.EnvPrefix,
137+
ExtraDependencies: vb.ExtraDeps,
137138
}
138139
}
139140
}
@@ -169,8 +170,8 @@ func parseAPIFromOwlBot(owlBotPath string) (string, error) {
169170

170171
// parseWrapperOf sets the WrapperOf field for wrapper libraries.
171172
func parseWrapperOf(libraries []*config.Library) {
172-
sort.Slice(libraries, func(i, j int) bool {
173-
return libraries[i].Name < libraries[j].Name
173+
slices.SortFunc(libraries, func(a, b *config.Library) int {
174+
return strings.Compare(a.Name, b.Name)
174175
})
175176
for i, lib := range libraries {
176177
if len(lib.APIs) != 0 {
@@ -215,6 +216,8 @@ func parseVersionedBuild(googleapisDir, apiPath string) (*VersionedBuild, error)
215216
switch {
216217
case strings.HasPrefix(dep, "ruby-cloud-env-prefix="):
217218
vb.EnvPrefix, _ = strings.CutPrefix(dep, "ruby-cloud-env-prefix=")
219+
case strings.HasPrefix(dep, "ruby-cloud-extra-dependencies="):
220+
vb.ExtraDeps, _ = strings.CutPrefix(dep, "ruby-cloud-extra-dependencies=")
218221
}
219222
}
220223
}

tool/cmd/migrate/ruby_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ func TestFindRubyLibraries(t *testing.T) {
9090
t.Fatal(err)
9191
}
9292
want := []*config.Library{
93+
{
94+
Name: "google-cloud-compute-v1",
95+
APIs: []*config.API{
96+
{
97+
Path: "google/cloud/compute/v1",
98+
Ruby: &config.RubyAPI{
99+
EnvPrefix: "COMPUTE",
100+
ExtraDependencies: "google-cloud-common=~> 1.0",
101+
},
102+
},
103+
},
104+
},
93105
{
94106
Name: "google-cloud-secret_manager",
95107
Ruby: &config.RubyPackage{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
deep-copy-regex:
15+
- source: /google/cloud/compute/v1/[^/]+-ruby/(.*)
16+
dest: /owl-bot-staging/google-cloud-compute-v1/$1

tool/cmd/migrate/testdata/googleapis/google/cloud/compute/v1/BUILD.bazel

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,49 @@ go_gapic_assembly_pkg(
6060
":compute_go_gapic_srcjar-test.srcjar",
6161
":compute_go_proto",
6262
],
63+
)
64+
65+
###############################################################################
66+
# Ruby
67+
###############################################################################
68+
load(
69+
"@com_google_googleapis_imports//:imports.bzl",
70+
"ruby_cloud_gapic_library",
71+
"ruby_gapic_assembly_pkg",
72+
"ruby_proto_library",
73+
)
74+
75+
ruby_proto_library(
76+
name = "compute_ruby_proto",
77+
deps = [":compute_proto"],
78+
)
79+
80+
ruby_cloud_gapic_library(
81+
name = "compute_ruby_gapic",
82+
srcs = [":compute_proto_with_info"],
83+
extra_protoc_parameters = [
84+
"ruby-cloud-api-id=compute.googleapis.com",
85+
"ruby-cloud-api-shortname=compute",
86+
"ruby-cloud-gem-name=google-cloud-compute-v1",
87+
"ruby-cloud-generate-metadata=false",
88+
"ruby-cloud-generate-transports=rest",
89+
"ruby-cloud-env-prefix=COMPUTE",
90+
"ruby-cloud-product-url=https://cloud.google.com/compute/",
91+
"ruby-cloud-wrapper-gem-override=",
92+
"ruby-cloud-extra-dependencies=google-cloud-common=~> 1.0",
93+
],
94+
grpc_service_config = ":compute_grpc_service_config.json",
95+
ruby_cloud_description = "google-cloud-compute-v1 is the official client library for the Google Cloud Compute V1 API.",
96+
ruby_cloud_title = "Google Cloud Compute V1",
97+
deps = [
98+
":compute_ruby_proto",
99+
],
100+
)
101+
102+
ruby_gapic_assembly_pkg(
103+
name = "google-cloud-compute-v1-ruby",
104+
deps = [
105+
":compute_ruby_gapic",
106+
":compute_ruby_proto",
107+
],
63108
)

0 commit comments

Comments
 (0)