blob: 4012def526eaf36663c58cf498dbdaf0519fcf1d [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 {
25 exportedFlagsProducer
26 libraryInterface
Inseob Kimeda2e9c2020-03-03 22:06:32 +090027 collectHeadersForSnapshot(ctx android.ModuleContext)
28 snapshotHeaders() android.Paths
Inseob Kim8471cda2019-11-15 09:59:12 +090029}
30
31var _ snapshotLibraryInterface = (*prebuiltLibraryLinker)(nil)
32var _ snapshotLibraryInterface = (*libraryDecorator)(nil)
33
Inseob Kimeec88e12020-01-22 11:11:29 +090034type snapshotMap struct {
35 snapshots map[string]string
36}
37
38func newSnapshotMap() *snapshotMap {
39 return &snapshotMap{
40 snapshots: make(map[string]string),
41 }
42}
43
44func snapshotMapKey(name string, arch android.ArchType) string {
45 return name + ":" + arch.String()
46}
47
48// Adds a snapshot name for given module name and architecture.
49// e.g. add("libbase", X86, "libbase.vndk.29.x86")
50func (s *snapshotMap) add(name string, arch android.ArchType, snapshot string) {
51 s.snapshots[snapshotMapKey(name, arch)] = snapshot
52}
53
54// Returns snapshot name for given module name and architecture, if found.
55// e.g. get("libcutils", X86) => "libcutils.vndk.29.x86", true
56func (s *snapshotMap) get(name string, arch android.ArchType) (snapshot string, found bool) {
57 snapshot, found = s.snapshots[snapshotMapKey(name, arch)]
58 return snapshot, found
59}
60
Inseob Kimeda2e9c2020-03-03 22:06:32 +090061func isSnapshotAware(ctx android.ModuleContext, m *Module) bool {
62 if _, _, ok := isVndkSnapshotLibrary(ctx.DeviceConfig(), m); ok {
63 return ctx.Config().VndkSnapshotBuildArtifacts()
64 } else if isVendorSnapshotModule(m, ctx.ModuleDir()) {
65 return true
Inseob Kim8471cda2019-11-15 09:59:12 +090066 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +090067 return false
Inseob Kim8471cda2019-11-15 09:59:12 +090068}
69
70func copyFile(ctx android.SingletonContext, path android.Path, out string) android.OutputPath {
71 outPath := android.PathForOutput(ctx, out)
72 ctx.Build(pctx, android.BuildParams{
73 Rule: android.Cp,
74 Input: path,
75 Output: outPath,
76 Description: "Cp " + out,
77 Args: map[string]string{
78 "cpFlags": "-f -L",
79 },
80 })
81 return outPath
82}
83
Bob Badoura75b0572020-02-18 20:21:55 -080084func combineNotices(ctx android.SingletonContext, paths android.Paths, out string) android.OutputPath {
85 outPath := android.PathForOutput(ctx, out)
86 ctx.Build(pctx, android.BuildParams{
87 Rule: android.Cat,
88 Inputs: paths,
89 Output: outPath,
90 Description: "combine notices for " + out,
91 })
92 return outPath
93}
94
Inseob Kim8471cda2019-11-15 09:59:12 +090095func writeStringToFile(ctx android.SingletonContext, content, out string) android.OutputPath {
96 outPath := android.PathForOutput(ctx, out)
97 ctx.Build(pctx, android.BuildParams{
98 Rule: android.WriteFile,
99 Output: outPath,
100 Description: "WriteFile " + out,
101 Args: map[string]string{
102 "content": content,
103 },
104 })
105 return outPath
106}