File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -51,9 +51,19 @@ func RunTidy() error {
5151 if err := validateLibraries (cfg ); err != nil {
5252 return err
5353 }
54+ for _ , lib := range cfg .Libraries {
55+ if lib .Output != "" && len (lib .Channels ) == 1 && isDerivableOutput (cfg , lib ) {
56+ lib .Output = ""
57+ }
58+ }
5459 return yaml .Write (librarianConfigPath , formatConfig (cfg ))
5560}
5661
62+ func isDerivableOutput (cfg * config.Config , lib * config.Library ) bool {
63+ derivedOutput := defaultOutput (cfg .Language , lib .Channels [0 ].Path , cfg .Default .Output )
64+ return lib .Output == derivedOutput
65+ }
66+
5767func validateLibraries (cfg * config.Config ) error {
5868 var (
5969 errs []error
Original file line number Diff line number Diff line change @@ -150,3 +150,35 @@ libraries:
150150 t .Errorf ("expected %v, got %v" , errDuplicateLibraryName , err )
151151 }
152152}
153+
154+ func TestTidy_DerivableOutput (t * testing.T ) {
155+ tempDir := t .TempDir ()
156+ t .Chdir (tempDir )
157+ configPath := filepath .Join (tempDir , librarianConfigPath )
158+ configContent := `
159+ language: rust
160+ default:
161+ output: generated/
162+ libraries:
163+ - name: google-cloud-secretmanager-v1
164+ output: generated/cloud/secretmanager/v1
165+ channels:
166+ - path: google/cloud/secretmanager/v1
167+ `
168+ if err := os .WriteFile (configPath , []byte (configContent ), 0644 ); err != nil {
169+ t .Fatal (err )
170+ }
171+ if err := RunTidy (); err != nil {
172+ t .Fatal (err )
173+ }
174+ cfg , err := yaml.Read [config.Config ](configPath )
175+ if err != nil {
176+ t .Fatal (err )
177+ }
178+ if len (cfg .Libraries ) != 1 {
179+ t .Fatalf ("expected 1 library, got %d" , len (cfg .Libraries ))
180+ }
181+ if cfg .Libraries [0 ].Output != "" {
182+ t .Errorf ("expected output to be empty, got %q" , cfg .Libraries [0 ].Output )
183+ }
184+ }
You can’t perform that action at this time.
0 commit comments