blob: 65774752048d620fc8a74624676713296dc9843e [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 Cross1b6a3cf2018-07-24 14:51:30 -070028 Command: `${config.ManifestFixerCmd} --minSdkVersion ${minSdkVersion} $args $in $out`,
Colin Cross31656952018-05-24 16:11:20 -070029 CommandDeps: []string{"${config.ManifestFixerCmd}"},
30 },
Colin Cross1b6a3cf2018-07-24 14:51:30 -070031 "minSdkVersion", "args")
Colin Cross31656952018-05-24 16:11:20 -070032
33var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
34 blueprint.RuleParams{
35 Command: `${config.JavaCmd} -classpath ${config.ManifestMergerClasspath} com.android.manifmerger.Merger ` +
36 `--main $in $libs --out $out`,
37 CommandDeps: config.ManifestMergerClasspath,
38 },
39 "libs")
40
41func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
Colin Cross1b6a3cf2018-07-24 14:51:30 -070042 staticLibManifests android.Paths, isLibrary bool) android.Path {
43
44 var args []string
45 if isLibrary {
46 args = append(args, "--library")
47 }
Colin Cross31656952018-05-24 16:11:20 -070048
49 // Inject minSdkVersion into the manifest
50 fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
51 ctx.Build(pctx, android.BuildParams{
52 Rule: manifestFixerRule,
53 Input: manifest,
54 Output: fixedManifest,
55 Args: map[string]string{
56 "minSdkVersion": sdkVersionOrDefault(ctx, sdkContext.minSdkVersion()),
Colin Cross1b6a3cf2018-07-24 14:51:30 -070057 "args": strings.Join(args, " "),
Colin Cross31656952018-05-24 16:11:20 -070058 },
59 })
60 manifest = fixedManifest
61
62 // Merge static aar dependency manifests if necessary
63 if len(staticLibManifests) > 0 {
64 mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
65 ctx.Build(pctx, android.BuildParams{
66 Rule: manifestMergerRule,
67 Input: manifest,
68 Implicits: staticLibManifests,
69 Output: mergedManifest,
70 Args: map[string]string{
Jason Monk6f937a92018-08-09 21:47:37 -040071 "libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "),
Colin Cross31656952018-05-24 16:11:20 -070072 },
73 })
74 manifest = mergedManifest
75 }
76
77 return manifest
78}