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 | |
| 26 | "android/soong/common" |
| 27 | ) |
| 28 | |
| 29 | var ( |
| 30 | aaptCreateResourceJavaFile = pctx.StaticRule("aaptCreateResourceJavaFile", |
| 31 | blueprint.RuleParams{ |
| 32 | Command: `rm -rf "$javaDir" && mkdir -p "$javaDir" && ` + |
| 33 | `$aaptCmd package -m $aaptFlags -P $publicResourcesFile -G $proguardOptionsFile ` + |
| 34 | `-J $javaDir || ( rm -rf "$javaDir/*"; exit 41 ) && ` + |
| 35 | `find $javaDir -name "*.java" > $javaFileList`, |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 36 | CommandDeps: []string{"$aaptCmd"}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 37 | Description: "aapt create R.java $out", |
| 38 | }, |
| 39 | "aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList") |
| 40 | |
| 41 | aaptCreateAssetsPackage = pctx.StaticRule("aaptCreateAssetsPackage", |
| 42 | blueprint.RuleParams{ |
Colin Cross | 5adac8a | 2015-04-28 13:29:20 -0700 | [diff] [blame] | 43 | Command: `rm -f $out && $aaptCmd package $aaptFlags -F $out`, |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 44 | CommandDeps: []string{"$aaptCmd"}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 45 | Description: "aapt export package $out", |
| 46 | }, |
| 47 | "aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList") |
| 48 | |
| 49 | aaptAddResources = pctx.StaticRule("aaptAddResources", |
| 50 | blueprint.RuleParams{ |
| 51 | // TODO: add-jni-shared-libs-to-package |
| 52 | Command: `cp -f $in $out.tmp && $aaptCmd package -u $aaptFlags -F $out.tmp && mv $out.tmp $out`, |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 53 | CommandDeps: []string{"$aaptCmd"}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 54 | Description: "aapt package $out", |
| 55 | }, |
| 56 | "aaptFlags") |
| 57 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 58 | signapk = pctx.StaticRule("signapk", |
| 59 | blueprint.RuleParams{ |
| 60 | Command: `java -jar $signapkCmd $certificates $in $out`, |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 61 | CommandDeps: []string{"$signapkCmd"}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 62 | Description: "signapk $out", |
| 63 | }, |
| 64 | "certificates") |
| 65 | |
| 66 | androidManifestMerger = pctx.StaticRule("androidManifestMerger", |
| 67 | blueprint.RuleParams{ |
| 68 | Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " + |
| 69 | "--main $in --libs $libsManifests --out $out", |
Dan Willemsen | c94a768 | 2015-11-17 15:27:28 -0800 | [diff] [blame] | 70 | CommandDeps: []string{"$androidManifestMergerCmd"}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 71 | Description: "merge manifest files $out", |
| 72 | }, |
| 73 | "libsManifests") |
| 74 | ) |
| 75 | |
| 76 | func init() { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 77 | pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar") |
| 78 | pctx.HostBinToolVariable("aaptCmd", "aapt") |
| 79 | pctx.HostJavaToolVariable("signapkCmd", "signapk.jar") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | func CreateResourceJavaFiles(ctx common.AndroidModuleContext, flags []string, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 83 | deps common.Paths) (common.Path, common.Path, common.Path) { |
| 84 | javaDir := common.PathForModuleGen(ctx, "R") |
| 85 | javaFileList := common.PathForModuleOut(ctx, "R.filelist") |
| 86 | publicResourcesFile := common.PathForModuleOut(ctx, "public_resources.xml") |
| 87 | proguardOptionsFile := common.PathForModuleOut(ctx, "proguard.options") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 88 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 89 | ctx.ModuleBuild(pctx, common.ModuleBuildParams{ |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 90 | Rule: aaptCreateResourceJavaFile, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 91 | Outputs: common.WritablePaths{publicResourcesFile, proguardOptionsFile, javaFileList}, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 92 | Implicits: deps, |
| 93 | Args: map[string]string{ |
| 94 | "aaptFlags": strings.Join(flags, " "), |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 95 | "publicResourcesFile": publicResourcesFile.String(), |
| 96 | "proguardOptionsFile": proguardOptionsFile.String(), |
| 97 | "javaDir": javaDir.String(), |
| 98 | "javaFileList": javaFileList.String(), |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 99 | }, |
| 100 | }) |
| 101 | |
| 102 | return publicResourcesFile, proguardOptionsFile, javaFileList |
| 103 | } |
| 104 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 105 | func CreateExportPackage(ctx common.AndroidModuleContext, flags []string, deps common.Paths) common.ModuleOutPath { |
| 106 | outputFile := common.PathForModuleOut(ctx, "package-export.apk") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 107 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 108 | ctx.ModuleBuild(pctx, common.ModuleBuildParams{ |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 109 | Rule: aaptCreateAssetsPackage, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 110 | Output: outputFile, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 111 | Implicits: deps, |
| 112 | Args: map[string]string{ |
| 113 | "aaptFlags": strings.Join(flags, " "), |
| 114 | }, |
| 115 | }) |
| 116 | |
| 117 | return outputFile |
| 118 | } |
| 119 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 120 | func CreateAppPackage(ctx common.AndroidModuleContext, flags []string, jarFile common.Path, |
| 121 | certificates []string) common.Path { |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 122 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 123 | resourceApk := common.PathForModuleOut(ctx, "resources.apk") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 124 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 125 | ctx.ModuleBuild(pctx, common.ModuleBuildParams{ |
| 126 | Rule: aaptAddResources, |
| 127 | Output: resourceApk, |
| 128 | Input: jarFile, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 129 | Args: map[string]string{ |
| 130 | "aaptFlags": strings.Join(flags, " "), |
| 131 | }, |
| 132 | }) |
| 133 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 134 | outputFile := common.PathForModuleOut(ctx, "package.apk") |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 135 | |
| 136 | var certificateArgs []string |
| 137 | for _, c := range certificates { |
| 138 | certificateArgs = append(certificateArgs, c+".x509.pem", c+".pk8") |
| 139 | } |
| 140 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame^] | 141 | ctx.ModuleBuild(pctx, common.ModuleBuildParams{ |
| 142 | Rule: signapk, |
| 143 | Output: outputFile, |
| 144 | Input: resourceApk, |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 145 | Args: map[string]string{ |
| 146 | "certificates": strings.Join(certificateArgs, " "), |
| 147 | }, |
| 148 | }) |
| 149 | |
Colin Cross | 30e076a | 2015-04-13 13:58:27 -0700 | [diff] [blame] | 150 | return outputFile |
| 151 | } |