| 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{ | 
| Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 32 | Command: `${config.JavaCmd} -Djava.library.path=$$(dirname $signapkJniLibrary) ` + | 
|  | 33 | `-jar $signapkCmd $certificates $in $out`, | 
|  | 34 | CommandDeps: []string{"$signapkCmd", "$signapkJniLibrary"}, | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 35 | }, | 
|  | 36 | "certificates") | 
|  | 37 |  | 
| Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 38 | androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger", | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 39 | blueprint.RuleParams{ | 
|  | 40 | Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " + | 
|  | 41 | "--main $in --libs $libsManifests --out $out", | 
| Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 42 | CommandDeps: []string{"$androidManifestMergerCmd"}, | 
| Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 43 | Description: "merge manifest files", | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 44 | }, | 
|  | 45 | "libsManifests") | 
|  | 46 | ) | 
|  | 47 |  | 
|  | 48 | func init() { | 
| Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 49 | pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar") | 
|  | 50 | pctx.HostBinToolVariable("aaptCmd", "aapt") | 
|  | 51 | pctx.HostJavaToolVariable("signapkCmd", "signapk.jar") | 
| Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 52 | // TODO(ccross): this should come from the signapk dependencies, but we don't have any way | 
|  | 53 | // to express host JNI dependencies yet. | 
|  | 54 | pctx.HostJNIToolVariable("signapkJniLibrary", "libconscrypt_openjdk_jni") | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 55 | } | 
|  | 56 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 57 | var combineApk = pctx.AndroidStaticRule("combineApk", | 
|  | 58 | blueprint.RuleParams{ | 
|  | 59 | Command:     `${config.MergeZipsCmd} $out $in`, | 
|  | 60 | CommandDeps: []string{"${config.MergeZipsCmd}"}, | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 61 | }) | 
|  | 62 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 63 | func CreateAppPackage(ctx android.ModuleContext, outputFile android.WritablePath, | 
| Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 64 | resJarFile, dexJarFile android.Path, certificates []certificate) { | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 65 |  | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 66 | // TODO(ccross): JNI libs | 
|  | 67 |  | 
|  | 68 | unsignedApk := android.PathForModuleOut(ctx, "unsigned.apk") | 
|  | 69 |  | 
|  | 70 | inputs := android.Paths{resJarFile} | 
|  | 71 | if dexJarFile != nil { | 
|  | 72 | inputs = append(inputs, dexJarFile) | 
|  | 73 | } | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 74 |  | 
| Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 75 | ctx.Build(pctx, android.BuildParams{ | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 76 | Rule:   combineApk, | 
|  | 77 | Inputs: inputs, | 
|  | 78 | Output: unsignedApk, | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 79 | }) | 
|  | 80 |  | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 81 | var certificateArgs []string | 
|  | 82 | for _, c := range certificates { | 
| Colin Cross | e1731a5 | 2017-12-14 11:22:55 -0800 | [diff] [blame] | 83 | certificateArgs = append(certificateArgs, c.pem.String(), c.key.String()) | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
| Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 86 | // TODO(ccross): sometimes uncompress dex | 
|  | 87 | // TODO(ccross): sometimes strip dex | 
|  | 88 |  | 
| Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 89 | ctx.Build(pctx, android.BuildParams{ | 
| Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 90 | Rule:        signapk, | 
|  | 91 | Description: "signapk", | 
|  | 92 | Output:      outputFile, | 
| Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 93 | Input:       unsignedApk, | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 94 | Args: map[string]string{ | 
|  | 95 | "certificates": strings.Join(certificateArgs, " "), | 
|  | 96 | }, | 
|  | 97 | }) | 
| Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 98 | } |