From 095819530af067884e1b131d9332c8c4ace31295 Mon Sep 17 00:00:00 2001 From: Vinh Tran Date: Tue, 16 May 2023 16:03:20 -0400 Subject: 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 --- aidl_library/aidl_library.go | 21 +++++++++++++++++---- aidl_library/aidl_library_test.go | 18 ++++++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) (limited to 'aidl_library') diff --git a/aidl_library/aidl_library.go b/aidl_library/aidl_library.go index 8a84e6bfa..598510386 100644 --- a/aidl_library/aidl_library.go +++ b/aidl_library/aidl_library.go @@ -107,8 +107,10 @@ func (lib *AidlLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) { type AidlLibraryInfo struct { // The direct aidl files of the module 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 + // The direct hdrs and hdrs from transitive deps + Hdrs android.DepSet } // 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) { includeDirsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER) + hdrsDepSetBuilder := android.NewDepSetBuilder(android.PREORDER) if len(lib.properties.Srcs) == 0 && len(lib.properties.Hdrs) == 0 { ctx.ModuleErrorf("at least srcs or hdrs prop must be non-empty") } srcs := android.PathsForModuleSrc(ctx, lib.properties.Srcs) + hdrs := android.PathsForModuleSrc(ctx, lib.properties.Hdrs) + if lib.properties.Strip_import_prefix != nil { srcs = android.PathsWithModuleSrcSubDir( ctx, 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( ctx, proptools.StringDefault(lib.properties.Strip_import_prefix, ""), ) - includeDirsDepSetBuilder.Direct(includeDir) for _, dep := range ctx.GetDirectDepsWithTag(aidlLibraryTag) { if ctx.OtherModuleHasProvider(dep, AidlLibraryProvider) { info := ctx.OtherModuleProvider(dep, AidlLibraryProvider).(AidlLibraryInfo) 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{ Srcs: srcs, IncludeDirs: *includeDirsDepSetBuilder.Build(), + Hdrs: *hdrsDepSetBuilder.Build(), }) } diff --git a/aidl_library/aidl_library_test.go b/aidl_library/aidl_library_test.go index d9b410acc..d9dd24515 100644 --- a/aidl_library/aidl_library_test.go +++ b/aidl_library/aidl_library_test.go @@ -37,7 +37,7 @@ func TestAidlLibrary(t *testing.T) { aidl_library { name: "foo", srcs: ["a/b/Foo.aidl"], - hdrs: ["Header.aidl"], + hdrs: ["a/Header.aidl"], strip_import_prefix: "a", deps: ["bar"], } @@ -61,6 +61,13 @@ func TestAidlLibrary(t *testing.T) { []string{"package_foo/a/b/Foo.aidl"}, actualInfo.Srcs, ) + + android.AssertPathsRelativeToTopEquals( + t, + "aidl hdrs paths", + []string{"package_foo/a/Header.aidl"}, + actualInfo.Hdrs.ToList(), + ) } func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { @@ -72,6 +79,7 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { aidl_library { name: "bar", srcs: ["x/y/Bar.aidl"], + hdrs: ["BarHeader.aidl"], } `), }.AddToFixture(), @@ -80,7 +88,6 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { aidl_library { name: "foo", srcs: ["a/b/Foo.aidl"], - hdrs: ["Header.aidl"], deps: ["bar"], } `), @@ -103,6 +110,13 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { []string{"package_foo/a/b/Foo.aidl"}, actualInfo.Srcs, ) + + android.AssertPathsRelativeToTopEquals( + t, + "aidl hdrs paths", + []string{"package_bar/BarHeader.aidl"}, + actualInfo.Hdrs.ToList(), + ) } func TestAidlLibraryWithNoSrcsHdrsDeps(t *testing.T) { -- cgit v1.2.3-59-g8ed1b