Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/java/config" |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame^] | 19 | "strings" |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 20 | |
| 21 | "github.com/google/blueprint" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | ) |
| 25 | |
| 26 | var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer", |
| 27 | blueprint.RuleParams{ |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame^] | 28 | Command: `${config.ManifestFixerCmd} --minSdkVersion ${minSdkVersion} $args $in $out`, |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 29 | CommandDeps: []string{"${config.ManifestFixerCmd}"}, |
| 30 | }, |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame^] | 31 | "minSdkVersion", "args") |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 32 | |
| 33 | var 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 | |
| 41 | func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, |
Colin Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame^] | 42 | staticLibManifests android.Paths, isLibrary bool) android.Path { |
| 43 | |
| 44 | var args []string |
| 45 | if isLibrary { |
| 46 | args = append(args, "--library") |
| 47 | } |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 48 | |
| 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 Cross | 1b6a3cf | 2018-07-24 14:51:30 -0700 | [diff] [blame^] | 57 | "args": strings.Join(args, " "), |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 58 | }, |
| 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{ |
| 71 | "libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--uses-library "), |
| 72 | }, |
| 73 | }) |
| 74 | manifest = mergedManifest |
| 75 | } |
| 76 | |
| 77 | return manifest |
| 78 | } |