blob: 77d82f1b50c2241f296d37a093583af092089c93 [file] [log] [blame]
Inseob Kim8471cda2019-11-15 09:59:12 +09001// Copyright 2020 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.
14package cc
15
Inseob Kimde5744a2020-12-02 13:14:28 +090016// This file contains utility types and functions for VNDK / vendor snapshot.
17
Inseob Kim8471cda2019-11-15 09:59:12 +090018import (
Inseob Kim8471cda2019-11-15 09:59:12 +090019 "android/soong/android"
20)
21
22var (
23 headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
24)
25
Inseob Kimde5744a2020-12-02 13:14:28 +090026// snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
Inseob Kim8471cda2019-11-15 09:59:12 +090027type snapshotLibraryInterface interface {
Inseob Kim8471cda2019-11-15 09:59:12 +090028 libraryInterface
Inseob Kimde5744a2020-12-02 13:14:28 +090029
30 // collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware
31 // modules (See isSnapshotAware below).
32 // This function should gather all headers needed for snapshot.
Inseob Kimeda2e9c2020-03-03 22:06:32 +090033 collectHeadersForSnapshot(ctx android.ModuleContext)
Inseob Kimde5744a2020-12-02 13:14:28 +090034
35 // snapshotHeaders should return collected headers by collectHeadersForSnapshot.
36 // Calling snapshotHeaders before collectHeadersForSnapshot is an error.
Inseob Kimeda2e9c2020-03-03 22:06:32 +090037 snapshotHeaders() android.Paths
Inseob Kim8471cda2019-11-15 09:59:12 +090038}
39
40var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
41var _ snapshotLibraryInterface = (*libraryDecorator)(nil)
42
Inseob Kimde5744a2020-12-02 13:14:28 +090043// snapshotMap is a helper wrapper to a map from base module name to snapshot module name.
Inseob Kimeec88e12020-01-22 11:11:29 +090044type snapshotMap struct {
45 snapshots map[string]string
46}
47
48func newSnapshotMap() *snapshotMap {
49 return &snapshotMap{
50 snapshots: make(map[string]string),
51 }
52}
53
54func snapshotMapKey(name string, arch android.ArchType) string {
55 return name + ":" + arch.String()
56}
57
58// Adds a snapshot name for given module name and architecture.
59// e.g. add("libbase", X86, "libbase.vndk.29.x86")
60func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) {
61 s.snapshots[snapshotMapKey(name, arch)] = snapshot
62}
63
64// Returns snapshot name for given module name and architecture, if found.
65// e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true
66func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) {
67 snapshot, found = s.snapshots[snapshotMapKey(name, arch)]
68 return snapshot, found
69}
70
Inseob Kimde5744a2020-12-02 13:14:28 +090071// shouldCollectHeadersForSnapshot determines if the module is a possible candidate for snapshot.
72// If it's true, collectHeadersForSnapshot will be called in GenerateAndroidBuildActions.
73func shouldCollectHeadersForSnapshot(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool {
Jose Galmes6f843bc2020-12-11 13:36:29 -080074 if ctx.DeviceConfig().VndkVersion() != "current" &&
75 ctx.DeviceConfig().RecoverySnapshotVersion() != "current" {
76 return false
77 }
Inseob Kimde5744a2020-12-02 13:14:28 +090078 if _, _, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo); ok {
Inseob Kimeda2e9c2020-03-03 22:06:32 +090079 return ctx.Config().VndkSnapshotBuildArtifacts()
Inseob Kimde5744a2020-12-02 13:14:28 +090080 } else if isVendorSnapshotAware(m, isVendorProprietaryPath(ctx.ModuleDir()), apexInfo) ||
81 isRecoverySnapshotAware(m, isRecoveryProprietaryPath(ctx.ModuleDir()), apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +090082 return true
Inseob Kim8471cda2019-11-15 09:59:12 +090083 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +090084 return false
Inseob Kim8471cda2019-11-15 09:59:12 +090085}