Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 4 | "fmt" |
| 5 | ) |
| 6 | |
| 7 | // Data from the code generation process that is used to improve compatibility |
| 8 | // between build systems. |
| 9 | type 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. |
| 17 | func (compatLayer CodegenCompatLayer) AddNameToLabelEntry(name, label string) { |
Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame] | 18 | 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 | } |