github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/language/go/work.go (about) 1 /* Copyright 2022 The Bazel Authors. All rights reserved. 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 http://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 16 package golang 17 18 import ( 19 "fmt" 20 "path/filepath" 21 22 "github.com/bazelbuild/bazel-gazelle/language" 23 ) 24 25 func importReposFromWork(args language.ImportReposArgs) language.ImportReposResult { 26 // run go list in the dir where go.work is located 27 data, err := goListModules(filepath.Dir(args.Path)) 28 if err != nil { 29 return language.ImportReposResult{Error: processGoListError(nil, data)} 30 } 31 32 pathToModule, err := extractModules(data) 33 if err != nil { 34 return language.ImportReposResult{Error: err} 35 } 36 37 pathToModule, err = fillMissingSums(pathToModule) 38 if err != nil { 39 return language.ImportReposResult{Error: fmt.Errorf("finding module sums: %v", err)} 40 } 41 42 return language.ImportReposResult{Gen: toRepositoryRules(pathToModule)} 43 }