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

Commit a4278eba authored by Liz Kammer's avatar Liz Kammer Committed by Automerger Merge Worker
Browse files

Merge "Add property api_levels_jar_filename to droidstubs" am: 9c55b0ef

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1388544

Change-Id: I4da722343ed53baedf40ad7661fc1f017051a70d
parents 285318aa 9c55b0ef
Loading
Loading
Loading
Loading
+30 −24
Original line number Diff line number Diff line
@@ -294,6 +294,9 @@ type DroidstubsProperties struct {
	// the dirs which Metalava extracts API levels annotations from.
	Api_levels_annotations_dirs []string

	// the filename which Metalava extracts API levels annotations from. Defaults to android.jar.
	Api_levels_jar_filename *string

	// if set to true, collect the values used by the Dev tools and
	// write them in files packaged with the SDK. Defaults to false.
	Write_sdk_values *bool
@@ -1407,7 +1410,10 @@ func (d *Droidstubs) inclusionAnnotationsFlags(ctx android.ModuleContext, cmd *a
}

func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
	if Bool(d.properties.Api_levels_annotations_enabled) {
	if !Bool(d.properties.Api_levels_annotations_enabled) {
		return
	}

	d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml")

	if len(d.properties.Api_levels_annotations_dirs) == 0 {
@@ -1420,21 +1426,21 @@ func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *a
	cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion())
	cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename())

	filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar")

	ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) {
		if t, ok := m.(*ExportedDroiddocDir); ok {
			for _, dep := range t.deps {
					if strings.HasSuffix(dep.String(), "android.jar") {
				if strings.HasSuffix(dep.String(), filename) {
					cmd.Implicit(dep)
				}
			}
				cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/android.jar")
			cmd.FlagWithArg("--android-jar-pattern ", t.dir.String()+"/%/public/"+filename)
		} else {
			ctx.PropertyErrorf("api_levels_annotations_dirs",
				"module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m))
		}
	})

	}
}

func (d *Droidstubs) apiToXmlFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) {
+56 −0
Original line number Diff line number Diff line
@@ -1170,6 +1170,62 @@ func TestDroiddocArgsAndFlagsCausesError(t *testing.T) {
		`)
}

func TestDroidstubs(t *testing.T) {
	ctx, _ := testJavaWithFS(t, `
		droiddoc_exported_dir {
		    name: "droiddoc-templates-sdk",
		    path: ".",
		}

		droidstubs {
		    name: "bar-stubs",
		    srcs: [
		        "bar-doc/a.java",
				],
				api_levels_annotations_dirs: [
					"droiddoc-templates-sdk",
				],
				api_levels_annotations_enabled: true,
		}

		droidstubs {
		    name: "bar-stubs-other",
		    srcs: [
		        "bar-doc/a.java",
				],
				api_levels_annotations_dirs: [
					"droiddoc-templates-sdk",
				],
				api_levels_annotations_enabled: true,
				api_levels_jar_filename: "android.other.jar",
		}
		`,
		map[string][]byte{
			"bar-doc/a.java": nil,
		})
	testcases := []struct {
		moduleName          string
		expectedJarFilename string
	}{
		{
			moduleName:          "bar-stubs",
			expectedJarFilename: "android.jar",
		},
		{
			moduleName:          "bar-stubs-other",
			expectedJarFilename: "android.other.jar",
		},
	}
	for _, c := range testcases {
		m := ctx.ModuleForTests(c.moduleName, "android_common")
		metalava := m.Rule("metalava")
		expected := "--android-jar-pattern ./%/public/" + c.expectedJarFilename
		if actual := metalava.RuleParams.Command; !strings.Contains(actual, expected) {
			t.Errorf("For %q, expected metalava argument %q, but was not found %q", c.moduleName, expected, actual)
		}
	}
}

func TestDroidstubsWithSystemModules(t *testing.T) {
	ctx, _ := testJava(t, `
		droidstubs {