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