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

Commit 6cbb3304 authored by Trevor Radcliffe's avatar Trevor Radcliffe Committed by Gerrit Code Review
Browse files

Merge "Create Stub targets for cc_library_(static|shared)"

parents 2901c3b3 087af547
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -1367,26 +1367,6 @@ func makeCcLibraryTargets(name string, attrs AttrNameToString) []string {
	return []string{staticTarget, sharedTarget}
}

func makeCcStubSuiteTargets(name string, attrs AttrNameToString) string {
	if _, hasStubs := attrs["stubs_symbol_file"]; !hasStubs {
		return ""
	}
	STUB_SUITE_ATTRS := map[string]string{
		"stubs_symbol_file": "symbol_file",
		"stubs_versions":    "versions",
		"soname":            "soname",
		"source_library":    "source_library",
	}

	stubSuiteAttrs := AttrNameToString{}
	for key, _ := range attrs {
		if _, stubSuiteAttr := STUB_SUITE_ATTRS[key]; stubSuiteAttr {
			stubSuiteAttrs[STUB_SUITE_ATTRS[key]] = attrs[key]
		}
	}
	return MakeBazelTarget("cc_stub_suite", name+"_stub_libs", stubSuiteAttrs)
}

func TestCCLibraryNoLibCrtFalse(t *testing.T) {
	runCcLibraryTestCase(t, Bp2buildTestCase{
		ModuleTypeUnderTest:        "cc_library",
+10 −0
Original line number Diff line number Diff line
@@ -491,6 +491,16 @@ cc_library_shared {
		ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
			"has_stubs": `True`,
		}),
			makeCcStubSuiteTargets("a", AttrNameToString{
				"soname":            `"a.so"`,
				"source_library":    `":a"`,
				"stubs_symbol_file": `"a.map.txt"`,
				"stubs_versions": `[
        "28",
        "29",
        "current",
    ]`,
			}),
		},
	},
	)
+20 −0
Original line number Diff line number Diff line
@@ -463,3 +463,23 @@ type ExpectedRuleTarget struct {
func (ebr ExpectedRuleTarget) String() string {
	return makeBazelTargetHostOrDevice(ebr.Rule, ebr.Name, ebr.Attrs, ebr.Hod)
}

func makeCcStubSuiteTargets(name string, attrs AttrNameToString) string {
	if _, hasStubs := attrs["stubs_symbol_file"]; !hasStubs {
		return ""
	}
	STUB_SUITE_ATTRS := map[string]string{
		"stubs_symbol_file": "symbol_file",
		"stubs_versions":    "versions",
		"soname":            "soname",
		"source_library":    "source_library",
	}

	stubSuiteAttrs := AttrNameToString{}
	for key, _ := range attrs {
		if _, stubSuiteAttr := STUB_SUITE_ATTRS[key]; stubSuiteAttr {
			stubSuiteAttrs[STUB_SUITE_ATTRS[key]] = attrs[key]
		}
	}
	return MakeBazelTarget("cc_stub_suite", name+"_stub_libs", stubSuiteAttrs)
}
+6 −0
Original line number Diff line number Diff line
@@ -441,6 +441,10 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
		android.CommonAttributes{Name: m.Name()},
		sharedTargetAttrs, sharedAttrs.Enabled)

	createStubsBazelTargetIfNeeded(ctx, m, compilerAttrs, exportedIncludes, baseAttributes)
}

func createStubsBazelTargetIfNeeded(ctx android.TopDownMutatorContext, m *Module, compilerAttrs compilerAttributes, exportedIncludes BazelIncludes, baseAttributes baseAttributes) {
	if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 {
		stubSuitesProps := bazel.BazelTargetModuleProperties{
			Rule_class:        "cc_stub_suite",
@@ -2707,6 +2711,8 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
	}

	ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)

	createStubsBazelTargetIfNeeded(ctx, module, compilerAttrs, exportedIncludes, baseAttributes)
}

// TODO(b/199902614): Can this be factored to share with the other Attributes?