Rearrange manifest file handling in merge_zips and soong_zip
Jar always puts default MANIFEST.MF files in if none was specified. Copying that behavior in soong_zip causes problems with merge_zips, because it ends up taking the default manifest from the classes.jar instead of the user's manifest from res.jar. We don't want the user's manifest in the classes.jar, otherwise a change to the manifest will cause all the class files to rebuild. Instead, move the manifest insertion to the final merge_zips stage. Test: m -j checkbuild Change-Id: Id6376961dbaf743c2fb92843f9bdf2e44b963be0
This commit is contained in:
@@ -78,10 +78,10 @@ var (
|
||||
|
||||
combineJar = pctx.AndroidStaticRule("combineJar",
|
||||
blueprint.RuleParams{
|
||||
Command: `${config.MergeZipsCmd} -j $out $in`,
|
||||
Command: `${config.MergeZipsCmd} -j $jarArgs $out $in`,
|
||||
CommandDeps: []string{"${config.MergeZipsCmd}"},
|
||||
},
|
||||
"outDir")
|
||||
"jarArgs")
|
||||
|
||||
dx = pctx.AndroidStaticRule("dx",
|
||||
blueprint.RuleParams{
|
||||
@@ -126,7 +126,7 @@ func TransformJavaToClasses(ctx android.ModuleContext, srcFiles, srcFileLists an
|
||||
|
||||
classDir := android.PathForModuleOut(ctx, "classes")
|
||||
annoDir := android.PathForModuleOut(ctx, "anno")
|
||||
classJar := android.PathForModuleOut(ctx, "classes.jar")
|
||||
classJar := android.PathForModuleOut(ctx, "classes-compiled.jar")
|
||||
|
||||
javacFlags := flags.javacFlags + android.JoinWithPrefix(srcFileLists.Strings(), "@")
|
||||
|
||||
@@ -187,7 +187,7 @@ func RunErrorProne(ctx android.ModuleContext, srcFiles android.Paths, srcFileLis
|
||||
}
|
||||
|
||||
func TransformResourcesToJar(ctx android.ModuleContext, resources []jarSpec,
|
||||
manifest android.OptionalPath, deps android.Paths) android.Path {
|
||||
deps android.Paths) android.Path {
|
||||
|
||||
outputFile := android.PathForModuleOut(ctx, "res.jar")
|
||||
|
||||
@@ -198,11 +198,6 @@ func TransformResourcesToJar(ctx android.ModuleContext, resources []jarSpec,
|
||||
jarArgs = append(jarArgs, j.soongJarArgs())
|
||||
}
|
||||
|
||||
if manifest.Valid() {
|
||||
deps = append(deps, manifest.Path())
|
||||
jarArgs = append(jarArgs, "-m "+manifest.String())
|
||||
}
|
||||
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: jar,
|
||||
Description: "jar",
|
||||
@@ -216,19 +211,36 @@ func TransformResourcesToJar(ctx android.ModuleContext, resources []jarSpec,
|
||||
return outputFile
|
||||
}
|
||||
|
||||
func TransformJarsToJar(ctx android.ModuleContext, stem string, jars android.Paths) android.Path {
|
||||
func TransformJarsToJar(ctx android.ModuleContext, stem string, jars android.Paths,
|
||||
manifest android.OptionalPath, stripDirs bool) android.Path {
|
||||
|
||||
outputFile := android.PathForModuleOut(ctx, stem)
|
||||
|
||||
if len(jars) == 1 {
|
||||
if len(jars) == 1 && !manifest.Valid() {
|
||||
return jars[0]
|
||||
}
|
||||
|
||||
var deps android.Paths
|
||||
|
||||
var jarArgs []string
|
||||
if manifest.Valid() {
|
||||
jarArgs = append(jarArgs, "-m "+manifest.String())
|
||||
deps = append(deps, manifest.Path())
|
||||
}
|
||||
|
||||
if stripDirs {
|
||||
jarArgs = append(jarArgs, "-D")
|
||||
}
|
||||
|
||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||
Rule: combineJar,
|
||||
Description: "combine jars",
|
||||
Output: outputFile,
|
||||
Inputs: jars,
|
||||
Implicits: deps,
|
||||
Args: map[string]string{
|
||||
"jarArgs": strings.Join(jarArgs, " "),
|
||||
},
|
||||
})
|
||||
|
||||
return outputFile
|
||||
|
12
java/java.go
12
java/java.go
@@ -385,11 +385,9 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
||||
}
|
||||
|
||||
resourceJarSpecs := ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs, j.properties.Exclude_resource_dirs)
|
||||
manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
|
||||
|
||||
if len(resourceJarSpecs) > 0 || manifest.Valid() {
|
||||
if len(resourceJarSpecs) > 0 {
|
||||
// Combine classes + resources into classes-full-debug.jar
|
||||
resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, manifest, extraJarDeps)
|
||||
resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, extraJarDeps)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -399,9 +397,11 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
||||
|
||||
jars = append(jars, deps.staticJars...)
|
||||
|
||||
manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
|
||||
|
||||
// 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)
|
||||
outputFile := TransformJarsToJar(ctx, "classes.jar", jars, manifest, false)
|
||||
|
||||
if j.properties.Jarjar_rules != nil {
|
||||
jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
|
||||
@@ -616,7 +616,7 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
|
||||
|
||||
j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles)
|
||||
j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles, android.OptionalPath{}, false)
|
||||
}
|
||||
|
||||
var _ Dependency = (*Import)(nil)
|
||||
|
@@ -119,8 +119,8 @@ func TestSimple(t *testing.T) {
|
||||
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
||||
}
|
||||
|
||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes.jar")
|
||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes.jar")
|
||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes-compiled.jar")
|
||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes-compiled.jar")
|
||||
|
||||
if !strings.Contains(javac.Args["classpath"], bar) {
|
||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
||||
@@ -182,7 +182,7 @@ func TestSdk(t *testing.T) {
|
||||
|
||||
check := func(module string, depType depType, deps ...string) {
|
||||
for i := range deps {
|
||||
deps[i] = filepath.Join(buildDir, ".intermediates", deps[i], "classes.jar")
|
||||
deps[i] = filepath.Join(buildDir, ".intermediates", deps[i], "classes-compiled.jar")
|
||||
}
|
||||
dep := strings.Join(deps, ":")
|
||||
|
||||
@@ -279,12 +279,12 @@ func TestDefaults(t *testing.T) {
|
||||
t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs)
|
||||
}
|
||||
|
||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes.jar")
|
||||
bar := filepath.Join(buildDir, ".intermediates", "bar", "classes-compiled.jar")
|
||||
if !strings.Contains(javac.Args["classpath"], bar) {
|
||||
t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
|
||||
}
|
||||
|
||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes.jar")
|
||||
baz := filepath.Join(buildDir, ".intermediates", "baz", "classes-compiled.jar")
|
||||
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
||||
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
||||
}
|
||||
|
Reference in New Issue
Block a user