Skip to content

Commit 97f2dfb

Browse files
authored
refactor: rename channel to api (#3708)
1 parent 3c8af0b commit 97f2dfb

17 files changed

Lines changed: 132 additions & 139 deletions

File tree

internal/config/config.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ type Library struct {
192192
// overrides Default.Transport.
193193
Transport string `yaml:"transport,omitempty"`
194194

195-
// Veneer indicates this library has hand-written code with generated
196-
// submodules. When true, the library uses language-specific module
197-
// configuration (e.g., rust.modules) instead of generating a complete crate
198-
// from channels.
195+
// Veneer indicates this library has hand-written code. A veneer may
196+
// contain generated libraries.
199197
Veneer bool `yaml:"veneer,omitempty"`
200198

201199
// Language-specific fields are below.

internal/librarian/add.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ func addCommand() *cli.Command {
4545
if name == "" {
4646
return errMissingLibraryName
4747
}
48-
var channels []string
48+
var apis []string
4949
if len(args.Slice()) > 1 {
50-
channels = args.Slice()[1:]
50+
apis = args.Slice()[1:]
5151
}
52-
return runAdd(ctx, name, channels...)
52+
return runAdd(ctx, name, apis...)
5353
},
5454
}
5555
}
@@ -74,15 +74,15 @@ func runAdd(ctx context.Context, name string, channel ...string) error {
7474
return nil
7575
}
7676

77-
func addLibraryToLibrarianConfig(cfg *config.Config, name string, channel ...string) *config.Config {
77+
func addLibraryToLibrarianConfig(cfg *config.Config, name string, api ...string) *config.Config {
7878
lib := &config.Library{
7979
Name: name,
8080
CopyrightYear: strconv.Itoa(time.Now().Year()),
8181
}
8282

83-
for _, c := range channel {
83+
for _, a := range api {
8484
lib.APIs = append(lib.APIs, &config.API{
85-
Path: c,
85+
Path: a,
8686
})
8787
}
8888
cfg.Libraries = append(cfg.Libraries, lib)

internal/librarian/add_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func TestAddCommand(t *testing.T) {
238238
}
239239
if test.wantAPIs != nil {
240240
if diff := cmp.Diff(test.wantAPIs, got.APIs); diff != "" {
241-
t.Errorf("channels mismatch (-want +got):\n%s", diff)
241+
t.Errorf("apis mismatch (-want +got):\n%s", diff)
242242
}
243243
}
244244
})
@@ -249,7 +249,7 @@ func TestAddLibraryToLibrarianYaml(t *testing.T) {
249249
for _, test := range []struct {
250250
name string
251251
libraryName string
252-
channels []string
252+
apis []string
253253
want []*config.API
254254
}{
255255
{
@@ -259,7 +259,7 @@ func TestAddLibraryToLibrarianYaml(t *testing.T) {
259259
{
260260
name: "library with single API",
261261
libraryName: "newlib",
262-
channels: []string{"google/cloud/storage/v1"},
262+
apis: []string{"google/cloud/storage/v1"},
263263
want: []*config.API{
264264
{
265265
Path: "google/cloud/storage/v1",
@@ -269,7 +269,7 @@ func TestAddLibraryToLibrarianYaml(t *testing.T) {
269269
{
270270
name: "library with multiple APIs",
271271
libraryName: "google-cloud-secret-manager",
272-
channels: []string{
272+
apis: []string{
273273
"google/cloud/secretmanager/v1",
274274
"google/cloud/secretmanager/v1beta2",
275275
"google/cloud/secrets/v1beta1",
@@ -303,7 +303,7 @@ func TestAddLibraryToLibrarianYaml(t *testing.T) {
303303
if err := yaml.Write(librarianConfigPath, cfg); err != nil {
304304
t.Fatal(err)
305305
}
306-
cfg = addLibraryToLibrarianConfig(cfg, test.libraryName, test.channels...)
306+
cfg = addLibraryToLibrarianConfig(cfg, test.libraryName, test.apis...)
307307
if len(cfg.Libraries) != 2 {
308308
t.Errorf("libraries count = %d, want 2", len(cfg.Libraries))
309309
}
@@ -316,7 +316,7 @@ func TestAddLibraryToLibrarianYaml(t *testing.T) {
316316
t.Errorf("version = %q, want %q", found.Version, "")
317317
}
318318
if diff := cmp.Diff(test.want, found.APIs); diff != "" {
319-
t.Errorf("channels mismatch (-want +got):\n%s", diff)
319+
t.Errorf("mismatch (-want +got):\n%s", diff)
320320
}
321321
})
322322
}

internal/librarian/dart/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func toSidekickConfig(library *config.Library, ch *config.API, googleapisDir str
5656
"googleapis-root": googleapisDir,
5757
}
5858

59-
channel, err := serviceconfig.Find(googleapisDir, ch.Path)
59+
api, err := serviceconfig.Find(googleapisDir, ch.Path)
6060
if err != nil {
6161
return nil, err
6262
}
@@ -65,7 +65,7 @@ func toSidekickConfig(library *config.Library, ch *config.API, googleapisDir str
6565
General: sidekickconfig.GeneralConfig{
6666
Language: "dart",
6767
SpecificationFormat: "protobuf",
68-
ServiceConfig: channel.ServiceConfig,
68+
ServiceConfig: api.ServiceConfig,
6969
SpecificationSource: ch.Path,
7070
},
7171
Source: source,

internal/librarian/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ func postGenerate(ctx context.Context, language string) error {
167167
}
168168
}
169169

170-
func defaultOutput(language, channel, defaultOut string) string {
170+
func defaultOutput(language, api, defaultOut string) string {
171171
switch language {
172172
case languageRust:
173-
return rust.DefaultOutput(channel, defaultOut)
173+
return rust.DefaultOutput(api, defaultOut)
174174
default:
175175
return defaultOut
176176
}

internal/librarian/library.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func mergePackageDependencies(defaults, lib []*config.RustPackageDependency) []*
9090

9191
// libraryOutput returns the output path for a library. If the library has an
9292
// explicit output path, it returns that. Otherwise, it computes the default
93-
// output path based on the channel path and default configuration.
93+
// output path based on the api path and default configuration.
9494
func libraryOutput(language string, lib *config.Library, defaults *config.Default) string {
9595
if lib.Output != "" {
9696
return lib.Output
@@ -99,23 +99,23 @@ func libraryOutput(language string, lib *config.Library, defaults *config.Defaul
9999
// Veneers require explicit output, so return empty if not set.
100100
return ""
101101
}
102-
channelPath := deriveAPIPath(language, lib.Name)
102+
apiPath := deriveAPIPath(language, lib.Name)
103103
if len(lib.APIs) > 0 && lib.APIs[0].Path != "" {
104-
channelPath = lib.APIs[0].Path
104+
apiPath = lib.APIs[0].Path
105105
}
106106
defaultOut := ""
107107
if defaults != nil {
108108
defaultOut = defaults.Output
109109
}
110-
return defaultOutput(language, channelPath, defaultOut)
110+
return defaultOutput(language, apiPath, defaultOut)
111111
}
112112

113113
// prepareLibrary applies language-specific derivations and fills defaults.
114114
// For Rust libraries without an explicit output path, it derives the output
115-
// from the first channel path.
115+
// from the first api path.
116116
func prepareLibrary(language string, lib *config.Library, defaults *config.Default, fillInDefaults bool) (*config.Library, error) {
117117
if len(lib.APIs) == 0 {
118-
// If no channels are specified, create an empty channel first
118+
// If no apis are specified, create an empty api first
119119
lib.APIs = append(lib.APIs, &config.API{})
120120
}
121121

internal/librarian/library_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,43 +253,43 @@ func TestPrepareLibrary(t *testing.T) {
253253
language string
254254
output string
255255
veneer bool
256-
channels []*config.API
256+
apis []*config.API
257257
wantOutput string
258258
wantErr bool
259259
wantAPIPath string
260260
}{
261261
{
262-
name: "empty output derives path from channel",
262+
name: "empty output derives path from api",
263263
language: "rust",
264-
channels: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
264+
apis: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
265265
wantOutput: "src/generated/cloud/secretmanager/v1",
266266
},
267267
{
268268
name: "explicit output keeps explicit path",
269269
language: "rust",
270270
output: "custom/output",
271-
channels: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
271+
apis: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
272272
wantOutput: "custom/output",
273273
},
274274
{
275275
name: "empty output uses default for non-rust",
276276
language: "go",
277-
channels: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
277+
apis: []*config.API{{Path: "google/cloud/secretmanager/v1"}},
278278
wantOutput: "src/generated",
279279
},
280280
{
281-
name: "rust with no channels creates default and derives path",
281+
name: "rust with no apis creates default and derives path",
282282
language: "rust",
283-
channels: nil,
283+
apis: nil,
284284
wantOutput: "src/generated/cloud/secretmanager/v1",
285285
wantAPIPath: "google/cloud/secretmanager/v1",
286286
},
287287
{
288-
name: "veneer rust with no channels does not derive path",
288+
name: "veneer rust with no apis does not derive path",
289289
language: "rust",
290290
output: "src/storage/test/v1",
291291
veneer: true,
292-
channels: nil,
292+
apis: nil,
293293
wantOutput: "src/storage/test/v1",
294294
wantAPIPath: "",
295295
},
@@ -307,7 +307,7 @@ func TestPrepareLibrary(t *testing.T) {
307307
{
308308
name: "rust lib without service config",
309309
language: "rust",
310-
channels: []*config.API{{Path: "google/cloud/orgpolicy/v1"}},
310+
apis: []*config.API{{Path: "google/cloud/orgpolicy/v1"}},
311311
wantOutput: "src/generated/cloud/orgpolicy/v1",
312312
wantAPIPath: "google/cloud/orgpolicy/v1",
313313
},
@@ -317,7 +317,7 @@ func TestPrepareLibrary(t *testing.T) {
317317
Name: "google-cloud-secretmanager-v1",
318318
Output: test.output,
319319
Veneer: test.veneer,
320-
APIs: test.channels,
320+
APIs: test.apis,
321321
}
322322
defaults := &config.Default{
323323
Output: "src/generated",
@@ -338,7 +338,7 @@ func TestPrepareLibrary(t *testing.T) {
338338
if len(got.APIs) > 0 {
339339
ch := got.APIs[0]
340340
if test.wantAPIPath != "" && ch.Path != test.wantAPIPath {
341-
t.Errorf("got channel path %q, want %q", ch.Path, test.wantAPIPath)
341+
t.Errorf("got %q, want %q", ch.Path, test.wantAPIPath)
342342
}
343343
}
344344
})

internal/librarian/python/generate.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
// Generate generates a Python client library.
3232
func Generate(ctx context.Context, library *config.Library, googleapisDir string) error {
3333
if len(library.APIs) == 0 {
34-
return fmt.Errorf("no channels configured for library %q", library.Name)
34+
return fmt.Errorf("no apis configured for library %q", library.Name)
3535
}
3636

3737
// Convert library.Output to absolute path since protoc runs from a
@@ -50,11 +50,9 @@ func Generate(ctx context.Context, library *config.Library, googleapisDir string
5050
// Some aspects of generation currently require the repo root. Compute it once here
5151
// and pass it down.
5252
repoRoot := filepath.Dir(filepath.Dir(outdir))
53-
54-
// Generate each channel separately.
55-
for _, channel := range library.APIs {
56-
if err := generateAPI(ctx, channel, library, googleapisDir, repoRoot); err != nil {
57-
return fmt.Errorf("failed to generate channel %q: %w", channel.Path, err)
53+
for _, api := range library.APIs {
54+
if err := generateAPI(ctx, api, library, googleapisDir, repoRoot); err != nil {
55+
return fmt.Errorf("failed to generate api %q: %w", api.Path, err)
5856
}
5957
}
6058

@@ -64,19 +62,19 @@ func Generate(ctx context.Context, library *config.Library, googleapisDir string
6462

6563
// TODO(https://github.com/googleapis/librarian/issues/3146):
6664
// Remove the default version fudget here, as Generate should
67-
// compute it. For now, use the last component of the first channel path as
65+
// compute it. For now, use the last component of the first api path as
6866
// the default version.
6967
defaultVersion := filepath.Base(library.APIs[0].Path)
7068

7169
// Generate .repo-metadata.json from the service config in the first
72-
// channel.
70+
// api.
7371
// TODO(https://github.com/googleapis/librarian/issues/3159): stop
7472
// hardcoding the language and repo name, instead getting it passed in.
75-
channel, err := serviceconfig.Find(googleapisDir, library.APIs[0].Path)
73+
api, err := serviceconfig.Find(googleapisDir, library.APIs[0].Path)
7674
if err != nil {
7775
return fmt.Errorf("failed to find service config: %w", err)
7876
}
79-
absoluteServiceConfig := filepath.Join(googleapisDir, channel.ServiceConfig)
77+
absoluteServiceConfig := filepath.Join(googleapisDir, api.ServiceConfig)
8078
if err := repometadata.Generate(library, "python", "googleapis/google-cloud-python", absoluteServiceConfig, defaultVersion, outdir); err != nil {
8179
return fmt.Errorf("failed to generate .repo-metadata.json: %w", err)
8280
}
@@ -100,32 +98,32 @@ func Generate(ctx context.Context, library *config.Library, googleapisDir string
10098
return nil
10199
}
102100

103-
// generateAPI generates part of a library for a single channel.
104-
func generateAPI(ctx context.Context, channel *config.API, library *config.Library, googleapisDir, repoRoot string) error {
101+
// generateAPI generates part of a library for a single api.
102+
func generateAPI(ctx context.Context, api *config.API, library *config.Library, googleapisDir, repoRoot string) error {
105103
// Note: the Python Librarian container generates to a temporary directory,
106104
// then the results into owl-bot-staging. We generate straight into
107105
// owl-bot-staging instead. The post-processor then moves the files into
108106
// the correct final position in the repository.
109107
// TODO(https://github.com/googleapis/librarian/issues/3210): generate
110108
// directly in place.
111109

112-
stagingChildDirectory := getStagingChildDirectory(channel.Path)
110+
stagingChildDirectory := getStagingChildDirectory(api.Path)
113111
stagingDir := filepath.Join(repoRoot, "owl-bot-staging", library.Name, stagingChildDirectory)
114112
if err := os.MkdirAll(stagingDir, 0755); err != nil {
115113
return err
116114
}
117-
protocOptions, err := createProtocOptions(channel, library, googleapisDir, stagingDir)
115+
protocOptions, err := createProtocOptions(api, library, googleapisDir, stagingDir)
118116
if err != nil {
119117
return err
120118
}
121119

122-
apiDir := filepath.Join(googleapisDir, channel.Path)
120+
apiDir := filepath.Join(googleapisDir, api.Path)
123121
protos, err := filepath.Glob(apiDir + "/*.proto")
124122
if err != nil {
125123
return fmt.Errorf("failed to find protos: %w", err)
126124
}
127125
if len(protos) == 0 {
128-
return fmt.Errorf("no protos found in channel %q", channel.Path)
126+
return fmt.Errorf("no protos found in api %q", api.Path)
129127
}
130128

131129
// We want the proto filenames to be relative to googleapisDir
@@ -167,11 +165,11 @@ func createProtocOptions(ch *config.API, library *config.Library, googleapisDir,
167165
opts = append(opts, "metadata")
168166

169167
// Add Python-specific options
170-
// First common options that apply to all channels
168+
// First common options that apply to all apis
171169
if library.Python != nil && len(library.Python.OptArgs) > 0 {
172170
opts = append(opts, library.Python.OptArgs...)
173171
}
174-
// Then options that apply to this specific channel
172+
// Then options that apply to this specific api
175173
if library.Python != nil && len(library.Python.OptArgsByAPI) > 0 {
176174
apiOptArgs, ok := library.Python.OptArgsByAPI[ch.Path]
177175
if ok {
@@ -202,12 +200,12 @@ func createProtocOptions(ch *config.API, library *config.Library, googleapisDir,
202200
if grpcConfigPath != "" {
203201
opts = append(opts, fmt.Sprintf("retry-config=%s", grpcConfigPath))
204202
}
205-
channel, err := serviceconfig.Find(googleapisDir, ch.Path)
203+
api, err := serviceconfig.Find(googleapisDir, ch.Path)
206204
if err != nil {
207205
return nil, err
208206
}
209-
if channel != nil && channel.ServiceConfig != "" {
210-
opts = append(opts, fmt.Sprintf("service-yaml=%s", channel.ServiceConfig))
207+
if api != nil && api.ServiceConfig != "" {
208+
opts = append(opts, fmt.Sprintf("service-yaml=%s", api.ServiceConfig))
211209
}
212210

213211
return []string{

0 commit comments

Comments
 (0)