blob: 168a22d312d6acc285fcb007d6d8db4e38683a9f [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"
Colin Cross1b6a3cf2018-07-24 14:51:30 -070019 "strings"
Colin Cross31656952018-05-24 16:11:20 -070020
21 "github.com/google/blueprint"
22
23 "android/soong/android"
24)
25
26var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer",
27 blueprint.RuleParams{
Colin Cross7b59e7b2018-09-10 13:35:13 -070028 Command: `${config.ManifestFixerCmd} ` +
29 `--minSdkVersion ${minSdkVersion} ` +
30 `--targetSdkVersion ${targetSdkVersion} ` +
31 `--raise-min-sdk-version ` +
32 `$args $in $out`,
Colin Cross31656952018-05-24 16:11:20 -070033 CommandDeps: []string{"${config.ManifestFixerCmd}"},
34 },
Colin Cross7b59e7b2018-09-10 13:35:13 -070035 "minSdkVersion", "targetSdkVersion", "args")
Colin Cross31656952018-05-24 16:11:20 -070036
37var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
38 blueprint.RuleParams{
39 Command: `${config.JavaCmd} -classpath ${config.ManifestMergerClasspath} com.android.manifmerger.Merger ` +
40 `--main $in $libs --out $out`,
41 CommandDeps: config.ManifestMergerClasspath,
42 },
43 "libs")
44
45func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
Colin Cross1b6a3cf2018-07-24 14:51:30 -070046 staticLibManifests android.Paths, isLibrary bool) android.Path {
47
48 var args []string
49 if isLibrary {
50 args = append(args, "--library")
51 }
Colin Cross31656952018-05-24 16:11:20 -070052
53 // Inject minSdkVersion into the manifest
54 fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
55 ctx.Build(pctx, android.BuildParams{
56 Rule: manifestFixerRule,
57 Input: manifest,
58 Output: fixedManifest,
59 Args: map[string]string{
Colin Cross7b59e7b2018-09-10 13:35:13 -070060 "minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
61 "targetSdkVersion": sdkVersionOrDefault(ctx, sdkContext.sdkVersion()),
62 "args": strings.Join(args, " "),
Colin Cross31656952018-05-24 16:11:20 -070063 },
64 })
65 manifest = fixedManifest
66
67 // Merge static aar dependency manifests if necessary
68 if len(staticLibManifests) > 0 {
69 mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
70 ctx.Build(pctx, android.BuildParams{
71 Rule: manifestMergerRule,
72 Input: manifest,
73 Implicits: staticLibManifests,
74 Output: mergedManifest,
75 Args: map[string]string{
Jason Monk6f937a92018-08-09 21:47:37 -040076 "libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "),
Colin Cross31656952018-05-24 16:11:20 -070077 },
78 })
79 manifest = mergedManifest
80 }
81
82 return manifest
83}