Skip to content

Commit 28b17bc

Browse files
authored
refactor: rename source_oaths to source_roots (#1531)
Fixes: #1513
1 parent 918507c commit 28b17bc

File tree

11 files changed

+41
-40
lines changed

11 files changed

+41
-40
lines changed

doc/container-contract.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ For more details, see the Go implementation in [state.go](../internal/librarian/
127127
| `version` | string | The last released version of the library. | No | Must be a valid semantic version, "v" prefix is optional. |
128128
| `last_generated_commit` | string | The commit hash from the API definition repository at which the library was last generated. | No | Must be a 40-character hexadecimal string. |
129129
| `apis` | list | A list of [APIs](#apis-object) that are part of this library. | Yes | Must not be empty. |
130-
| `source_paths` | list | A list of directories in the language repository where Librarian contributes code. | Yes | Must not be empty, and each path must be a valid directory path. |
130+
| `source_roots` | list | A list of directories in the language repository where Librarian contributes code. | Yes | Must not be empty, and each path must be a valid directory path. |
131131
| `preserve_regex` | list | A list of regular expressions for files and directories to preserve during the copy and remove process. | No | Each entry must be a valid regular expression. |
132-
| `remove_regex` | list | A list of regular expressions for files and directories to remove before copying generated code. If not set, this defaults to the `source_paths`. A more specific `preserve_regex` takes precedence. | No | Each entry must be a valid regular expression. |
132+
| `remove_regex` | list | A list of regular expressions for files and directories to remove before copying generated code. If not set, this defaults to the `source_roots`. A more specific `preserve_regex` takes precedence. | No | Each entry must be a valid regular expression. |
133133

134134
#### `apis` Object
135135

@@ -153,7 +153,7 @@ Each object in the `apis` list represents a single API and has the following fie
153153
"service_config": "storage.yaml"
154154
}
155155
],
156-
"source_paths": [
156+
"source_roots": [
157157
"src/google/cloud/storage",
158158
"test/google/cloud/storage"
159159
],

doc/state-schema.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Each object in the `libraries` list represents a single library and has the foll
2121
| `version` | string | The last released version of the library. | No | Must be a valid semantic version, "v" prefix is optional. |
2222
| `last_generated_commit` | string | The commit hash from the API definition repository at which the library was last generated. | No | Must be a 40-character hexadecimal string. |
2323
| `apis` | list | A list of [APIs](#apis-object) that are part of this library. | Yes | Must not be empty. |
24-
| `source_paths` | list | A list of directories in the language repository where Librarian contributes code. | Yes | Must not be empty, and each path must be a valid directory path. |
24+
| `source_roots` | list | A list of directories in the language repository where Librarian contributes code. | Yes | Must not be empty, and each path must be a valid directory path. |
2525
| `preserve_regex` | list | A list of regular expressions for files and directories to preserve during the copy and remove process. | No | Each entry must be a valid regular expression. |
26-
| `remove_regex` | list | A list of regular expressions for files and directories to remove before copying generated code. If not set, this defaults to the `source_paths`. A more specific `preserve_regex` takes precedence. | No | Each entry must be a valid regular expression. |
26+
| `remove_regex` | list | A list of regular expressions for files and directories to remove before copying generated code. If not set, this defaults to the `source_roots`. A more specific `preserve_regex` takes precedence. | No | Each entry must be a valid regular expression. |
2727

2828
## `apis` Object
2929

@@ -45,7 +45,7 @@ libraries:
4545
apis:
4646
- path: "google/storage/v1"
4747
service_config: "storage.yaml"
48-
source_paths:
48+
source_roots:
4949
- "src/google/cloud/storage"
5050
- "test/google/cloud/storage"
5151
preserve_regex:

internal/config/state.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ type LibraryState struct {
9292
// A list of APIs that are part of this library.
9393
APIs []*API `yaml:"apis" json:"apis"`
9494
// A list of directories in the language repository where Librarian contributes code.
95-
SourcePaths []string `yaml:"source_paths" json:"source_paths"`
95+
SourceRoots []string `yaml:"source_roots" json:"source_roots"`
9696
// A list of regular expressions for files and directories to preserve during the copy and remove process.
9797
PreserveRegex []string `yaml:"preserve_regex" json:"preserve_regex"`
9898
// A list of regular expressions for files and directories to remove before copying generated code.
99-
// If not set, this defaults to the `source_paths`.
99+
// If not set, this defaults to the `source_roots`.
100100
// A more specific `preserve_regex` takes precedence.
101101
RemoveRegex []string `yaml:"remove_regex" json:"remove_regex"`
102102
}
@@ -137,10 +137,10 @@ func (l *LibraryState) Validate() error {
137137
return fmt.Errorf("invalid api at index %d: %w", i, err)
138138
}
139139
}
140-
if len(l.SourcePaths) == 0 {
141-
return fmt.Errorf("source_paths cannot be empty")
140+
if len(l.SourceRoots) == 0 {
141+
return fmt.Errorf("source_roots cannot be empty")
142142
}
143-
for i, p := range l.SourcePaths {
143+
for i, p := range l.SourceRoots {
144144
if !isValidDirPath(p) {
145145
return fmt.Errorf("invalid source_path at index %d: %q", i, p)
146146
}

internal/config/state_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestLibrarianState_Validate(t *testing.T) {
3131
Libraries: []*LibraryState{
3232
{
3333
ID: "a/b",
34-
SourcePaths: []string{"src/a", "src/b"},
34+
SourceRoots: []string{"src/a", "src/b"},
3535
APIs: []*API{
3636
{
3737
Path: "a/b/v1",
@@ -47,7 +47,7 @@ func TestLibrarianState_Validate(t *testing.T) {
4747
Libraries: []*LibraryState{
4848
{
4949
ID: "a/b",
50-
SourcePaths: []string{"src/a", "src/b"},
50+
SourceRoots: []string{"src/a", "src/b"},
5151
APIs: []*API{
5252
{
5353
Path: "a/b/v1",
@@ -84,7 +84,7 @@ func TestLibrary_Validate(t *testing.T) {
8484
name: "valid library",
8585
library: &LibraryState{
8686
ID: "a/b",
87-
SourcePaths: []string{"src/a", "src/b"},
87+
SourceRoots: []string{"src/a", "src/b"},
8888
APIs: []*API{
8989
{
9090
Path: "a/b/v1",
@@ -95,7 +95,7 @@ func TestLibrary_Validate(t *testing.T) {
9595
{
9696
name: "missing id",
9797
library: &LibraryState{
98-
SourcePaths: []string{"src/a", "src/b"},
98+
SourceRoots: []string{"src/a", "src/b"},
9999
APIs: []*API{
100100
{
101101
Path: "a/b/v1",
@@ -108,7 +108,7 @@ func TestLibrary_Validate(t *testing.T) {
108108
name: "id is dot",
109109
library: &LibraryState{
110110
ID: ".",
111-
SourcePaths: []string{"src/a", "src/b"},
111+
SourceRoots: []string{"src/a", "src/b"},
112112
APIs: []*API{
113113
{
114114
Path: "a/b/v1",
@@ -121,7 +121,7 @@ func TestLibrary_Validate(t *testing.T) {
121121
name: "id is double dot",
122122
library: &LibraryState{
123123
ID: "..",
124-
SourcePaths: []string{"src/a", "src/b"},
124+
SourceRoots: []string{"src/a", "src/b"},
125125
APIs: []*API{
126126
{
127127
Path: "a/b/v1",
@@ -146,7 +146,7 @@ func TestLibrary_Validate(t *testing.T) {
146146
name: "missing apis",
147147
library: &LibraryState{
148148
ID: "a/b",
149-
SourcePaths: []string{"src/a", "src/b"},
149+
SourceRoots: []string{"src/a", "src/b"},
150150
},
151151
wantErr: true,
152152
},
@@ -155,7 +155,7 @@ func TestLibrary_Validate(t *testing.T) {
155155
library: &LibraryState{
156156
ID: "a/b",
157157
Version: "1.2.3",
158-
SourcePaths: []string{"src/a", "src/b"},
158+
SourceRoots: []string{"src/a", "src/b"},
159159
APIs: []*API{
160160
{
161161
Path: "a/b/v1",
@@ -167,7 +167,7 @@ func TestLibrary_Validate(t *testing.T) {
167167
name: "invalid id characters",
168168
library: &LibraryState{
169169
ID: "a/b!",
170-
SourcePaths: []string{"src/a", "src/b"},
170+
SourceRoots: []string{"src/a", "src/b"},
171171
APIs: []*API{
172172
{
173173
Path: "a/b/v1",
@@ -181,7 +181,7 @@ func TestLibrary_Validate(t *testing.T) {
181181
library: &LibraryState{
182182
ID: "a/b",
183183
LastGeneratedCommit: "not-a-hex-string",
184-
SourcePaths: []string{"src/a", "src/b"},
184+
SourceRoots: []string{"src/a", "src/b"},
185185
APIs: []*API{
186186
{
187187
Path: "a/b/v1",
@@ -195,7 +195,7 @@ func TestLibrary_Validate(t *testing.T) {
195195
library: &LibraryState{
196196
ID: "a/b",
197197
LastGeneratedCommit: "deadbeef",
198-
SourcePaths: []string{"src/a", "src/b"},
198+
SourceRoots: []string{"src/a", "src/b"},
199199
APIs: []*API{
200200
{
201201
Path: "a/b/v1",
@@ -208,7 +208,7 @@ func TestLibrary_Validate(t *testing.T) {
208208
name: "valid preserve_regex",
209209
library: &LibraryState{
210210
ID: "a/b",
211-
SourcePaths: []string{"src/a"},
211+
SourceRoots: []string{"src/a"},
212212
APIs: []*API{{Path: "a/b/v1"}},
213213
PreserveRegex: []string{".*\\.txt"},
214214
},
@@ -217,7 +217,7 @@ func TestLibrary_Validate(t *testing.T) {
217217
name: "invalid preserve_regex",
218218
library: &LibraryState{
219219
ID: "a/b",
220-
SourcePaths: []string{"src/a"},
220+
SourceRoots: []string{"src/a"},
221221
APIs: []*API{{Path: "a/b/v1"}},
222222
PreserveRegex: []string{"["},
223223
},
@@ -227,7 +227,7 @@ func TestLibrary_Validate(t *testing.T) {
227227
name: "valid remove_regex",
228228
library: &LibraryState{
229229
ID: "a/b",
230-
SourcePaths: []string{"src/a"},
230+
SourceRoots: []string{"src/a"},
231231
APIs: []*API{{Path: "a/b/v1"}},
232232
RemoveRegex: []string{".*\\.log"},
233233
},
@@ -236,7 +236,7 @@ func TestLibrary_Validate(t *testing.T) {
236236
name: "invalid remove_regex",
237237
library: &LibraryState{
238238
ID: "a/b",
239-
SourcePaths: []string{"src/a"},
239+
SourceRoots: []string{"src/a"},
240240
APIs: []*API{{Path: "a/b/v1"}},
241241
RemoveRegex: []string{"("},
242242
},

internal/docker/docker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestDockerRun(t *testing.T) {
304304
ServiceConfig: "another_v1.yaml",
305305
},
306306
},
307-
SourcePaths: []string{
307+
SourceRoots: []string{
308308
"another-example-source-path",
309309
},
310310
},
@@ -446,7 +446,7 @@ func TestToGenerateRequestJSON(t *testing.T) {
446446
ServiceConfig: "example_service_config.yaml",
447447
},
448448
},
449-
SourcePaths: []string{
449+
SourceRoots: []string{
450450
"src/example/path",
451451
},
452452
PreserveRegex: []string{

internal/librarian/generate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func TestNewGenerateRunner(t *testing.T) {
368368
{
369369
ID: "some-library",
370370
APIs: []*config.API{{Path: "some/api", ServiceConfig: "api_config.yaml"}},
371-
SourcePaths: []string{"src/a"},
371+
SourceRoots: []string{"src/a"},
372372
},
373373
},
374374
}

internal/librarian/state_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import (
1919
"encoding/json"
2020
"errors"
2121
"fmt"
22-
"gopkg.in/yaml.v3"
2322
"io"
2423
"os"
2524
"path/filepath"
2625
"strings"
2726
"testing"
2827

28+
"gopkg.in/yaml.v3"
29+
2930
"github.com/google/go-cmp/cmp"
3031
"github.com/googleapis/librarian/internal/config"
3132
)
@@ -43,7 +44,7 @@ func TestParseLibrarianState(t *testing.T) {
4344
content: `image: gcr.io/test/image:v1.2.3
4445
libraries:
4546
- id: a/b
46-
source_paths:
47+
source_roots:
4748
- src/a
4849
- src/b
4950
apis:
@@ -56,7 +57,7 @@ libraries:
5657
Libraries: []*config.LibraryState{
5758
{
5859
ID: "a/b",
59-
SourcePaths: []string{"src/a", "src/b"},
60+
SourceRoots: []string{"src/a", "src/b"},
6061
APIs: []*config.API{
6162
{
6263
Path: "a/b/v1",
@@ -72,7 +73,7 @@ libraries:
7273
content: `image: gcr.io/test/image:v1.2.3
7374
libraries:
7475
- id: a/b
75-
source_paths:
76+
source_roots:
7677
- src/a
7778
- src/b
7879
apis:
@@ -287,7 +288,7 @@ func TestReadConfigureResponseJSON(t *testing.T) {
287288
ServiceConfig: "example_service_config.yaml",
288289
},
289290
},
290-
SourcePaths: []string{"src/example/path"},
291+
SourceRoots: []string{"src/example/path"},
291292
PreserveRegex: []string{"example-preserve-regex"},
292293
RemoveRegex: []string{"example-remove-regex"},
293294
},
@@ -385,7 +386,7 @@ func TestWriteLibrarianState(t *testing.T) {
385386
ServiceConfig: "example_service_config.yaml",
386387
},
387388
},
388-
SourcePaths: []string{
389+
SourceRoots: []string{
389390
"src/example/path",
390391
},
391392
PreserveRegex: []string{

testdata/e2e/generate/repo_backup/.librarian/state.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ libraries:
55
last_generated_commit:
66
apis:
77
- path: google/cloud/pubsub/v1
8-
source_paths:
8+
source_roots:
99
- google-cloud-pubsub/v1

testdata/successful-marshaling-and-writing.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"service_config": "example_service_config.yaml"
99
}
1010
],
11-
"source_paths": [
11+
"source_roots": [
1212
"src/example/path"
1313
],
1414
"preserve_regex": [

testdata/successful-parsing-librarianState-yaml.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ libraries:
66
apis:
77
- path: google/cloud/compute/v1
88
service_config: example_service_config.yaml
9-
source_paths:
9+
source_roots:
1010
- src/example/path
1111
preserve_regex:
1212
- example-preserve-regex
@@ -18,6 +18,6 @@ libraries:
1818
apis:
1919
- path: google/storage/v1
2020
service_config: storage_service_config.yaml
21-
source_paths: []
21+
source_roots: []
2222
preserve_regex: []
2323
remove_regex: []

0 commit comments

Comments
 (0)