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

Commit ed9c17d0 authored by Jingwen Chen's avatar Jingwen Chen
Browse files

bp2build: refactor/standardize cc_* bp2build converters

This CL refactors the cc* bp2build converters to use the common
attribute extractors in cc/bp2build.go.

This also adds include_build_directory to be handled by the compiler
attr extractor to generate recursive headers as inputs.

This also turns include_dirs and local_include_dirs into the
execroot-relative -I flags.

e.g. if a module in  bionic/libc has "private" in local_include_dirs,
the "-Ibionic/libc/private" copt is generated for it.

Fixes: 185139955

Test: TH
Test: Forrest for mixed_clean-droid
Change-Id: Ib67056482227e62068fbbea0455035bdf5d56319
parent dac45171
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -125,7 +125,9 @@ func (ll *LabelList) Append(other LabelList) {
	}
}

func UniqueBazelLabels(originalLabels []Label) []Label {
// UniqueSortedBazelLabels takes a []Label and deduplicates the labels, and returns
// the slice in a sorted order.
func UniqueSortedBazelLabels(originalLabels []Label) []Label {
	uniqueLabelsSet := make(map[Label]bool)
	for _, l := range originalLabels {
		uniqueLabelsSet[l] = true
@@ -142,8 +144,8 @@ func UniqueBazelLabels(originalLabels []Label) []Label {

func UniqueBazelLabelList(originalLabelList LabelList) LabelList {
	var uniqueLabelList LabelList
	uniqueLabelList.Includes = UniqueBazelLabels(originalLabelList.Includes)
	uniqueLabelList.Excludes = UniqueBazelLabels(originalLabelList.Excludes)
	uniqueLabelList.Includes = UniqueSortedBazelLabels(originalLabelList.Includes)
	uniqueLabelList.Excludes = UniqueSortedBazelLabels(originalLabelList.Excludes)
	return uniqueLabelList
}

@@ -292,7 +294,7 @@ func MakeLabelListAttribute(value LabelList) LabelListAttribute {
	return LabelListAttribute{Value: UniqueBazelLabelList(value)}
}

// Append appends all values, including os and arch specific ones, from another
// Append all values, including os and arch specific ones, from another
// LabelListAttribute to this LabelListAttribute.
func (attrs *LabelListAttribute) Append(other LabelListAttribute) {
	for arch := range PlatformArchMap {
@@ -500,6 +502,26 @@ func (attrs *StringListAttribute) SetValueForOS(os string, value []string) {
	*v = value
}

// Append appends all values, including os and arch specific ones, from another
// StringListAttribute to this StringListAttribute
func (attrs *StringListAttribute) Append(other StringListAttribute) {
	for arch := range PlatformArchMap {
		this := attrs.GetValueForArch(arch)
		that := other.GetValueForArch(arch)
		this = append(this, that...)
		attrs.SetValueForArch(arch, this)
	}

	for os := range PlatformOsMap {
		this := attrs.GetValueForOS(os)
		that := other.GetValueForOS(os)
		this = append(this, that...)
		attrs.SetValueForOS(os, this)
	}

	attrs.Value = append(attrs.Value, other.Value...)
}

// TryVariableSubstitution, replace string substitution formatting within each string in slice with
// Starlark string.format compatible tag for productVariable.
func TryVariableSubstitutions(slice []string, productVariable string) ([]string, bool) {
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ func TestUniqueBazelLabels(t *testing.T) {
		},
	}
	for _, tc := range testCases {
		actualUniqueLabels := UniqueBazelLabels(tc.originalLabels)
		actualUniqueLabels := UniqueSortedBazelLabels(tc.originalLabels)
		if !reflect.DeepEqual(tc.expectedUniqueLabels, actualUniqueLabels) {
			t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabels, actualUniqueLabels)
		}
+23 −18
Original line number Diff line number Diff line
@@ -109,10 +109,22 @@ cc_library {
`,
			expectedBazelTargets: []string{`cc_library(
    name = "foo-lib",
    copts = ["-Wall"],
    copts = [
        "-Wall",
        "-I.",
    ],
    deps = [":some-headers"],
    hdrs = [
    hdrs = ["foo-dir/a.h"],
    includes = ["foo-dir"],
    linkopts = ["-Wl,--exclude-libs=bar.a"] + select({
        "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"],
        "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"],
        "//conditions:default": [],
    }),
    srcs = [
        "impl.cpp",
        "header.h",
        "foo-dir/a.h",
        "header.hh",
        "header.hpp",
        "header.hxx",
@@ -121,15 +133,7 @@ cc_library {
        "header.inc",
        "header.ipp",
        "header.h.generic",
        "foo-dir/a.h",
    ],
    includes = ["foo-dir"],
    linkopts = ["-Wl,--exclude-libs=bar.a"] + select({
        "//build/bazel/platforms/arch:x86": ["-Wl,--exclude-libs=baz.a"],
        "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=qux.a"],
        "//conditions:default": [],
    }),
    srcs = ["impl.cpp"] + select({
    ] + select({
        "//build/bazel/platforms/arch:x86": ["x86.cpp"],
        "//build/bazel/platforms/arch:x86_64": ["x86_64.cpp"],
        "//conditions:default": [],
@@ -190,14 +194,9 @@ cc_library {
        "-Wextra",
        "-Wunused",
        "-Werror",
        "-I.",
    ],
    deps = [":libc_headers"],
    hdrs = [
        "linked_list.h",
        "linker.h",
        "linker_block_allocator.h",
        "linker_cfi.h",
    ],
    linkopts = [
        "-Wl,--exclude-libs=libgcc.a",
        "-Wl,--exclude-libs=libgcc_stripped.a",
@@ -210,7 +209,13 @@ cc_library {
        "//build/bazel/platforms/arch:x86_64": ["-Wl,--exclude-libs=libgcc_eh.a"],
        "//conditions:default": [],
    }),
    srcs = ["ld_android.cpp"],
    srcs = [
        "ld_android.cpp",
        "linked_list.h",
        "linker.h",
        "linker_block_allocator.h",
        "linker_cfi.h",
    ],
)`},
		},
	}
+14 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ cc_library_headers {
}`,
			expectedBazelTargets: []string{`cc_library_headers(
    name = "foo_headers",
    copts = ["-I."],
    deps = [
        ":lib-1",
        ":lib-2",
@@ -157,6 +158,7 @@ cc_library_headers {
    }),
)`, `cc_library_headers(
    name = "lib-1",
    copts = ["-I."],
    hdrs = [
        "lib-1/lib1a.h",
        "lib-1/lib1b.h",
@@ -164,6 +166,7 @@ cc_library_headers {
    includes = ["lib-1"],
)`, `cc_library_headers(
    name = "lib-2",
    copts = ["-I."],
    hdrs = [
        "lib-2/lib2a.h",
        "lib-2/lib2b.h",
@@ -201,12 +204,16 @@ cc_library_headers {
}`,
			expectedBazelTargets: []string{`cc_library_headers(
    name = "android-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "base-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "darwin-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "foo_headers",
    copts = ["-I."],
    deps = [":base-lib"] + select({
        "//build/bazel/platforms/os:android": [":android-lib"],
        "//build/bazel/platforms/os:darwin": [":darwin-lib"],
@@ -218,12 +225,16 @@ cc_library_headers {
    }),
)`, `cc_library_headers(
    name = "fuchsia-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "linux-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "linux_bionic-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "windows-lib",
    copts = ["-I."],
)`},
		},
		{
@@ -244,10 +255,13 @@ cc_library_headers {
}`,
			expectedBazelTargets: []string{`cc_library_headers(
    name = "android-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "exported-lib",
    copts = ["-I."],
)`, `cc_library_headers(
    name = "foo_headers",
    copts = ["-I."],
    deps = select({
        "//build/bazel/platforms/os:android": [
            ":android-lib",
+370 −50
Original line number Diff line number Diff line
@@ -119,25 +119,21 @@ cc_library_headers {
cc_library_static {
    name: "static_lib_1",
    srcs: ["static_lib_1.cc"],
    bazel_module: { bp2build_available: true },
}

cc_library_static {
    name: "static_lib_2",
    srcs: ["static_lib_2.cc"],
    bazel_module: { bp2build_available: true },
}

cc_library_static {
    name: "whole_static_lib_1",
    srcs: ["whole_static_lib_1.cc"],
    bazel_module: { bp2build_available: true },
}

cc_library_static {
    name: "whole_static_lib_2",
    srcs: ["whole_static_lib_2.cc"],
    bazel_module: { bp2build_available: true },
}

cc_library_static {
@@ -176,14 +172,17 @@ cc_library_static {
    ],

    // TODO: Also support export_header_lib_headers

    bazel_module: { bp2build_available: true },
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = [
        "-Dflag1",
        "-Dflag2",
        "-Iinclude_dir_1",
        "-Iinclude_dir_2",
        "-Ilocal_include_dir_1",
        "-Ilocal_include_dir_2",
        "-I.",
    ],
    deps = [
        ":header_lib_1",
@@ -194,8 +193,6 @@ cc_library_static {
        ":whole_static_lib_2",
    ],
    hdrs = [
        "implicit_include_1.h",
        "implicit_include_2.h",
        "export_include_dir_1/export_include_dir_1_a.h",
        "export_include_dir_1/export_include_dir_1_b.h",
        "export_include_dir_2/export_include_dir_2_a.h",
@@ -204,16 +201,17 @@ cc_library_static {
    includes = [
        "export_include_dir_1",
        "export_include_dir_2",
        "include_dir_1",
        "include_dir_2",
        "local_include_dir_1",
        "local_include_dir_2",
        ".",
    ],
    linkstatic = True,
    srcs = [
        "foo_static1.cc",
        "foo_static2.cc",
        "implicit_include_1.h",
        "implicit_include_2.h",
        "export_include_dir_1/export_include_dir_1_a.h",
        "export_include_dir_1/export_include_dir_1_b.h",
        "export_include_dir_2/export_include_dir_2_a.h",
        "export_include_dir_2/export_include_dir_2_b.h",
        "include_dir_1/include_dir_1_a.h",
        "include_dir_1/include_dir_1_b.h",
        "include_dir_2/include_dir_2_a.h",
@@ -222,60 +220,90 @@ cc_library_static {
        "local_include_dir_1/local_include_dir_1_b.h",
        "local_include_dir_2/local_include_dir_2_a.h",
        "local_include_dir_2/local_include_dir_2_b.h",
        "implicit_include_1.h",
        "implicit_include_2.h",
    ],
)`, `cc_library_static(
    name = "static_lib_1",
    hdrs = [
        "implicit_include_1.h",
        "implicit_include_2.h",
    ],
    includes = ["."],
    copts = ["-I."],
    linkstatic = True,
    srcs = [
        "static_lib_1.cc",
        "implicit_include_1.h",
        "implicit_include_2.h",
        "export_include_dir_1/export_include_dir_1_a.h",
        "export_include_dir_1/export_include_dir_1_b.h",
        "export_include_dir_2/export_include_dir_2_a.h",
        "export_include_dir_2/export_include_dir_2_b.h",
        "include_dir_1/include_dir_1_a.h",
        "include_dir_1/include_dir_1_b.h",
        "include_dir_2/include_dir_2_a.h",
        "include_dir_2/include_dir_2_b.h",
        "local_include_dir_1/local_include_dir_1_a.h",
        "local_include_dir_1/local_include_dir_1_b.h",
        "local_include_dir_2/local_include_dir_2_a.h",
        "local_include_dir_2/local_include_dir_2_b.h",
    ],
)`, `cc_library_static(
    name = "static_lib_2",
    hdrs = [
        "implicit_include_1.h",
        "implicit_include_2.h",
    ],
    includes = ["."],
    copts = ["-I."],
    linkstatic = True,
    srcs = [
        "static_lib_2.cc",
        "implicit_include_1.h",
        "implicit_include_2.h",
        "export_include_dir_1/export_include_dir_1_a.h",
        "export_include_dir_1/export_include_dir_1_b.h",
        "export_include_dir_2/export_include_dir_2_a.h",
        "export_include_dir_2/export_include_dir_2_b.h",
        "include_dir_1/include_dir_1_a.h",
        "include_dir_1/include_dir_1_b.h",
        "include_dir_2/include_dir_2_a.h",
        "include_dir_2/include_dir_2_b.h",
        "local_include_dir_1/local_include_dir_1_a.h",
        "local_include_dir_1/local_include_dir_1_b.h",
        "local_include_dir_2/local_include_dir_2_a.h",
        "local_include_dir_2/local_include_dir_2_b.h",
    ],
)`, `cc_library_static(
    name = "whole_static_lib_1",
    hdrs = [
        "implicit_include_1.h",
        "implicit_include_2.h",
    ],
    includes = ["."],
    copts = ["-I."],
    linkstatic = True,
    srcs = [
        "whole_static_lib_1.cc",
        "implicit_include_1.h",
        "implicit_include_2.h",
        "export_include_dir_1/export_include_dir_1_a.h",
        "export_include_dir_1/export_include_dir_1_b.h",
        "export_include_dir_2/export_include_dir_2_a.h",
        "export_include_dir_2/export_include_dir_2_b.h",
        "include_dir_1/include_dir_1_a.h",
        "include_dir_1/include_dir_1_b.h",
        "include_dir_2/include_dir_2_a.h",
        "include_dir_2/include_dir_2_b.h",
        "local_include_dir_1/local_include_dir_1_a.h",
        "local_include_dir_1/local_include_dir_1_b.h",
        "local_include_dir_2/local_include_dir_2_a.h",
        "local_include_dir_2/local_include_dir_2_b.h",
    ],
)`, `cc_library_static(
    name = "whole_static_lib_2",
    hdrs = [
        "implicit_include_1.h",
        "implicit_include_2.h",
    ],
    includes = ["."],
    copts = ["-I."],
    linkstatic = True,
    srcs = [
        "whole_static_lib_2.cc",
        "implicit_include_1.h",
        "implicit_include_2.h",
        "export_include_dir_1/export_include_dir_1_a.h",
        "export_include_dir_1/export_include_dir_1_b.h",
        "export_include_dir_2/export_include_dir_2_a.h",
        "export_include_dir_2/export_include_dir_2_b.h",
        "include_dir_1/include_dir_1_a.h",
        "include_dir_1/include_dir_1_b.h",
        "include_dir_2/include_dir_2_a.h",
        "include_dir_2/include_dir_2_b.h",
        "local_include_dir_1/local_include_dir_1_a.h",
        "local_include_dir_1/local_include_dir_1_b.h",
        "local_include_dir_2/local_include_dir_2_a.h",
        "local_include_dir_2/local_include_dir_2_b.h",
    ],
)`},
		},
@@ -306,14 +334,12 @@ cc_library_static {
    include_dirs: [
	"subpackage",
    ],

    bazel_module: { bp2build_available: true },
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    includes = [
        "subpackage",
        ".",
    copts = [
        "-Isubpackage",
        "-I.",
    ],
    linkstatic = True,
    srcs = [
@@ -324,6 +350,299 @@ cc_library_static {
        "//subpackage/subsubpackage/subsubsubpackage:subsubsubpackage_header.h",
        "//subpackage/subsubpackage/subsubsubpackage:subdirectory/subdirectory_header.h",
    ],
)`},
		},
		{
			description:                        "cc_library_static export include dir",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			filesystem: map[string]string{
				// subpackage with subdirectory
				"subpackage/Android.bp":                         "",
				"subpackage/subpackage_header.h":                "",
				"subpackage/subdirectory/subdirectory_header.h": "",
			},
			bp: soongCcLibraryStaticPreamble + `
cc_library_static {
    name: "foo_static",
    export_include_dirs: ["subpackage"],
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = ["-I."],
    hdrs = [
        "//subpackage:subdirectory/subdirectory_header.h",
        "//subpackage:subpackage_header.h",
    ],
    includes = ["subpackage"],
    linkstatic = True,
    srcs = [
        "//subpackage:subpackage_header.h",
        "//subpackage:subdirectory/subdirectory_header.h",
    ],
)`},
		},
		{
			description:                        "cc_library_static export system include dir",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			filesystem: map[string]string{
				// subpackage with subdirectory
				"subpackage/Android.bp":                         "",
				"subpackage/subpackage_header.h":                "",
				"subpackage/subdirectory/subdirectory_header.h": "",
			},
			bp: soongCcLibraryStaticPreamble + `
cc_library_static {
    name: "foo_static",
    export_system_include_dirs: ["subpackage"],
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = ["-I."],
    hdrs = [
        "//subpackage:subdirectory/subdirectory_header.h",
        "//subpackage:subpackage_header.h",
    ],
    includes = ["subpackage"],
    linkstatic = True,
    srcs = [
        "//subpackage:subpackage_header.h",
        "//subpackage:subdirectory/subdirectory_header.h",
    ],
)`},
		},
		{
			description:                        "cc_library_static include_dirs, local_include_dirs, export_include_dirs (b/183742505)",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			dir:                                "subpackage",
			filesystem: map[string]string{
				// subpackage with subdirectory
				"subpackage/Android.bp": `
cc_library_static {
    name: "foo_static",
    // include_dirs are workspace/root relative
    include_dirs: [
        "subpackage/subsubpackage",
        "subpackage2",
        "subpackage3/subsubpackage"
    ],
    local_include_dirs: ["subsubpackage2"], // module dir relative
    export_include_dirs: ["./exported_subsubpackage"], // module dir relative
    include_build_directory: true,
    bazel_module: { bp2build_available: true },
}`,
				"subpackage/subsubpackage/header.h":          "",
				"subpackage/subsubpackage2/header.h":         "",
				"subpackage/exported_subsubpackage/header.h": "",
				"subpackage2/header.h":                       "",
				"subpackage3/subsubpackage/header.h":         "",
			},
			bp: soongCcLibraryStaticPreamble,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = [
        "-Isubpackage/subsubpackage",
        "-Isubpackage2",
        "-Isubpackage3/subsubpackage",
        "-Isubpackage/subsubpackage2",
        "-Isubpackage",
    ],
    hdrs = ["exported_subsubpackage/header.h"],
    includes = ["./exported_subsubpackage"],
    linkstatic = True,
    srcs = [
        "exported_subsubpackage/header.h",
        "subsubpackage/header.h",
        "subsubpackage2/header.h",
    ],
)`},
		},
		{
			description:                        "cc_library_static include_build_directory disabled",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			filesystem: map[string]string{
				// subpackage with subdirectory
				"subpackage/Android.bp":                         "",
				"subpackage/subpackage_header.h":                "",
				"subpackage/subdirectory/subdirectory_header.h": "",
			},
			bp: soongCcLibraryStaticPreamble + `
cc_library_static {
    name: "foo_static",
    include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
    local_include_dirs: ["subpackage2"],
    include_build_directory: false,
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = [
        "-Isubpackage",
        "-Isubpackage2",
    ],
    linkstatic = True,
)`},
		},
		{
			description:                        "cc_library_static include_build_directory enabled",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			filesystem: map[string]string{
				// subpackage with subdirectory
				"subpackage/Android.bp":                         "",
				"subpackage/subpackage_header.h":                "",
				"subpackage2/Android.bp":                        "",
				"subpackage2/subpackage2_header.h":              "",
				"subpackage/subdirectory/subdirectory_header.h": "",
			},
			bp: soongCcLibraryStaticPreamble + `
cc_library_static {
    name: "foo_static",
    include_dirs: ["subpackage"], // still used, but local_include_dirs is recommended
    local_include_dirs: ["subpackage2"],
    include_build_directory: true,
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = [
        "-Isubpackage",
        "-Isubpackage2",
        "-I.",
    ],
    linkstatic = True,
    srcs = [
        "//subpackage:subpackage_header.h",
        "//subpackage:subdirectory/subdirectory_header.h",
        "//subpackage2:subpackage2_header.h",
    ],
)`},
		},
		{
			description:                        "cc_library_static arch-specific static_libs",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			depsMutators:                       []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
			filesystem:                         map[string]string{},
			bp: soongCcLibraryStaticPreamble + `
cc_library_static { name: "static_dep" }
cc_library_static { name: "static_dep2" }
cc_library_static {
    name: "foo_static",
    arch: { arm64: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = ["-I."],
    deps = select({
        "//build/bazel/platforms/arch:arm64": [
            ":static_dep",
            ":static_dep2",
        ],
        "//conditions:default": [],
    }),
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep",
    copts = ["-I."],
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep2",
    copts = ["-I."],
    linkstatic = True,
)`},
		},
		{
			description:                        "cc_library_static os-specific static_libs",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			depsMutators:                       []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
			filesystem:                         map[string]string{},
			bp: soongCcLibraryStaticPreamble + `
cc_library_static { name: "static_dep" }
cc_library_static { name: "static_dep2" }
cc_library_static {
    name: "foo_static",
    target: { android: { static_libs: ["static_dep"], whole_static_libs: ["static_dep2"] } },
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = ["-I."],
    deps = select({
        "//build/bazel/platforms/os:android": [
            ":static_dep",
            ":static_dep2",
        ],
        "//conditions:default": [],
    }),
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep",
    copts = ["-I."],
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep2",
    copts = ["-I."],
    linkstatic = True,
)`},
		},
		{
			description:                        "cc_library_static base, arch and os-specific static_libs",
			moduleTypeUnderTest:                "cc_library_static",
			moduleTypeUnderTestFactory:         cc.LibraryStaticFactory,
			moduleTypeUnderTestBp2BuildMutator: cc.CcLibraryStaticBp2Build,
			depsMutators:                       []android.RegisterMutatorFunc{cc.RegisterDepsBp2Build},
			filesystem:                         map[string]string{},
			bp: soongCcLibraryStaticPreamble + `
cc_library_static { name: "static_dep" }
cc_library_static { name: "static_dep2" }
cc_library_static { name: "static_dep3" }
cc_library_static { name: "static_dep4" }
cc_library_static {
    name: "foo_static",
    static_libs: ["static_dep"],
    whole_static_libs: ["static_dep2"],
    target: { android: { static_libs: ["static_dep3"] } },
    arch: { arm64: { static_libs: ["static_dep4"] } },
}`,
			expectedBazelTargets: []string{`cc_library_static(
    name = "foo_static",
    copts = ["-I."],
    deps = [
        ":static_dep",
        ":static_dep2",
    ] + select({
        "//build/bazel/platforms/arch:arm64": [":static_dep4"],
        "//conditions:default": [],
    }) + select({
        "//build/bazel/platforms/os:android": [":static_dep3"],
        "//conditions:default": [],
    }),
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep",
    copts = ["-I."],
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep2",
    copts = ["-I."],
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep3",
    copts = ["-I."],
    linkstatic = True,
)`, `cc_library_static(
    name = "static_dep4",
    copts = ["-I."],
    linkstatic = True,
)`},
		},
	}
@@ -352,6 +671,7 @@ cc_library_static {
			ctx.DepsBp2BuildMutators(m)
		}
		ctx.RegisterBp2BuildMutator(testCase.moduleTypeUnderTest, testCase.moduleTypeUnderTestBp2BuildMutator)
		ctx.RegisterBp2BuildConfig(bp2buildConfig)
		ctx.RegisterForBazelConversion()

		_, errs := ctx.ParseFileList(dir, toParse)
Loading