blob: 238508dc9eb32dcbfa27a7851d58694a622b7acf [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
16import (
Inseob Kim8471cda2019-11-15 09:59:12 +090017 "android/soong/android"
18)
19
20var (
21 headerExts = []string{".h", ".hh", ".hpp", ".hxx", ".h++", ".inl", ".inc", ".ipp", ".h.generic"}
22)
23
24type snapshotLibraryInterface interface {
Inseob Kim8471cda2019-11-15 09:59:12 +090025 libraryInterface
Inseob Kimeda2e9c2020-03-03 22:06:32 +090026 collectHeadersForSnapshot(ctx android.ModuleContext)
27 snapshotHeaders() android.Paths
Inseob Kim8471cda2019-11-15 09:59:12 +090028}
29
30var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
31var _ snapshotLibraryInterface = (*libraryDecorator)(nil)
32
Inseob Kimeec88e12020-01-22 11:11:29 +090033type snapshotMap struct {
34 snapshots map[string]string
35}
36
37func newSnapshotMap() *snapshotMap {
38 return &snapshotMap{
39 snapshots: make(map[string]string),
40 }
41}
42
43func snapshotMapKey(name string, arch android.ArchType) string {
44 return name + ":" + arch.String()
45}
46
47// Adds a snapshot name for given module name and architecture.
48// e.g. add("libbase", X86, "libbase.vndk.29.x86")
49func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) {
50 s.snapshots[snapshotMapKey(name, arch)] = snapshot
51}
52
53// Returns snapshot name for given module name and architecture, if found.
54// e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true
55func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) {
56 snapshot, found = s.snapshots[snapshotMapKey(name, arch)]
57 return snapshot, found
58}
59
Colin Cross56a83212020-09-15 18:30:11 -070060func isSnapshotAware(ctx android.ModuleContext, m *Module, apexInfo android.ApexInfo) bool {
61 if _, _, ok := isVndkSnapshotLibrary(ctx.DeviceConfig(), m, apexInfo); ok {
Inseob Kimeda2e9c2020-03-03 22:06:32 +090062 return ctx.Config().VndkSnapshotBuildArtifacts()
Colin Cross56a83212020-09-15 18:30:11 -070063 } else if isVendorSnapshotModule(m, isVendorProprietaryPath(ctx.ModuleDir()), apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +090064 return true
Inseob Kim8471cda2019-11-15 09:59:12 +090065 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +090066 return false
Inseob Kim8471cda2019-11-15 09:59:12 +090067}
68
69func copyFile(ctx android.SingletonContext, path android.Path, out string) android.OutputPath {
70 outPath := android.PathForOutput(ctx, out)
71 ctx.Build(pctx, android.BuildParams{
72 Rule: android.Cp,
73 Input: path,
74 Output: outPath,
75 Description: "Cp " + out,
76 Args: map[string]string{
77 "cpFlags": "-f -L",
78 },
79 })
80 return outPath
81}
82
Bob Badoura75b0572020-02-18 20:21:55 -080083func combineNotices(ctx android.SingletonContext, paths android.Paths, out string) android.OutputPath {
84 outPath := android.PathForOutput(ctx, out)
85 ctx.Build(pctx, android.BuildParams{
86 Rule: android.Cat,
87 Inputs: paths,
88 Output: outPath,
89 Description: "combine notices for " + out,
90 })
91 return outPath
92}
93
Inseob Kim8471cda2019-11-15 09:59:12 +090094func writeStringToFile(ctx android.SingletonContext, content, out string) android.OutputPath {
95 outPath := android.PathForOutput(ctx, out)
96 ctx.Build(pctx, android.BuildParams{
97 Rule: android.WriteFile,
98 Output: outPath,
99 Description: "WriteFile " + out,
100 Args: map[string]string{
101 "content": content,
102 },
103 })
104 return outPath
105}