github.com/wolfd/bazel-gazelle@v0.14.0/internal/repos/dep.go (about) 1 /* Copyright 2017 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 repos 17 18 import ( 19 "io/ioutil" 20 21 "github.com/bazelbuild/bazel-gazelle/internal/label" 22 toml "github.com/pelletier/go-toml" 23 ) 24 25 type depLockFile struct { 26 Projects []depProject `toml:"projects"` 27 } 28 29 type depProject struct { 30 Name string `toml:"name"` 31 Revision string `toml:"revision"` 32 Source string `toml:"source"` 33 } 34 35 func importRepoRulesDep(filename string) ([]Repo, error) { 36 data, err := ioutil.ReadFile(filename) 37 if err != nil { 38 return nil, err 39 } 40 var file depLockFile 41 if err := toml.Unmarshal(data, &file); err != nil { 42 return nil, err 43 } 44 45 var repos []Repo 46 for _, p := range file.Projects { 47 repos = append(repos, Repo{ 48 Name: label.ImportPathToBazelRepoName(p.Name), 49 GoPrefix: p.Name, 50 Commit: p.Revision, 51 Remote: p.Source, 52 }) 53 } 54 return repos, nil 55 }