Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | // This file generates the final rules for compiling all Java. All properties related to |
| 18 | // compiling should have been translated into javaBuilderFlags or another argument to the Transform* |
| 19 | // functions. |
| 20 | |
| 21 | import ( |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 22 | "strings" |
| 23 | |
| 24 | "github.com/google/blueprint" |
| 25 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 26 | "android/soong/android" |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | var ( |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 30 | signapk = pctx.AndroidStaticRule("signapk", |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 31 | blueprint.RuleParams{ |
| 32 | Command: `java -jar $signapkCmd $certificates $in $out`, |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 33 | CommandDeps: []string{"$signapkCmd"}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 34 | }, |
| 35 | "certificates") |
| 36 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 37 | androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger", |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 38 | blueprint.RuleParams{ |
| 39 | Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " + |
| 40 | "--main $in --libs $libsManifests --out $out", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 41 | CommandDeps: []string{"$androidManifestMergerCmd"}, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 42 | Description: "merge manifest files", |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 43 | }, |
| 44 | "libsManifests") |
| 45 | ) |
| 46 | |
| 47 | func init() { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 48 | pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar") |
| 49 | pctx.HostBinToolVariable("aaptCmd", "aapt") |
| 50 | pctx.HostJavaToolVariable("signapkCmd", "signapk.jar") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 53 | var combineApk = pctx.AndroidStaticRule("combineApk", |
| 54 | blueprint.RuleParams{ |
| 55 | Command: `${config.MergeZipsCmd} $out $in`, |
| 56 | CommandDeps: []string{"${config.MergeZipsCmd}"}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 57 | }) |
| 58 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 59 | func CreateAppPackage(ctx android.ModuleContext, outputFile android.WritablePath, |
| 60 | resJarFile, dexJarFile android.Path, certificates []string) { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 61 | |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 62 | // TODO(ccross): JNI libs |
| 63 | |
| 64 | unsignedApk := android.PathForModuleOut(ctx, "unsigned.apk") |
| 65 | |
| 66 | inputs := android.Paths{resJarFile} |
| 67 | if dexJarFile != nil { |
| 68 | inputs = append(inputs, dexJarFile) |
| 69 | } |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 70 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 71 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 72 | Rule: combineApk, |
| 73 | Inputs: inputs, |
| 74 | Output: unsignedApk, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 75 | }) |
| 76 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 77 | var certificateArgs []string |
| 78 | for _, c := range certificates { |
| 79 | certificateArgs = append(certificateArgs, c+".x509.pem", c+".pk8") |
| 80 | } |
| 81 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 82 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 83 | Rule: signapk, |
| 84 | Description: "signapk", |
| 85 | Output: outputFile, |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame^] | 86 | Input: unsignedApk, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 87 | Args: map[string]string{ |
| 88 | "certificates": strings.Join(certificateArgs, " "), |
| 89 | }, |
| 90 | }) |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 91 | } |