github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/language/proto/lang.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 provides support for protocol buffer rules. 17 // It generates proto_library rules only (not go_proto_library or any other 18 // language-specific implementations). 19 // 20 // Configuration 21 // 22 // Configuration is largely controlled by Mode. In disable mode, proto rules are 23 // left alone (neither generated nor deleted). In legacy mode, filegroups are 24 // emitted containing protos. In default mode, proto_library rules are 25 // emitted. The proto mode may be set with the -proto command line flag or the 26 // "# gazelle:proto" directive. 27 // 28 // The configuration is largely public, and other languages may depend on it. 29 // For example, go uses Mode to determine whether to generate go_proto_library 30 // rules and ignore static .pb.go files. 31 // 32 // Rule generation 33 // 34 // Currently, Gazelle generates at most one proto_library per directory. Protos 35 // in the same package are grouped together into a proto_library. If there are 36 // sources for multiple packages, the package name that matches the directory 37 // name will be chosen; if there is no such package, an error will be printed. 38 // We expect to provide support for multiple proto_libraries in the future 39 // when Go has support for multiple packages and we have better rule matching. 40 // The generated proto_library will be named after the directory, not the 41 // proto or the package. For example, for foo/bar/baz.proto, a proto_library 42 // rule will be generated named //foo/bar:bar_proto. 43 // 44 // Dependency resolution 45 // 46 // proto_library rules are indexed by their srcs attribute. Gazelle attempts 47 // to resolve proto imports (e.g., import foo/bar/bar.proto) to the 48 // proto_library that contains the named source file 49 // (e.g., //foo/bar:bar_proto). If no indexed proto_library provides the source 50 // file, Gazelle will guess a label, following conventions. 51 // 52 // No attempt is made to resolve protos to rules in external repositories, 53 // since there's no indication that a proto import comes from an external 54 // repository. In the future, build files in external repos will be indexed, 55 // so we can support this (#12). 56 // 57 // Gazelle has special cases for Well Known Types (i.e., imports of the form 58 // google/protobuf/*.proto). These are resolved to rules in 59 // @com_google_protobuf. 60 package proto 61 62 import "github.com/bazelbuild/bazel-gazelle/language" 63 64 const protoName = "proto" 65 66 type protoLang struct{} 67 68 func (*protoLang) Name() string { return protoName } 69 70 func NewLanguage() language.Language { 71 return &protoLang{} 72 }