Skip to content

Commit 9f8bcba

Browse files
authored
feat: migrate root sidekick config to librarian config in Dart repo (#3764)
Preparation for Dart migration, migrate root sidekick configuration to librarian configuration. For #3580
1 parent be4d443 commit 9f8bcba

3 files changed

Lines changed: 142 additions & 100 deletions

File tree

tool/cmd/migrate/main.go

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,37 +149,32 @@ func readRootSidekick(repoPath string) (*config.Config, error) {
149149
return nil, err
150150
}
151151

152-
releaseLevel := sidekick.Codec["release-level"]
153-
warnings := sidekick.Codec["disabled-rustdoc-warnings"]
154-
discoverySHA256 := sidekick.Source["discovery-sha256"]
155-
discoveryRoot := sidekick.Source["discovery-root"]
152+
version := sidekick.Codec["version"]
153+
apiKeys := sidekick.Codec["api-keys-environment-variables"]
154+
issueTrackerURL := sidekick.Codec["issue-tracker-url"]
156155
googleapisSHA256 := sidekick.Source["googleapis-sha256"]
157156
googleapisRoot := sidekick.Source["googleapis-root"]
158157
showcaseRoot := sidekick.Source["showcase-root"]
159158
showcaseSHA256 := sidekick.Source["showcase-sha256"]
160-
protobufRoot := sidekick.Source["protobuf-src-root"]
161-
protobufSHA256 := sidekick.Source["protobuf-src-sha256"]
162-
protobufSubDir := sidekick.Source["protobuf-src-subdir"]
159+
protobufRoot := sidekick.Source["protobuf-root"]
160+
protobufSHA256 := sidekick.Source["protobuf-sha256"]
161+
protobufSubDir := sidekick.Source["protobuf-subdir"]
163162
conformanceRoot := sidekick.Source["conformance-root"]
164163
conformanceSHA256 := sidekick.Source["conformance-sha256"]
165-
generateSetterSamples := sidekick.Codec["generate-setter-samples"]
166164

167-
discoveryCommit := strings.TrimSuffix(strings.TrimPrefix(discoveryRoot, discoveryArchivePrefix), tarballSuffix)
168165
googleapisCommit := strings.TrimSuffix(strings.TrimPrefix(googleapisRoot, googleapisArchivePrefix), tarballSuffix)
169166
showcaseCommit := strings.TrimSuffix(strings.TrimPrefix(showcaseRoot, showcaseArchivePrefix), tarballSuffix)
170167
protobufCommit := strings.TrimSuffix(strings.TrimPrefix(protobufRoot, protobufArchivePrefix), tarballSuffix)
171168
conformanceCommit := strings.TrimSuffix(strings.TrimPrefix(conformanceRoot, conformanceArchivePrefix), tarballSuffix)
172169

173-
// Parse package dependencies
174-
packageDependencies := parsePackageDependencies(sidekick.Codec)
170+
prefix := parseKeyWithPrefix(sidekick.Codec, "prefix:")
171+
packages := parseKeyWithPrefix(sidekick.Codec, "package:")
172+
protos := parseKeyWithPrefix(sidekick.Codec, "proto:")
175173

176174
cfg := &config.Config{
177-
Language: "rust",
175+
Language: "dart",
176+
Version: version,
178177
Sources: &config.Sources{
179-
Discovery: &config.Source{
180-
Commit: discoveryCommit,
181-
SHA256: discoverySHA256,
182-
},
183178
Googleapis: &config.Source{
184179
Commit: googleapisCommit,
185180
SHA256: googleapisSHA256,
@@ -199,12 +194,13 @@ func readRootSidekick(repoPath string) (*config.Config, error) {
199194
},
200195
},
201196
Default: &config.Default{
202-
Output: "src/generated/",
203-
ReleaseLevel: releaseLevel,
204-
Rust: &config.RustDefault{
205-
PackageDependencies: packageDependencies,
206-
DisabledRustdocWarnings: strToSlice(warnings, false),
207-
GenerateSetterSamples: generateSetterSamples,
197+
Output: "generated/",
198+
Dart: &config.DartPackage{
199+
APIKeysEnvironmentVariables: apiKeys,
200+
IssueTrackerURL: issueTrackerURL,
201+
Prefixes: prefix,
202+
Protos: protos,
203+
Packages: packages,
208204
},
209205
},
210206
}
@@ -714,15 +710,15 @@ func parsePackageDependencies(codec map[string]string) []*config.RustPackageDepe
714710
return packageDeps
715711
}
716712

717-
func parseDartPackages(codec map[string]string) map[string]string {
718-
packages := make(map[string]string)
713+
func parseKeyWithPrefix(codec map[string]string, prefix string) map[string]string {
714+
res := make(map[string]string)
719715
for key, value := range codec {
720-
if !strings.HasPrefix(key, "package:") {
716+
if !strings.HasPrefix(key, prefix) {
721717
continue
722718
}
723-
packages[key] = value
719+
res[key] = value
724720
}
725-
return packages
721+
return res
726722
}
727723

728724
func strToBool(s string) bool {

tool/cmd/migrate/main_test.go

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@ func TestReadRootSidekick(t *testing.T) {
3636
name: "success",
3737
path: "testdata/root-sidekick/success",
3838
want: &config.Config{
39-
Language: "rust",
39+
Language: "dart",
40+
Version: "0.4.0",
4041
Sources: &config.Sources{
41-
Discovery: &config.Source{
42-
Commit: "0bb1100f52bf0bae06f4b4d76742e7eba5c59793",
43-
SHA256: "67c8d3792f0ebf5f0582dce675c379d0f486604eb0143814c79e788954aa1212",
44-
},
4542
Googleapis: &config.Source{
46-
Commit: "fe58211356a91f4140ed51893703910db05ade91",
47-
SHA256: "839e897c39cada559b97d64f90378715a4a43fbc972d8cf93296db4156662085",
43+
Commit: "211d22fa6dfabfa52cbda04d1aee852a01301edf",
44+
SHA256: "9aa6e5167f76b869b53b71f9fe963e6e17ec58b2cbdeb30715ef95b92faabfc5",
4845
},
4946
Showcase: &config.Source{
5047
Commit: "69bdd62035d793f3d23a0c960dee547023c1c5ac",
@@ -61,36 +58,37 @@ func TestReadRootSidekick(t *testing.T) {
6158
},
6259
},
6360
Default: &config.Default{
64-
Output: "src/generated/",
65-
ReleaseLevel: "stable",
66-
Rust: &config.RustDefault{
67-
DisabledRustdocWarnings: []string{
68-
"redundant_explicit_links",
69-
"broken_intra_doc_links",
61+
Output: "generated/",
62+
ReleaseLevel: "",
63+
Dart: &config.DartPackage{
64+
APIKeysEnvironmentVariables: "GOOGLE_API_KEY",
65+
IssueTrackerURL: "https://github.com/googleapis/google-cloud-dart/issues",
66+
Packages: map[string]string{
67+
"package:google_cloud_api": "^0.4.0",
68+
"package:google_cloud_iam_v1": "^0.4.0",
69+
"package:google_cloud_location": "^0.4.0",
70+
"package:google_cloud_logging_type": "^0.4.0",
71+
"package:google_cloud_longrunning": "^0.4.0",
72+
"package:google_cloud_protobuf": "^0.4.0",
73+
"package:google_cloud_rpc": "^0.4.0",
74+
"package:google_cloud_type": "^0.4.0",
75+
"package:googleapis_auth": "^2.0.0",
76+
"package:http": "^1.3.0",
7077
},
71-
PackageDependencies: []*config.RustPackageDependency{
72-
{
73-
Feature: "_internal-http-client",
74-
Name: "gaxi",
75-
Package: "google-cloud-gax-internal",
76-
Source: "internal",
77-
UsedIf: "services",
78-
},
79-
{
80-
Name: "lazy_static",
81-
Package: "lazy_static",
82-
UsedIf: "services",
83-
ForceUsed: true,
84-
},
78+
Prefixes: map[string]string{"prefix:google.logging.type": "logging_type"},
79+
Protos: map[string]string{
80+
"proto:google.api": "package:google_cloud_api/api.dart",
81+
"proto:google.cloud.common": "package:google_cloud_common/common.dart",
82+
"proto:google.cloud.location": "package:google_cloud_location/location.dart",
83+
"proto:google.iam.v1": "package:google_cloud_iam_v1/iam.dart",
84+
"proto:google.logging.type": "package:google_cloud_logging_type/logging_type.dart",
85+
"proto:google.longrunning": "package:google_cloud_longrunning/longrunning.dart",
86+
"proto:google.protobuf": "package:google_cloud_protobuf/protobuf.dart",
87+
"proto:google.rpc": "package:google_cloud_rpc/rpc.dart",
88+
"proto:google.type": "package:google_cloud_type/type.dart",
8589
},
86-
GenerateSetterSamples: "true",
8790
},
8891
},
89-
Release: &config.Release{
90-
Remote: "upstream",
91-
Branch: "main",
92-
IgnoredChanges: []string{".repo-metadata.json", ".sidekick.toml"},
93-
},
9492
},
9593
},
9694
{
@@ -890,29 +888,41 @@ func TestRunMigrateCommand(t *testing.T) {
890888
}
891889
}
892890

893-
func TestParseDartPackages(t *testing.T) {
894-
t.Parallel()
891+
func TestParseWithPrefix(t *testing.T) {
895892
for _, test := range []struct {
896-
name string
897-
codec map[string]string
898-
want map[string]string
893+
name string
894+
prefix string
895+
want map[string]string
899896
}{
900897
{
901-
name: "success",
902-
codec: map[string]string{
898+
name: "prefix: as a prefix",
899+
prefix: "prefix:",
900+
want: map[string]string{
903901
"prefix:google.logging.type": "logging_type",
904-
"package:googleapis_auth": "^2.0.0",
905-
"package:http": "^1.3.0",
906902
},
903+
},
904+
{
905+
name: "package: as a prefix",
906+
prefix: "package:",
907907
want: map[string]string{
908908
"package:googleapis_auth": "^2.0.0",
909-
"package:http": "^1.3.0",
909+
},
910+
},
911+
{
912+
name: "proto: as a prefix",
913+
prefix: "proto:",
914+
want: map[string]string{
915+
"proto:google.protobuf": "package:google_cloud_protobuf/protobuf.dart",
910916
},
911917
},
912918
} {
913919
t.Run(test.name, func(t *testing.T) {
914-
t.Parallel()
915-
got := parseDartPackages(test.codec)
920+
codec := map[string]string{
921+
"prefix:google.logging.type": "logging_type",
922+
"package:googleapis_auth": "^2.0.0",
923+
"proto:google.protobuf": "package:google_cloud_protobuf/protobuf.dart",
924+
}
925+
got := parseKeyWithPrefix(codec, test.prefix)
916926
if diff := cmp.Diff(test.want, got); diff != "" {
917927
t.Errorf("mismatch (-want +got):\n%s", diff)
918928
}
Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,69 @@
1+
# Copyright 2025 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+
15+
[general]
16+
language = 'dart'
17+
specification-format = 'protobuf'
18+
119
[source]
2-
showcase-root = 'https://github.com/googleapis/gapic-showcase/archive/69bdd62035d793f3d23a0c960dee547023c1c5ac.tar.gz'
3-
showcase-sha256 = '96491310ba1b5c0c71738d3d80327a95196c1b6ac16f033e3fa440870efbbf5c'
4-
googleapis-root = 'https://github.com/googleapis/googleapis/archive/fe58211356a91f4140ed51893703910db05ade91.tar.gz'
5-
googleapis-sha256 = '839e897c39cada559b97d64f90378715a4a43fbc972d8cf93296db4156662085'
6-
discovery-root = 'https://github.com/googleapis/discovery-artifact-manager/archive/0bb1100f52bf0bae06f4b4d76742e7eba5c59793.tar.gz'
7-
discovery-sha256 = '67c8d3792f0ebf5f0582dce675c379d0f486604eb0143814c79e788954aa1212'
8-
protobuf-src-root = 'https://github.com/protocolbuffers/protobuf/archive/b407e8416e3893036aee5af9a12bd9b6a0e2b2e6.tar.gz'
9-
protobuf-src-sha256 = '55912546338433f465a552e9ef09930c63b9eb697053937416890cff83a8622d'
10-
protobuf-src-subdir = 'src'
20+
roots = 'googleapis'
21+
googleapis-root = 'https://github.com/googleapis/googleapis/archive/211d22fa6dfabfa52cbda04d1aee852a01301edf.tar.gz'
22+
googleapis-sha256 = '9aa6e5167f76b869b53b71f9fe963e6e17ec58b2cbdeb30715ef95b92faabfc5'
23+
# protobuf 29.3
24+
protobuf-extracted-name = 'protobuf-b407e8416e3893036aee5af9a12bd9b6a0e2b2e6'
25+
protobuf-root = 'https://github.com/protocolbuffers/protobuf/archive/b407e8416e3893036aee5af9a12bd9b6a0e2b2e6.tar.gz'
26+
protobuf-sha256 = '55912546338433f465a552e9ef09930c63b9eb697053937416890cff83a8622d'
27+
protobuf-subdir = 'src'
28+
# showcase 0.36.2
29+
showcase-extracted-name = 'gapic-showcase-69bdd62035d793f3d23a0c960dee547023c1c5ac'
30+
showcase-root = 'https://github.com/googleapis/gapic-showcase/archive/69bdd62035d793f3d23a0c960dee547023c1c5ac.tar.gz'
31+
showcase-sha256 = '96491310ba1b5c0c71738d3d80327a95196c1b6ac16f033e3fa440870efbbf5c'
32+
conformance-extracted-name = 'protobuf-b407e8416e3893036aee5af9a12bd9b6a0e2b2e6'
1133
conformance-root = 'https://github.com/protocolbuffers/protobuf/archive/b407e8416e3893036aee5af9a12bd9b6a0e2b2e6.tar.gz'
1234
conformance-sha256 = '55912546338433f465a552e9ef09930c63b9eb697053937416890cff83a8622d'
1335

1436
[codec]
15-
# The default version for all crates. This can be overridden in the crate's
16-
# `.sidekick.toml` file.
17-
version = "1.0.0"
18-
# The default release level for all crates.
19-
release-level = "stable"
20-
# Disable a number of warnings.
21-
# TODO(#1285) - remove `redundant_explicit_links` workaround when no longer needed
22-
# TODO(#742) - remove `broken_intro_doc_links` workaround when no longer needed
23-
disabled-rustdoc-warnings = "redundant_explicit_links,broken_intra_doc_links"
24-
# These are external (not part of `google-cloud-rust`) crates used by (nearly
25-
# all) generated crates.
26-
'package:lazy_static' = 'used-if=services,package=lazy_static,force-used=true'
27-
'package:gaxi' = 'used-if=services,package=google-cloud-gax-internal,feature=_internal-http-client,source=internal'
28-
'generate-setter-samples' = 'true'
29-
30-
[release]
31-
remote = 'upstream'
32-
branch = 'main'
33-
ignored-changes = ['.repo-metadata.json', '.sidekick.toml']
37+
# The default version for Dart packages.
38+
version = '0.4.0'
39+
40+
api-keys-environment-variables = 'GOOGLE_API_KEY'
41+
issue-tracker-url = 'https://github.com/googleapis/google-cloud-dart/issues'
42+
43+
# Dart names for `as` imports.
44+
'prefix:google.logging.type' = 'logging_type'
45+
46+
# Default package dependency versions.
47+
'package:googleapis_auth' = '^2.0.0'
48+
'package:http' = '^1.3.0'
49+
50+
# Generated packages
51+
'package:google_cloud_api' = '^0.4.0'
52+
'package:google_cloud_iam_v1' = '^0.4.0'
53+
'package:google_cloud_protobuf' = '^0.4.0'
54+
'package:google_cloud_location' = '^0.4.0'
55+
'package:google_cloud_longrunning' = '^0.4.0'
56+
'package:google_cloud_logging_type' = '^0.4.0'
57+
'package:google_cloud_rpc' = '^0.4.0'
58+
'package:google_cloud_type' = '^0.4.0'
59+
60+
# A mapping from protobuf packages to Dart imports.
61+
'proto:google.api' = 'package:google_cloud_api/api.dart'
62+
'proto:google.cloud.common' = 'package:google_cloud_common/common.dart'
63+
'proto:google.cloud.location' = 'package:google_cloud_location/location.dart'
64+
'proto:google.iam.v1' = 'package:google_cloud_iam_v1/iam.dart'
65+
'proto:google.logging.type' = 'package:google_cloud_logging_type/logging_type.dart'
66+
'proto:google.longrunning' = 'package:google_cloud_longrunning/longrunning.dart'
67+
'proto:google.protobuf' = 'package:google_cloud_protobuf/protobuf.dart'
68+
'proto:google.rpc' = 'package:google_cloud_rpc/rpc.dart'
69+
'proto:google.type' = 'package:google_cloud_type/type.dart'

0 commit comments

Comments
 (0)