blob: 5baa5249b5ea4ce5b71a0dfe32f1518c155b618d [file] [log] [blame]
Jingwen Chenc63677b2021-06-17 05:43:19 +00001package bp2build
2
3import (
4 "android/soong/bazel"
5 "fmt"
6)
7
8// Data from the code generation process that is used to improve compatibility
9// between build systems.
10type CodegenCompatLayer struct {
11 // A map from the original module name to the generated/handcrafted Bazel
12 // label for legacy build systems to be able to build a fully-qualified
13 // Bazel target from an unique module name.
14 NameToLabelMap map[string]string
15}
16
17// Log an entry of module name -> Bazel target label.
18func (compatLayer CodegenCompatLayer) AddNameToLabelEntry(name, label string) {
19 // The module name may be prefixed with bazel.BazelTargetModuleNamePrefix if
20 // generated from bp2build.
21 name = bazel.StripNamePrefix(name)
22 if existingLabel, ok := compatLayer.NameToLabelMap[name]; ok {
23 panic(fmt.Errorf(
24 "Module '%s' maps to more than one Bazel target label: %s, %s. "+
25 "This shouldn't happen. It probably indicates a bug with the bp2build internals.",
26 name,
27 existingLabel,
28 label))
29 }
30 compatLayer.NameToLabelMap[name] = label
31}