blob: 82574aeff79d22107008bcd7c7b5792de189bef7 [file] [log] [blame]
Colin Cross30e076a2015-04-13 13:58:27 -07001// 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
15package 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
21import (
Colin Cross30e076a2015-04-13 13:58:27 -070022 "strings"
23
24 "github.com/google/blueprint"
25
Colin Cross635c3b02016-05-18 15:37:25 -070026 "android/soong/android"
Colin Cross30e076a2015-04-13 13:58:27 -070027)
28
29var (
Colin Cross9d45bb72016-08-29 16:14:13 -070030 signapk = pctx.AndroidStaticRule("signapk",
Colin Cross30e076a2015-04-13 13:58:27 -070031 blueprint.RuleParams{
32 Command: `java -jar $signapkCmd $certificates $in $out`,
Dan Willemsenc94a7682015-11-17 15:27:28 -080033 CommandDeps: []string{"$signapkCmd"},
Colin Cross30e076a2015-04-13 13:58:27 -070034 },
35 "certificates")
36
Colin Cross9d45bb72016-08-29 16:14:13 -070037 androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger",
Colin Cross30e076a2015-04-13 13:58:27 -070038 blueprint.RuleParams{
39 Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " +
40 "--main $in --libs $libsManifests --out $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080041 CommandDeps: []string{"$androidManifestMergerCmd"},
Colin Cross67a5c132017-05-09 13:45:28 -070042 Description: "merge manifest files",
Colin Cross30e076a2015-04-13 13:58:27 -070043 },
44 "libsManifests")
45)
46
47func init() {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070048 pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar")
49 pctx.HostBinToolVariable("aaptCmd", "aapt")
50 pctx.HostJavaToolVariable("signapkCmd", "signapk.jar")
Colin Cross30e076a2015-04-13 13:58:27 -070051}
52
Colin Cross3bc7ffa2017-11-22 16:19:37 -080053var combineApk = pctx.AndroidStaticRule("combineApk",
54 blueprint.RuleParams{
55 Command: `${config.MergeZipsCmd} $out $in`,
56 CommandDeps: []string{"${config.MergeZipsCmd}"},
Colin Cross30e076a2015-04-13 13:58:27 -070057 })
58
Colin Cross3bc7ffa2017-11-22 16:19:37 -080059func CreateAppPackage(ctx android.ModuleContext, outputFile android.WritablePath,
60 resJarFile, dexJarFile android.Path, certificates []string) {
Colin Cross30e076a2015-04-13 13:58:27 -070061
Colin Cross3bc7ffa2017-11-22 16:19:37 -080062 // 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 Cross30e076a2015-04-13 13:58:27 -070070
Colin Crossae887032017-10-23 17:16:14 -070071 ctx.Build(pctx, android.BuildParams{
Colin Cross3bc7ffa2017-11-22 16:19:37 -080072 Rule: combineApk,
73 Inputs: inputs,
74 Output: unsignedApk,
Colin Cross30e076a2015-04-13 13:58:27 -070075 })
76
Colin Cross30e076a2015-04-13 13:58:27 -070077 var certificateArgs []string
78 for _, c := range certificates {
79 certificateArgs = append(certificateArgs, c+".x509.pem", c+".pk8")
80 }
81
Colin Crossae887032017-10-23 17:16:14 -070082 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070083 Rule: signapk,
84 Description: "signapk",
85 Output: outputFile,
Colin Cross3bc7ffa2017-11-22 16:19:37 -080086 Input: unsignedApk,
Colin Cross30e076a2015-04-13 13:58:27 -070087 Args: map[string]string{
88 "certificates": strings.Join(certificateArgs, " "),
89 },
90 })
Colin Cross30e076a2015-04-13 13:58:27 -070091}