github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/language/proto/package.go (about) 1 /* Copyright 2018 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 proto 17 18 import "path/filepath" 19 20 // Package contains metadata for a set of .proto files that have the 21 // same package name. This translates to a proto_library rule. 22 type Package struct { 23 Name string 24 RuleName string // if not set, defaults to Name 25 Files map[string]FileInfo 26 Imports map[string]bool 27 Options map[string]string 28 HasServices bool 29 } 30 31 func newPackage(name string) *Package { 32 return &Package{ 33 Name: name, 34 Files: map[string]FileInfo{}, 35 Imports: map[string]bool{}, 36 Options: map[string]string{}, 37 } 38 } 39 40 func (p *Package) addFile(info FileInfo) { 41 p.Files[info.Name] = info 42 for _, imp := range info.Imports { 43 p.Imports[imp] = true 44 } 45 for _, opt := range info.Options { 46 p.Options[opt.Key] = opt.Value 47 } 48 p.HasServices = p.HasServices || info.HasServices 49 } 50 51 func (p *Package) addGenFile(dir, name string) { 52 p.Files[name] = FileInfo{ 53 Name: name, 54 Path: filepath.Join(dir, filepath.FromSlash(name)), 55 } 56 }