blob: ec57f06f4b02556e0df4099c4290fd81f5624b57 [file] [log] [blame]
Colin Crossc511bc52020-04-07 16:50:32 +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
17import (
18 "android/soong/android"
19 "android/soong/genrule"
20)
21
22// sdkMutator sets a creates a platform and an SDK variant for modules
23// that set sdk_version, and ignores sdk_version for the platform
24// variant. The SDK variant will be used for embedding in APKs
25// that may be installed on older platforms. Apexes use their own
26// variants that enforce backwards compatibility.
27func sdkMutator(ctx android.BottomUpMutatorContext) {
28 if ctx.Os() != android.Android {
29 return
30 }
31
32 switch m := ctx.Module().(type) {
33 case LinkableInterface:
34 if m.AlwaysSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -070035 if !m.UseSdk() && !m.SplitPerApiLevel() {
Colin Crossc511bc52020-04-07 16:50:32 +000036 ctx.ModuleErrorf("UseSdk() must return true when AlwaysSdk is set, did the factory forget to set Sdk_version?")
37 }
38 ctx.CreateVariations("sdk")
Colin Cross1348ce32020-10-01 13:37:16 -070039 } else if m.UseSdk() || m.SplitPerApiLevel() {
Colin Crossc511bc52020-04-07 16:50:32 +000040 modules := ctx.CreateVariations("", "sdk")
41 modules[0].(*Module).Properties.Sdk_version = nil
42 modules[1].(*Module).Properties.IsSdkVariant = true
43
Martin Stjernholmfd9eb4b2020-06-17 01:13:15 +010044 if ctx.Config().UnbundledBuildApps() {
Colin Crossc511bc52020-04-07 16:50:32 +000045 modules[0].(*Module).Properties.HideFromMake = true
Martin Stjernholm02229a22020-06-02 18:57:05 +010046 modules[0].(*Module).Properties.PreventInstall = true
Colin Crossc511bc52020-04-07 16:50:32 +000047 } else {
48 modules[1].(*Module).Properties.SdkAndPlatformVariantVisibleToMake = true
49 modules[1].(*Module).Properties.PreventInstall = true
50 }
51 ctx.AliasVariation("")
52 } else {
53 ctx.CreateVariations("")
54 ctx.AliasVariation("")
55 }
56 case *genrule.Module:
57 if p, ok := m.Extra.(*GenruleExtraProperties); ok {
58 if String(p.Sdk_version) != "" {
59 ctx.CreateVariations("", "sdk")
60 } else {
61 ctx.CreateVariations("")
62 }
63 ctx.AliasVariation("")
64 }
65 }
66}