Skip to content

Commit 9f691cd

Browse files
authored
fix: set output path based on currently generated output path (#3184)
The output path should be where the code gets generated. This doesn't match a specific pattern, so for the sake of migration easiest to set it to the existing output path. See https://paste.googleplex.com/6379904404946944 Fixes #3130 --------- Signed-off-by: ldetmer <[email protected]>
1 parent 671a3c2 commit 9f691cd

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

devtools/cmd/migrate-sidekick/main.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ const (
4040
)
4141

4242
var (
43-
errRepoNotFound = errors.New("repo path argument is required")
44-
errSidekickNotFound = errors.New(".sidekick.toml not found")
45-
errSrcNotFound = errors.New("src/generated directory not found")
46-
errTidyFailed = errors.New("librarian tidy failed")
43+
errRepoNotFound = errors.New("-repo flag is required")
44+
errSidekickNotFound = errors.New(".sidekick.toml not found")
45+
errSrcNotFound = errors.New("src/generated directory not found")
46+
errTidyFailed = errors.New("librarian tidy failed")
47+
errUnableToCalculateOutputPath = errors.New("unable to calculate output path")
4748
)
4849

4950
// SidekickConfig represents the structure of a .sidekick.toml file.
@@ -96,7 +97,6 @@ func run(args []string) error {
9697

9798
slog.Info("Reading sidekick.toml...", "path", repoPath)
9899

99-
// Read root .sidekick.toml for defaults
100100
defaults, err := readRootSidekick(repoPath)
101101
if err != nil {
102102
return fmt.Errorf("failed to read root .sidekick.toml: %w", err)
@@ -109,7 +109,7 @@ func run(args []string) error {
109109
}
110110

111111
// Read all sidekick.toml files
112-
libraries, err := readSidekickFiles(sidekickFiles)
112+
libraries, err := readSidekickFiles(sidekickFiles, repoPath)
113113
if err != nil {
114114
return fmt.Errorf("failed to read sidekick.toml files: %w", err)
115115
}
@@ -242,7 +242,7 @@ func findSidekickFiles(repoPath string) ([]string, error) {
242242
}
243243

244244
// readSidekickFiles reads all sidekick.toml files and extracts library information.
245-
func readSidekickFiles(files []string) (map[string]*config.Library, error) {
245+
func readSidekickFiles(files []string, repoPath string) (map[string]*config.Library, error) {
246246
libraries := make(map[string]*config.Library)
247247

248248
for _, file := range files {
@@ -296,6 +296,11 @@ func readSidekickFiles(files []string) (map[string]*config.Library, error) {
296296
libraries[libraryName] = lib
297297
}
298298
lib.SpecificationFormat = specificationFormat
299+
relativePath, err := filepath.Rel(repoPath, dir)
300+
if err != nil {
301+
return nil, fmt.Errorf("failed to calculate relative path: %w", errUnableToCalculateOutputPath)
302+
}
303+
lib.Output = relativePath
299304

300305
// Add channels
301306
lib.Channels = append(lib.Channels, &config.Channel{

devtools/cmd/migrate-sidekick/main_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ func TestFindSidekickFiles(t *testing.T) {
141141

142142
func TestReadSidekickFiles(t *testing.T) {
143143
for _, test := range []struct {
144-
name string
145-
files []string
146-
want map[string]*config.Library
147-
wantErr error
144+
name string
145+
files []string
146+
repoName string
147+
want map[string]*config.Library
148+
wantErr error
148149
}{
149150
{
150151
name: "read_sidekick_files",
@@ -165,6 +166,7 @@ func TestReadSidekickFiles(t *testing.T) {
165166
CopyrightYear: "2025",
166167
DescriptionOverride: "Description override",
167168
SpecificationFormat: "discovery",
169+
Output: "testdata/read-sidekick-files/success-read/nested",
168170
Rust: &config.RustCrate{
169171
RustDefault: config.RustDefault{
170172
DisabledRustdocWarnings: []string{"bare_urls", "broken_intra_doc_links", "redundant_explicit_links"},
@@ -202,6 +204,7 @@ func TestReadSidekickFiles(t *testing.T) {
202204
Version: "1.2.0",
203205
CopyrightYear: "2025",
204206
SpecificationFormat: "openapi",
207+
Output: "testdata/read-sidekick-files/success-read",
205208
Rust: &config.RustCrate{
206209
RustDefault: config.RustDefault{
207210
PackageDependencies: []*config.RustPackageDependency{
@@ -238,6 +241,14 @@ func TestReadSidekickFiles(t *testing.T) {
238241
},
239242
},
240243
},
244+
{
245+
name: "unable_to_calculate_output_path",
246+
files: []string{
247+
"testdata/read-sidekick-files/success-read/.sidekick.toml",
248+
},
249+
repoName: "/invalid/repo/path",
250+
wantErr: errUnableToCalculateOutputPath,
251+
},
241252
{
242253
name: "no_api_path",
243254
files: []string{
@@ -254,7 +265,7 @@ func TestReadSidekickFiles(t *testing.T) {
254265
},
255266
} {
256267
t.Run(test.name, func(t *testing.T) {
257-
got, err := readSidekickFiles(test.files)
268+
got, err := readSidekickFiles(test.files, test.repoName)
258269
if test.wantErr != nil {
259270
if !errors.Is(err, test.wantErr) {
260271
t.Errorf("got error %v, want %v", err, test.wantErr)

0 commit comments

Comments
 (0)