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

Commit df5f356c authored by Neil Fuller's avatar Neil Fuller
Browse files

Add soong build restrictions for libcore targets

Add soong build restrictions for libcore targets to stop
other targets depending on internals.

Test: cd build/soong/; ./build_test.bash --products aosp_arm
Bug: 113148576
Change-Id: I2c15924fbecaf0c2076d08de65814a6dcb790e73
parent 1e30905f
Loading
Loading
Loading
Loading
+79 −29
Original line number Original line Diff line number Diff line
@@ -45,7 +45,17 @@ func registerNeverallowMutator(ctx RegisterMutatorsContext) {
	ctx.BottomUp("neverallow", neverallowMutator).Parallel()
	ctx.BottomUp("neverallow", neverallowMutator).Parallel()
}
}


var neverallows = []*rule{
var neverallows = createNeverAllows()

func createNeverAllows() []*rule {
	rules := []*rule{}
	rules = append(rules, createTrebleRules()...)
	rules = append(rules, createLibcoreRules()...)
	return rules
}

func createTrebleRules() []*rule {
	return []*rule{
		neverallow().
		neverallow().
			in("vendor", "device").
			in("vendor", "device").
			with("vndk.enabled", "true").
			with("vndk.enabled", "true").
@@ -56,9 +66,6 @@ var neverallows = []*rule{
			without("vendor", "true").
			without("vendor", "true").
			without("owner", "").
			without("owner", "").
			because("a VNDK module can never have an owner."),
			because("a VNDK module can never have an owner."),
	neverallow().
		notIn("libcore", "development", "external/apache-harmony", "external/apache-xml", "external/bouncycastle", "external/conscrypt", "external/icu", "external/okhttp", "external/wycheproof").
		with("no_standard_libs", "true"),


		// TODO(b/67974785): always enforce the manifest
		// TODO(b/67974785): always enforce the manifest
		neverallow().
		neverallow().
@@ -73,7 +80,50 @@ var neverallows = []*rule{
			because("nothing should care if linker namespaces are enabled or not"),
			because("nothing should care if linker namespaces are enabled or not"),


		// Example:
		// Example:
	// *neverallow().with("Srcs", "main.cpp"),
		// *neverallow().with("Srcs", "main.cpp"))
	}
}

func createLibcoreRules() []*rule {
	var coreLibraryProjects = []string{
		"libcore",
		"external/apache-harmony",
		"external/apache-xml",
		"external/bouncycastle",
		"external/conscrypt",
		"external/icu",
		"external/okhttp",
		"external/wycheproof",
	}

	var coreModules = []string{
		"core-all",
		"core-oj",
		"core-libart",
		"core-simple",
		"okhttp",
		"bouncycastle",
		"conscrypt",
		"apache-xml",
	}

	// Core library constraints. Prevent targets adding dependencies on core
	// library internals, which could lead to compatibility issues with the ART
	// mainline module. They should use core.platform.api.stubs instead.
	rules := []*rule{
		neverallow().
			notIn(append(coreLibraryProjects, "development")...).
			with("no_standard_libs", "true"),
	}

	for _, m := range coreModules {
		r := neverallow().
			notIn(coreLibraryProjects...).
			with("libs", m).
			because("Only core libraries projects can depend on " + m)
		rules = append(rules, r)
	}
	return rules
}
}


func neverallowMutator(ctx BottomUpMutatorContext) {
func neverallowMutator(ctx BottomUpMutatorContext) {
+36 −2
Original line number Original line Diff line number Diff line
@@ -137,6 +137,17 @@ var neverallowTests = []struct {
		},
		},
		expectedError: "",
		expectedError: "",
	},
	},
	{
		name: "dependency on core-libart",
		fs: map[string][]byte{
			"Blueprints": []byte(`
				java_library {
					name: "needs_core_libart",
					libs: ["core-libart"],
				}`),
		},
		expectedError: "Only core libraries projects can depend on core-libart",
	},
}
}


func TestNeverallow(t *testing.T) {
func TestNeverallow(t *testing.T) {
@@ -164,6 +175,7 @@ func TestNeverallow(t *testing.T) {
func testNeverallow(t *testing.T, config Config, fs map[string][]byte) (*TestContext, []error) {
func testNeverallow(t *testing.T, config Config, fs map[string][]byte) (*TestContext, []error) {
	ctx := NewTestContext()
	ctx := NewTestContext()
	ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule))
	ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule))
	ctx.RegisterModuleType("java_library", ModuleFactoryAdaptor(newMockJavaLibraryModule))
	ctx.PostDepsMutators(registerNeverallowMutator)
	ctx.PostDepsMutators(registerNeverallowMutator)
	ctx.Register()
	ctx.Register()


@@ -178,7 +190,7 @@ func testNeverallow(t *testing.T, config Config, fs map[string][]byte) (*TestCon
	return ctx, errs
	return ctx, errs
}
}


type mockProperties struct {
type mockCcLibraryProperties struct {
	Vendor_available *bool
	Vendor_available *bool


	Vndk struct {
	Vndk struct {
@@ -200,7 +212,7 @@ type mockProperties struct {


type mockCcLibraryModule struct {
type mockCcLibraryModule struct {
	ModuleBase
	ModuleBase
	properties mockProperties
	properties mockCcLibraryProperties
}
}


func newMockCcLibraryModule() Module {
func newMockCcLibraryModule() Module {
@@ -215,3 +227,25 @@ func (p *mockCcLibraryModule) DepsMutator(ctx BottomUpMutatorContext) {


func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
}
}

type mockJavaLibraryProperties struct {
	Libs []string
}

type mockJavaLibraryModule struct {
	ModuleBase
	properties mockJavaLibraryProperties
}

func newMockJavaLibraryModule() Module {
	m := &mockJavaLibraryModule{}
	m.AddProperties(&m.properties)
	InitAndroidModule(m)
	return m
}

func (p *mockJavaLibraryModule) DepsMutator(ctx BottomUpMutatorContext) {
}

func (p *mockJavaLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
}