blob: e27b1b70e77a8deaff25cb72d9703dbba499ced8 [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{
Colin Cross5ab4e6d2017-11-22 16:20:45 -080032 Command: `${config.JavaCmd} -Djava.library.path=$$(dirname $signapkJniLibrary) ` +
33 `-jar $signapkCmd $certificates $in $out`,
34 CommandDeps: []string{"$signapkCmd", "$signapkJniLibrary"},
Colin Cross30e076a2015-04-13 13:58:27 -070035 },
36 "certificates")
37
Colin Cross9d45bb72016-08-29 16:14:13 -070038 androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger",
Colin Cross30e076a2015-04-13 13:58:27 -070039 blueprint.RuleParams{
40 Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " +
41 "--main $in --libs $libsManifests --out $out",
Dan Willemsenc94a7682015-11-17 15:27:28 -080042 CommandDeps: []string{"$androidManifestMergerCmd"},
Colin Cross67a5c132017-05-09 13:45:28 -070043 Description: "merge manifest files",
Colin Cross30e076a2015-04-13 13:58:27 -070044 },
45 "libsManifests")
46)
47
48func init() {
Dan Willemsen34cc69e2015-09-23 15:26:20 -070049 pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar")
50 pctx.HostBinToolVariable("aaptCmd", "aapt")
51 pctx.HostJavaToolVariable("signapkCmd", "signapk.jar")
Colin Cross5ab4e6d2017-11-22 16:20:45 -080052 // 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 Cross30e076a2015-04-13 13:58:27 -070055}
56
Colin Cross3bc7ffa2017-11-22 16:19:37 -080057var combineApk = pctx.AndroidStaticRule("combineApk",
58 blueprint.RuleParams{
59 Command: `${config.MergeZipsCmd} $out $in`,
60 CommandDeps: []string{"${config.MergeZipsCmd}"},
Colin Cross30e076a2015-04-13 13:58:27 -070061 })
62
Colin Cross3bc7ffa2017-11-22 16:19:37 -080063func CreateAppPackage(ctx android.ModuleContext, outputFile android.WritablePath,
Colin Crosse1731a52017-12-14 11:22:55 -080064 resJarFile, dexJarFile android.Path, certificates []certificate) {
Colin Cross30e076a2015-04-13 13:58:27 -070065
Colin Cross3bc7ffa2017-11-22 16:19:37 -080066 // 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 Cross30e076a2015-04-13 13:58:27 -070074
Colin Crossae887032017-10-23 17:16:14 -070075 ctx.Build(pctx, android.BuildParams{
Colin Cross3bc7ffa2017-11-22 16:19:37 -080076 Rule: combineApk,
77 Inputs: inputs,
78 Output: unsignedApk,
Colin Cross30e076a2015-04-13 13:58:27 -070079 })
80
Colin Cross30e076a2015-04-13 13:58:27 -070081 var certificateArgs []string
82 for _, c := range certificates {
Colin Crosse1731a52017-12-14 11:22:55 -080083 certificateArgs = append(certificateArgs, c.pem.String(), c.key.String())
Colin Cross30e076a2015-04-13 13:58:27 -070084 }
85
Colin Cross5ab4e6d2017-11-22 16:20:45 -080086 // TODO(ccross): sometimes uncompress dex
87 // TODO(ccross): sometimes strip dex
88
Colin Crossae887032017-10-23 17:16:14 -070089 ctx.Build(pctx, android.BuildParams{
Colin Cross67a5c132017-05-09 13:45:28 -070090 Rule: signapk,
91 Description: "signapk",
92 Output: outputFile,
Colin Cross3bc7ffa2017-11-22 16:19:37 -080093 Input: unsignedApk,
Colin Cross30e076a2015-04-13 13:58:27 -070094 Args: map[string]string{
95 "certificates": strings.Join(certificateArgs, " "),
96 },
97 })
Colin Cross30e076a2015-04-13 13:58:27 -070098}
Colin Crossa97c5d32018-03-28 14:58:31 -070099
100var buildAAR = pctx.AndroidStaticRule("buildAAR",
101 blueprint.RuleParams{
102 Command: `rm -rf ${outDir} && mkdir -p ${outDir} && ` +
103 `cp ${manifest} ${outDir}/AndroidManifest.xml && ` +
104 `cp ${classesJar} ${outDir}/classes.jar && ` +
105 `cp ${rTxt} ${outDir}/R.txt && ` +
Colin Cross1d98ee22018-09-18 17:05:15 -0700106 `${config.SoongZipCmd} -jar -o $out -C ${outDir} -D ${outDir}`,
Colin Crossa97c5d32018-03-28 14:58:31 -0700107 CommandDeps: []string{"${config.SoongZipCmd}"},
108 },
Colin Cross1d98ee22018-09-18 17:05:15 -0700109 "manifest", "classesJar", "rTxt", "outDir")
Colin Crossa97c5d32018-03-28 14:58:31 -0700110
111func BuildAAR(ctx android.ModuleContext, outputFile android.WritablePath,
112 classesJar, manifest, rTxt android.Path, res android.Paths) {
113
114 // TODO(ccross): uniquify and copy resources with dependencies
115
116 deps := android.Paths{manifest, rTxt}
117 classesJarPath := ""
118 if classesJar != nil {
119 deps = append(deps, classesJar)
120 classesJarPath = classesJar.String()
121 }
122
123 ctx.Build(pctx, android.BuildParams{
124 Rule: buildAAR,
125 Implicits: deps,
126 Output: outputFile,
127 Args: map[string]string{
128 "manifest": manifest.String(),
129 "classesJar": classesJarPath,
130 "rTxt": rTxt.String(),
131 "outDir": android.PathForModuleOut(ctx, "aar").String(),
132 },
133 })
134}