diff --git a/android/bazel.go b/android/bazel.go index 40c971f17..19f5700f9 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -336,9 +336,8 @@ var ( "host_bionic_linker_asm", // depends on extract_linker, a go binary. "host_bionic_linker_script", // depends on extract_linker, a go binary. - "pbtombstone", // depends on libprotobuf-cpp-lite, libtombstone_proto - "crash_dump", // depends on unconverted module libprotobuf-cpp-lite - "libprotobuf-cpp-full", "libprotobuf-cpp-lite", // Unsupported product&vendor suffix. b/204811222 and b/204810610. + "pbtombstone", // depends on libprotobuf-cpp-lite, libtombstone_proto + "crash_dump", // depends on unconverted module libprotobuf-cpp-lite "libunwindstack_local", "libunwindstack_utils", // depends on unconverted module libunwindstack "libunwindstack", // depends on libdexfile_support, of unsupported module type art_cc_library_static @@ -373,19 +372,10 @@ var ( // APEX support "com.android.runtime", // http://b/194746715, apex, depends on 'libc_malloc_debug' - "libadb_crypto", // Depends on libadb_protos - "libadb_crypto_static", // Depends on libadb_protos_static - "libadb_pairing_connection", // Depends on libadb_protos - "libadb_pairing_connection_static", // Depends on libadb_protos_static - "libadb_pairing_server", // Depends on libadb_protos - "libadb_pairing_server_static", // Depends on libadb_protos_static - "libadbd", // Depends on libadbd_core - "libadbd_core", // Depends on libadb_protos - "libadbd_services", // Depends on libadb_protos + "libadbd_core", // http://b/208481704: requijres use_version_lib + "libadbd_services", // http://b/208481704: requires use_version_lib - "libadb_protos_static", // b/200601772: Requires cc_library proto support - "libadb_protos", // b/200601772: Requires cc_library proto support - "libapp_processes_protos_lite", // b/200601772: Requires cc_library proto support + "libadbd", // depends on unconverted modules: libadbd_core, libadbd_services "libgtest_ndk_c++", // b/201816222: Requires sdk_version support. "libgtest_main_ndk_c++", // b/201816222: Requires sdk_version support. @@ -418,6 +408,13 @@ var ( "cap_names.h", // TODO(b/204913827) runfiles need to be handled in mixed builds "libcap", // TODO(b/204913827) runfiles need to be handled in mixed builds "libprotobuf-cpp-full", "libprotobuf-cpp-lite", // Unsupported product&vendor suffix. b/204811222 and b/204810610. + + // Depends on libprotobuf-cpp-* + "libadb_crypto", "libadb_crypto_static", "libadb_pairing_connection", + "libadb_pairing_connection_static", + "libadb_pairing_server", "libadb_pairing_server_static", + "libadb_protos_static", "libadb_protos", + "libapp_processes_protos_lite", } // Used for quicker lookups diff --git a/android/mutator.go b/android/mutator.go index 461cb17d8..6606dbb8b 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -221,6 +221,13 @@ var bp2buildMutators = map[string]RegisterMutatorFunc{} // See http://b/192523357 var bp2buildLock sync.Mutex +// A minimal context for Bp2build conversion +type Bp2buildMutatorContext interface { + BazelConversionPathContext + + CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}) +} + // RegisterBp2BuildMutator registers specially crafted mutators for // converting Blueprint/Android modules into special modules that can // be code-generated into Bazel BUILD targets. diff --git a/android/proto.go b/android/proto.go index 0be7893c8..64d4d057c 100644 --- a/android/proto.go +++ b/android/proto.go @@ -15,12 +15,17 @@ package android import ( + "android/soong/bazel" "strings" "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) +const ( + canonicalPathFromRootDefault = true +) + // TODO(ccross): protos are often used to communicate between multiple modules. If the only // way to convert a proto to source is to reference it as a source file, and external modules cannot // reference source files in other modules, then every module that owns a proto file will need to @@ -90,7 +95,7 @@ func GetProtoFlags(ctx ModuleContext, p *ProtoProperties) ProtoFlags { Flags: flags, Deps: deps, OutTypeFlag: protoOutFlag, - CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, true), + CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, canonicalPathFromRootDefault), Dir: PathForModuleGen(ctx, "proto"), SubDir: PathForModuleGen(ctx, "proto", ctx.ModuleDir()), } @@ -146,3 +151,57 @@ func ProtoRule(rule *RuleBuilder, protoFile Path, flags ProtoFlags, deps Paths, rule.Command(). BuiltTool("dep_fixer").Flag(depFile.String()) } + +// Bp2buildProtoInfo contains information necessary to pass on to language specific conversion. +type Bp2buildProtoInfo struct { + Type *string + Name string +} + +type protoAttrs struct { + Srcs bazel.LabelListAttribute + Strip_import_prefix *string +} + +// Bp2buildProtoProperties converts proto properties, creating a proto_library and returning the +// information necessary for language-specific handling. +func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, module Module, srcs bazel.LabelListAttribute) (Bp2buildProtoInfo, bool) { + var info Bp2buildProtoInfo + if srcs.IsEmpty() { + return info, false + } + m := module.base() + + info.Name = m.Name() + "_proto" + attrs := protoAttrs{ + Srcs: srcs, + } + + for axis, configToProps := range m.GetArchVariantProperties(ctx, &ProtoProperties{}) { + for _, rawProps := range configToProps { + var props *ProtoProperties + var ok bool + if props, ok = rawProps.(*ProtoProperties); !ok { + ctx.ModuleErrorf("Could not cast ProtoProperties to expected type") + } + if axis == bazel.NoConfigAxis { + info.Type = props.Proto.Type + + if proptools.BoolDefault(props.Proto.Canonical_path_from_root, canonicalPathFromRootDefault) { + // an empty string indicates to strips the package path + path := "" + attrs.Strip_import_prefix = &path + } + } else if props.Proto.Type != info.Type && props.Proto.Type != nil { + ctx.ModuleErrorf("Cannot handle arch-variant types for protos at this time.") + } + } + } + + ctx.CreateBazelTargetModule( + bazel.BazelTargetModuleProperties{Rule_class: "proto_library"}, + CommonAttributes{Name: info.Name}, + &attrs) + + return info, true +} diff --git a/bazel/properties.go b/bazel/properties.go index b370bbfb2..bbaa33e2f 100644 --- a/bazel/properties.go +++ b/bazel/properties.go @@ -107,6 +107,14 @@ func (ll *LabelList) uniqueParentDirectories() []string { return dirs } +// Add inserts the label Label at the end of the LabelList. +func (ll *LabelList) Add(label *Label) { + if label == nil { + return + } + ll.Includes = append(ll.Includes, *label) +} + // Append appends the fields of other labelList to the corresponding fields of ll. func (ll *LabelList) Append(other LabelList) { if len(ll.Includes) > 0 || len(other.Includes) > 0 { @@ -366,6 +374,17 @@ func (ba *BoolAttribute) SortedConfigurationAxes() []ConfigurationAxis { // labelListSelectValues supports config-specific label_list typed Bazel attribute values. type labelListSelectValues map[string]LabelList +func (ll labelListSelectValues) addSelects(label labelSelectValues) { + for k, v := range label { + if label == nil { + continue + } + l := ll[k] + (&l).Add(v) + ll[k] = l + } +} + func (ll labelListSelectValues) appendSelects(other labelListSelectValues) { for k, v := range other { l := ll[k] @@ -500,6 +519,25 @@ func (lla *LabelListAttribute) Append(other LabelListAttribute) { lla.ConfigurableValues.Append(other.ConfigurableValues) } +// Add inserts the labels for each axis of LabelAttribute at the end of corresponding axis's +// LabelList within the LabelListAttribute +func (lla *LabelListAttribute) Add(label *LabelAttribute) { + if label == nil { + return + } + + lla.Value.Add(label.Value) + if lla.ConfigurableValues == nil && label.ConfigurableValues != nil { + lla.ConfigurableValues = make(configurableLabelLists) + } + for axis, _ := range label.ConfigurableValues { + if _, exists := lla.ConfigurableValues[axis]; !exists { + lla.ConfigurableValues[axis] = make(labelListSelectValues) + } + lla.ConfigurableValues[axis].addSelects(label.ConfigurableValues[axis]) + } +} + // HasConfigurableValues returns true if the attribute contains axis-specific label list values. func (lla LabelListAttribute) HasConfigurableValues() bool { return len(lla.ConfigurableValues) > 0 @@ -566,7 +604,7 @@ type OtherModuleContext interface { // LabelMapper is a function that takes a OtherModuleContext and returns a (potentially changed) // label and whether it was changed. -type LabelMapper func(OtherModuleContext, string) (string, bool) +type LabelMapper func(OtherModuleContext, Label) (string, bool) // LabelPartition contains descriptions of a partition for labels type LabelPartition struct { @@ -588,7 +626,7 @@ type LabelPartitions map[string]LabelPartition // not. func (lf LabelPartition) filter(ctx OtherModuleContext, label Label) *Label { if lf.LabelMapper != nil { - if newLabel, changed := lf.LabelMapper(ctx, label.Label); changed { + if newLabel, changed := lf.LabelMapper(ctx, label); changed { return &Label{newLabel, label.OriginalModuleName} } } diff --git a/bazel/properties_test.go b/bazel/properties_test.go index 7a7d6f3b8..c7f977678 100644 --- a/bazel/properties_test.go +++ b/bazel/properties_test.go @@ -313,16 +313,16 @@ func TestResolveExcludes(t *testing.T) { // labelAddSuffixForTypeMapper returns a LabelMapper that adds suffix to label name for modules of // typ func labelAddSuffixForTypeMapper(suffix, typ string) LabelMapper { - return func(omc OtherModuleContext, label string) (string, bool) { - m, ok := omc.ModuleFromName(label) + return func(omc OtherModuleContext, label Label) (string, bool) { + m, ok := omc.ModuleFromName(label.Label) if !ok { - return label, false + return label.Label, false } mTyp := omc.OtherModuleType(m) if typ == mTyp { - return label + suffix, true + return label.Label + suffix, true } - return label, false + return label.Label, false } } diff --git a/bp2build/cc_binary_conversion_test.go b/bp2build/cc_binary_conversion_test.go index f9abcba6f..24468506f 100644 --- a/bp2build/cc_binary_conversion_test.go +++ b/bp2build/cc_binary_conversion_test.go @@ -24,8 +24,7 @@ import ( ) const ( - ccBinaryTypePlaceHolder = "{rule_name}" - compatibleWithPlaceHolder = "{target_compatible_with}" + ccBinaryTypePlaceHolder = "{rule_name}" ) type testBazelTarget struct { @@ -84,12 +83,15 @@ func runCcBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) { func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) { t.Helper() testCase := tc - for i, t := range testCase.targets { - t.attrs["target_compatible_with"] = `select({ + for i, tar := range testCase.targets { + if tar.typ != "cc_binary" { + continue + } + tar.attrs["target_compatible_with"] = `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })` - testCase.targets[i] = t + testCase.targets[i] = tar } moduleTypeUnderTest := "cc_binary_host" t.Run(testCase.description, func(t *testing.T) { @@ -448,3 +450,51 @@ func TestCcBinaryPropertiesToFeatures(t *testing.T) { }) } } + +func TestCcBinarySharedProto(t *testing.T) { + runCcBinaryTests(t, ccBinaryBp2buildTestCase{ + blueprint: soongCcProtoLibraries + `{rule_name} { + name: "foo", + srcs: ["foo.proto"], + proto: { + canonical_path_from_root: false, + }, + include_build_directory: false, +}`, + targets: []testBazelTarget{ + {"proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }}, {"cc_binary", "foo", attrNameToString{ + "dynamic_deps": `[":libprotobuf-cpp-lite"]`, + "whole_archive_deps": `[":foo_cc_proto_lite"]`, + }}, + }, + }) +} + +func TestCcBinaryStaticProto(t *testing.T) { + runCcBinaryTests(t, ccBinaryBp2buildTestCase{ + blueprint: soongCcProtoLibraries + `{rule_name} { + name: "foo", + srcs: ["foo.proto"], + static_executable: true, + proto: { + canonical_path_from_root: false, + }, + include_build_directory: false, +}`, + targets: []testBazelTarget{ + {"proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }}, {"cc_binary", "foo", attrNameToString{ + "deps": `[":libprotobuf-cpp-lite"]`, + "whole_archive_deps": `[":foo_cc_proto_lite"]`, + "linkshared": `False`, + }}, + }, + }) +} diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index d23ea01ed..8c8898e3e 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -39,6 +39,19 @@ toolchain_library { native_bridge_supported: true, src: "", }` + + soongCcProtoLibraries = ` +cc_library { + name: "libprotobuf-cpp-lite", + bazel_module: { bp2build_available: false }, +} + +cc_library { + name: "libprotobuf-cpp-full", + bazel_module: { bp2build_available: false }, +}` + + soongCcProtoPreamble = soongCcLibraryPreamble + soongCcProtoLibraries ) func runCcLibraryTestCase(t *testing.T, tc bp2buildTestCase) { @@ -1829,3 +1842,187 @@ cc_library_shared { }) } } + +func TestCcLibraryProtoSimple(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + blueprint: soongCcProtoPreamble + `cc_library { + name: "foo", + srcs: ["foo.proto"], + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + "strip_import_prefix": `""`, + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library", "foo", attrNameToString{ + "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, + "shared": `{ + "dynamic_deps": [":libprotobuf-cpp-lite"], + }`, + "static": `{ + "deps": [":libprotobuf-cpp-lite"], + }`, + }), + }, + }) +} + +func TestCcLibraryProtoNoCanonicalPathFromRoot(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + blueprint: soongCcProtoPreamble + `cc_library { + name: "foo", + srcs: ["foo.proto"], + proto: { canonical_path_from_root: false}, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library", "foo", attrNameToString{ + "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, + "shared": `{ + "dynamic_deps": [":libprotobuf-cpp-lite"], + }`, + "static": `{ + "deps": [":libprotobuf-cpp-lite"], + }`, + }), + }, + }) +} + +func TestCcLibraryProtoExplicitCanonicalPathFromRoot(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + blueprint: soongCcProtoPreamble + `cc_library { + name: "foo", + srcs: ["foo.proto"], + proto: { canonical_path_from_root: true}, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + "strip_import_prefix": `""`, + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library", "foo", attrNameToString{ + "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, + "shared": `{ + "dynamic_deps": [":libprotobuf-cpp-lite"], + }`, + "static": `{ + "deps": [":libprotobuf-cpp-lite"], + }`, + }), + }, + }) +} + +func TestCcLibraryProtoFull(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + blueprint: soongCcProtoPreamble + `cc_library { + name: "foo", + srcs: ["foo.proto"], + proto: { + canonical_path_from_root: false, + type: "full", + }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }), makeBazelTarget("cc_proto_library", "foo_cc_proto", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library", "foo", attrNameToString{ + "implementation_whole_archive_deps": `[":foo_cc_proto"]`, + "shared": `{ + "dynamic_deps": [":libprotobuf-cpp-full"], + }`, + "static": `{ + "deps": [":libprotobuf-cpp-full"], + }`, + }), + }, + }) +} + +func TestCcLibraryProtoLite(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + blueprint: soongCcProtoPreamble + `cc_library { + name: "foo", + srcs: ["foo.proto"], + proto: { + canonical_path_from_root: false, + type: "lite", + }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library", "foo", attrNameToString{ + "implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`, + "shared": `{ + "dynamic_deps": [":libprotobuf-cpp-lite"], + }`, + "static": `{ + "deps": [":libprotobuf-cpp-lite"], + }`, + }), + }, + }) +} + +func TestCcLibraryProtoExportHeaders(t *testing.T) { + runCcLibraryTestCase(t, bp2buildTestCase{ + moduleTypeUnderTest: "cc_library", + moduleTypeUnderTestFactory: cc.LibraryFactory, + moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, + blueprint: soongCcProtoPreamble + `cc_library { + name: "foo", + srcs: ["foo.proto"], + proto: { + canonical_path_from_root: false, + export_proto_headers: true, + }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library", "foo", attrNameToString{ + "whole_archive_deps": `[":foo_cc_proto_lite"]`, + "shared": `{ + "dynamic_deps": [":libprotobuf-cpp-lite"], + }`, + "static": `{ + "deps": [":libprotobuf-cpp-lite"], + }`, + }), + }, + }) +} diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index 4ec95c3a3..e0331bee5 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -33,6 +33,7 @@ func registerCcLibrarySharedModuleTypes(ctx android.RegistrationContext) { ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) ctx.RegisterModuleType("cc_library_headers", cc.LibraryHeaderFactory) ctx.RegisterModuleType("cc_library_static", cc.LibraryStaticFactory) + ctx.RegisterModuleType("cc_library", cc.LibraryFactory) } func runCcLibrarySharedTestCase(t *testing.T, tc bp2buildTestCase) { @@ -425,3 +426,27 @@ cc_library_shared { expectedErr: fmt.Errorf("Android.bp:16:1: module \"foo_shared\": nocrt is not supported for arch variants"), }) } + +func TestCcLibrarySharedProto(t *testing.T) { + runCcLibrarySharedTestCase(t, bp2buildTestCase{ + blueprint: soongCcProtoPreamble + `cc_library_shared { + name: "foo", + srcs: ["foo.proto"], + proto: { + canonical_path_from_root: false, + export_proto_headers: true, + }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library_shared", "foo", attrNameToString{ + "dynamic_deps": `[":libprotobuf-cpp-lite"]`, + "whole_archive_deps": `[":foo_cc_proto_lite"]`, + }), + }, + }) +} diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go index 2f760d236..02229e51e 100644 --- a/bp2build/cc_library_static_conversion_test.go +++ b/bp2build/cc_library_static_conversion_test.go @@ -1419,3 +1419,27 @@ cc_library_static { }, }) } + +func TestCcLibraryStaticProto(t *testing.T) { + runCcLibraryStaticTestCase(t, bp2buildTestCase{ + blueprint: soongCcProtoPreamble + `cc_library_static { + name: "foo", + srcs: ["foo.proto"], + proto: { + canonical_path_from_root: false, + export_proto_headers: true, + }, + include_build_directory: false, +}`, + expectedBazelTargets: []string{ + makeBazelTarget("proto_library", "foo_proto", attrNameToString{ + "srcs": `["foo.proto"]`, + }), makeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{ + "deps": `[":foo_proto"]`, + }), makeBazelTarget("cc_library_static", "foo", attrNameToString{ + "deps": `[":libprotobuf-cpp-lite"]`, + "whole_archive_deps": `[":foo_cc_proto_lite"]`, + }), + }, + }) +} diff --git a/cc/binary.go b/cc/binary.go index a5afb0725..63657e4dd 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -18,6 +18,7 @@ import ( "path/filepath" "github.com/google/blueprint" + "github.com/google/blueprint/proptools" "android/soong/android" "android/soong/bazel" @@ -578,9 +579,16 @@ func binaryBp2build(ctx android.TopDownMutatorContext, typ string) { } baseAttrs := bp2BuildParseBaseProps(ctx, m) + binaryLinkerAttrs := bp2buildBinaryLinkerProps(ctx, m) + + if proptools.BoolDefault(binaryLinkerAttrs.Linkshared, true) { + baseAttrs.implementationDynamicDeps.Add(baseAttrs.protoDependency) + } else { + baseAttrs.implementationDeps.Add(baseAttrs.protoDependency) + } attrs := &binaryAttributes{ - binaryLinkerAttrs: bp2buildBinaryLinkerProps(ctx, m), + binaryLinkerAttrs: binaryLinkerAttrs, Srcs: baseAttrs.srcs, Srcs_c: baseAttrs.cSrcs, diff --git a/cc/bp2build.go b/cc/bp2build.go index 888c3bacb..f9bbe8752 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -27,9 +27,10 @@ import ( ) const ( - cSrcPartition = "c" - asSrcPartition = "as" - cppSrcPartition = "cpp" + cSrcPartition = "c" + asSrcPartition = "as" + cppSrcPartition = "cpp" + protoSrcPartition = "proto" ) // staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties -- @@ -41,52 +42,53 @@ type staticOrSharedAttributes struct { Hdrs bazel.LabelListAttribute Copts bazel.StringListAttribute - Deps bazel.LabelListAttribute - Implementation_deps bazel.LabelListAttribute - Dynamic_deps bazel.LabelListAttribute - Implementation_dynamic_deps bazel.LabelListAttribute - Whole_archive_deps bazel.LabelListAttribute + Deps bazel.LabelListAttribute + Implementation_deps bazel.LabelListAttribute + Dynamic_deps bazel.LabelListAttribute + Implementation_dynamic_deps bazel.LabelListAttribute + Whole_archive_deps bazel.LabelListAttribute + Implementation_whole_archive_deps bazel.LabelListAttribute System_dynamic_deps bazel.LabelListAttribute } func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute { - // Check that a module is a filegroup type named