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

Commit 8ec23f84 authored by Jingwen Chen's avatar Jingwen Chen Committed by Gerrit Code Review
Browse files

Merge "Convert apex_available (for supported modules) to bazel tags."

parents 62ed3dd5 c4c34e1e
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -705,6 +705,28 @@ func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions(
	t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty)
}

// ApexAvailableTags converts the apex_available property value of an ApexModule
// module and returns it as a list of keyed tags.
func ApexAvailableTags(mod Module) bazel.StringListAttribute {
	attr := bazel.StringListAttribute{}
	tags := []string{}
	// Transform specific attributes into tags.
	if am, ok := mod.(ApexModule); ok {
		// TODO(b/218841706): hidl_interface has the apex_available prop, but it's
		// defined directly as a prop and not via ApexModule, so this doesn't
		// pick those props up.
		// TODO(b/260694842): This does not pick up aidl_interface.backend.ndk.apex_available.
		for _, a := range am.apexModuleBase().ApexAvailable() {
			tags = append(tags, "apex_available="+a)
		}
	}
	if len(tags) > 0 {
		// This avoids creating a tags attr with an empty list if there are no tags.
		attr.Value = tags
	}
	return attr
}

func (t *topDownMutatorContext) createBazelTargetModule(
	bazelProps bazel.BazelTargetModuleProperties,
	commonAttrs CommonAttributes,
+5 −0
Original line number Diff line number Diff line
@@ -2676,6 +2676,10 @@ func (o *OverrideApex) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
	}
	attrs, props := convertWithBp2build(a, ctx)

	// We just want the name, not module reference.
	baseApexName := strings.TrimPrefix(baseApexModuleName, ":")
	attrs.Base_apex_name = &baseApexName

	for _, p := range o.GetProperties() {
		overridableProperties, ok := p.(*overridableProperties)
		if !ok {
@@ -3397,6 +3401,7 @@ type bazelApexBundleAttributes struct {
	Package_name          *string
	Logging_parent        *string
	Tests                 bazel.LabelListAttribute
	Base_apex_name        *string
}

type convertedNativeSharedLibs struct {
+39 −25
Original line number Diff line number Diff line
@@ -663,6 +663,7 @@ override_apex {
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"android_manifest": `"ApogeeAndroidManifest.xml"`,
				"base_apex_name":   `"com.android.apogee"`,
				"binaries": `[
        ":cc_binary_1",
        ":sh_binary_2",
@@ -729,6 +730,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"//a/b:apex_manifest.json"`,
			}),
@@ -763,6 +765,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"//a/b:apogee_manifest.json"`,
			}),
@@ -795,6 +798,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apex_manifest.json"`,
			}),
@@ -828,6 +832,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apogee_manifest.json"`,
			}),
@@ -861,6 +866,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apex_manifest.json"`,
				"package_name":   `"com.google.android.apogee"`,
@@ -900,6 +906,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apex_manifest.json"`,
				"prebuilts":      `[":prebuilt_file"]`,
@@ -945,6 +952,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apex_manifest.json"`,
				"prebuilts":      `[":prebuilt_file2"]`,
@@ -985,6 +993,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apex_manifest.json"`,
				"prebuilts":      `[]`,
@@ -1019,6 +1028,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apex_manifest.json"`,
				"logging_parent": `"foo.bar.baz"`,
@@ -1054,6 +1064,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `"//system/sepolicy/apex:com.android.apogee-file_contexts"`,
				"manifest":       `"apex_manifest.json"`,
				"logging_parent": `"foo.bar.baz.override"`,
@@ -1099,6 +1110,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `":com.android.apogee-file_contexts"`,
				"manifest":       `"apogee_manifest.json"`,
			}),
@@ -1200,6 +1212,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name": `"com.android.apogee"`,
				"file_contexts":  `":com.android.apogee-file_contexts"`,
				"certificate":    `":com.google.android.apogee.certificate"`,
				"manifest":       `"apogee_manifest.json"`,
@@ -1244,6 +1257,7 @@ override_apex {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("apex", "com.google.android.apogee", AttrNameToString{
				"base_apex_name":   `"com.android.apogee"`,
				"file_contexts":    `":com.android.apogee-file_contexts"`,
				"certificate_name": `"com.google.android.apogee.certificate"`,
				"manifest":         `"apogee_manifest.json"`,
+46 −0
Original line number Diff line number Diff line
@@ -3645,3 +3645,49 @@ func TestCcLibraryHeaderAbiChecker(t *testing.T) {
		},
	})
}

func TestCcLibraryApexAvailable(t *testing.T) {
	runCcLibraryTestCase(t, Bp2buildTestCase{
		Description:                "cc_library apex_available converted to tags",
		ModuleTypeUnderTest:        "cc_library",
		ModuleTypeUnderTestFactory: cc.LibraryFactory,
		Blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "a",
    srcs: ["a.cpp"],
    apex_available: ["com.android.foo"],
}
`,
		ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
			"tags":           `["apex_available=com.android.foo"]`,
			"srcs":           `["a.cpp"]`,
			"local_includes": `["."]`,
		}),
	},
	)
}

func TestCcLibraryApexAvailableMultiple(t *testing.T) {
	runCcLibraryTestCase(t, Bp2buildTestCase{
		Description:                "cc_library apex_available converted to multiple tags",
		ModuleTypeUnderTest:        "cc_library",
		ModuleTypeUnderTestFactory: cc.LibraryFactory,
		Blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "a",
    srcs: ["a.cpp"],
    apex_available: ["com.android.foo", "//apex_available:platform", "com.android.bar"],
}
`,
		ExpectedBazelTargets: makeCcLibraryTargets("a", AttrNameToString{
			"tags": `[
        "apex_available=com.android.foo",
        "apex_available=//apex_available:platform",
        "apex_available=com.android.bar",
    ]`,
			"srcs":           `["a.cpp"]`,
			"local_includes": `["."]`,
		}),
	},
	)
}
+2 −1
Original line number Diff line number Diff line
@@ -655,11 +655,12 @@ func binaryBp2build(ctx android.TopDownMutatorContext, m *Module) {
	// shared with cc_test
	binaryAttrs := binaryBp2buildAttrs(ctx, m)

	tags := android.ApexAvailableTags(m)
	ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
		Rule_class:        "cc_binary",
		Bzl_load_location: "//build/bazel/rules/cc:cc_binary.bzl",
	},
		android.CommonAttributes{Name: m.Name()},
		android.CommonAttributes{Name: m.Name(), Tags: tags},
		&binaryAttrs)
}

Loading