blob: 076ce80a516fc5e225b256f1147306eee313f1f6 [file] [log] [blame]
Paul Duffin1c6c1c72020-02-21 10:28:43 +00001// Copyright 2020 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
15package cc
16
Rupert Shuttleworth54e78412021-02-15 11:04:32 +000017import (
18 "android/soong/android"
19 "android/soong/bazel"
20)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000021
22func init() {
23 RegisterLibraryHeadersBuildComponents(android.InitRegistrationContext)
Paul Duffin91756d22020-02-21 16:29:57 +000024
25 // Register sdk member types.
26 android.RegisterSdkMemberType(headersLibrarySdkMemberType)
Rupert Shuttleworth54e78412021-02-15 11:04:32 +000027
28 android.RegisterBp2BuildMutator("cc_library_headers", CcLibraryHeadersBp2Build)
Paul Duffin91756d22020-02-21 16:29:57 +000029}
30
31var headersLibrarySdkMemberType = &librarySdkMemberType{
32 SdkMemberTypeBase: android.SdkMemberTypeBase{
Martin Stjernholmcaa47d72020-07-11 04:52:24 +010033 PropertyName: "native_header_libs",
34 SupportsSdk: true,
35 HostOsDependent: true,
Paul Duffin91756d22020-02-21 16:29:57 +000036 },
37 prebuiltModuleType: "cc_prebuilt_library_headers",
Martin Stjernholmcd07bce2020-03-10 22:37:59 +000038 noOutputFiles: true,
Paul Duffin1c6c1c72020-02-21 10:28:43 +000039}
40
41func RegisterLibraryHeadersBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_library_headers", LibraryHeaderFactory)
Paul Duffinf5ea9e12020-02-21 10:57:00 +000043 ctx.RegisterModuleType("cc_prebuilt_library_headers", prebuiltLibraryHeaderFactory)
Paul Duffin1c6c1c72020-02-21 10:28:43 +000044}
45
46// cc_library_headers contains a set of c/c++ headers which are imported by
47// other soong cc modules using the header_libs property. For best practices,
48// use export_include_dirs property or LOCAL_EXPORT_C_INCLUDE_DIRS for
49// Make.
50func LibraryHeaderFactory() android.Module {
51 module, library := NewLibrary(android.HostAndDeviceSupported)
52 library.HeaderOnly()
Paul Duffin91756d22020-02-21 16:29:57 +000053 module.sdkMemberTypes = []android.SdkMemberType{headersLibrarySdkMemberType}
Paul Duffin1c6c1c72020-02-21 10:28:43 +000054 return module.Init()
55}
Paul Duffinf5ea9e12020-02-21 10:57:00 +000056
57// cc_prebuilt_library_headers is a prebuilt version of cc_library_headers
58func prebuiltLibraryHeaderFactory() android.Module {
59 module, library := NewPrebuiltLibrary(android.HostAndDeviceSupported)
60 library.HeaderOnly()
61 return module.Init()
62}
Rupert Shuttleworth54e78412021-02-15 11:04:32 +000063
64type bazelCcLibraryHeadersAttributes struct {
Jingwen Chenc1c26502021-04-05 10:35:13 +000065 Copts bazel.StringListAttribute
Jingwen Chen07027912021-03-15 06:02:43 -040066 Hdrs bazel.LabelListAttribute
Rupert Shuttleworthb8151682021-04-06 20:06:21 +000067 Includes bazel.StringListAttribute
Jingwen Chen07027912021-03-15 06:02:43 -040068 Deps bazel.LabelListAttribute
Rupert Shuttleworth54e78412021-02-15 11:04:32 +000069}
70
71type bazelCcLibraryHeaders struct {
72 android.BazelTargetModuleBase
73 bazelCcLibraryHeadersAttributes
74}
75
76func BazelCcLibraryHeadersFactory() android.Module {
77 module := &bazelCcLibraryHeaders{}
78 module.AddProperties(&module.bazelCcLibraryHeadersAttributes)
79 android.InitBazelTargetModule(module)
80 return module
81}
82
83func CcLibraryHeadersBp2Build(ctx android.TopDownMutatorContext) {
84 module, ok := ctx.Module().(*Module)
85 if !ok {
86 // Not a cc module
87 return
88 }
89
Jingwen Chen12b4c272021-03-10 02:05:59 -050090 if !module.ConvertWithBp2build(ctx) {
Jingwen Chen8c1b97e2021-02-18 03:21:34 -050091 return
92 }
93
Jingwen Chenc7846f32021-03-18 05:16:10 -040094 if ctx.ModuleType() != "cc_library_headers" {
Rupert Shuttleworth54e78412021-02-15 11:04:32 +000095 return
96 }
Jingwen Chenc7846f32021-03-18 05:16:10 -040097
Rupert Shuttleworthb8151682021-04-06 20:06:21 +000098 exportedIncludes, exportedIncludesHeaders := bp2BuildParseExportedIncludes(ctx, module)
Jingwen Chen107c0de2021-04-09 10:43:12 +000099 compilerAttrs := bp2BuildParseCompilerProps(ctx, module)
100 linkerAttrs := bp2BuildParseLinkerProps(ctx, module)
Rupert Shuttleworth54e78412021-02-15 11:04:32 +0000101
102 attrs := &bazelCcLibraryHeadersAttributes{
Jingwen Chen107c0de2021-04-09 10:43:12 +0000103 Copts: compilerAttrs.copts,
Rupert Shuttleworthb8151682021-04-06 20:06:21 +0000104 Includes: exportedIncludes,
105 Hdrs: exportedIncludesHeaders,
Jingwen Chen107c0de2021-04-09 10:43:12 +0000106 Deps: linkerAttrs.deps,
Rupert Shuttleworth54e78412021-02-15 11:04:32 +0000107 }
108
Liz Kammerfc46bc12021-02-19 11:06:17 -0500109 props := bazel.BazelTargetModuleProperties{
110 Rule_class: "cc_library_headers",
111 Bzl_load_location: "//build/bazel/rules:cc_library_headers.bzl",
112 }
Rupert Shuttleworth54e78412021-02-15 11:04:32 +0000113
Liz Kammerfc46bc12021-02-19 11:06:17 -0500114 ctx.CreateBazelTargetModule(BazelCcLibraryHeadersFactory, module.Name(), props, attrs)
Rupert Shuttleworth54e78412021-02-15 11:04:32 +0000115}
116
117func (m *bazelCcLibraryHeaders) Name() string {
118 return m.BaseModuleName()
119}
120
121func (m *bazelCcLibraryHeaders) GenerateAndroidBuildActions(ctx android.ModuleContext) {}