github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/java/app_builder.go (about) 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 ( 22 "strings" 23 24 "github.com/google/blueprint" 25 26 "android/soong/android" 27 ) 28 29 var ( 30 signapk = pctx.AndroidStaticRule("signapk", 31 blueprint.RuleParams{ 32 Command: `${config.JavaCmd} -Djava.library.path=$$(dirname $signapkJniLibrary) ` + 33 `-jar $signapkCmd $certificates $in $out`, 34 CommandDeps: []string{"$signapkCmd", "$signapkJniLibrary"}, 35 }, 36 "certificates") 37 38 androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger", 39 blueprint.RuleParams{ 40 Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " + 41 "--main $in --libs $libsManifests --out $out", 42 CommandDeps: []string{"$androidManifestMergerCmd"}, 43 Description: "merge manifest files", 44 }, 45 "libsManifests") 46 ) 47 48 func init() { 49 pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar") 50 pctx.HostBinToolVariable("aaptCmd", "aapt") 51 pctx.HostJavaToolVariable("signapkCmd", "signapk.jar") 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") 55 } 56 57 var combineApk = pctx.AndroidStaticRule("combineApk", 58 blueprint.RuleParams{ 59 Command: `${config.MergeZipsCmd} $out $in`, 60 CommandDeps: []string{"${config.MergeZipsCmd}"}, 61 }) 62 63 func CreateAppPackage(ctx android.ModuleContext, outputFile android.WritablePath, 64 resJarFile, dexJarFile android.Path, certificates []certificate) { 65 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 } 74 75 ctx.Build(pctx, android.BuildParams{ 76 Rule: combineApk, 77 Inputs: inputs, 78 Output: unsignedApk, 79 }) 80 81 var certificateArgs []string 82 for _, c := range certificates { 83 certificateArgs = append(certificateArgs, c.pem.String(), c.key.String()) 84 } 85 86 // TODO(ccross): sometimes uncompress dex 87 // TODO(ccross): sometimes strip dex 88 89 ctx.Build(pctx, android.BuildParams{ 90 Rule: signapk, 91 Description: "signapk", 92 Output: outputFile, 93 Input: unsignedApk, 94 Args: map[string]string{ 95 "certificates": strings.Join(certificateArgs, " "), 96 }, 97 }) 98 } 99 100 var 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 && ` + 106 `${config.SoongZipCmd} -jar -o $out -C ${outDir} -D ${outDir} ${resArgs}`, 107 CommandDeps: []string{"${config.SoongZipCmd}"}, 108 }, 109 "manifest", "classesJar", "rTxt", "resArgs", "outDir") 110 111 func 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 }