Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 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 cc |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/bazel" |
| 20 | ) |
| 21 | |
| 22 | // TODO(b/240463568): Additional properties will be added for API validation |
| 23 | type bazelSyspropLibraryAttributes struct { |
| 24 | Srcs bazel.LabelListAttribute |
Liz Kammer | 10e5a0e | 2023-03-23 11:51:22 -0400 | [diff] [blame] | 25 | Tags bazel.StringListAttribute |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | type bazelCcSyspropLibraryAttributes struct { |
| 29 | Dep bazel.LabelAttribute |
| 30 | Min_sdk_version *string |
Liz Kammer | 10e5a0e | 2023-03-23 11:51:22 -0400 | [diff] [blame] | 31 | Tags bazel.StringListAttribute |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | type SyspropLibraryLabels struct { |
| 35 | SyspropLibraryLabel string |
| 36 | SharedLibraryLabel string |
| 37 | StaticLibraryLabel string |
| 38 | } |
| 39 | |
| 40 | func Bp2buildSysprop(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, srcs bazel.LabelListAttribute, minSdkVersion *string) { |
Spandan Das | 39b6cc5 | 2023-04-12 19:05:49 +0000 | [diff] [blame] | 41 | apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module()) |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 42 | ctx.CreateBazelTargetModule( |
| 43 | bazel.BazelTargetModuleProperties{ |
| 44 | Rule_class: "sysprop_library", |
| 45 | Bzl_load_location: "//build/bazel/rules/sysprop:sysprop_library.bzl", |
| 46 | }, |
| 47 | android.CommonAttributes{Name: labels.SyspropLibraryLabel}, |
| 48 | &bazelSyspropLibraryAttributes{ |
| 49 | Srcs: srcs, |
Liz Kammer | 10e5a0e | 2023-03-23 11:51:22 -0400 | [diff] [blame] | 50 | Tags: apexAvailableTags, |
| 51 | }, |
| 52 | ) |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 53 | |
| 54 | attrs := &bazelCcSyspropLibraryAttributes{ |
| 55 | Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel), |
| 56 | Min_sdk_version: minSdkVersion, |
Liz Kammer | 10e5a0e | 2023-03-23 11:51:22 -0400 | [diff] [blame] | 57 | Tags: apexAvailableTags, |
Trevor Radcliffe | cee4e05 | 2022-09-06 19:31:25 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | if labels.SharedLibraryLabel != "" { |
| 61 | ctx.CreateBazelTargetModule( |
| 62 | bazel.BazelTargetModuleProperties{ |
| 63 | Rule_class: "cc_sysprop_library_shared", |
| 64 | Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl", |
| 65 | }, |
| 66 | android.CommonAttributes{Name: labels.SharedLibraryLabel}, |
| 67 | attrs) |
| 68 | } |
| 69 | |
| 70 | ctx.CreateBazelTargetModule( |
| 71 | bazel.BazelTargetModuleProperties{ |
| 72 | Rule_class: "cc_sysprop_library_static", |
| 73 | Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl", |
| 74 | }, |
| 75 | android.CommonAttributes{Name: labels.StaticLibraryLabel}, |
| 76 | attrs) |
| 77 | } |