Skip to content

Commit 0ef6508

Browse files
authored
chore(tool/cmd/migrate): add a special output to name mapping (#3826)
Two libraries have special output dir name that can't be calculated based on API path. Therefore use a map to store the output to name mapping. For #3580
1 parent 4ed9c28 commit 0ef6508

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

tool/cmd/migrate/main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ var (
5555
errFetchSource = errors.New("cannot fetch source")
5656

5757
fetchSource = fetchGoogleapis
58+
59+
pathToName = map[string]string{
60+
"google_cloud_protojson_conformance": "google_cloud_protobuf_test_messages_proto3",
61+
"google_cloud_showcase_v1beta1": "google_cloud_showcase_v1beta1",
62+
}
5863
)
5964

6065
func main() {
@@ -243,9 +248,14 @@ func buildGAPIC(files []string, repoPath string) ([]*config.Library, error) {
243248
specificationFormat = "protobuf"
244249
}
245250

246-
// Library name or package name is derived from api path by packageName function in dart package.
247-
// However, each library in the librarian configuration should have a name.
248-
libraryName := genLibraryName(apiPath)
251+
var libraryName string
252+
if name, ok := pathToName[filepath.Base(filepath.Dir(file))]; ok {
253+
libraryName = name
254+
} else {
255+
// Library name or package name is derived from api path by packageName function in dart package.
256+
// However, each library in the librarian configuration should have a name.
257+
libraryName = genLibraryName(apiPath)
258+
}
249259
lib := &config.Library{
250260
Name: libraryName,
251261
APIs: []*config.API{

tool/cmd/migrate/main_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ API key as an argument when initializing the client.
257257
},
258258
want: nil,
259259
},
260+
{
261+
name: "special library dir",
262+
files: []string{
263+
"testdata/read-sidekick-files/special-dir/google_cloud_protojson_conformance/.sidekick.toml",
264+
},
265+
want: []*config.Library{
266+
{
267+
Name: "google_cloud_protobuf_test_messages_proto3",
268+
APIs: []*config.API{
269+
{
270+
Path: "src/google/protobuf",
271+
},
272+
},
273+
Output: "testdata/read-sidekick-files/special-dir/google_cloud_protojson_conformance",
274+
SpecificationFormat: "protobuf",
275+
},
276+
},
277+
},
260278
} {
261279
t.Run(test.name, func(t *testing.T) {
262280
got, err := buildGAPIC(test.files, test.repoPath)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[general]
2+
specification-source = 'src/google/protobuf'

0 commit comments

Comments
 (0)