Add jarjar support
If jarjar_rules is set, pass the compiled jar through jarjar to produce a new intermediate jar. Change-Id: Ied596433fd5c49d05f07c04245f3abe8b9aadc5e
This commit is contained in:
@@ -21,6 +21,7 @@ var stringProperties = map[string]string{
|
|||||||
"LOCAL_SDK_VERSION": "sdk_version",
|
"LOCAL_SDK_VERSION": "sdk_version",
|
||||||
"LOCAL_NDK_STL_VARIANT": "stl",
|
"LOCAL_NDK_STL_VARIANT": "stl",
|
||||||
"LOCAL_JAR_MANIFEST": "manifest",
|
"LOCAL_JAR_MANIFEST": "manifest",
|
||||||
|
"LOCAL_JARJAR_RULES": "jarjar_rules",
|
||||||
}
|
}
|
||||||
|
|
||||||
var listProperties = map[string]string{
|
var listProperties = map[string]string{
|
||||||
|
@@ -195,3 +195,13 @@ func (c *Config) HostBin() string {
|
|||||||
func (c *Config) HostBinTool(tool string) (string, error) {
|
func (c *Config) HostBinTool(tool string) (string, error) {
|
||||||
return filepath.Join(c.HostBin(), tool), nil
|
return filepath.Join(c.HostBin(), tool), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HostJavaDir returns the path to framework directory for host targets
|
||||||
|
func (c *Config) HostJavaDir() string {
|
||||||
|
return filepath.Join(c.HostOut(), "framework")
|
||||||
|
}
|
||||||
|
|
||||||
|
// HostJavaTool returns the path to a host tool in the frameworks directory for host targets
|
||||||
|
func (c *Config) HostJavaTool(tool string) (string, error) {
|
||||||
|
return filepath.Join(c.HostJavaDir(), tool), nil
|
||||||
|
}
|
||||||
|
@@ -62,6 +62,13 @@ var (
|
|||||||
},
|
},
|
||||||
"outDir", "dxFlags")
|
"outDir", "dxFlags")
|
||||||
|
|
||||||
|
jarjar = pctx.StaticRule("jarjar",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: "java -jar $jarjarCmd process $rulesFile $in $out",
|
||||||
|
Description: "jarjar $out",
|
||||||
|
},
|
||||||
|
"rulesFile")
|
||||||
|
|
||||||
extractPrebuilt = pctx.StaticRule("extractPrebuilt",
|
extractPrebuilt = pctx.StaticRule("extractPrebuilt",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf $outDir && unzip -qo $in -d $outDir && ` +
|
Command: `rm -rf $outDir && unzip -qo $in -d $outDir && ` +
|
||||||
@@ -80,6 +87,9 @@ func init() {
|
|||||||
pctx.VariableFunc("dxCmd", func(c interface{}) (string, error) {
|
pctx.VariableFunc("dxCmd", func(c interface{}) (string, error) {
|
||||||
return c.(Config).HostBinTool("dx")
|
return c.(Config).HostBinTool("dx")
|
||||||
})
|
})
|
||||||
|
pctx.VariableFunc("jarjarCmd", func(c interface{}) (string, error) {
|
||||||
|
return c.(Config).HostJavaTool("jarjar.jar")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type javaBuilderFlags struct {
|
type javaBuilderFlags struct {
|
||||||
@@ -198,6 +208,21 @@ func TransformDexToJavaLib(ctx common.AndroidModuleContext, resources []jarSpec,
|
|||||||
return outputFile
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TransformJarJar(ctx common.AndroidModuleContext, classesJar string, rulesFile string) string {
|
||||||
|
outputFile := filepath.Join(common.ModuleOutDir(ctx), "classes-jarjar.jar")
|
||||||
|
ctx.Build(pctx, blueprint.BuildParams{
|
||||||
|
Rule: jarjar,
|
||||||
|
Outputs: []string{outputFile},
|
||||||
|
Inputs: []string{classesJar},
|
||||||
|
Implicits: []string{"$jarjarCmd"},
|
||||||
|
Args: map[string]string{
|
||||||
|
"rulesFile": rulesFile,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return outputFile
|
||||||
|
}
|
||||||
|
|
||||||
func TransformPrebuiltJarToClasses(ctx common.AndroidModuleContext,
|
func TransformPrebuiltJarToClasses(ctx common.AndroidModuleContext,
|
||||||
prebuilt string) (classJarSpec, resourceJarSpec jarSpec) {
|
prebuilt string) (classJarSpec, resourceJarSpec jarSpec) {
|
||||||
|
|
||||||
|
15
java/java.go
15
java/java.go
@@ -33,6 +33,7 @@ type Config interface {
|
|||||||
SrcDir() string
|
SrcDir() string
|
||||||
PrebuiltOS() string
|
PrebuiltOS() string
|
||||||
HostBinTool(string) (string, error)
|
HostBinTool(string) (string, error)
|
||||||
|
HostJavaTool(string) (string, error)
|
||||||
Getenv(string) string
|
Getenv(string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +91,9 @@ type javaBase struct {
|
|||||||
// Set for device java libraries, and for host versions of device java libraries
|
// Set for device java libraries, and for host versions of device java libraries
|
||||||
// built for testing
|
// built for testing
|
||||||
Dex bool `blueprint:"mutated"`
|
Dex bool `blueprint:"mutated"`
|
||||||
|
|
||||||
|
// jarjar_rules: if not blank, run jarjar using the specified rules file
|
||||||
|
Jarjar_rules string
|
||||||
}
|
}
|
||||||
|
|
||||||
// output file suitable for inserting into the classpath of another compile
|
// output file suitable for inserting into the classpath of another compile
|
||||||
@@ -235,8 +239,19 @@ func (j *javaBase) GenerateJavaBuildActions(ctx common.AndroidModuleContext) {
|
|||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
j.classJarSpecs = classJarSpecs
|
j.classJarSpecs = classJarSpecs
|
||||||
j.resourceJarSpecs = resourceJarSpecs
|
j.resourceJarSpecs = resourceJarSpecs
|
||||||
|
|
||||||
|
if j.properties.Jarjar_rules != "" {
|
||||||
|
jarjar_rules := filepath.Join(common.ModuleSrcDir(ctx), j.properties.Jarjar_rules)
|
||||||
|
// Transform classes-full-debug.jar into classes-jarjar.jar
|
||||||
|
outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
|
||||||
|
if ctx.Failed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
j.classpathFile = outputFile
|
j.classpathFile = outputFile
|
||||||
|
|
||||||
if j.properties.Dex {
|
if j.properties.Dex {
|
||||||
|
Reference in New Issue
Block a user