package.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright 2018 The Bazel Authors. All rights reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package proto
  13. import "path/filepath"
  14. // Package contains metadata for a set of .proto files that have the
  15. // same package name. This translates to a proto_library rule.
  16. type Package struct {
  17. Name string
  18. Files map[string]FileInfo
  19. Imports map[string]bool
  20. Options map[string]string
  21. HasServices bool
  22. }
  23. func newPackage(name string) *Package {
  24. return &Package{
  25. Name: name,
  26. Files: map[string]FileInfo{},
  27. Imports: map[string]bool{},
  28. Options: map[string]string{},
  29. }
  30. }
  31. func (p *Package) addFile(info FileInfo) {
  32. p.Files[info.Name] = info
  33. for _, imp := range info.Imports {
  34. p.Imports[imp] = true
  35. }
  36. for _, opt := range info.Options {
  37. p.Options[opt.Key] = opt.Value
  38. }
  39. p.HasServices = p.HasServices || info.HasServices
  40. }
  41. func (p *Package) addGenFile(dir, name string) {
  42. p.Files[name] = FileInfo{
  43. Name: name,
  44. Path: filepath.Join(dir, filepath.FromSlash(name)),
  45. }
  46. }