blob: 18991de60d2e1dd4f549e288712bff4374fceb3a [file] [log] [blame]
Trevor Radcliffe9b81d792023-09-29 15:22:52 +00001// 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
15package bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/bazel"
20)
21
22type SyspropLibraryLabels struct {
23 SyspropLibraryLabel string
24 CcSharedLibraryLabel string
25 CcStaticLibraryLabel string
26 JavaLibraryLabel string
27}
28
29// TODO(b/240463568): Additional properties will be added for API validation
30type bazelSyspropLibraryAttributes struct {
31 Srcs bazel.LabelListAttribute
32 Tags bazel.StringListAttribute
33}
34
35func Bp2buildBaseSyspropLibrary(ctx android.Bp2buildMutatorContext, name string, srcs bazel.LabelListAttribute) {
36 apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
37
38 ctx.CreateBazelTargetModule(
39 bazel.BazelTargetModuleProperties{
40 Rule_class: "sysprop_library",
41 Bzl_load_location: "//build/bazel/rules/sysprop:sysprop_library.bzl",
42 },
43 android.CommonAttributes{Name: name},
44 &bazelSyspropLibraryAttributes{
45 Srcs: srcs,
46 Tags: apexAvailableTags,
47 },
48 )
49}
50
51type bazelCcSyspropLibraryAttributes struct {
52 Dep bazel.LabelAttribute
53 Min_sdk_version *string
54 Tags bazel.StringListAttribute
55}
56
57func Bp2buildSyspropCc(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, minSdkVersion *string) {
58 apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
59
60 attrs := &bazelCcSyspropLibraryAttributes{
61 Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
62 Min_sdk_version: minSdkVersion,
63 Tags: apexAvailableTags,
64 }
65
66 if labels.CcSharedLibraryLabel != "" {
67 ctx.CreateBazelTargetModule(
68 bazel.BazelTargetModuleProperties{
69 Rule_class: "cc_sysprop_library_shared",
70 Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
71 },
72 android.CommonAttributes{Name: labels.CcSharedLibraryLabel},
73 attrs)
74 }
75 if labels.CcStaticLibraryLabel != "" {
76 ctx.CreateBazelTargetModule(
77 bazel.BazelTargetModuleProperties{
78 Rule_class: "cc_sysprop_library_static",
79 Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
80 },
81 android.CommonAttributes{Name: labels.CcStaticLibraryLabel},
82 attrs)
83 }
84}
85
86type bazelJavaLibraryAttributes struct {
87 Dep bazel.LabelAttribute
88 Min_sdk_version *string
89 Tags bazel.StringListAttribute
90}
91
92func Bp2buildSyspropJava(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, minSdkVersion *string) {
93 apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
94
95 ctx.CreateBazelTargetModule(
96 bazel.BazelTargetModuleProperties{
97 Rule_class: "java_sysprop_library",
98 Bzl_load_location: "//build/bazel/rules/java:java_sysprop_library.bzl",
99 },
100 android.CommonAttributes{Name: labels.JavaLibraryLabel},
101 &bazelJavaLibraryAttributes{
102 Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
103 Min_sdk_version: minSdkVersion,
104 Tags: apexAvailableTags,
105 })
106}