Skip to content

Commit 161aa9b

Browse files
authored
fix(internal/config): add IncludeList to dart config (#3837)
Prepare for Dart migration, add `IncludeList` to DartPackage config. Pass the value to sidekick config in library generation. For #3580
1 parent af1c5b7 commit 161aa9b

7 files changed

Lines changed: 105 additions & 16 deletions

File tree

internal/config/language.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ type DartPackage struct {
290290
// ExtraImports is additional imports to include in the generated library.
291291
ExtraImports string `yaml:"extra_imports,omitempty"`
292292

293+
// IncludeList is a list of items to include.
294+
IncludeList []string `yaml:"include_list,omitempty"`
295+
293296
// IssueTrackerURL is the URL for the issue tracker.
294297
IssueTrackerURL string `yaml:"issue_tracker_url,omitempty"`
295298

internal/librarian/dart/generate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package dart
1818

1919
import (
2020
"context"
21+
"strings"
2122

2223
"github.com/googleapis/librarian/internal/command"
2324
"github.com/googleapis/librarian/internal/config"
@@ -65,6 +66,9 @@ func toSidekickConfig(library *config.Library, ch *config.API, googleapisDir str
6566
if library.Dart != nil && library.Dart.TitleOverride != "" {
6667
source["title-override"] = library.Dart.TitleOverride
6768
}
69+
if library.Dart != nil && len(library.Dart.IncludeList) > 0 {
70+
source["include-list"] = strings.Join(library.Dart.IncludeList, ",")
71+
}
6872

6973
api, err := serviceconfig.Find(googleapisDir, ch.Path)
7074
if err != nil {

internal/librarian/dart/generate_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,36 @@ func TestToSidekickConfig(t *testing.T) {
440440
Codec: map[string]string{},
441441
},
442442
},
443+
{
444+
name: "with include list",
445+
library: &config.Library{
446+
Dart: &config.DartPackage{
447+
IncludeList: []string{
448+
"api.proto",
449+
"duration.proto",
450+
"empty.proto",
451+
"field_mask.proto",
452+
},
453+
},
454+
},
455+
channel: &config.API{
456+
Path: "google/cloud/secretmanager/v1",
457+
},
458+
googleapisDir: googleapisDir,
459+
want: &sidekickconfig.Config{
460+
General: sidekickconfig.GeneralConfig{
461+
Language: "dart",
462+
SpecificationFormat: "protobuf",
463+
ServiceConfig: "",
464+
SpecificationSource: "google/cloud/secretmanager/v1",
465+
},
466+
Source: map[string]string{
467+
"googleapis-root": googleapisDir,
468+
"include-list": "api.proto,duration.proto,empty.proto,field_mask.proto",
469+
},
470+
Codec: map[string]string{},
471+
},
472+
},
443473
{
444474
name: "with dart package",
445475
library: &config.Library{

tool/cmd/migrate/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ func buildGAPIC(files []string, repoPath string) ([]*config.Library, error) {
336336
if extraImports, ok := sidekick.Codec["extra-imports"]; ok && extraImports != "" {
337337
dartPackage.ExtraImports = extraImports
338338
}
339+
if includeList, ok := sidekick.Source["include-list"]; ok && includeList != "" {
340+
dartPackage.IncludeList = strings.Split(includeList, ",")
341+
}
339342
if partFile, ok := sidekick.Codec["part-file"]; ok && partFile != "" {
340343
// part-file in .sidekick.toml starts with src/, however, the file path is
341344
// actually {output}/lib/src/*.

tool/cmd/migrate/main_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ API key as an argument when initializing the client.
297297
},
298298
want: []*config.Library{
299299
{
300-
Name: "google_cloud_protobuf",
300+
Name: "google_cloud_appengine_v1",
301301
APIs: []*config.API{
302302
{
303-
Path: "google/protobuf",
303+
Path: "google/appengine/v1",
304304
},
305305
},
306306
Output: "testdata/read-sidekick-files/roots-update",
@@ -343,6 +343,37 @@ API key as an argument when initializing the client.
343343
},
344344
},
345345
},
346+
{
347+
name: "with include list",
348+
files: []string{
349+
"testdata/read-sidekick-files/include-list/.sidekick.toml",
350+
},
351+
want: []*config.Library{
352+
{
353+
Name: "google_cloud_protobuf",
354+
APIs: []*config.API{
355+
{
356+
Path: "google/protobuf",
357+
},
358+
},
359+
Output: "testdata/read-sidekick-files/include-list",
360+
SpecificationFormat: "protobuf",
361+
Dart: &config.DartPackage{
362+
IncludeList: []string{
363+
"api.proto",
364+
"duration.proto",
365+
"empty.proto",
366+
"field_mask.proto",
367+
"source_context.proto",
368+
"struct.proto",
369+
"timestamp.proto",
370+
"type.proto",
371+
"wrappers.proto",
372+
},
373+
},
374+
},
375+
},
376+
},
346377
} {
347378
t.Run(test.name, func(t *testing.T) {
348379
got, err := buildGAPIC(test.files, test.repoPath)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
specification-source = 'google/protobuf'
17+
18+
[source]
19+
# Don't generate 'any.proto'; use the hand-written version in protobuf.p.dart.
20+
include-list = """\
21+
api.proto,\
22+
duration.proto,\
23+
empty.proto,\
24+
field_mask.proto,\
25+
source_context.proto,\
26+
struct.proto,\
27+
timestamp.proto,\
28+
type.proto,\
29+
wrappers.proto\
30+
"""

tool/cmd/migrate/testdata/read-sidekick-files/roots-update/.sidekick.toml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,7 @@
1313
# limitations under the License.
1414

1515
[general]
16-
specification-source = 'google/protobuf'
16+
specification-source = 'google/appengine/v1'
1717

1818
[source]
19-
roots = 'protobuf'
20-
# Don't generate 'any.proto'; use the hand-written version in protobuf.p.dart.
21-
include-list = """\
22-
api.proto,\
23-
duration.proto,\
24-
empty.proto,\
25-
field_mask.proto,\
26-
source_context.proto,\
27-
struct.proto,\
28-
timestamp.proto,\
29-
type.proto,\
30-
wrappers.proto\
31-
"""
19+
roots = 'protobuf'

0 commit comments

Comments
 (0)