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

Commit 0d1b4029 authored by Trevor Radcliffe's avatar Trevor Radcliffe
Browse files

Add musl defaults in bp2build

Bug: 261657184
Test: Unit Tests
Test: Manual Inspection of generated files
Change-Id: I69864abb410fddecd530fc75f2531aff33b33c97
parent 57b1e406
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -814,6 +814,16 @@ func (lla LabelListAttribute) HasConfigurableValues() bool {
	return false
}

// HasAxisSpecificValues returns true if the attribute contains axis specific label list values from a given axis
func (lla LabelListAttribute) HasAxisSpecificValues(axis ConfigurationAxis) bool {
	for _, values := range lla.ConfigurableValues[axis] {
		if !values.IsNil() {
			return true
		}
	}
	return false
}

// IsEmpty returns true if the attribute has no values under any configuration.
func (lla LabelListAttribute) IsEmpty() bool {
	if len(lla.Value.Includes) > 0 {
+71 −2
Original line number Diff line number Diff line
@@ -1805,6 +1805,11 @@ func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
		ModuleTypeUnderTest:        "cc_library",
		ModuleTypeUnderTestFactory: cc.LibraryFactory,
		Blueprint: soongCcLibraryPreamble + `
cc_library {
	name: "libc_musl",
	bazel_module: { bp2build_available: false },
}

cc_library {
    name: "target_linux_bionic_empty",
    target: {
@@ -1816,7 +1821,10 @@ cc_library {
}
`,
		ExpectedBazelTargets: makeCcLibraryTargets("target_linux_bionic_empty", AttrNameToString{
			"system_dynamic_deps": `[]`,
			"system_dynamic_deps": `select({
        "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
        "//conditions:default": [],
    })`,
		}),
	},
	)
@@ -1828,6 +1836,11 @@ func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
		ModuleTypeUnderTest:        "cc_library",
		ModuleTypeUnderTestFactory: cc.LibraryFactory,
		Blueprint: soongCcLibraryPreamble + `
cc_library {
	name: "libc_musl",
	bazel_module: { bp2build_available: false },
}

cc_library {
    name: "target_bionic_empty",
    target: {
@@ -1839,12 +1852,68 @@ cc_library {
}
`,
		ExpectedBazelTargets: makeCcLibraryTargets("target_bionic_empty", AttrNameToString{
			"system_dynamic_deps": `[]`,
			"system_dynamic_deps": `select({
        "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
        "//conditions:default": [],
    })`,
		}),
	},
	)
}

func TestCcLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
	runCcLibraryTestCase(t, Bp2buildTestCase{
		Description:                "cc_library system_shared_lib empty for musl variant",
		ModuleTypeUnderTest:        "cc_library",
		ModuleTypeUnderTestFactory: cc.LibraryFactory,
		Blueprint: soongCcLibraryPreamble + `
cc_library {
		name: "libc_musl",
		bazel_module: { bp2build_available: false },
}

cc_library {
    name: "target_musl_empty",
    target: {
        musl: {
            system_shared_libs: [],
        },
    },
    include_build_directory: false,
}
`,
		ExpectedBazelTargets: makeCcLibraryTargets("target_musl_empty", AttrNameToString{
			"system_dynamic_deps": `[]`,
		}),
	})
}

func TestCcLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
	runCcLibraryTestCase(t, Bp2buildTestCase{
		Description:                "cc_library system_shared_lib empty for linux_musl variant",
		ModuleTypeUnderTest:        "cc_library",
		ModuleTypeUnderTestFactory: cc.LibraryFactory,
		Blueprint: soongCcLibraryPreamble + `
cc_library {
		name: "libc_musl",
		bazel_module: { bp2build_available: false },
}

cc_library {
    name: "target_linux_musl_empty",
    target: {
        linux_musl: {
            system_shared_libs: [],
        },
    },
    include_build_directory: false,
}
`,
		ExpectedBazelTargets: makeCcLibraryTargets("target_linux_musl_empty", AttrNameToString{
			"system_dynamic_deps": `[]`,
		}),
	})
}
func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) {
	runCcLibraryTestCase(t, Bp2buildTestCase{
		Description:                "cc_library system_shared_libs set for shared and root",
+83 −1
Original line number Diff line number Diff line
@@ -1310,6 +1310,11 @@ func TestStaticLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
	runCcLibraryStaticTestCase(t, Bp2buildTestCase{
		Description: "cc_library_static system_shared_lib empty for bionic variant",
		Blueprint: soongCcLibraryStaticPreamble + `
cc_library {
		name: "libc_musl",
		bazel_module: { bp2build_available: false },
}

cc_library_static {
    name: "target_bionic_empty",
    target: {
@@ -1322,7 +1327,10 @@ cc_library_static {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_library_static", "target_bionic_empty", AttrNameToString{
				"system_dynamic_deps": `[]`,
				"system_dynamic_deps": `select({
        "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
        "//conditions:default": [],
    })`,
			}),
		},
	})
@@ -1336,6 +1344,11 @@ func TestStaticLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
	runCcLibraryStaticTestCase(t, Bp2buildTestCase{
		Description: "cc_library_static system_shared_lib empty for linux_bionic variant",
		Blueprint: soongCcLibraryStaticPreamble + `
cc_library {
		name: "libc_musl",
		bazel_module: { bp2build_available: false },
}

cc_library_static {
    name: "target_linux_bionic_empty",
    target: {
@@ -1348,6 +1361,63 @@ cc_library_static {
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_library_static", "target_linux_bionic_empty", AttrNameToString{
				"system_dynamic_deps": `select({
        "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
        "//conditions:default": [],
    })`,
			}),
		},
	})
}

func TestStaticLibrary_SystemSharedLibsMuslEmpty(t *testing.T) {
	runCcLibraryStaticTestCase(t, Bp2buildTestCase{
		Description: "cc_library_static system_shared_lib empty for musl variant",
		Blueprint: soongCcLibraryStaticPreamble + `
cc_library {
		name: "libc_musl",
		bazel_module: { bp2build_available: false },
}

cc_library_static {
    name: "target_musl_empty",
    target: {
        musl: {
            system_shared_libs: [],
        },
    },
    include_build_directory: false,
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_library_static", "target_musl_empty", AttrNameToString{
				"system_dynamic_deps": `[]`,
			}),
		},
	})
}

func TestStaticLibrary_SystemSharedLibsLinuxMuslEmpty(t *testing.T) {
	runCcLibraryStaticTestCase(t, Bp2buildTestCase{
		Description: "cc_library_static system_shared_lib empty for linux_musl variant",
		Blueprint: soongCcLibraryStaticPreamble + `
cc_library {
		name: "libc_musl",
		bazel_module: { bp2build_available: false },
}

cc_library_static {
    name: "target_linux_musl_empty",
    target: {
        linux_musl: {
            system_shared_libs: [],
        },
    },
    include_build_directory: false,
}
`,
		ExpectedBazelTargets: []string{
			MakeBazelTarget("cc_library_static", "target_linux_musl_empty", AttrNameToString{
				"system_dynamic_deps": `[]`,
			}),
		},
@@ -1359,6 +1429,11 @@ func TestStaticLibrary_SystemSharedLibsBionic(t *testing.T) {
		Description: "cc_library_static system_shared_libs set for bionic variant",
		Blueprint: soongCcLibraryStaticPreamble +
			simpleModuleDoNotConvertBp2build("cc_library", "libc") + `
cc_library {
	name: "libc_musl",
	bazel_module: { bp2build_available: false },
}

cc_library_static {
    name: "target_bionic",
    target: {
@@ -1374,6 +1449,7 @@ cc_library_static {
				"system_dynamic_deps": `select({
        "//build/bazel/platforms/os:android": [":libc"],
        "//build/bazel/platforms/os:linux_bionic": [":libc"],
        "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
        "//conditions:default": [],
    })`,
			}),
@@ -1387,6 +1463,11 @@ func TestStaticLibrary_SystemSharedLibsLinuxRootAndLinuxBionic(t *testing.T) {
		Blueprint: soongCcLibraryStaticPreamble +
			simpleModuleDoNotConvertBp2build("cc_library", "libc") +
			simpleModuleDoNotConvertBp2build("cc_library", "libm") + `
cc_library {
	name: "libc_musl",
	bazel_module: { bp2build_available: false },
}

cc_library_static {
    name: "target_linux_bionic",
    system_shared_libs: ["libc"],
@@ -1402,6 +1483,7 @@ cc_library_static {
			MakeBazelTarget("cc_library_static", "target_linux_bionic", AttrNameToString{
				"system_dynamic_deps": `[":libc"] + select({
        "//build/bazel/platforms/os:linux_bionic": [":libm"],
        "//build/bazel/platforms/os:linux_musl": [":libc_musl"],
        "//conditions:default": [],
    })`,
			}),
+12 −0
Original line number Diff line number Diff line
@@ -813,6 +813,8 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
	features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module))
	features.DeduplicateAxesFromBase()

	addMuslSystemDynamicDeps(ctx, linkerAttrs)

	return baseAttributes{
		compilerAttrs,
		linkerAttrs,
@@ -823,6 +825,16 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
	}
}

// As a workaround for b/261657184, we are manually adding the default value
// of system_dynamic_deps for the linux_musl os.
// TODO: Solve this properly
func addMuslSystemDynamicDeps(ctx android.Bp2buildMutatorContext, attrs linkerAttributes) {
	systemDynamicDeps := attrs.systemDynamicDeps.SelectValue(bazel.OsConfigurationAxis, "linux_musl")
	if attrs.systemDynamicDeps.HasAxisSpecificValues(bazel.OsConfigurationAxis) && systemDynamicDeps.IsNil() {
		attrs.systemDynamicDeps.SetSelectValue(bazel.OsConfigurationAxis, "linux_musl", android.BazelLabelForModuleDeps(ctx, config.MuslDefaultSharedLibraries))
	}
}

type fdoProfileAttributes struct {
	Absolute_path_profile string
}
+2 −2
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ var (
	muslCrtBeginSharedBinary, muslCrtEndSharedBinary   = []string{"libc_musl_crtbegin_dynamic"}, []string{"libc_musl_crtend"}
	muslCrtBeginSharedLibrary, muslCrtEndSharedLibrary = []string{"libc_musl_crtbegin_so"}, []string{"libc_musl_crtend_so"}

	muslDefaultSharedLibraries = []string{"libc_musl"}
	MuslDefaultSharedLibraries = []string{"libc_musl"}
)

const (
@@ -331,7 +331,7 @@ func (toolchainMusl) CrtEndStaticBinary() []string { return muslCrtEndStaticB
func (toolchainMusl) CrtEndSharedBinary() []string    { return muslCrtEndSharedBinary }
func (toolchainMusl) CrtEndSharedLibrary() []string   { return muslCrtEndSharedLibrary }

func (toolchainMusl) DefaultSharedLibraries() []string { return muslDefaultSharedLibraries }
func (toolchainMusl) DefaultSharedLibraries() []string { return MuslDefaultSharedLibraries }

func (toolchainMusl) Cflags() string {
	return "${config.LinuxMuslCflags}"