blob: 63508d78bdc05147f84c0c30968422fce7650cea [file] [log] [blame]
Paul Duffin064b70c2020-11-02 17:32:38 +00001// Copyright (C) 2021 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.
14
15package android
16
17import (
18 "fmt"
19 "strings"
20
21 "github.com/google/blueprint"
22)
23
24// Provides support for interacting with the `deapexer` module to which a `prebuilt_apex` module
25// will delegate the work to export files from a prebuilt '.apex` file.
26
27// The information exported by the `deapexer` module, access it using `DeapxerInfoProvider`.
28type DeapexerInfo struct {
29 // map from the name of an exported file from a prebuilt_apex to the path to that file. The
30 // exported file name is of the form <module>{<tag>} where <tag> is currently only allowed to be
31 // ".dexjar".
32 //
33 // See Prebuilt.ApexInfoMutator for more information.
34 exports map[string]Path
35}
36
37// The set of supported prebuilt export tags. Used to verify the tag parameter for
38// `PrebuiltExportPath`.
39var supportedPrebuiltExportTags = map[string]struct{}{
40 ".dexjar": {},
41}
42
43// PrebuiltExportPath provides the path, or nil if not available, of a file exported from the
44// prebuilt_apex that created this ApexInfo.
45//
46// The exported file is identified by the module name and the tag:
47// * The module name is the name of the module that contributed the file when the .apex file
48// referenced by the prebuilt_apex was built. It must be specified in one of the exported_...
49// properties on the prebuilt_apex module.
50// * The tag identifies the type of file and is dependent on the module type.
51//
52// See apex/deapexer.go for more information.
53func (i DeapexerInfo) PrebuiltExportPath(name, tag string) Path {
54
55 if _, ok := supportedPrebuiltExportTags[tag]; !ok {
56 panic(fmt.Errorf("unsupported prebuilt export tag %q, expected one of %s",
57 tag, strings.Join(SortedStringKeys(supportedPrebuiltExportTags), ", ")))
58 }
59
60 path := i.exports[name+"{"+tag+"}"]
61 return path
62}
63
64// Provider that can be used from within the `GenerateAndroidBuildActions` of a module that depends
65// on a `deapexer` module to retrieve its `DeapexerInfo`.
66var DeapexerProvider = blueprint.NewProvider(DeapexerInfo{})
67
68// NewDeapexerInfo creates and initializes a DeapexerInfo that is suitable
69// for use with a prebuilt_apex module.
70//
71// See apex/deapexer.go for more information.
72func NewDeapexerInfo(exports map[string]Path) DeapexerInfo {
73 return DeapexerInfo{
74 exports: exports,
75 }
76}
77
78type deapexerTagStruct struct {
79 blueprint.BaseDependencyTag
80}
81
82// A tag that is used for dependencies on the `deapexer` module.
83var DeapexerTag = deapexerTagStruct{}