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

Commit 09581953 authored by Vinh Tran's avatar Vinh Tran
Browse files

Sandbox inputs to aidl rule in cc

Bug: 279960133
Test: go test
Test: Remove hdrs prop from IDropBoxManagerService_aidl && run  BUILD_BROKEN_DISABLE_BAZEL=true m libservices && Expect an error from aidl
Change-Id: Ifdb260d8e2da9a5767f1e212393de4134b210616
parent a2244043
Loading
Loading
Loading
Loading
+17 −4
Original line number Original line Diff line number Diff line
@@ -107,8 +107,10 @@ func (lib *AidlLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
type AidlLibraryInfo struct {
type AidlLibraryInfo struct {
	// The direct aidl files of the module
	// The direct aidl files of the module
	Srcs android.Paths
	Srcs android.Paths
	// The include dirs to the direct aidl files and those provided from aidl_library deps
	// The include dirs to the direct aidl files and those provided from transitive aidl_library deps
	IncludeDirs android.DepSet
	IncludeDirs android.DepSet
	// The direct hdrs and hdrs from transitive deps
	Hdrs android.DepSet
}
}


// AidlLibraryProvider provides the srcs and the transitive include dirs
// AidlLibraryProvider provides the srcs and the transitive include dirs
@@ -116,37 +118,48 @@ var AidlLibraryProvider = blueprint.NewProvider(AidlLibraryInfo{})


func (lib *AidlLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (lib *AidlLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	includeDirsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER)
	includeDirsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER)
	hdrsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER)


	if len(lib.properties.Srcs) == 0 && len(lib.properties.Hdrs) == 0 {
	if len(lib.properties.Srcs) == 0 && len(lib.properties.Hdrs) == 0 {
		ctx.ModuleErrorf("at least srcs or hdrs prop must be non-empty")
		ctx.ModuleErrorf("at least srcs or hdrs prop must be non-empty")
	}
	}


	srcs := android.PathsForModuleSrc(ctx, lib.properties.Srcs)
	srcs := android.PathsForModuleSrc(ctx, lib.properties.Srcs)
	hdrs := android.PathsForModuleSrc(ctx, lib.properties.Hdrs)

	if lib.properties.Strip_import_prefix != nil {
	if lib.properties.Strip_import_prefix != nil {
		srcs = android.PathsWithModuleSrcSubDir(
		srcs = android.PathsWithModuleSrcSubDir(
			ctx,
			ctx,
			srcs,
			srcs,
			android.String(lib.properties.Strip_import_prefix))
			android.String(lib.properties.Strip_import_prefix),
		)

		hdrs = android.PathsWithModuleSrcSubDir(
			ctx,
			hdrs,
			android.String(lib.properties.Strip_import_prefix),
		)
	}
	}
	hdrsDepSetBuilder.Direct(hdrs...)


	includeDir := android.PathForModuleSrc(
	includeDir := android.PathForModuleSrc(
		ctx,
		ctx,
		proptools.StringDefault(lib.properties.Strip_import_prefix, ""),
		proptools.StringDefault(lib.properties.Strip_import_prefix, ""),
	)
	)

	includeDirsDepSetBuilder.Direct(includeDir)
	includeDirsDepSetBuilder.Direct(includeDir)


	for _, dep := range ctx.GetDirectDepsWithTag(aidlLibraryTag) {
	for _, dep := range ctx.GetDirectDepsWithTag(aidlLibraryTag) {
		if ctx.OtherModuleHasProvider(dep, AidlLibraryProvider) {
		if ctx.OtherModuleHasProvider(dep, AidlLibraryProvider) {
			info := ctx.OtherModuleProvider(dep, AidlLibraryProvider).(AidlLibraryInfo)
			info := ctx.OtherModuleProvider(dep, AidlLibraryProvider).(AidlLibraryInfo)
			includeDirsDepSetBuilder.Transitive(&info.IncludeDirs)
			includeDirsDepSetBuilder.Transitive(&info.IncludeDirs)
			hdrsDepSetBuilder.Transitive(&info.Hdrs)
		}
		}
	}
	}


	// TODO(b/279960133) Propagate direct and transitive headers/srcs when aidl action sandboxes inputs
	ctx.SetProvider(AidlLibraryProvider, AidlLibraryInfo{
	ctx.SetProvider(AidlLibraryProvider, AidlLibraryInfo{
		Srcs:        srcs,
		Srcs:        srcs,
		IncludeDirs: *includeDirsDepSetBuilder.Build(),
		IncludeDirs: *includeDirsDepSetBuilder.Build(),
		Hdrs:        *hdrsDepSetBuilder.Build(),
	})
	})
}
}


+16 −2
Original line number Original line Diff line number Diff line
@@ -37,7 +37,7 @@ func TestAidlLibrary(t *testing.T) {
			aidl_library {
			aidl_library {
					name: "foo",
					name: "foo",
					srcs: ["a/b/Foo.aidl"],
					srcs: ["a/b/Foo.aidl"],
					hdrs: ["Header.aidl"],
					hdrs: ["a/Header.aidl"],
					strip_import_prefix: "a",
					strip_import_prefix: "a",
					deps: ["bar"],
					deps: ["bar"],
				}
				}
@@ -61,6 +61,13 @@ func TestAidlLibrary(t *testing.T) {
		[]string{"package_foo/a/b/Foo.aidl"},
		[]string{"package_foo/a/b/Foo.aidl"},
		actualInfo.Srcs,
		actualInfo.Srcs,
	)
	)

	android.AssertPathsRelativeToTopEquals(
		t,
		"aidl hdrs paths",
		[]string{"package_foo/a/Header.aidl"},
		actualInfo.Hdrs.ToList(),
	)
}
}


func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
@@ -72,6 +79,7 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
			aidl_library {
			aidl_library {
					name: "bar",
					name: "bar",
					srcs: ["x/y/Bar.aidl"],
					srcs: ["x/y/Bar.aidl"],
					hdrs: ["BarHeader.aidl"],
				}
				}
			`),
			`),
		}.AddToFixture(),
		}.AddToFixture(),
@@ -80,7 +88,6 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
			aidl_library {
			aidl_library {
					name: "foo",
					name: "foo",
					srcs: ["a/b/Foo.aidl"],
					srcs: ["a/b/Foo.aidl"],
					hdrs: ["Header.aidl"],
					deps: ["bar"],
					deps: ["bar"],
				}
				}
			`),
			`),
@@ -103,6 +110,13 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
		[]string{"package_foo/a/b/Foo.aidl"},
		[]string{"package_foo/a/b/Foo.aidl"},
		actualInfo.Srcs,
		actualInfo.Srcs,
	)
	)

	android.AssertPathsRelativeToTopEquals(
		t,
		"aidl hdrs paths",
		[]string{"package_bar/BarHeader.aidl"},
		actualInfo.Hdrs.ToList(),
	)
}
}


func TestAidlLibraryWithNoSrcsHdrsDeps(t *testing.T) {
func TestAidlLibraryWithNoSrcsHdrsDeps(t *testing.T) {
+8 −0
Original line number Original line Diff line number Diff line
@@ -726,6 +726,14 @@ func (c *config) HostJavaToolPath(ctx PathContext, tool string) Path {
	return path
	return path
}
}


func (c *config) HostCcSharedLibPath(ctx PathContext, lib string) Path {
	libDir := "lib"
	if ctx.Config().BuildArch.Multilib == "lib64" {
		libDir = "lib64"
	}
	return pathForInstall(ctx, ctx.Config().BuildOS, ctx.Config().BuildArch, libDir, false, lib+".so")
}

// PrebuiltOS returns the name of the host OS used in prebuilts directories.
// PrebuiltOS returns the name of the host OS used in prebuilts directories.
func (c *config) PrebuiltOS() string {
func (c *config) PrebuiltOS() string {
	switch runtime.GOOS {
	switch runtime.GOOS {
+79 −15
Original line number Original line Diff line number Diff line
@@ -39,7 +39,6 @@ func TestMain(m *testing.M) {


var prepareForCcTest = android.GroupFixturePreparers(
var prepareForCcTest = android.GroupFixturePreparers(
	PrepareForTestWithCcIncludeVndk,
	PrepareForTestWithCcIncludeVndk,
	aidl_library.PrepareForTestWithAidlLibrary,
	android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
	android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
		variables.DeviceVndkVersion = StringPtr("current")
		variables.DeviceVndkVersion = StringPtr("current")
		variables.ProductVndkVersion = StringPtr("current")
		variables.ProductVndkVersion = StringPtr("current")
@@ -4420,7 +4419,7 @@ func TestStubsLibReexportsHeaders(t *testing.T) {
	}
	}
}
}


func TestAidlLibraryWithHeader(t *testing.T) {
func TestAidlLibraryWithHeaders(t *testing.T) {
	t.Parallel()
	t.Parallel()
	ctx := android.GroupFixturePreparers(
	ctx := android.GroupFixturePreparers(
		prepareForCcTest,
		prepareForCcTest,
@@ -4430,6 +4429,7 @@ func TestAidlLibraryWithHeader(t *testing.T) {
			aidl_library {
			aidl_library {
				name: "bar",
				name: "bar",
				srcs: ["x/y/Bar.aidl"],
				srcs: ["x/y/Bar.aidl"],
				hdrs: ["x/HeaderBar.aidl"],
				strip_import_prefix: "x",
				strip_import_prefix: "x",
			}
			}
			`)}.AddToFixture(),
			`)}.AddToFixture(),
@@ -4438,6 +4438,7 @@ func TestAidlLibraryWithHeader(t *testing.T) {
			aidl_library {
			aidl_library {
				name: "foo",
				name: "foo",
				srcs: ["a/b/Foo.aidl"],
				srcs: ["a/b/Foo.aidl"],
				hdrs: ["a/HeaderFoo.aidl"],
				strip_import_prefix: "a",
				strip_import_prefix: "a",
				deps: ["bar"],
				deps: ["bar"],
			}
			}
@@ -4452,7 +4453,20 @@ func TestAidlLibraryWithHeader(t *testing.T) {
	).RunTest(t).TestContext
	).RunTest(t).TestContext


	libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
	libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static")
	manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto"))

	android.AssertPathsRelativeToTopEquals(
		t,
		"aidl headers",
		[]string{
			"package_bar/x/HeaderBar.aidl",
			"package_foo/a/HeaderFoo.aidl",
			"package_foo/a/b/Foo.aidl",
			"out/soong/.intermediates/package_foo/libfoo/android_arm64_armv8-a_static/gen/aidl_library.sbox.textproto",
		},
		libfoo.Rule("aidl_library").Implicits,
	)

	manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl_library.sbox.textproto"))
	aidlCommand := manifest.Commands[0].GetCommand()
	aidlCommand := manifest.Commands[0].GetCommand()


	expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x"
	expectedAidlFlags := "-Ipackage_foo/a -Ipackage_bar/x"
@@ -4462,14 +4476,14 @@ func TestAidlLibraryWithHeader(t *testing.T) {


	outputs := strings.Join(libfoo.AllOutputs(), " ")
	outputs := strings.Join(libfoo.AllOutputs(), " ")


	android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/BpFoo.h")
	android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BpFoo.h")
	android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/BnFoo.h")
	android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/BnFoo.h")
	android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl/b/Foo.h")
	android.AssertStringDoesContain(t, "aidl-generated header", outputs, "gen/aidl_library/b/Foo.h")
	android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp")
	android.AssertStringDoesContain(t, "aidl-generated cpp", outputs, "b/Foo.cpp")
	// Confirm that the aidl header doesn't get compiled to cpp and h files
	// Confirm that the aidl header doesn't get compiled to cpp and h files
	android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/BpBar.h")
	android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BpBar.h")
	android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/BnBar.h")
	android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/BnBar.h")
	android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl/y/Bar.h")
	android.AssertStringDoesNotContain(t, "aidl-generated header", outputs, "gen/aidl_library/y/Bar.h")
	android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp")
	android.AssertStringDoesNotContain(t, "aidl-generated cpp", outputs, "y/Bar.cpp")
}
}


@@ -4548,6 +4562,55 @@ func TestAidlFlagsWithMinSdkVersion(t *testing.T) {
	}
	}
}
}


func TestInvalidAidlProp(t *testing.T) {
	t.Parallel()

	testCases := []struct {
		description string
		bp          string
	}{
		{
			description: "Invalid use of aidl.libs and aidl.include_dirs",
			bp: `
			cc_library {
				name: "foo",
				aidl: {
					libs: ["foo_aidl"],
					include_dirs: ["bar/include"],
				}
			}
			`,
		},
		{
			description: "Invalid use of aidl.libs and aidl.local_include_dirs",
			bp: `
			cc_library {
				name: "foo",
				aidl: {
					libs: ["foo_aidl"],
					local_include_dirs: ["include"],
				}
			}
			`,
		},
	}

	for _, testCase := range testCases {
		t.Run(testCase.description, func(t *testing.T) {
			bp := `
			aidl_library {
				name: "foo_aidl",
				srcs: ["Foo.aidl"],
			} ` + testCase.bp
			android.GroupFixturePreparers(
				prepareForCcTest,
				aidl_library.PrepareForTestWithAidlLibrary.
					ExtendWithErrorHandler(android.FixtureExpectsOneErrorPattern("For aidl headers, please only use aidl.libs prop")),
			).RunTestWithBp(t, bp)
		})
	}
}

func TestMinSdkVersionInClangTriple(t *testing.T) {
func TestMinSdkVersionInClangTriple(t *testing.T) {
	t.Parallel()
	t.Parallel()
	ctx := testCc(t, `
	ctx := testCc(t, `
@@ -4789,23 +4852,24 @@ func TestIncludeDirsExporting(t *testing.T) {
		checkIncludeDirs(t, ctx, foo,
		checkIncludeDirs(t, ctx, foo,
			expectedIncludeDirs(`
			expectedIncludeDirs(`
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library
			`),
			`),
			expectedSystemIncludeDirs(``),
			expectedSystemIncludeDirs(``),
			expectedGeneratedHeaders(`
			expectedGeneratedHeaders(`
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/Bar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BnBar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BpBar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h
			`),
			`),
			expectedOrderOnlyDeps(`
			expectedOrderOnlyDeps(`
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/b.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bnb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/Bpb.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/Bar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/Bar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BnBar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BnBar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl/y/BpBar.h
				.intermediates/libfoo/android_arm64_armv8-a_shared/gen/aidl_library/y/BpBar.h
			`),
			`),
		)
		)
	})
	})
+13 −2
Original line number Original line Diff line number Diff line
@@ -565,6 +565,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
			"-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String())
			"-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String())
	}
	}


	if len(compiler.Properties.Aidl.Libs) > 0 &&
		(len(compiler.Properties.Aidl.Include_dirs) > 0 || len(compiler.Properties.Aidl.Local_include_dirs) > 0) {
		ctx.ModuleErrorf("aidl.libs and (aidl.include_dirs or aidl.local_include_dirs) can't be set at the same time. For aidl headers, please only use aidl.libs prop")
	}

	if compiler.hasAidl(deps) {
	if compiler.hasAidl(deps) {
		flags.aidlFlags = append(flags.aidlFlags, compiler.Properties.Aidl.Flags...)
		flags.aidlFlags = append(flags.aidlFlags, compiler.Properties.Aidl.Flags...)
		if len(compiler.Properties.Aidl.Local_include_dirs) > 0 {
		if len(compiler.Properties.Aidl.Local_include_dirs) > 0 {
@@ -594,9 +599,15 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
		}
		}
		flags.aidlFlags = append(flags.aidlFlags, "--min_sdk_version="+aidlMinSdkVersion)
		flags.aidlFlags = append(flags.aidlFlags, "--min_sdk_version="+aidlMinSdkVersion)


		if compiler.hasSrcExt(".aidl") {
			flags.Local.CommonFlags = append(flags.Local.CommonFlags,
			flags.Local.CommonFlags = append(flags.Local.CommonFlags,
				"-I"+android.PathForModuleGen(ctx, "aidl").String())
				"-I"+android.PathForModuleGen(ctx, "aidl").String())
		}
		}
		if len(deps.AidlLibraryInfos) > 0 {
			flags.Local.CommonFlags = append(flags.Local.CommonFlags,
				"-I"+android.PathForModuleGen(ctx, "aidl_library").String())
		}
	}


	if compiler.hasSrcExt(".rscript") || compiler.hasSrcExt(".fs") {
	if compiler.hasSrcExt(".rscript") || compiler.hasSrcExt(".fs") {
		flags = rsFlags(ctx, flags, &compiler.Properties)
		flags = rsFlags(ctx, flags, &compiler.Properties)
Loading