Liz Kammer | ea6666f | 2021-02-17 10:17:28 -0500 | [diff] [blame] | 1 | // Copyright 2021 Google Inc. 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 | package android |
| 16 | |
| 17 | import "android/soong/bazel" |
| 18 | |
| 19 | // BazelModuleBase contains the property structs with metadata for modules which can be converted to |
| 20 | // Bazel. |
| 21 | type BazelModuleBase struct { |
| 22 | bazelProperties bazel.Properties |
| 23 | } |
| 24 | |
| 25 | // Bazelable is specifies the interface for modules that can be converted to Bazel. |
| 26 | type Bazelable interface { |
| 27 | bazelProps() *bazel.Properties |
| 28 | GetBazelLabel() string |
| 29 | ConvertWithBp2build() bool |
| 30 | } |
| 31 | |
| 32 | // BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules. |
| 33 | type BazelModule interface { |
| 34 | Module |
| 35 | Bazelable |
| 36 | } |
| 37 | |
| 38 | // InitBazelModule is a wrapper function that decorates a BazelModule with Bazel-conversion |
| 39 | // properties. |
| 40 | func InitBazelModule(module BazelModule) { |
| 41 | module.AddProperties(module.bazelProps()) |
| 42 | } |
| 43 | |
| 44 | // bazelProps returns the Bazel properties for the given BazelModuleBase. |
| 45 | func (b *BazelModuleBase) bazelProps() *bazel.Properties { |
| 46 | return &b.bazelProperties |
| 47 | } |
| 48 | |
| 49 | // GetBazelLabel returns the Bazel label for the given BazelModuleBase. |
| 50 | func (b *BazelModuleBase) GetBazelLabel() string { |
| 51 | return b.bazelProperties.Bazel_module.Label |
| 52 | } |
| 53 | |
| 54 | // ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build. |
| 55 | func (b *BazelModuleBase) ConvertWithBp2build() bool { |
| 56 | return b.bazelProperties.Bazel_module.Bp2build_available |
| 57 | } |