2015-04-13 22:58:27 +02:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
// This file generates the final rules for compiling all Java. All properties related to
|
|
|
|
// compiling should have been translated into javaBuilderFlags or another argument to the Transform*
|
|
|
|
// functions.
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-04-13 22:58:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-08-30 01:14:13 +02:00
|
|
|
aaptCreateResourceJavaFile = pctx.AndroidStaticRule("aaptCreateResourceJavaFile",
|
2015-04-13 22:58:27 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `rm -rf "$javaDir" && mkdir -p "$javaDir" && ` +
|
|
|
|
`$aaptCmd package -m $aaptFlags -P $publicResourcesFile -G $proguardOptionsFile ` +
|
|
|
|
`-J $javaDir || ( rm -rf "$javaDir/*"; exit 41 ) && ` +
|
|
|
|
`find $javaDir -name "*.java" > $javaFileList`,
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$aaptCmd"},
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
"aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList")
|
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
aaptCreateAssetsPackage = pctx.AndroidStaticRule("aaptCreateAssetsPackage",
|
2015-04-13 22:58:27 +02:00
|
|
|
blueprint.RuleParams{
|
2015-04-28 22:29:20 +02:00
|
|
|
Command: `rm -f $out && $aaptCmd package $aaptFlags -F $out`,
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$aaptCmd"},
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
"aaptFlags", "publicResourcesFile", "proguardOptionsFile", "javaDir", "javaFileList")
|
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
aaptAddResources = pctx.AndroidStaticRule("aaptAddResources",
|
2015-04-13 22:58:27 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
// TODO: add-jni-shared-libs-to-package
|
|
|
|
Command: `cp -f $in $out.tmp && $aaptCmd package -u $aaptFlags -F $out.tmp && mv $out.tmp $out`,
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$aaptCmd"},
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
"aaptFlags")
|
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
signapk = pctx.AndroidStaticRule("signapk",
|
2015-04-13 22:58:27 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `java -jar $signapkCmd $certificates $in $out`,
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$signapkCmd"},
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
"certificates")
|
|
|
|
|
2016-08-30 01:14:13 +02:00
|
|
|
androidManifestMerger = pctx.AndroidStaticRule("androidManifestMerger",
|
2015-04-13 22:58:27 +02:00
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "java -classpath $androidManifestMergerCmd com.android.manifmerger.Main merge " +
|
|
|
|
"--main $in --libs $libsManifests --out $out",
|
2015-11-18 00:27:28 +01:00
|
|
|
CommandDeps: []string{"$androidManifestMergerCmd"},
|
2017-05-09 22:45:28 +02:00
|
|
|
Description: "merge manifest files",
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
"libsManifests")
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-09-24 00:26:20 +02:00
|
|
|
pctx.SourcePathVariable("androidManifestMergerCmd", "prebuilts/devtools/tools/lib/manifest-merger.jar")
|
|
|
|
pctx.HostBinToolVariable("aaptCmd", "aapt")
|
|
|
|
pctx.HostJavaToolVariable("signapkCmd", "signapk.jar")
|
2015-04-13 22:58:27 +02:00
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func CreateResourceJavaFiles(ctx android.ModuleContext, flags []string,
|
|
|
|
deps android.Paths) (android.Path, android.Path, android.Path) {
|
|
|
|
javaDir := android.PathForModuleGen(ctx, "R")
|
|
|
|
javaFileList := android.PathForModuleOut(ctx, "R.filelist")
|
|
|
|
publicResourcesFile := android.PathForModuleOut(ctx, "public_resources.xml")
|
|
|
|
proguardOptionsFile := android.PathForModuleOut(ctx, "proguard.options")
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: aaptCreateResourceJavaFile,
|
|
|
|
Description: "aapt create R.java",
|
|
|
|
Outputs: android.WritablePaths{publicResourcesFile, proguardOptionsFile, javaFileList},
|
|
|
|
Implicits: deps,
|
2015-04-13 22:58:27 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"aaptFlags": strings.Join(flags, " "),
|
2015-09-24 00:26:20 +02:00
|
|
|
"publicResourcesFile": publicResourcesFile.String(),
|
|
|
|
"proguardOptionsFile": proguardOptionsFile.String(),
|
|
|
|
"javaDir": javaDir.String(),
|
|
|
|
"javaFileList": javaFileList.String(),
|
2015-04-13 22:58:27 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return publicResourcesFile, proguardOptionsFile, javaFileList
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func CreateExportPackage(ctx android.ModuleContext, flags []string, deps android.Paths) android.ModuleOutPath {
|
|
|
|
outputFile := android.PathForModuleOut(ctx, "package-export.apk")
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: aaptCreateAssetsPackage,
|
|
|
|
Description: "aapt export package",
|
|
|
|
Output: outputFile,
|
|
|
|
Implicits: deps,
|
2015-04-13 22:58:27 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"aaptFlags": strings.Join(flags, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return outputFile
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func CreateAppPackage(ctx android.ModuleContext, flags []string, jarFile android.Path,
|
|
|
|
certificates []string) android.Path {
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
resourceApk := android.PathForModuleOut(ctx, "resources.apk")
|
2015-04-13 22:58:27 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: aaptAddResources,
|
|
|
|
Description: "aapt package",
|
|
|
|
Output: resourceApk,
|
|
|
|
Input: jarFile,
|
2015-04-13 22:58:27 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"aaptFlags": strings.Join(flags, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile := android.PathForModuleOut(ctx, "package.apk")
|
2015-04-13 22:58:27 +02:00
|
|
|
|
|
|
|
var certificateArgs []string
|
|
|
|
for _, c := range certificates {
|
|
|
|
certificateArgs = append(certificateArgs, c+".x509.pem", c+".pk8")
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
2017-05-09 22:45:28 +02:00
|
|
|
Rule: signapk,
|
|
|
|
Description: "signapk",
|
|
|
|
Output: outputFile,
|
|
|
|
Input: resourceApk,
|
2015-04-13 22:58:27 +02:00
|
|
|
Args: map[string]string{
|
|
|
|
"certificates": strings.Join(certificateArgs, " "),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return outputFile
|
|
|
|
}
|