Merge changes from topic "cherrypicker-L81900000961112686:N90100001376046683" into udc-mainline-prod

* changes:
  Sandbox inputs to aidl rule in cc
  Allowlist libservices
  Pass includes attrs to cc_aidl_library
This commit is contained in:
Vinh Tran
2023-06-08 23:24:08 +00:00
committed by Android (Google) Code Review
10 changed files with 266 additions and 84 deletions

View File

@@ -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(),
}) })
} }

View File

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

View File

@@ -201,6 +201,7 @@ var (
"frameworks/av/media/module/minijail": Bp2BuildDefaultTrueRecursively, "frameworks/av/media/module/minijail": Bp2BuildDefaultTrueRecursively,
"frameworks/av/services/minijail": Bp2BuildDefaultTrueRecursively, "frameworks/av/services/minijail": Bp2BuildDefaultTrueRecursively,
"frameworks/base/libs/androidfw": Bp2BuildDefaultTrue, "frameworks/base/libs/androidfw": Bp2BuildDefaultTrue,
"frameworks/base/libs/services": Bp2BuildDefaultTrue,
"frameworks/base/media/tests/MediaDump": Bp2BuildDefaultTrue, "frameworks/base/media/tests/MediaDump": Bp2BuildDefaultTrue,
"frameworks/base/services/tests/servicestests/aidl": Bp2BuildDefaultTrue, "frameworks/base/services/tests/servicestests/aidl": Bp2BuildDefaultTrue,
"frameworks/base/proto": Bp2BuildDefaultTrue, "frameworks/base/proto": Bp2BuildDefaultTrue,
@@ -559,6 +560,9 @@ var (
//external/fec //external/fec
"libfec_rs", "libfec_rs",
//frameworks/base/core/java
"IDropBoxManagerService_aidl",
//system/core/libsparse //system/core/libsparse
"libsparse", "libsparse",

View File

@@ -702,6 +702,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 {

View File

@@ -3328,7 +3328,8 @@ cc_library {
name: "foo", name: "foo",
aidl: { aidl: {
libs: ["A_aidl"], libs: ["A_aidl"],
} },
export_include_dirs: ["include"],
}`, }`,
ExpectedBazelTargets: []string{ ExpectedBazelTargets: []string{
MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{ MakeBazelTargetNoRestrictions("aidl_library", "A_aidl", AttrNameToString{
@@ -3338,15 +3339,19 @@ cc_library {
"tags": `["apex_available=//apex_available:anyapex"]`, "tags": `["apex_available=//apex_available:anyapex"]`,
}), }),
MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
"deps": `[":A_aidl"]`, "deps": `[":A_aidl"]`,
"local_includes": `["."]`,
"export_includes": `["include"]`,
}), }),
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
"implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
"local_includes": `["."]`, "local_includes": `["."]`,
"export_includes": `["include"]`,
}), }),
MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
"implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
"local_includes": `["."]`, "local_includes": `["."]`,
"export_includes": `["include"]`,
}), }),
}, },
}) })
@@ -3380,6 +3385,7 @@ cc_library {
"srcs": `["B.aidl"]`, "srcs": `["B.aidl"]`,
}), }),
MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
"local_includes": `["."]`,
"deps": `[ "deps": `[
":A_aidl", ":A_aidl",
":foo_aidl_library", ":foo_aidl_library",
@@ -3419,7 +3425,8 @@ cc_library {
}`, }`,
ExpectedBazelTargets: []string{ ExpectedBazelTargets: []string{
MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
"deps": `["//path/to/A:A_aidl"]`, "local_includes": `["."]`,
"deps": `["//path/to/A:A_aidl"]`,
}), }),
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
"implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`, "implementation_whole_archive_deps": `[":foo_cc_aidl_library"]`,
@@ -3438,7 +3445,8 @@ func TestCcLibraryWithExportAidlHeaders(t *testing.T) {
expectedBazelTargets := []string{ expectedBazelTargets := []string{
MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
"deps": `[":foo_aidl_library"]`, "local_includes": `["."]`,
"deps": `[":foo_aidl_library"]`,
}), }),
MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{ MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
"whole_archive_deps": `[":foo_cc_aidl_library"]`, "whole_archive_deps": `[":foo_cc_aidl_library"]`,
@@ -3719,7 +3727,8 @@ cc_library_static {
"srcs": `["Foo.aidl"]`, "srcs": `["Foo.aidl"]`,
}), }),
MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{ MakeBazelTarget("cc_aidl_library", "foo_cc_aidl_library", AttrNameToString{
"deps": `[":foo_aidl_library"]`, "local_includes": `["."]`,
"deps": `[":foo_aidl_library"]`,
"implementation_deps": `[ "implementation_deps": `[
":baz-static", ":baz-static",
":bar-static", ":bar-static",

View File

@@ -814,6 +814,7 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
Value: aidlLibs, Value: aidlLibs,
}, },
linkerAttrs, linkerAttrs,
compilerAttrs,
) )
if aidlDep != nil { if aidlDep != nil {
if lib, ok := module.linker.(*libraryDecorator); ok { if lib, ok := module.linker.(*libraryDecorator); ok {
@@ -913,6 +914,7 @@ func bp2buildCcAidlLibrary(
aidlSrcs bazel.LabelListAttribute, aidlSrcs bazel.LabelListAttribute,
aidlLibs bazel.LabelListAttribute, aidlLibs bazel.LabelListAttribute,
linkerAttrs linkerAttributes, linkerAttrs linkerAttributes,
compilerAttrs compilerAttributes,
) *bazel.LabelAttribute { ) *bazel.LabelAttribute {
var aidlLibsFromSrcs, aidlFiles bazel.LabelListAttribute var aidlLibsFromSrcs, aidlFiles bazel.LabelListAttribute
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module()) apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.TopDownMutatorContext), ctx.Module())
@@ -959,6 +961,15 @@ func bp2buildCcAidlLibrary(
sdkAttrs := bp2BuildParseSdkAttributes(m) sdkAttrs := bp2BuildParseSdkAttributes(m)
exportedIncludes := bp2BuildParseExportedIncludes(ctx, m, &compilerAttrs.includes)
includeAttrs := includesAttributes{
Export_includes: exportedIncludes.Includes,
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
}
ctx.CreateBazelTargetModule( ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{ bazel.BazelTargetModuleProperties{
Rule_class: "cc_aidl_library", Rule_class: "cc_aidl_library",
@@ -971,6 +982,7 @@ func bp2buildCcAidlLibrary(
Implementation_dynamic_deps: *implementationDynamicDeps, Implementation_dynamic_deps: *implementationDynamicDeps,
Tags: apexAvailableTags, Tags: apexAvailableTags,
sdkAttributes: sdkAttrs, sdkAttributes: sdkAttrs,
includesAttributes: includeAttrs,
}, },
) )
label := &bazel.LabelAttribute{ label := &bazel.LabelAttribute{

View File

@@ -4420,7 +4420,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 +4430,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 +4439,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 +4454,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 +4477,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 +4563,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 +4853,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
`), `),
) )
}) })

View File

@@ -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,8 +599,14 @@ 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)
flags.Local.CommonFlags = append(flags.Local.CommonFlags, if compiler.hasSrcExt(".aidl") {
"-I"+android.PathForModuleGen(ctx, "aidl").String()) flags.Local.CommonFlags = append(flags.Local.CommonFlags,
"-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") {

View File

@@ -107,7 +107,14 @@ func genYacc(ctx android.ModuleContext, rule *android.RuleBuilder, yaccFile andr
return ret return ret
} }
func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile android.Path, aidlFlags string) (cppFile android.OutputPath, headerFiles android.Paths) { func genAidl(
ctx android.ModuleContext,
rule *android.RuleBuilder,
outDirBase string,
aidlFile android.Path,
aidlHdrs android.Paths,
aidlFlags string,
) (cppFile android.OutputPath, headerFiles android.Paths) {
aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base()) aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base())
baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext()) baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext())
shortName := baseName shortName := baseName
@@ -119,7 +126,7 @@ func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile andr
shortName = strings.TrimPrefix(baseName, "I") shortName = strings.TrimPrefix(baseName, "I")
} }
outDir := android.PathForModuleGen(ctx, "aidl") outDir := android.PathForModuleGen(ctx, outDirBase)
cppFile = outDir.Join(ctx, aidlPackage, baseName+".cpp") cppFile = outDir.Join(ctx, aidlPackage, baseName+".cpp")
depFile := outDir.Join(ctx, aidlPackage, baseName+".cpp.d") depFile := outDir.Join(ctx, aidlPackage, baseName+".cpp.d")
headerI := outDir.Join(ctx, aidlPackage, baseName+".h") headerI := outDir.Join(ctx, aidlPackage, baseName+".h")
@@ -128,6 +135,8 @@ func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile andr
cmd := rule.Command() cmd := rule.Command()
cmd.BuiltTool("aidl-cpp"). cmd.BuiltTool("aidl-cpp").
// libc++ is default stl for aidl-cpp (a cc_binary_host module)
ImplicitTool(ctx.Config().HostCcSharedLibPath(ctx, "libc++")).
FlagWithDepFile("-d", depFile). FlagWithDepFile("-d", depFile).
Flag("--ninja"). Flag("--ninja").
Flag(aidlFlags). Flag(aidlFlags).
@@ -140,6 +149,10 @@ func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile andr
headerBp, headerBp,
}) })
if aidlHdrs != nil {
cmd.Implicits(aidlHdrs)
}
return cppFile, android.Paths{ return cppFile, android.Paths{
headerI, headerI,
headerBn, headerBn,
@@ -283,14 +296,19 @@ func genSources(
ctx android.ModuleContext, ctx android.ModuleContext,
aidlLibraryInfos []aidl_library.AidlLibraryInfo, aidlLibraryInfos []aidl_library.AidlLibraryInfo,
srcFiles android.Paths, srcFiles android.Paths,
buildFlags builderFlags) (android.Paths, android.Paths, generatedSourceInfo) { buildFlags builderFlags,
) (android.Paths, android.Paths, generatedSourceInfo) {
var info generatedSourceInfo var info generatedSourceInfo
var deps android.Paths var deps android.Paths
var rsFiles android.Paths var rsFiles android.Paths
// aidlRule supports compiling aidl files from srcs prop while aidlLibraryRule supports
// compiling aidl files from aidl_library modules specified in aidl.libs prop.
// The rules are separated so that they don't wipe out the other's outputDir
var aidlRule *android.RuleBuilder var aidlRule *android.RuleBuilder
var aidlLibraryRule *android.RuleBuilder
var yaccRule_ *android.RuleBuilder var yaccRule_ *android.RuleBuilder
yaccRule := func() *android.RuleBuilder { yaccRule := func() *android.RuleBuilder {
@@ -331,7 +349,14 @@ func genSources(
android.PathForModuleGen(ctx, "aidl.sbox.textproto")) android.PathForModuleGen(ctx, "aidl.sbox.textproto"))
} }
baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel()) baseDir := strings.TrimSuffix(srcFile.String(), srcFile.Rel())
cppFile, aidlHeaders := genAidl(ctx, aidlRule, srcFile, buildFlags.aidlFlags+" -I"+baseDir) cppFile, aidlHeaders := genAidl(
ctx,
aidlRule,
"aidl",
srcFile,
nil,
buildFlags.aidlFlags+" -I"+baseDir,
)
srcFiles[i] = cppFile srcFiles[i] = cppFile
info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...) info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
@@ -354,13 +379,21 @@ func genSources(
} }
for _, aidlLibraryInfo := range aidlLibraryInfos { for _, aidlLibraryInfo := range aidlLibraryInfos {
if aidlLibraryRule == nil {
aidlLibraryRule = android.NewRuleBuilder(pctx, ctx).Sbox(
android.PathForModuleGen(ctx, "aidl_library"),
android.PathForModuleGen(ctx, "aidl_library.sbox.textproto"),
).SandboxInputs()
}
for _, aidlSrc := range aidlLibraryInfo.Srcs { for _, aidlSrc := range aidlLibraryInfo.Srcs {
if aidlRule == nil { cppFile, aidlHeaders := genAidl(
// TODO(b/279960133): Sandbox inputs to ensure aidl headers are explicitly specified ctx,
aidlRule = android.NewRuleBuilder(pctx, ctx).Sbox(android.PathForModuleGen(ctx, "aidl"), aidlLibraryRule,
android.PathForModuleGen(ctx, "aidl.sbox.textproto")) "aidl_library",
} aidlSrc,
cppFile, aidlHeaders := genAidl(ctx, aidlRule, aidlSrc, buildFlags.aidlFlags) aidlLibraryInfo.Hdrs.ToList(),
buildFlags.aidlFlags,
)
srcFiles = append(srcFiles, cppFile) srcFiles = append(srcFiles, cppFile)
info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...) info.aidlHeaders = append(info.aidlHeaders, aidlHeaders...)
@@ -375,6 +408,10 @@ func genSources(
aidlRule.Build("aidl", "gen aidl") aidlRule.Build("aidl", "gen aidl")
} }
if aidlLibraryRule != nil {
aidlLibraryRule.Build("aidl_library", "gen aidl_library")
}
if yaccRule_ != nil { if yaccRule_ != nil {
yaccRule_.Build("yacc", "gen yacc") yaccRule_.Build("yacc", "gen yacc")
} }

View File

@@ -271,7 +271,9 @@ type ccAidlLibraryAttributes struct {
Implementation_deps bazel.LabelListAttribute Implementation_deps bazel.LabelListAttribute
Implementation_dynamic_deps bazel.LabelListAttribute Implementation_dynamic_deps bazel.LabelListAttribute
Tags bazel.StringListAttribute Tags bazel.StringListAttribute
sdkAttributes sdkAttributes
includesAttributes
} }
type stripAttributes struct { type stripAttributes struct {
@@ -330,6 +332,14 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
Native_coverage: baseAttributes.Native_coverage, Native_coverage: baseAttributes.Native_coverage,
} }
includeAttrs := includesAttributes{
Export_includes: exportedIncludes.Includes,
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
}
sharedCommonAttrs := staticOrSharedAttributes{ sharedCommonAttrs := staticOrSharedAttributes{
Srcs: *srcs.Clone().Append(sharedAttrs.Srcs), Srcs: *srcs.Clone().Append(sharedAttrs.Srcs),
Srcs_c: *compilerAttrs.cSrcs.Clone().Append(sharedAttrs.Srcs_c), Srcs_c: *compilerAttrs.cSrcs.Clone().Append(sharedAttrs.Srcs_c),
@@ -351,41 +361,34 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
staticTargetAttrs := &bazelCcLibraryStaticAttributes{ staticTargetAttrs := &bazelCcLibraryStaticAttributes{
staticOrSharedAttributes: staticCommonAttrs, staticOrSharedAttributes: staticCommonAttrs,
includesAttributes: includeAttrs,
Cppflags: compilerAttrs.cppFlags, Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags, Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags, Asflags: asFlags,
Export_includes: exportedIncludes.Includes, Rtti: compilerAttrs.rtti,
Export_absolute_includes: exportedIncludes.AbsoluteIncludes, Stl: compilerAttrs.stl,
Export_system_includes: exportedIncludes.SystemIncludes, Cpp_std: compilerAttrs.cppStd,
Local_includes: compilerAttrs.localIncludes, C_std: compilerAttrs.cStd,
Absolute_includes: compilerAttrs.absoluteIncludes,
Rtti: compilerAttrs.rtti,
Stl: compilerAttrs.stl,
Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd,
Features: baseAttributes.features, Features: baseAttributes.features,
} }
sharedTargetAttrs := &bazelCcLibrarySharedAttributes{ sharedTargetAttrs := &bazelCcLibrarySharedAttributes{
staticOrSharedAttributes: sharedCommonAttrs, staticOrSharedAttributes: sharedCommonAttrs,
Cppflags: compilerAttrs.cppFlags, includesAttributes: includeAttrs,
Conlyflags: compilerAttrs.conlyFlags,
Asflags: asFlags,
Export_includes: exportedIncludes.Includes, Cppflags: compilerAttrs.cppFlags,
Export_absolute_includes: exportedIncludes.AbsoluteIncludes, Conlyflags: compilerAttrs.conlyFlags,
Export_system_includes: exportedIncludes.SystemIncludes, Asflags: asFlags,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes, Linkopts: linkerAttrs.linkopts,
Linkopts: linkerAttrs.linkopts, Rtti: compilerAttrs.rtti,
Rtti: compilerAttrs.rtti, Stl: compilerAttrs.stl,
Stl: compilerAttrs.stl, Cpp_std: compilerAttrs.cppStd,
Cpp_std: compilerAttrs.cppStd, C_std: compilerAttrs.cStd,
C_std: compilerAttrs.cStd, Use_version_lib: linkerAttrs.useVersionLib,
Use_version_lib: linkerAttrs.useVersionLib,
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs, Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
@@ -2110,8 +2113,14 @@ func (library *libraryDecorator) link(ctx ModuleContext,
// Optionally export aidl headers. // Optionally export aidl headers.
if Bool(library.Properties.Aidl.Export_aidl_headers) { if Bool(library.Properties.Aidl.Export_aidl_headers) {
if library.baseCompiler.hasAidl(deps) { if library.baseCompiler.hasAidl(deps) {
dir := android.PathForModuleGen(ctx, "aidl") if library.baseCompiler.hasSrcExt(".aidl") {
library.reexportDirs(dir) dir := android.PathForModuleGen(ctx, "aidl")
library.reexportDirs(dir)
}
if len(deps.AidlLibraryInfos) > 0 {
dir := android.PathForModuleGen(ctx, "aidl_library")
library.reexportDirs(dir)
}
library.reexportDeps(library.baseCompiler.aidlOrderOnlyDeps...) library.reexportDeps(library.baseCompiler.aidlOrderOnlyDeps...)
library.addExportedGeneratedHeaders(library.baseCompiler.aidlHeaders...) library.addExportedGeneratedHeaders(library.baseCompiler.aidlHeaders...)
@@ -2875,6 +2884,13 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
linkerAttrs := baseAttributes.linkerAttributes linkerAttrs := baseAttributes.linkerAttributes
exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, &compilerAttrs.includes) exportedIncludes := bp2BuildParseExportedIncludes(ctx, module, &compilerAttrs.includes)
includeAttrs := includesAttributes{
Export_includes: exportedIncludes.Includes,
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
}
// Append shared/static{} stanza properties. These won't be specified on // Append shared/static{} stanza properties. These won't be specified on
// cc_library_* itself, but may be specified in cc_defaults that this module // cc_library_* itself, but may be specified in cc_defaults that this module
@@ -2929,11 +2945,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
Cpp_std: compilerAttrs.cppStd, Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd, C_std: compilerAttrs.cStd,
Export_includes: exportedIncludes.Includes, includesAttributes: includeAttrs,
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Cppflags: compilerAttrs.cppFlags, Cppflags: compilerAttrs.cppFlags,
Conlyflags: compilerAttrs.conlyFlags, Conlyflags: compilerAttrs.conlyFlags,
@@ -2959,11 +2971,8 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
Cpp_std: compilerAttrs.cppStd, Cpp_std: compilerAttrs.cppStd,
C_std: compilerAttrs.cStd, C_std: compilerAttrs.cStd,
Export_includes: exportedIncludes.Includes, includesAttributes: includeAttrs,
Export_absolute_includes: exportedIncludes.AbsoluteIncludes,
Export_system_includes: exportedIncludes.SystemIncludes,
Local_includes: compilerAttrs.localIncludes,
Absolute_includes: compilerAttrs.absoluteIncludes,
Additional_linker_inputs: linkerAttrs.additionalLinkerInputs, Additional_linker_inputs: linkerAttrs.additionalLinkerInputs,
Strip: stripAttrsFromLinkerAttrs(&linkerAttrs), Strip: stripAttrsFromLinkerAttrs(&linkerAttrs),
@@ -2999,9 +3008,18 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name(), Tags: tags}, attrs) ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name(), Tags: tags}, attrs)
} }
type includesAttributes struct {
Export_includes bazel.StringListAttribute
Export_absolute_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute
Absolute_includes bazel.StringListAttribute
}
// TODO(b/199902614): Can this be factored to share with the other Attributes? // TODO(b/199902614): Can this be factored to share with the other Attributes?
type bazelCcLibraryStaticAttributes struct { type bazelCcLibraryStaticAttributes struct {
staticOrSharedAttributes staticOrSharedAttributes
includesAttributes
Use_version_lib bazel.BoolAttribute Use_version_lib bazel.BoolAttribute
Rtti bazel.BoolAttribute Rtti bazel.BoolAttribute
@@ -3009,12 +3027,7 @@ type bazelCcLibraryStaticAttributes struct {
Cpp_std *string Cpp_std *string
C_std *string C_std *string
Export_includes bazel.StringListAttribute Hdrs bazel.LabelListAttribute
Export_absolute_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute
Absolute_includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute
Cppflags bazel.StringListAttribute Cppflags bazel.StringListAttribute
Conlyflags bazel.StringListAttribute Conlyflags bazel.StringListAttribute
@@ -3026,6 +3039,7 @@ type bazelCcLibraryStaticAttributes struct {
// TODO(b/199902614): Can this be factored to share with the other Attributes? // TODO(b/199902614): Can this be factored to share with the other Attributes?
type bazelCcLibrarySharedAttributes struct { type bazelCcLibrarySharedAttributes struct {
staticOrSharedAttributes staticOrSharedAttributes
includesAttributes
Linkopts bazel.StringListAttribute Linkopts bazel.StringListAttribute
Use_version_lib bazel.BoolAttribute Use_version_lib bazel.BoolAttribute
@@ -3035,12 +3049,7 @@ type bazelCcLibrarySharedAttributes struct {
Cpp_std *string Cpp_std *string
C_std *string C_std *string
Export_includes bazel.StringListAttribute Hdrs bazel.LabelListAttribute
Export_absolute_includes bazel.StringListAttribute
Export_system_includes bazel.StringListAttribute
Local_includes bazel.StringListAttribute
Absolute_includes bazel.StringListAttribute
Hdrs bazel.LabelListAttribute
Strip stripAttributes Strip stripAttributes
Additional_linker_inputs bazel.LabelListAttribute Additional_linker_inputs bazel.LabelListAttribute