Do not sort after subtraction.
This allows labels/strings to remain in their original order. Test: go test bazel tests Change-Id: I69f575df9e4a358fee4392ae48edf4550e463efb
This commit is contained in:
parent
7e1956643c
commit
9bad9d645e
4 changed files with 45 additions and 57 deletions
|
@ -164,48 +164,36 @@ func UniqueSortedBazelLabelList(originalLabelList LabelList) LabelList {
|
||||||
// Subtract needle from haystack
|
// Subtract needle from haystack
|
||||||
func SubtractStrings(haystack []string, needle []string) []string {
|
func SubtractStrings(haystack []string, needle []string) []string {
|
||||||
// This is really a set
|
// This is really a set
|
||||||
remainder := make(map[string]bool)
|
needleMap := make(map[string]bool)
|
||||||
|
|
||||||
for _, s := range haystack {
|
|
||||||
remainder[s] = true
|
|
||||||
}
|
|
||||||
for _, s := range needle {
|
for _, s := range needle {
|
||||||
delete(remainder, s)
|
needleMap[s] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var strings []string
|
var strings []string
|
||||||
for s, _ := range remainder {
|
for _, s := range haystack {
|
||||||
strings = append(strings, s)
|
if exclude := needleMap[s]; !exclude {
|
||||||
|
strings = append(strings, s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.SliceStable(strings, func(i, j int) bool {
|
|
||||||
return strings[i] < strings[j]
|
|
||||||
})
|
|
||||||
|
|
||||||
return strings
|
return strings
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract needle from haystack
|
// Subtract needle from haystack
|
||||||
func SubtractBazelLabels(haystack []Label, needle []Label) []Label {
|
func SubtractBazelLabels(haystack []Label, needle []Label) []Label {
|
||||||
// This is really a set
|
// This is really a set
|
||||||
remainder := make(map[Label]bool)
|
needleMap := make(map[Label]bool)
|
||||||
|
for _, s := range needle {
|
||||||
for _, label := range haystack {
|
needleMap[s] = true
|
||||||
remainder[label] = true
|
|
||||||
}
|
|
||||||
for _, label := range needle {
|
|
||||||
delete(remainder, label)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var labels []Label
|
var labels []Label
|
||||||
for label, _ := range remainder {
|
for _, label := range haystack {
|
||||||
labels = append(labels, label)
|
if exclude := needleMap[label]; !exclude {
|
||||||
|
labels = append(labels, label)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.SliceStable(labels, func(i, j int) bool {
|
|
||||||
return labels[i].Label < labels[j].Label
|
|
||||||
})
|
|
||||||
|
|
||||||
return labels
|
return labels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1669,21 +1669,21 @@ cc_library {
|
||||||
srcs = ["base.cpp"] + select({
|
srcs = ["base.cpp"] + select({
|
||||||
"//build/bazel/platforms/os:android": [
|
"//build/bazel/platforms/os:android": [
|
||||||
"android.cpp",
|
"android.cpp",
|
||||||
"bionic.cpp",
|
|
||||||
"linux.cpp",
|
"linux.cpp",
|
||||||
|
"bionic.cpp",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/os:darwin": ["darwin.cpp"],
|
"//build/bazel/platforms/os:darwin": ["darwin.cpp"],
|
||||||
"//build/bazel/platforms/os:linux": [
|
"//build/bazel/platforms/os:linux": [
|
||||||
"linux.cpp",
|
|
||||||
"linux_glibc.cpp",
|
"linux_glibc.cpp",
|
||||||
|
"linux.cpp",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/os:linux_bionic": [
|
"//build/bazel/platforms/os:linux_bionic": [
|
||||||
"bionic.cpp",
|
|
||||||
"linux.cpp",
|
"linux.cpp",
|
||||||
|
"bionic.cpp",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/os:linux_musl": [
|
"//build/bazel/platforms/os:linux_musl": [
|
||||||
"linux.cpp",
|
|
||||||
"linux_musl.cpp",
|
"linux_musl.cpp",
|
||||||
|
"linux.cpp",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/os:windows": ["windows.cpp"],
|
"//build/bazel/platforms/os:windows": ["windows.cpp"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
|
|
|
@ -641,12 +641,12 @@ cc_library_static {
|
||||||
name = "foo_static",
|
name = "foo_static",
|
||||||
srcs_c = ["common.c"] + select({
|
srcs_c = ["common.c"] + select({
|
||||||
"//build/bazel/platforms/arch:arm": [
|
"//build/bazel/platforms/arch:arm": [
|
||||||
"for-arm.c",
|
|
||||||
"not-for-x86.c",
|
"not-for-x86.c",
|
||||||
|
"for-arm.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:x86": [
|
"//build/bazel/platforms/arch:x86": [
|
||||||
"for-x86.c",
|
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
|
"for-x86.c",
|
||||||
],
|
],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
|
@ -691,28 +691,28 @@ cc_library_static {
|
||||||
name = "foo_static",
|
name = "foo_static",
|
||||||
srcs_c = ["common.c"] + select({
|
srcs_c = ["common.c"] + select({
|
||||||
"//build/bazel/platforms/arch:arm": [
|
"//build/bazel/platforms/arch:arm": [
|
||||||
"for-arm.c",
|
|
||||||
"not-for-arm64.c",
|
"not-for-arm64.c",
|
||||||
"not-for-x86.c",
|
"not-for-x86.c",
|
||||||
"not-for-x86_64.c",
|
"not-for-x86_64.c",
|
||||||
|
"for-arm.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:arm64": [
|
"//build/bazel/platforms/arch:arm64": [
|
||||||
"for-arm64.c",
|
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
"not-for-x86.c",
|
"not-for-x86.c",
|
||||||
"not-for-x86_64.c",
|
"not-for-x86_64.c",
|
||||||
|
"for-arm64.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:x86": [
|
"//build/bazel/platforms/arch:x86": [
|
||||||
"for-x86.c",
|
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
"not-for-arm64.c",
|
"not-for-arm64.c",
|
||||||
"not-for-x86_64.c",
|
"not-for-x86_64.c",
|
||||||
|
"for-x86.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:x86_64": [
|
"//build/bazel/platforms/arch:x86_64": [
|
||||||
"for-x86_64.c",
|
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
"not-for-arm64.c",
|
"not-for-arm64.c",
|
||||||
"not-for-x86.c",
|
"not-for-x86.c",
|
||||||
|
"for-x86_64.c",
|
||||||
],
|
],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
|
@ -875,20 +875,20 @@ cc_library_static {
|
||||||
name = "foo_static2",
|
name = "foo_static2",
|
||||||
srcs_c = ["common.c"] + select({
|
srcs_c = ["common.c"] + select({
|
||||||
"//build/bazel/platforms/arch:arm": [
|
"//build/bazel/platforms/arch:arm": [
|
||||||
"for-lib32.c",
|
|
||||||
"not-for-lib64.c",
|
"not-for-lib64.c",
|
||||||
|
"for-lib32.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:arm64": [
|
"//build/bazel/platforms/arch:arm64": [
|
||||||
"for-lib64.c",
|
|
||||||
"not-for-lib32.c",
|
"not-for-lib32.c",
|
||||||
|
"for-lib64.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:x86": [
|
"//build/bazel/platforms/arch:x86": [
|
||||||
"for-lib32.c",
|
|
||||||
"not-for-lib64.c",
|
"not-for-lib64.c",
|
||||||
|
"for-lib32.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:x86_64": [
|
"//build/bazel/platforms/arch:x86_64": [
|
||||||
"for-lib64.c",
|
|
||||||
"not-for-lib32.c",
|
"not-for-lib32.c",
|
||||||
|
"for-lib64.c",
|
||||||
],
|
],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"not-for-lib32.c",
|
"not-for-lib32.c",
|
||||||
|
@ -942,36 +942,36 @@ cc_library_static {
|
||||||
name = "foo_static3",
|
name = "foo_static3",
|
||||||
srcs_c = ["common.c"] + select({
|
srcs_c = ["common.c"] + select({
|
||||||
"//build/bazel/platforms/arch:arm": [
|
"//build/bazel/platforms/arch:arm": [
|
||||||
|
"not-for-arm64.c",
|
||||||
|
"not-for-lib64.c",
|
||||||
|
"not-for-x86.c",
|
||||||
|
"not-for-x86_64.c",
|
||||||
"for-arm.c",
|
"for-arm.c",
|
||||||
"for-lib32.c",
|
"for-lib32.c",
|
||||||
"not-for-arm64.c",
|
|
||||||
"not-for-lib64.c",
|
|
||||||
"not-for-x86.c",
|
|
||||||
"not-for-x86_64.c",
|
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:arm64": [
|
"//build/bazel/platforms/arch:arm64": [
|
||||||
"for-arm64.c",
|
|
||||||
"for-lib64.c",
|
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
"not-for-lib32.c",
|
"not-for-lib32.c",
|
||||||
"not-for-x86.c",
|
"not-for-x86.c",
|
||||||
"not-for-x86_64.c",
|
"not-for-x86_64.c",
|
||||||
|
"for-arm64.c",
|
||||||
|
"for-lib64.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:x86": [
|
"//build/bazel/platforms/arch:x86": [
|
||||||
"for-lib32.c",
|
|
||||||
"for-x86.c",
|
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
"not-for-arm64.c",
|
"not-for-arm64.c",
|
||||||
"not-for-lib64.c",
|
"not-for-lib64.c",
|
||||||
"not-for-x86_64.c",
|
"not-for-x86_64.c",
|
||||||
|
"for-x86.c",
|
||||||
|
"for-lib32.c",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/arch:x86_64": [
|
"//build/bazel/platforms/arch:x86_64": [
|
||||||
"for-lib64.c",
|
|
||||||
"for-x86_64.c",
|
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
"not-for-arm64.c",
|
"not-for-arm64.c",
|
||||||
"not-for-lib32.c",
|
"not-for-lib32.c",
|
||||||
"not-for-x86.c",
|
"not-for-x86.c",
|
||||||
|
"for-x86_64.c",
|
||||||
|
"for-lib64.c",
|
||||||
],
|
],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
"not-for-arm.c",
|
"not-for-arm.c",
|
||||||
|
@ -1066,19 +1066,19 @@ cc_library_static {
|
||||||
expectedBazelTargets: []string{`cc_library_static(
|
expectedBazelTargets: []string{`cc_library_static(
|
||||||
name = "foo_static3",
|
name = "foo_static3",
|
||||||
srcs = [
|
srcs = [
|
||||||
"//dep:generated_hdr_other_pkg",
|
|
||||||
"//dep:generated_src_other_pkg",
|
|
||||||
":generated_hdr",
|
|
||||||
":generated_src",
|
|
||||||
"common.cpp",
|
"common.cpp",
|
||||||
|
":generated_hdr",
|
||||||
|
"//dep:generated_hdr_other_pkg",
|
||||||
|
":generated_src",
|
||||||
|
"//dep:generated_src_other_pkg",
|
||||||
] + select({
|
] + select({
|
||||||
"//build/bazel/platforms/arch:x86": [
|
"//build/bazel/platforms/arch:x86": [
|
||||||
"//dep:generated_hdr_other_pkg_x86",
|
|
||||||
"for-x86.cpp",
|
"for-x86.cpp",
|
||||||
|
"//dep:generated_hdr_other_pkg_x86",
|
||||||
],
|
],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
":generated_src_not_x86",
|
|
||||||
"not-for-x86.cpp",
|
"not-for-x86.cpp",
|
||||||
|
":generated_src_not_x86",
|
||||||
],
|
],
|
||||||
}) + select({
|
}) + select({
|
||||||
"//build/bazel/platforms/os:android": [
|
"//build/bazel/platforms/os:android": [
|
||||||
|
|
|
@ -439,13 +439,13 @@ func TestCcObjectSelectOnLinuxAndBionicArchs(t *testing.T) {
|
||||||
copts = ["-fno-addrsig"],
|
copts = ["-fno-addrsig"],
|
||||||
srcs = ["base.cpp"] + select({
|
srcs = ["base.cpp"] + select({
|
||||||
"//build/bazel/platforms/os_arch:android_arm64": [
|
"//build/bazel/platforms/os_arch:android_arm64": [
|
||||||
"bionic_arm64.cpp",
|
|
||||||
"linux_arm64.cpp",
|
"linux_arm64.cpp",
|
||||||
|
"bionic_arm64.cpp",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/os_arch:android_x86": ["linux_x86.cpp"],
|
"//build/bazel/platforms/os_arch:android_x86": ["linux_x86.cpp"],
|
||||||
"//build/bazel/platforms/os_arch:linux_bionic_arm64": [
|
"//build/bazel/platforms/os_arch:linux_bionic_arm64": [
|
||||||
"bionic_arm64.cpp",
|
|
||||||
"linux_arm64.cpp",
|
"linux_arm64.cpp",
|
||||||
|
"bionic_arm64.cpp",
|
||||||
],
|
],
|
||||||
"//build/bazel/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"],
|
"//build/bazel/platforms/os_arch:linux_glibc_x86": ["linux_x86.cpp"],
|
||||||
"//build/bazel/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"],
|
"//build/bazel/platforms/os_arch:linux_musl_x86": ["linux_x86.cpp"],
|
||||||
|
|
Loading…
Reference in a new issue