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

Commit bcf97f5a authored by Neil Fuller's avatar Neil Fuller Committed by Gerrit Code Review
Browse files

Merge "Add soong build restrictions for libcore targets"

parents cbc64dca df5f356c
Loading
Loading
Loading
Loading
+79 −29
Original line number Diff line number Diff line
@@ -45,7 +45,17 @@ func registerNeverallowMutator(ctx RegisterMutatorsContext) {
	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().
			in("vendor", "device").
			with("vndk.enabled", "true").
@@ -56,9 +66,6 @@ var neverallows = []*rule{
			without("vendor", "true").
			without("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
		neverallow().
@@ -73,7 +80,50 @@ var neverallows = []*rule{
			because("nothing should care if linker namespaces are enabled or not"),

		// 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) {
+36 −2
Original line number Diff line number Diff line
@@ -137,6 +137,17 @@ var neverallowTests = []struct {
		},
		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) {
@@ -164,6 +175,7 @@ func TestNeverallow(t *testing.T) {
func testNeverallow(t *testing.T, config Config, fs map[string][]byte) (*TestContext, []error) {
	ctx := NewTestContext()
	ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule))
	ctx.RegisterModuleType("java_library", ModuleFactoryAdaptor(newMockJavaLibraryModule))
	ctx.PostDepsMutators(registerNeverallowMutator)
	ctx.Register()

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

type mockProperties struct {
type mockCcLibraryProperties struct {
	Vendor_available *bool

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

type mockCcLibraryModule struct {
	ModuleBase
	properties mockProperties
	properties mockCcLibraryProperties
}

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

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) {
}