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

Commit 496cb48b authored by Christopher Parsons's avatar Christopher Parsons Committed by Automerger Merge Worker
Browse files

Merge "bp2build: handle system_shared_libs" am: 67d6ccec am: 430c7d2c am: 6787777e

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1783210

Change-Id: I26f79e5f6855dd4b94a204568f0bba9ba30d39a6
parents 95a9d16f 6787777e
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -204,16 +204,11 @@ var (
		"libBionicBenchmarksUtils", // cc_library_static, fatal error: 'map' file not found, from libcxx
		"fmtlib",                   // cc_library_static, fatal error: 'cassert' file not found, from libcxx
		"fmtlib_ndk",               // cc_library_static, fatal error: 'cassert' file not found
		"liblog",                   // http://b/186822772: cc_library, 'sys/cdefs.h' file not found
		"libbase",                  // Requires liblog. http://b/186826479, cc_library, fatal error: 'memory' file not found, from libcxx.
		// Also depends on fmtlib.

		// http://b/186024507: Includes errors because of the system_shared_libs default value.
		// Missing -isystem bionic/libc/include through the libc/libm/libdl
		// default dependencies if system_shared_libs is unset.
		"liblog",                 // http://b/186822772: cc_library, 'sys/cdefs.h' file not found
		"libjemalloc5_jet",       // cc_library, 'sys/cdefs.h' file not found
		"libseccomp_policy",      // http://b/186476753: cc_library, 'linux/filter.h' not found
		"note_memtag_heap_async", // http://b/185127353: cc_library_static, error: feature.h not found
		"note_memtag_heap_sync",  // http://b/185127353: cc_library_static, error: feature.h not found
		"libseccomp_policy", // depends on libbase

		"gwp_asan_crash_handler", // cc_library, ld.lld: error: undefined symbol: memset

+5 −0
Original line number Diff line number Diff line
@@ -115,6 +115,11 @@ func BazelLabelForModuleWholeDepsExcludes(ctx BazelConversionPathContext, module

func bazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string, isWholeLibs bool) bazel.LabelList {
	var labels bazel.LabelList
	// In some cases, a nil string list is different than an explicitly empty list.
	if len(modules) == 0 && modules != nil {
		labels.Includes = []bazel.Label{}
		return labels
	}
	for _, module := range modules {
		bpText := module
		if m := SrcIsModule(module); m == "" {
+30 −30
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ const (
	// This is consistently named "conditions_default" to mirror the Soong
	// config variable default key in an Android.bp file, although there's no
	// integration with Soong config variables (yet).
	conditionsDefault = "conditions_default"
	ConditionsDefaultConfigKey = "conditions_default"

	ConditionsDefaultSelectKey = "//conditions:default"

@@ -76,7 +76,7 @@ var (
		archArm64:                  "//build/bazel/platforms/arch:arm64",
		archX86:                    "//build/bazel/platforms/arch:x86",
		archX86_64:                 "//build/bazel/platforms/arch:x86_64",
		conditionsDefault: ConditionsDefaultSelectKey, // The default condition of as arch select map.
		ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of as arch select map.
	}

	// A map of target operating systems to the Bazel label of the
@@ -88,12 +88,12 @@ var (
		osLinuxMusl:                "//build/bazel/platforms/os:linux_musl",
		osLinuxBionic:              "//build/bazel/platforms/os:linux_bionic",
		osWindows:                  "//build/bazel/platforms/os:windows",
		conditionsDefault: ConditionsDefaultSelectKey, // The default condition of an os select map.
		ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
	}

	platformBionicMap = map[string]string{
		"bionic":                   "//build/bazel/platforms/os:bionic",
		conditionsDefault: ConditionsDefaultSelectKey, // The default condition of an os select map.
		ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
	}

	platformOsArchMap = map[string]string{
@@ -110,7 +110,7 @@ var (
		osArchLinuxBionicX86_64:    "//build/bazel/platforms/os_arch:linux_bionic_x86_64",
		osArchWindowsX86:           "//build/bazel/platforms/os_arch:windows_x86",
		osArchWindowsX86_64:        "//build/bazel/platforms/os_arch:windows_x86_64",
		conditionsDefault:       ConditionsDefaultSelectKey, // The default condition of an os select map.
		ConditionsDefaultConfigKey: ConditionsDefaultSelectKey, // The default condition of an os select map.
	}
)

@@ -181,7 +181,7 @@ func (ct configurationType) SelectKey(config string) string {
	case bionic:
		return platformBionicMap[config]
	case productVariables:
		if config == conditionsDefault {
		if config == ConditionsDefaultConfigKey {
			return ConditionsDefaultSelectKey
		}
		return fmt.Sprintf("%s:%s", productVariableBazelPackage, strings.ToLower(config))
+29 −2
Original line number Diff line number Diff line
@@ -69,6 +69,23 @@ type LabelList struct {
	Excludes []Label
}

func (ll *LabelList) Equals(other LabelList) bool {
	if len(ll.Includes) != len(other.Includes) || len(ll.Excludes) != len(other.Excludes) {
		return false
	}
	for i, _ := range ll.Includes {
		if ll.Includes[i] != other.Includes[i] {
			return false
		}
	}
	for i, _ := range ll.Excludes {
		if ll.Excludes[i] != other.Excludes[i] {
			return false
		}
	}
	return true
}

func (ll *LabelList) IsNil() bool {
	return ll.Includes == nil && ll.Excludes == nil
}
@@ -446,7 +463,7 @@ func (ll labelListSelectValues) appendSelects(other labelListSelectValues) {
// HasConfigurableValues returns whether there are configurable values within this set of selects.
func (ll labelListSelectValues) HasConfigurableValues() bool {
	for _, v := range ll {
		if len(v.Includes) > 0 {
		if v.Includes != nil {
			return true
		}
	}
@@ -462,6 +479,13 @@ type LabelListAttribute struct {
	// The configured attribute label list Values. Optional
	// a map of independent configurability axes
	ConfigurableValues configurableLabelLists

	// If true, differentiate between "nil" and "empty" list. nil means that
	// this attribute should not be specified at all, and "empty" means that
	// the attribute should be explicitly specified as an empty list.
	// This mode facilitates use of attribute defaults: an empty list should
	// override the default.
	ForceSpecifyEmptyList bool
}

type configurableLabelLists map[ConfigurationAxis]labelListSelectValues
@@ -546,6 +570,9 @@ func (lla *LabelListAttribute) SortedConfigurationAxes() []ConfigurationAxis {
// Append all values, including os and arch specific ones, from another
// LabelListAttribute to this LabelListAttribute.
func (lla *LabelListAttribute) Append(other LabelListAttribute) {
	if lla.ForceSpecifyEmptyList && !other.Value.IsNil() {
		lla.Value.Includes = []Label{}
	}
	lla.Value.Append(other.Value)
	if lla.ConfigurableValues == nil {
		lla.ConfigurableValues = make(configurableLabelLists)
@@ -595,7 +622,7 @@ func (lla *LabelListAttribute) ResolveExcludes() {

		// Now that the Value list is finalized for this axis, compare it with the original
		// list, and put the difference into the default condition for the axis.
		lla.ConfigurableValues[axis][conditionsDefault] = SubtractBazelLabelList(baseLabels, lla.Value)
		lla.ConfigurableValues[axis][ConditionsDefaultConfigKey] = SubtractBazelLabelList(baseLabels, lla.Value)

		// if everything ends up without includes, just delete the axis
		if !lla.ConfigurableValues[axis].HasConfigurableValues() {
+210 −0
Original line number Diff line number Diff line
@@ -1454,3 +1454,213 @@ cc_library {
)`},
	})
}

func TestCcLibrary_SystemSharedLibsRootEmpty(t *testing.T) {
	runCcLibraryTestCase(t, bp2buildTestCase{
		description:                        "cc_library system_shared_libs empty at root",
		moduleTypeUnderTest:                "cc_library",
		moduleTypeUnderTestFactory:         cc.LibraryFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
		blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "root_empty",
	  system_shared_libs: [],
}
`,
		expectedBazelTargets: []string{`cc_library(
    name = "root_empty",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
    system_dynamic_deps = [],
)`},
	})
}

func TestCcLibrary_SystemSharedLibsStaticEmpty(t *testing.T) {
	runCcLibraryTestCase(t, bp2buildTestCase{
		description:                        "cc_library system_shared_libs empty for static variant",
		moduleTypeUnderTest:                "cc_library",
		moduleTypeUnderTestFactory:         cc.LibraryFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
		blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "static_empty",
    static: {
				system_shared_libs: [],
		},
}
`,
		expectedBazelTargets: []string{`cc_library(
    name = "static_empty",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
    static = {
        "system_dynamic_deps": [],
    },
)`},
	})
}

func TestCcLibrary_SystemSharedLibsSharedEmpty(t *testing.T) {
	runCcLibraryTestCase(t, bp2buildTestCase{
		description:                        "cc_library system_shared_libs empty for shared variant",
		moduleTypeUnderTest:                "cc_library",
		moduleTypeUnderTestFactory:         cc.LibraryFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
		blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "shared_empty",
    shared: {
				system_shared_libs: [],
		},
}
`,
		expectedBazelTargets: []string{`cc_library(
    name = "shared_empty",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
    shared = {
        "system_dynamic_deps": [],
    },
)`},
	})
}

func TestCcLibrary_SystemSharedLibsSharedBionicEmpty(t *testing.T) {
	runCcLibraryTestCase(t, bp2buildTestCase{
		description:                        "cc_library system_shared_libs empty for shared, bionic variant",
		moduleTypeUnderTest:                "cc_library",
		moduleTypeUnderTestFactory:         cc.LibraryFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
		blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "shared_empty",
    target: {
        bionic: {
            shared: {
                system_shared_libs: [],
            }
        }
		},
}
`,
		expectedBazelTargets: []string{`cc_library(
    name = "shared_empty",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
    shared = {
        "system_dynamic_deps": [],
    },
)`},
	})
}

func TestCcLibrary_SystemSharedLibsLinuxBionicEmpty(t *testing.T) {
	// Note that this behavior is technically incorrect (it's a simplification).
	// The correct behavior would be if bp2build wrote `system_dynamic_deps = []`
	// only for linux_bionic, but `android` had `["libc", "libdl", "libm"].
	// b/195791252 tracks the fix.
	runCcLibraryTestCase(t, bp2buildTestCase{
		description:                        "cc_library system_shared_libs empty for linux_bionic variant",
		moduleTypeUnderTest:                "cc_library",
		moduleTypeUnderTestFactory:         cc.LibraryFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
		blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "target_linux_bionic_empty",
    target: {
        linux_bionic: {
            system_shared_libs: [],
        },
    },
}
`,
		expectedBazelTargets: []string{`cc_library(
    name = "target_linux_bionic_empty",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
    system_dynamic_deps = [],
)`},
	})
}

func TestCcLibrary_SystemSharedLibsBionicEmpty(t *testing.T) {
	runCcLibraryTestCase(t, bp2buildTestCase{
		description:                        "cc_library system_shared_libs empty for bionic variant",
		moduleTypeUnderTest:                "cc_library",
		moduleTypeUnderTestFactory:         cc.LibraryFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
		blueprint: soongCcLibraryPreamble + `
cc_library {
    name: "target_bionic_empty",
    target: {
        bionic: {
            system_shared_libs: [],
        },
    },
}
`,
		expectedBazelTargets: []string{`cc_library(
    name = "target_bionic_empty",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
    system_dynamic_deps = [],
)`},
	})
}

func TestCcLibrary_SystemSharedLibsSharedAndRoot(t *testing.T) {
	runCcLibraryTestCase(t, bp2buildTestCase{
		description:                        "cc_library system_shared_libs set for shared and root",
		moduleTypeUnderTest:                "cc_library",
		moduleTypeUnderTestFactory:         cc.LibraryFactory,
		moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryBp2Build,
		blueprint: soongCcLibraryPreamble + `
cc_library {name: "libc"}
cc_library {name: "libm"}

cc_library {
    name: "foo",
    system_shared_libs: ["libc"],
    shared: {
				system_shared_libs: ["libm"],
    },
}
`,
		expectedBazelTargets: []string{`cc_library(
    name = "foo",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
    shared = {
        "system_dynamic_deps": [":libm"],
    },
    system_dynamic_deps = [":libc"],
)`, `cc_library(
    name = "libc",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
)`, `cc_library(
    name = "libm",
    copts = [
        "-I.",
        "-I$(BINDIR)/.",
    ],
)`},
	})
}
Loading