Loading bp2build/cc_library_conversion_test.go +62 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,68 @@ cc_library { )`, `cc_library( name = "mylib", copts = ["-Ifoo/bar"], )`}, }, { description: "cc_library pack_relocations test", moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` cc_library { name: "a", srcs: ["a.cpp"], pack_relocations: false, bazel_module: { bp2build_available: true }, } cc_library { name: "b", srcs: ["b.cpp"], arch: { x86_64: { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, } cc_library { name: "c", srcs: ["c.cpp"], target: { darwin: { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, }`, }, bp: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = ["-Ifoo/bar"], linkopts = ["-Wl,--pack-dyn-relocs=none"], srcs = ["a.cpp"], )`, `cc_library( name = "b", copts = ["-Ifoo/bar"], linkopts = select({ "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], }), srcs = ["b.cpp"], )`, `cc_library( name = "c", copts = ["-Ifoo/bar"], linkopts = select({ "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], }), srcs = ["c.cpp"], )`}, }, } Loading cc/bp2build.go +12 −3 Original line number Diff line number Diff line Loading @@ -252,6 +252,15 @@ type linkerAttributes struct { versionScript bazel.LabelAttribute } // FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string { flags := linkerProperties.Ldflags if !BoolDefault(linkerProperties.Pack_relocations, true) { flags = append(flags, "-Wl,--pack-dyn-relocs=none") } return flags } // bp2BuildParseLinkerProps parses the linker properties of a module, including // configurable attribute values. func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { Loading @@ -269,7 +278,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = android.SortedUniqueStrings(libs) deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs)) linkopts.Value = baseLinkerProps.Ldflags linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps) if baseLinkerProps.Version_script != nil { versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script) Loading @@ -291,7 +300,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = android.SortedUniqueStrings(libs) deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs)) linkopts.SetValueForArch(arch.Name, baseLinkerProps.Ldflags) linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps)) if baseLinkerProps.Version_script != nil { versionScript.SetValueForArch(arch.Name, Loading @@ -312,7 +321,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = android.SortedUniqueStrings(libs) deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs)) linkopts.SetValueForOS(os.Name, baseLinkerProps.Ldflags) linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps)) sharedLibs := baseLinkerProps.Shared_libs dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) Loading Loading
bp2build/cc_library_conversion_test.go +62 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,68 @@ cc_library { )`, `cc_library( name = "mylib", copts = ["-Ifoo/bar"], )`}, }, { description: "cc_library pack_relocations test", moduleTypeUnderTest: "cc_library", moduleTypeUnderTestFactory: cc.LibraryFactory, moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build, depsMutators: []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build}, dir: "foo/bar", filesystem: map[string]string{ "foo/bar/Android.bp": ` cc_library { name: "a", srcs: ["a.cpp"], pack_relocations: false, bazel_module: { bp2build_available: true }, } cc_library { name: "b", srcs: ["b.cpp"], arch: { x86_64: { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, } cc_library { name: "c", srcs: ["c.cpp"], target: { darwin: { pack_relocations: false, }, }, bazel_module: { bp2build_available: true }, }`, }, bp: soongCcLibraryPreamble, expectedBazelTargets: []string{`cc_library( name = "a", copts = ["-Ifoo/bar"], linkopts = ["-Wl,--pack-dyn-relocs=none"], srcs = ["a.cpp"], )`, `cc_library( name = "b", copts = ["-Ifoo/bar"], linkopts = select({ "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], }), srcs = ["b.cpp"], )`, `cc_library( name = "c", copts = ["-Ifoo/bar"], linkopts = select({ "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"], "//conditions:default": [], }), srcs = ["c.cpp"], )`}, }, } Loading
cc/bp2build.go +12 −3 Original line number Diff line number Diff line Loading @@ -252,6 +252,15 @@ type linkerAttributes struct { versionScript bazel.LabelAttribute } // FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string { flags := linkerProperties.Ldflags if !BoolDefault(linkerProperties.Pack_relocations, true) { flags = append(flags, "-Wl,--pack-dyn-relocs=none") } return flags } // bp2BuildParseLinkerProps parses the linker properties of a module, including // configurable attribute values. func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes { Loading @@ -269,7 +278,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = android.SortedUniqueStrings(libs) deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs)) linkopts.Value = baseLinkerProps.Ldflags linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps) if baseLinkerProps.Version_script != nil { versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script) Loading @@ -291,7 +300,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = android.SortedUniqueStrings(libs) deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs)) linkopts.SetValueForArch(arch.Name, baseLinkerProps.Ldflags) linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps)) if baseLinkerProps.Version_script != nil { versionScript.SetValueForArch(arch.Name, Loading @@ -312,7 +321,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) libs = android.SortedUniqueStrings(libs) deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs)) linkopts.SetValueForOS(os.Name, baseLinkerProps.Ldflags) linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps)) sharedLibs := baseLinkerProps.Shared_libs dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs)) Loading