Make javac rules output a jar with soong_zip
Make javac rules output a jar file instead of a classes.list. Combine the output jar, static jar dependencies, and resources into the final jar using a separate rule. For now, use a shell command with unzip and soong_zip to create the final jar, eventually it will be done with a zip2zip-style jar combiner. Bug: 64691570 Test: java_test.go Change-Id: Id8e6313e0097b78947d88e86e47b56ad08caca1a
This commit is contained in:
parent
fee57cb33e
commit
0a6e007e06
151
java/builder.go
151
java/builder.go
|
@ -43,8 +43,8 @@ var (
|
||||||
`$javacFlags $bootClasspath $classpath ` +
|
`$javacFlags $bootClasspath $classpath ` +
|
||||||
`-source $javaVersion -target $javaVersion ` +
|
`-source $javaVersion -target $javaVersion ` +
|
||||||
`-d $outDir -s $annoDir @$out.rsp && ` +
|
`-d $outDir -s $annoDir @$out.rsp && ` +
|
||||||
`find $outDir -type f | sort | ${config.JarArgsCmd} $outDir > $out`,
|
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
||||||
CommandDeps: []string{"${config.JavacCmd}", "${config.JarArgsCmd}"},
|
CommandDeps: []string{"${config.JavacCmd}", "${config.SoongZipCmd}"},
|
||||||
Rspfile: "$out.rsp",
|
Rspfile: "$out.rsp",
|
||||||
RspfileContent: "$in",
|
RspfileContent: "$in",
|
||||||
},
|
},
|
||||||
|
@ -57,12 +57,12 @@ var (
|
||||||
`$javacFlags $bootClasspath $classpath ` +
|
`$javacFlags $bootClasspath $classpath ` +
|
||||||
`-source $javaVersion -target $javaVersion ` +
|
`-source $javaVersion -target $javaVersion ` +
|
||||||
`-d $outDir -s $annoDir @$out.rsp && ` +
|
`-d $outDir -s $annoDir @$out.rsp && ` +
|
||||||
`find $outDir -type f | sort | ${config.JarArgsCmd} $outDir > $out`,
|
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
||||||
CommandDeps: []string{
|
CommandDeps: []string{
|
||||||
"${config.JavaCmd}",
|
"${config.JavaCmd}",
|
||||||
"${config.ErrorProneJavacJar}",
|
"${config.ErrorProneJavacJar}",
|
||||||
"${config.ErrorProneJar}",
|
"${config.ErrorProneJar}",
|
||||||
"${config.JarArgsCmd}",
|
"${config.SoongZipCmd}",
|
||||||
},
|
},
|
||||||
Rspfile: "$out.rsp",
|
Rspfile: "$out.rsp",
|
||||||
RspfileContent: "$in",
|
RspfileContent: "$in",
|
||||||
|
@ -71,17 +71,24 @@ var (
|
||||||
|
|
||||||
jar = pctx.AndroidStaticRule("jar",
|
jar = pctx.AndroidStaticRule("jar",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `${config.JarCmd} $operation ${out}.tmp $manifest $jarArgs && ${config.Zip2ZipCmd} -t -i ${out}.tmp -o ${out} && rm ${out}.tmp`,
|
Command: `${config.SoongZipCmd} -jar -o $out $jarArgs`,
|
||||||
CommandDeps: []string{"${config.JarCmd}"},
|
CommandDeps: []string{"${config.SoongZipCmd}"},
|
||||||
},
|
},
|
||||||
"operation", "manifest", "jarArgs")
|
"jarArgs")
|
||||||
|
|
||||||
|
combineJar = pctx.AndroidStaticRule("combineJar",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: `${config.MergeZipsCmd} -j $out $in`,
|
||||||
|
CommandDeps: []string{"${config.MergeZipsCmd}"},
|
||||||
|
},
|
||||||
|
"outDir")
|
||||||
|
|
||||||
dx = pctx.AndroidStaticRule("dx",
|
dx = pctx.AndroidStaticRule("dx",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||||
`${config.DxCmd} --dex --output=$outDir $dxFlags $in && ` +
|
`${config.DxCmd} --dex --output=$outDir $dxFlags $in || ( rm -rf "$outDir"; exit 41 ) && ` +
|
||||||
`find "$outDir" -name "classes*.dex" | sort | ${config.JarArgsCmd} ${outDir} > $out`,
|
`find "$outDir" -name "classes*.dex" | sort > $out`,
|
||||||
CommandDeps: []string{"${config.DxCmd}", "${config.JarArgsCmd}"},
|
CommandDeps: []string{"${config.DxCmd}"},
|
||||||
},
|
},
|
||||||
"outDir", "dxFlags")
|
"outDir", "dxFlags")
|
||||||
|
|
||||||
|
@ -91,22 +98,6 @@ var (
|
||||||
CommandDeps: []string{"${config.JavaCmd}", "${config.JarjarCmd}", "$rulesFile"},
|
CommandDeps: []string{"${config.JavaCmd}", "${config.JarjarCmd}", "$rulesFile"},
|
||||||
},
|
},
|
||||||
"rulesFile")
|
"rulesFile")
|
||||||
|
|
||||||
extractPrebuilt = pctx.AndroidStaticRule("extractPrebuilt",
|
|
||||||
blueprint.RuleParams{
|
|
||||||
Command: `rm -rf $outDir && unzip -qo $in -d $outDir && ` +
|
|
||||||
`find $outDir -name "*.class" | sort | ${config.JarArgsCmd} ${outDir} > $classFile && ` +
|
|
||||||
`find $outDir -type f -a \! -name "*.class" -a \! -name "MANIFEST.MF" | sort | ${config.JarArgsCmd} ${outDir} > $resourceFile`,
|
|
||||||
CommandDeps: []string{"${config.JarArgsCmd}"},
|
|
||||||
},
|
|
||||||
"outDir", "classFile", "resourceFile")
|
|
||||||
|
|
||||||
fileListToJarArgs = pctx.AndroidStaticRule("fileListToJarArgs",
|
|
||||||
blueprint.RuleParams{
|
|
||||||
Command: `${config.JarArgsCmd} -f $in -p ${outDir} -o $out`,
|
|
||||||
CommandDeps: []string{"${config.JarjarCmd}"},
|
|
||||||
},
|
|
||||||
"outDir")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -123,23 +114,19 @@ type javaBuilderFlags struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type jarSpec struct {
|
type jarSpec struct {
|
||||||
android.ModuleOutPath
|
fileList, dir android.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j jarSpec) jarArgs() string {
|
func (j jarSpec) soongJarArgs() string {
|
||||||
return "@" + j.String()
|
return "-C " + j.dir.String() + " -l " + j.fileList.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j jarSpec) path() android.Path {
|
func TransformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists android.Paths,
|
||||||
return j.ModuleOutPath
|
flags javaBuilderFlags, deps android.Paths) android.ModuleOutPath {
|
||||||
}
|
|
||||||
|
|
||||||
func TransformJavaToClasses(ctx android.ModuleContext, srcFiles android.Paths, srcFileLists android.Paths,
|
|
||||||
flags javaBuilderFlags, deps android.Paths) jarSpec {
|
|
||||||
|
|
||||||
classDir := android.PathForModuleOut(ctx, "classes")
|
classDir := android.PathForModuleOut(ctx, "classes")
|
||||||
annoDir := android.PathForModuleOut(ctx, "anno")
|
annoDir := android.PathForModuleOut(ctx, "anno")
|
||||||
classFileList := android.PathForModuleOut(ctx, "classes.list")
|
classJar := android.PathForModuleOut(ctx, "classes.jar")
|
||||||
|
|
||||||
javacFlags := flags.javacFlags + android.JoinWithPrefix(srcFileLists.Strings(), "@")
|
javacFlags := flags.javacFlags + android.JoinWithPrefix(srcFileLists.Strings(), "@")
|
||||||
|
|
||||||
|
@ -148,7 +135,7 @@ func TransformJavaToClasses(ctx android.ModuleContext, srcFiles android.Paths, s
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||||
Rule: javac,
|
Rule: javac,
|
||||||
Description: "javac",
|
Description: "javac",
|
||||||
Output: classFileList,
|
Output: classJar,
|
||||||
Inputs: srcFiles,
|
Inputs: srcFiles,
|
||||||
Implicits: deps,
|
Implicits: deps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
|
@ -161,7 +148,7 @@ func TransformJavaToClasses(ctx android.ModuleContext, srcFiles android.Paths, s
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return jarSpec{classFileList}
|
return classJar
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunErrorProne(ctx android.ModuleContext, srcFiles android.Paths, srcFileLists android.Paths,
|
func RunErrorProne(ctx android.ModuleContext, srcFiles android.Paths, srcFileLists android.Paths,
|
||||||
|
@ -199,22 +186,21 @@ func RunErrorProne(ctx android.ModuleContext, srcFiles android.Paths, srcFileLis
|
||||||
return classFileList
|
return classFileList
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformClassesToJar(ctx android.ModuleContext, classes []jarSpec,
|
func TransformResourcesToJar(ctx android.ModuleContext, resources []jarSpec,
|
||||||
manifest android.OptionalPath, deps android.Paths) android.Path {
|
manifest android.OptionalPath, deps android.Paths) android.Path {
|
||||||
|
|
||||||
outputFile := android.PathForModuleOut(ctx, "classes-full-debug.jar")
|
outputFile := android.PathForModuleOut(ctx, "res.jar")
|
||||||
|
|
||||||
jarArgs := []string{}
|
jarArgs := []string{}
|
||||||
|
|
||||||
for _, j := range classes {
|
for _, j := range resources {
|
||||||
deps = append(deps, j.path())
|
deps = append(deps, j.fileList)
|
||||||
jarArgs = append(jarArgs, j.jarArgs())
|
jarArgs = append(jarArgs, j.soongJarArgs())
|
||||||
}
|
}
|
||||||
|
|
||||||
operation := "cf"
|
|
||||||
if manifest.Valid() {
|
if manifest.Valid() {
|
||||||
operation = "cfm"
|
|
||||||
deps = append(deps, manifest.Path())
|
deps = append(deps, manifest.Path())
|
||||||
|
jarArgs = append(jarArgs, "-m "+manifest.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||||
|
@ -223,15 +209,31 @@ func TransformClassesToJar(ctx android.ModuleContext, classes []jarSpec,
|
||||||
Output: outputFile,
|
Output: outputFile,
|
||||||
Implicits: deps,
|
Implicits: deps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"jarArgs": strings.Join(jarArgs, " "),
|
"jarArgs": strings.Join(jarArgs, " "),
|
||||||
"operation": operation,
|
|
||||||
"manifest": manifest.String(),
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return outputFile
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TransformJarsToJar(ctx android.ModuleContext, stem string, jars android.Paths) android.Path {
|
||||||
|
|
||||||
|
outputFile := android.PathForModuleOut(ctx, stem)
|
||||||
|
|
||||||
|
if len(jars) == 1 {
|
||||||
|
return jars[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||||
|
Rule: combineJar,
|
||||||
|
Description: "combine jars",
|
||||||
|
Output: outputFile,
|
||||||
|
Inputs: jars,
|
||||||
|
})
|
||||||
|
|
||||||
|
return outputFile
|
||||||
|
}
|
||||||
|
|
||||||
func TransformClassesJarToDex(ctx android.ModuleContext, classesJar android.Path,
|
func TransformClassesJarToDex(ctx android.ModuleContext, classesJar android.Path,
|
||||||
flags javaBuilderFlags) jarSpec {
|
flags javaBuilderFlags) jarSpec {
|
||||||
|
|
||||||
|
@ -249,7 +251,7 @@ func TransformClassesJarToDex(ctx android.ModuleContext, classesJar android.Path
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return jarSpec{outputFile}
|
return jarSpec{outputFile, outDir}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformDexToJavaLib(ctx android.ModuleContext, resources []jarSpec,
|
func TransformDexToJavaLib(ctx android.ModuleContext, resources []jarSpec,
|
||||||
|
@ -260,12 +262,12 @@ func TransformDexToJavaLib(ctx android.ModuleContext, resources []jarSpec,
|
||||||
var jarArgs []string
|
var jarArgs []string
|
||||||
|
|
||||||
for _, j := range resources {
|
for _, j := range resources {
|
||||||
deps = append(deps, j.path())
|
deps = append(deps, j.fileList)
|
||||||
jarArgs = append(jarArgs, j.jarArgs())
|
jarArgs = append(jarArgs, j.soongJarArgs())
|
||||||
}
|
}
|
||||||
|
|
||||||
deps = append(deps, dexJarSpec.path())
|
deps = append(deps, dexJarSpec.fileList)
|
||||||
jarArgs = append(jarArgs, dexJarSpec.jarArgs())
|
jarArgs = append(jarArgs, dexJarSpec.soongJarArgs())
|
||||||
|
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||||
Rule: jar,
|
Rule: jar,
|
||||||
|
@ -273,15 +275,14 @@ func TransformDexToJavaLib(ctx android.ModuleContext, resources []jarSpec,
|
||||||
Output: outputFile,
|
Output: outputFile,
|
||||||
Implicits: deps,
|
Implicits: deps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"operation": "cf",
|
"jarArgs": strings.Join(jarArgs, " "),
|
||||||
"jarArgs": strings.Join(jarArgs, " "),
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return outputFile
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformJarJar(ctx android.ModuleContext, classesJar android.Path, rulesFile android.Path) android.Path {
|
func TransformJarJar(ctx android.ModuleContext, classesJar android.Path, rulesFile android.Path) android.ModuleOutPath {
|
||||||
outputFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
|
outputFile := android.PathForModuleOut(ctx, "classes-jarjar.jar")
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||||
Rule: jarjar,
|
Rule: jarjar,
|
||||||
|
@ -296,41 +297,3 @@ func TransformJarJar(ctx android.ModuleContext, classesJar android.Path, rulesFi
|
||||||
|
|
||||||
return outputFile
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformPrebuiltJarToClasses(ctx android.ModuleContext,
|
|
||||||
subdir string, prebuilt android.Path) (classJarSpec, resourceJarSpec jarSpec) {
|
|
||||||
|
|
||||||
classDir := android.PathForModuleOut(ctx, subdir, "classes")
|
|
||||||
classFileList := android.PathForModuleOut(ctx, subdir, "classes.list")
|
|
||||||
resourceFileList := android.PathForModuleOut(ctx, subdir, "resources.list")
|
|
||||||
|
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
|
||||||
Rule: extractPrebuilt,
|
|
||||||
Description: "extract classes",
|
|
||||||
Outputs: android.WritablePaths{classFileList, resourceFileList},
|
|
||||||
Input: prebuilt,
|
|
||||||
Args: map[string]string{
|
|
||||||
"outDir": classDir.String(),
|
|
||||||
"classFile": classFileList.String(),
|
|
||||||
"resourceFile": resourceFileList.String(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return jarSpec{classFileList}, jarSpec{resourceFileList}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TransformFileListToJarSpec(ctx android.ModuleContext, dir, fileListFile android.Path) jarSpec {
|
|
||||||
outputFile := android.PathForModuleOut(ctx, fileListFile.Base()+".jarArgs")
|
|
||||||
|
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
|
||||||
Rule: fileListToJarArgs,
|
|
||||||
Description: "file list to jar args",
|
|
||||||
Output: outputFile,
|
|
||||||
Input: fileListFile,
|
|
||||||
Args: map[string]string{
|
|
||||||
"outDir": dir.String(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return jarSpec{outputFile}
|
|
||||||
}
|
|
||||||
|
|
|
@ -57,8 +57,9 @@ func init() {
|
||||||
pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
|
pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
|
||||||
pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
|
pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
|
||||||
|
|
||||||
pctx.StaticVariable("Zip2ZipCmd", filepath.Join("${bootstrap.ToolDir}", "zip2zip"))
|
|
||||||
pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
|
pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh")
|
||||||
|
pctx.StaticVariable("SoongZipCmd", filepath.Join("${bootstrap.ToolDir}", "soong_zip"))
|
||||||
|
pctx.StaticVariable("MergeZipsCmd", filepath.Join("${bootstrap.ToolDir}", "merge_zips"))
|
||||||
pctx.HostBinToolVariable("DxCmd", "dx")
|
pctx.HostBinToolVariable("DxCmd", "dx")
|
||||||
pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
|
pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
|
||||||
|
|
||||||
|
|
97
java/java.go
97
java/java.go
|
@ -134,12 +134,6 @@ type Module struct {
|
||||||
// output file suitable for installing or running
|
// output file suitable for installing or running
|
||||||
outputFile android.Path
|
outputFile android.Path
|
||||||
|
|
||||||
// jarSpecs suitable for inserting classes from a static library into another jar
|
|
||||||
classJarSpecs []jarSpec
|
|
||||||
|
|
||||||
// jarSpecs suitable for inserting resources from a static library into another jar
|
|
||||||
resourceJarSpecs []jarSpec
|
|
||||||
|
|
||||||
exportAidlIncludeDirs android.Paths
|
exportAidlIncludeDirs android.Paths
|
||||||
|
|
||||||
logtagsSrcs android.Paths
|
logtagsSrcs android.Paths
|
||||||
|
@ -154,8 +148,6 @@ type Module struct {
|
||||||
|
|
||||||
type Dependency interface {
|
type Dependency interface {
|
||||||
ClasspathFiles() android.Paths
|
ClasspathFiles() android.Paths
|
||||||
ClassJarSpecs() []jarSpec
|
|
||||||
ResourceJarSpecs() []jarSpec
|
|
||||||
AidlIncludeDirs() android.Paths
|
AidlIncludeDirs() android.Paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,9 +221,8 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths,
|
func (j *Module) collectDeps(ctx android.ModuleContext) (classpath, bootClasspath, staticJars,
|
||||||
bootClasspath android.Paths, classJarSpecs, resourceJarSpecs []jarSpec, aidlPreprocess android.OptionalPath,
|
aidlIncludeDirs, srcFileLists android.Paths, aidlPreprocess android.OptionalPath) {
|
||||||
aidlIncludeDirs android.Paths, srcFileLists android.Paths) {
|
|
||||||
|
|
||||||
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
ctx.VisitDirectDeps(func(module blueprint.Module) {
|
||||||
otherName := ctx.OtherModuleName(module)
|
otherName := ctx.OtherModuleName(module)
|
||||||
|
@ -254,8 +245,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths
|
||||||
classpath = append(classpath, dep.ClasspathFiles()...)
|
classpath = append(classpath, dep.ClasspathFiles()...)
|
||||||
case staticLibTag:
|
case staticLibTag:
|
||||||
classpath = append(classpath, dep.ClasspathFiles()...)
|
classpath = append(classpath, dep.ClasspathFiles()...)
|
||||||
classJarSpecs = append(classJarSpecs, dep.ClassJarSpecs()...)
|
staticJars = append(staticJars, dep.ClasspathFiles()...)
|
||||||
resourceJarSpecs = append(resourceJarSpecs, dep.ResourceJarSpecs()...)
|
|
||||||
case frameworkResTag:
|
case frameworkResTag:
|
||||||
if ctx.ModuleName() == "framework" {
|
if ctx.ModuleName() == "framework" {
|
||||||
// framework.jar has a one-off dependency on the R.java and Manifest.java files
|
// framework.jar has a one-off dependency on the R.java and Manifest.java files
|
||||||
|
@ -280,16 +270,15 @@ func (j *Module) collectDeps(ctx android.ModuleContext) (classpath android.Paths
|
||||||
aidlIncludeDirs = append(aidlIncludeDirs, dep.AidlIncludeDirs()...)
|
aidlIncludeDirs = append(aidlIncludeDirs, dep.AidlIncludeDirs()...)
|
||||||
})
|
})
|
||||||
|
|
||||||
return classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
|
return
|
||||||
aidlIncludeDirs, srcFileLists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) compile(ctx android.ModuleContext) {
|
func (j *Module) compile(ctx android.ModuleContext) {
|
||||||
|
|
||||||
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
|
j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Export_aidl_include_dirs)
|
||||||
|
|
||||||
classpath, bootClasspath, classJarSpecs, resourceJarSpecs, aidlPreprocess,
|
classpath, bootClasspath, staticJars, aidlIncludeDirs, srcFileLists,
|
||||||
aidlIncludeDirs, srcFileLists := j.collectDeps(ctx)
|
aidlPreprocess := j.collectDeps(ctx)
|
||||||
|
|
||||||
var flags javaBuilderFlags
|
var flags javaBuilderFlags
|
||||||
|
|
||||||
|
@ -341,6 +330,8 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
||||||
|
|
||||||
var extraJarDeps android.Paths
|
var extraJarDeps android.Paths
|
||||||
|
|
||||||
|
var jars android.Paths
|
||||||
|
|
||||||
if len(srcFiles) > 0 {
|
if len(srcFiles) > 0 {
|
||||||
// Compile java sources into .class files
|
// Compile java sources into .class files
|
||||||
classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, deps)
|
classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, deps)
|
||||||
|
@ -359,37 +350,37 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
||||||
extraJarDeps = append(extraJarDeps, errorprone)
|
extraJarDeps = append(extraJarDeps, errorprone)
|
||||||
}
|
}
|
||||||
|
|
||||||
classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
|
jars = append(jars, classes)
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceJarSpecs = append(ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs, j.properties.Exclude_resource_dirs),
|
resourceJarSpecs := ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs, j.properties.Exclude_resource_dirs)
|
||||||
resourceJarSpecs...)
|
|
||||||
|
|
||||||
manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
|
manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
|
||||||
|
|
||||||
allJarSpecs := append([]jarSpec(nil), classJarSpecs...)
|
if len(resourceJarSpecs) > 0 || manifest.Valid() {
|
||||||
allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
|
// Combine classes + resources into classes-full-debug.jar
|
||||||
|
resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, manifest, extraJarDeps)
|
||||||
// Combine classes + resources into classes-full-debug.jar
|
|
||||||
outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest, extraJarDeps)
|
|
||||||
if ctx.Failed() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if j.properties.Jarjar_rules != nil {
|
|
||||||
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
|
||||||
// Transform classes-full-debug.jar into classes-jarjar.jar
|
|
||||||
outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
|
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
classes, _ := TransformPrebuiltJarToClasses(ctx, "jarjar_extracted", outputFile)
|
jars = append(jars, resourceJar)
|
||||||
classJarSpecs = []jarSpec{classes}
|
}
|
||||||
|
|
||||||
|
jars = append(jars, staticJars...)
|
||||||
|
|
||||||
|
// Combine the classes built from sources, any manifests, and any static libraries into
|
||||||
|
// classes-combined.jar. If there is only one input jar this step will be skipped.
|
||||||
|
outputFile := TransformJarsToJar(ctx, "classes-combined.jar", jars)
|
||||||
|
|
||||||
|
if j.properties.Jarjar_rules != nil {
|
||||||
|
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
||||||
|
// Transform classes-combined.jar into classes-jarjar.jar
|
||||||
|
outputFile = TransformJarJar(ctx, outputFile, jarjar_rules)
|
||||||
|
if ctx.Failed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
j.resourceJarSpecs = resourceJarSpecs
|
|
||||||
j.classJarSpecs = classJarSpecs
|
|
||||||
j.classpathFile = outputFile
|
j.classpathFile = outputFile
|
||||||
|
|
||||||
if j.deviceProperties.Dex && len(srcFiles) > 0 {
|
if j.deviceProperties.Dex && len(srcFiles) > 0 {
|
||||||
|
@ -447,14 +438,6 @@ func (j *Module) ClasspathFiles() android.Paths {
|
||||||
return android.Paths{j.classpathFile}
|
return android.Paths{j.classpathFile}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) ClassJarSpecs() []jarSpec {
|
|
||||||
return j.classJarSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Module) ResourceJarSpecs() []jarSpec {
|
|
||||||
return j.resourceJarSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Module) AidlIncludeDirs() android.Paths {
|
func (j *Module) AidlIncludeDirs() android.Paths {
|
||||||
return j.exportAidlIncludeDirs
|
return j.exportAidlIncludeDirs
|
||||||
}
|
}
|
||||||
|
@ -580,9 +563,8 @@ type Import struct {
|
||||||
|
|
||||||
properties ImportProperties
|
properties ImportProperties
|
||||||
|
|
||||||
classpathFiles android.Paths
|
classpathFiles android.Paths
|
||||||
combinedClasspathFile android.Path
|
combinedClasspathFile android.Path
|
||||||
classJarSpecs, resourceJarSpecs []jarSpec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) Prebuilt() *android.Prebuilt {
|
func (j *Import) Prebuilt() *android.Prebuilt {
|
||||||
|
@ -603,14 +585,7 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
|
j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
|
||||||
|
|
||||||
for i, prebuilt := range j.classpathFiles {
|
j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles)
|
||||||
subdir := "extracted" + strconv.Itoa(i)
|
|
||||||
classJarSpec, resourceJarSpec := TransformPrebuiltJarToClasses(ctx, subdir, prebuilt)
|
|
||||||
j.classJarSpecs = append(j.classJarSpecs, classJarSpec)
|
|
||||||
j.resourceJarSpecs = append(j.resourceJarSpecs, resourceJarSpec)
|
|
||||||
}
|
|
||||||
|
|
||||||
j.combinedClasspathFile = TransformClassesToJar(ctx, j.classJarSpecs, android.OptionalPath{}, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Dependency = (*Import)(nil)
|
var _ Dependency = (*Import)(nil)
|
||||||
|
@ -619,14 +594,6 @@ func (j *Import) ClasspathFiles() android.Paths {
|
||||||
return j.classpathFiles
|
return j.classpathFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) ClassJarSpecs() []jarSpec {
|
|
||||||
return j.classJarSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Import) ResourceJarSpecs() []jarSpec {
|
|
||||||
return j.resourceJarSpecs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Import) AidlIncludeDirs() android.Paths {
|
func (j *Import) AidlIncludeDirs() android.Paths {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ func testJava(t *testing.T, bp string) *android.TestContext {
|
||||||
bp += fmt.Sprintf(`
|
bp += fmt.Sprintf(`
|
||||||
java_library {
|
java_library {
|
||||||
name: "%s",
|
name: "%s",
|
||||||
|
srcs: ["a.java"],
|
||||||
no_standard_libs: true,
|
no_standard_libs: true,
|
||||||
}
|
}
|
||||||
`, extra)
|
`, extra)
|
||||||
|
@ -112,20 +113,25 @@ func TestSimple(t *testing.T) {
|
||||||
`)
|
`)
|
||||||
|
|
||||||
javac := ctx.ModuleForTests("foo", "").Rule("javac")
|
javac := ctx.ModuleForTests("foo", "").Rule("javac")
|
||||||
jar := ctx.ModuleForTests("foo", "").Rule("jar")
|
combineJar := ctx.ModuleForTests("foo", "").Rule("combineJar")
|
||||||
|
|
||||||
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
||||||
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes-full-debug.jar")
|
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes.jar")
|
||||||
|
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes.jar")
|
||||||
|
|
||||||
if !strings.Contains(javac.Args["classpath"], bar) {
|
if !strings.Contains(javac.Args["classpath"], bar) {
|
||||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes.list")
|
if !strings.Contains(javac.Args["classpath"], baz) {
|
||||||
if !strings.Contains(jar.Args["jarArgs"], baz) {
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], baz)
|
||||||
t.Errorf("foo jarArgs %v does not contain %q", jar.Args["jarArgs"], baz)
|
}
|
||||||
|
|
||||||
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
||||||
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +182,7 @@ func TestSdk(t *testing.T) {
|
||||||
|
|
||||||
check := func(module string, depType depType, deps ...string) {
|
check := func(module string, depType depType, deps ...string) {
|
||||||
for i := range deps {
|
for i := range deps {
|
||||||
deps[i] = filepath.Join(buildDir, ".intermediates", deps[i], "classes-full-debug.jar")
|
deps[i] = filepath.Join(buildDir, ".intermediates", deps[i], "classes.jar")
|
||||||
}
|
}
|
||||||
dep := strings.Join(deps, ":")
|
dep := strings.Join(deps, ":")
|
||||||
|
|
||||||
|
@ -229,16 +235,15 @@ func TestPrebuilts(t *testing.T) {
|
||||||
`)
|
`)
|
||||||
|
|
||||||
javac := ctx.ModuleForTests("foo", "").Rule("javac")
|
javac := ctx.ModuleForTests("foo", "").Rule("javac")
|
||||||
jar := ctx.ModuleForTests("foo", "").Rule("jar")
|
combineJar := ctx.ModuleForTests("foo", "").Rule("combineJar")
|
||||||
|
|
||||||
bar := "a.jar"
|
bar := "a.jar"
|
||||||
if !strings.Contains(javac.Args["classpath"], bar) {
|
if !strings.Contains(javac.Args["classpath"], bar) {
|
||||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "extracted0", "classes.list")
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != "b.jar" {
|
||||||
if !strings.Contains(jar.Args["jarArgs"], baz) {
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, "b.jar")
|
||||||
t.Errorf("foo jarArgs %v does not contain %q", jar.Args["jarArgs"], baz)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,20 +273,20 @@ func TestDefaults(t *testing.T) {
|
||||||
`)
|
`)
|
||||||
|
|
||||||
javac := ctx.ModuleForTests("foo", "").Rule("javac")
|
javac := ctx.ModuleForTests("foo", "").Rule("javac")
|
||||||
jar := ctx.ModuleForTests("foo", "").Rule("jar")
|
combineJar := ctx.ModuleForTests("foo", "").Rule("combineJar")
|
||||||
|
|
||||||
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" {
|
||||||
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes-full-debug.jar")
|
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes.jar")
|
||||||
if !strings.Contains(javac.Args["classpath"], bar) {
|
if !strings.Contains(javac.Args["classpath"], bar) {
|
||||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes.list")
|
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes.jar")
|
||||||
if !strings.Contains(jar.Args["jarArgs"], baz) {
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
||||||
t.Errorf("foo jarArgs %v does not contain %q", jar.Args["jarArgs"], baz)
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ func ResourceDirsToJarSpecs(ctx android.ModuleContext, resourceDirs, excludeDirs
|
||||||
|
|
||||||
pattern := filepath.Join(dir.String(), "**/*")
|
pattern := filepath.Join(dir.String(), "**/*")
|
||||||
bootstrap.GlobFile(ctx, pattern, excludes, fileListFile.String(), depFile)
|
bootstrap.GlobFile(ctx, pattern, excludes, fileListFile.String(), depFile)
|
||||||
jarSpecs = append(jarSpecs, TransformFileListToJarSpec(ctx, dir, fileListFile))
|
jarSpecs = append(jarSpecs, jarSpec{fileListFile, dir})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue