Jingwen Chen | c63677b | 2021-06-17 05:43:19 +0000 | [diff] [blame^] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
| 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. |
| 10 | type 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. |
| 18 | func (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 | } |