Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d71f86a7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add exclude_files and exclude_dirs properties to java_import"

parents 9611199b 37f6d79c
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -318,7 +318,8 @@ func TransformResourcesToJar(ctx android.ModuleContext, outputFile android.Writa
}

func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePath, desc string,
	jars android.Paths, manifest android.OptionalPath, stripDirs bool, dirsToStrip []string) {
	jars android.Paths, manifest android.OptionalPath, stripDirEntries bool, filesToStrip []string,
	dirsToStrip []string) {

	var deps android.Paths

@@ -328,22 +329,19 @@ func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePa
		deps = append(deps, manifest.Path())
	}

	if dirsToStrip != nil {
	for _, dir := range dirsToStrip {
		jarArgs = append(jarArgs, "-stripDir ", dir)
	}

	for _, file := range filesToStrip {
		jarArgs = append(jarArgs, "-stripFile ", file)
	}

	// Remove any module-info.class files that may have come from prebuilt jars, they cause problems
	// for downstream tools like desugar.
	jarArgs = append(jarArgs, "-stripFile module-info.class")

	// Remove any kotlin-reflect related files
	// TODO(pszczepaniak): Support kotlin-reflect
	jarArgs = append(jarArgs, "-stripFile \"*.kotlin_module\"")
	jarArgs = append(jarArgs, "-stripFile \"*.kotlin_builtin\"")

	if stripDirs {
	if stripDirEntries {
		jarArgs = append(jarArgs, "-D")
	}

+25 −10
Original line number Diff line number Diff line
@@ -995,6 +995,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
		}
	}

	var stripFiles []string

	if srcFiles.HasExt(".kt") {
		// If there are kotlin files, compile them first but pass all the kotlin and java files
		// kotlinc will use the java files to resolve types referenced by the kotlin files, but
@@ -1027,9 +1029,13 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
		// Jar kotlin classes into the final jar after javac
		jars = append(jars, kotlinJar)

		// Don't add kotlin-stdlib if using (on-device) renamed stdlib
		if Bool(j.properties.Renamed_kotlin_stdlib) {
			// Remove any kotlin-reflect related files
			// TODO(pszczepaniak): Support kotlin-reflect
			stripFiles = append(stripFiles, "*.kotlin_module", "*.kotlin_builtin")
		} else {
			// Only add kotlin-stdlib if not using (on-device) renamed stdlib
			// (it's expected to be on device bootclasspath)
		if !Bool(j.properties.Renamed_kotlin_stdlib) {
			jars = append(jars, deps.kotlinStdlib...)
		}
	}
@@ -1143,7 +1149,8 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
		outputFile = jars[0]
	} else {
		combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
		TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest, false, nil)
		TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
			false, stripFiles, nil)
		outputFile = combinedJar
	}

@@ -1219,7 +1226,8 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars
	// we cannot skip the combine step for now if there is only one jar
	// since we have to strip META-INF/TRANSITIVE dir from turbine.jar
	combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
	TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{}, false, []string{"META-INF"})
	TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
		false, nil, []string{"META-INF"})
	headerJar = combinedJar

	if j.properties.Jarjar_rules != nil {
@@ -1477,6 +1485,12 @@ type ImportProperties struct {

	// List of shared java libs that this module has dependencies to
	Libs []string

	// List of files to remove from the jar file(s)
	Exclude_files []string

	// List of directories to remove from the jar file(s)
	Exclude_dirs []string
}

type Import struct {
@@ -1485,7 +1499,6 @@ type Import struct {

	properties ImportProperties

	classpathFiles        android.Paths
	combinedClasspathFile android.Path
	exportedSdkLibs       []string
}
@@ -1511,14 +1524,16 @@ func (j *Import) Name() string {
}

func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
	android.ExtractSourcesDeps(ctx, j.properties.Jars)
	ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
}

func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
	jars := ctx.ExpandSources(j.properties.Jars, nil)

	outputFile := android.PathForModuleOut(ctx, "classes.jar")
	TransformJarsToJar(ctx, outputFile, "for prebuilts", j.classpathFiles, android.OptionalPath{}, false, nil)
	TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
		false, j.properties.Exclude_files, j.properties.Exclude_dirs)
	j.combinedClasspathFile = outputFile

	ctx.VisitDirectDeps(func(module android.Module) {
@@ -1547,11 +1562,11 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var _ Dependency = (*Import)(nil)

func (j *Import) HeaderJars() android.Paths {
	return j.classpathFiles
	return android.Paths{j.combinedClasspathFile}
}

func (j *Import) ImplementationJars() android.Paths {
	return j.classpathFiles
	return android.Paths{j.combinedClasspathFile}
}

func (j *Import) AidlIncludeDirs() android.Paths {
+6 −5
Original line number Diff line number Diff line
@@ -598,14 +598,15 @@ func TestPrebuilts(t *testing.T) {

	javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
	combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac")
	barJar := ctx.ModuleForTests("bar", "android_common").Rule("combineJar").Output
	bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output

	bar := "a.jar"
	if !strings.Contains(javac.Args["classpath"], bar) {
		t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bar)
	if !strings.Contains(javac.Args["classpath"], barJar.String()) {
		t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String())
	}

	if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != "b.jar" {
		t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, "b.jar")
	if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != bazJar.String() {
		t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String())
	}
}