blob: dae88cecca785a0e656dc029c00f9a2ad56e24f4 [file] [log] [blame]
Jiyong Park9d452992018-10-03 00:38:19 +09001// Copyright 2018 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 android
16
17// ApexModule is the interface that a module type is expected to implement if
18// the module has to be built differently depending on whether the module
19// is destined for an apex or not (installed to one of the regular partitions).
20//
21// Native shared libraries are one such module type; when it is built for an
22// APEX, it should depend only on stable interfaces such as NDK, stable AIDL,
23// or C APIs from other APEXs.
24//
25// A module implementing this interface will be mutated into multiple
26// variations by the apex mutator if it is directly or indirectly included
27// in one or more APEXs. Specifically, if a module is included in apex.foo and
28// apex.bar then three apex variants are created: platform, apex.foo and
29// apex.bar. The platform variant is for the regular partitions
30// (e.g., /system or /vendor, etc.) while the other two are for the APEXs,
31// respectively.
32type ApexModule interface {
33 Module
34 apexModuleBase() *ApexModuleBase
35
36 // Marks that this module should be built for the APEX of the specified name
37 BuildForApex(apexName string)
38
39 // Tests whether this module will be built for the platform or not (= APEXs)
40 IsForPlatform() bool
41
42 // Returns the name of APEX that this module will be built for. Empty string
43 // is returned when 'IsForPlatform() == true'. Note that a module can be
44 // included to multiple APEXs, in which case, the module is mutated into
45 // multiple modules each of which for an APEX. This method returns the
46 // name of the APEX that a variant module is for.
47 ApexName() string
48
49 // Tests if this module can have APEX variants. APEX variants are
50 // created only for the modules that returns true here. This is useful
51 // for not creating APEX variants for shared libraries such as NDK stubs.
52 CanHaveApexVariants() bool
53
54 // Tests if this module can be installed to APEX as a file. For example,
55 // this would return true for shared libs while return false for static
56 // libs.
57 IsInstallableToApex() bool
58}
59
60type ApexProperties struct {
61 ApexName string `blueprint:"mutated"`
62}
63
64// Provides default implementation for the ApexModule interface. APEX-aware
65// modules are expected to include this struct and call InitApexModule().
66type ApexModuleBase struct {
67 ApexProperties ApexProperties
68
69 canHaveApexVariants bool
70}
71
72func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase {
73 return m
74}
75
76func (m *ApexModuleBase) BuildForApex(apexName string) {
77 m.ApexProperties.ApexName = apexName
78}
79
80func (m *ApexModuleBase) IsForPlatform() bool {
81 return m.ApexProperties.ApexName == ""
82}
83
84func (m *ApexModuleBase) ApexName() string {
85 return m.ApexProperties.ApexName
86}
87
88func (m *ApexModuleBase) CanHaveApexVariants() bool {
89 return m.canHaveApexVariants
90}
91
92func (m *ApexModuleBase) IsInstallableToApex() bool {
93 // should be overriden if needed
94 return false
95}
96
97func InitApexModule(m ApexModule) {
98 base := m.apexModuleBase()
99 base.canHaveApexVariants = true
100
101 m.AddProperties(&base.ApexProperties)
102}