blob: 8fcdcbac1503975c955e4930c45a1c99464ef088 [file] [log] [blame]
Colin Cross31656952018-05-24 16:11:20 -07001// Copyright 2018 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 java
16
17import (
18 "android/soong/java/config"
19
20 "github.com/google/blueprint"
21
22 "android/soong/android"
23)
24
25var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer",
26 blueprint.RuleParams{
27 Command: `${config.ManifestFixerCmd} --minSdkVersion ${minSdkVersion} $usesLibraries $in $out`,
28 CommandDeps: []string{"${config.ManifestFixerCmd}"},
29 },
30 "minSdkVersion", "usesLibraries")
31
32var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
33 blueprint.RuleParams{
34 Command: `${config.JavaCmd} -classpath ${config.ManifestMergerClasspath} com.android.manifmerger.Merger ` +
35 `--main $in $libs --out $out`,
36 CommandDeps: config.ManifestMergerClasspath,
37 },
38 "libs")
39
40func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
41 staticLibManifests android.Paths) android.Path {
42
43 // Inject minSdkVersion into the manifest
44 fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
45 ctx.Build(pctx, android.BuildParams{
46 Rule: manifestFixerRule,
47 Input: manifest,
48 Output: fixedManifest,
49 Args: map[string]string{
50 "minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
51 },
52 })
53 manifest = fixedManifest
54
55 // Merge static aar dependency manifests if necessary
56 if len(staticLibManifests) > 0 {
57 mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
58 ctx.Build(pctx, android.BuildParams{
59 Rule: manifestMergerRule,
60 Input: manifest,
61 Implicits: staticLibManifests,
62 Output: mergedManifest,
63 Args: map[string]string{
64 "libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--uses-library "),
65 },
66 })
67 manifest = mergedManifest
68 }
69
70 return manifest
71}