blob: 7ddd4760e486c671945c9bb597843e8112d82606 [file] [log] [blame]
Trevor Radcliffecee4e052022-09-06 19:31:25 +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 cc
16
17import (
18 "android/soong/android"
19 "android/soong/bazel"
20)
21
22// TODO(b/240463568): Additional properties will be added for API validation
23type bazelSyspropLibraryAttributes struct {
24 Srcs bazel.LabelListAttribute
Liz Kammer10e5a0e2023-03-23 11:51:22 -040025 Tags bazel.StringListAttribute
Trevor Radcliffecee4e052022-09-06 19:31:25 +000026}
27
28type bazelCcSyspropLibraryAttributes struct {
29 Dep bazel.LabelAttribute
30 Min_sdk_version *string
Liz Kammer10e5a0e2023-03-23 11:51:22 -040031 Tags bazel.StringListAttribute
Trevor Radcliffecee4e052022-09-06 19:31:25 +000032}
33
34type SyspropLibraryLabels struct {
35 SyspropLibraryLabel string
36 SharedLibraryLabel string
37 StaticLibraryLabel string
38}
39
40func Bp2buildSysprop(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, srcs bazel.LabelListAttribute, minSdkVersion *string) {
Spandan Das39b6cc52023-04-12 19:05:49 +000041 apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
Trevor Radcliffecee4e052022-09-06 19:31:25 +000042 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 Kammer10e5a0e2023-03-23 11:51:22 -040050 Tags: apexAvailableTags,
51 },
52 )
Trevor Radcliffecee4e052022-09-06 19:31:25 +000053
54 attrs := &bazelCcSyspropLibraryAttributes{
55 Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
56 Min_sdk_version: minSdkVersion,
Liz Kammer10e5a0e2023-03-23 11:51:22 -040057 Tags: apexAvailableTags,
Trevor Radcliffecee4e052022-09-06 19:31:25 +000058 }
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}