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

Commit ef9c900e authored by Trevor Radcliffe's avatar Trevor Radcliffe
Browse files

Generate genlex rules from bp2build for cc targets

This change will cause bp2build to generate genlex targets any
time a .l or .ll file is present in the srcs for a cc target and
add those genlex targets to the srcs attribute of the original
target.

Bug: 207408632
Test: unit tests
Change-Id: I1bce82c9d3c3d458eae1cef547ffae3d6e975134
parent 91f10ecc
Loading
Loading
Loading
Loading
+8 −10
Original line number Original line Diff line number Diff line
@@ -310,7 +310,6 @@ var (


	Bp2buildModuleDoNotConvertList = []string{
	Bp2buildModuleDoNotConvertList = []string{
		// cc bugs
		// cc bugs
		"libsepol",                                  // TODO(b/207408632): Unsupported case of .l sources in cc library rules
		"libactivitymanager_aidl",                   // TODO(b/207426160): Unsupported use of aidl sources (via Dactivity_manager_procstate_aidl) in a cc_library
		"libactivitymanager_aidl",                   // TODO(b/207426160): Unsupported use of aidl sources (via Dactivity_manager_procstate_aidl) in a cc_library
		"gen-kotlin-build-file.py",                  // TODO(b/198619163) module has same name as source
		"gen-kotlin-build-file.py",                  // TODO(b/198619163) module has same name as source
		"libgtest_ndk_c++", "libgtest_main_ndk_c++", // TODO(b/201816222): Requires sdk_version support.
		"libgtest_ndk_c++", "libgtest_main_ndk_c++", // TODO(b/201816222): Requires sdk_version support.
@@ -371,7 +370,6 @@ var (
		"apex_manifest_proto_java",                                   // b/210751803, depends on libprotobuf-java-full
		"apex_manifest_proto_java",                                   // b/210751803, depends on libprotobuf-java-full
		"art-script",                                                 // depends on unconverted modules: dalvikvm, dex2oat
		"art-script",                                                 // depends on unconverted modules: dalvikvm, dex2oat
		"bin2c_fastdeployagent",                                      // depends on unconverted modules: deployagent
		"bin2c_fastdeployagent",                                      // depends on unconverted modules: deployagent
		"chkcon", "sefcontext_compile", // depends on unconverted modules: libsepol
		"com.android.runtime",                                        // depends on unconverted modules: bionic-linker-config, linkerconfig
		"com.android.runtime",                                        // depends on unconverted modules: bionic-linker-config, linkerconfig
		"conv_linker_config",                                         // depends on unconverted modules: linker_config_proto
		"conv_linker_config",                                         // depends on unconverted modules: linker_config_proto
		"currysrc",                                                   // depends on unconverted modules: currysrc_org.eclipse, guavalib, jopt-simple-4.9
		"currysrc",                                                   // depends on unconverted modules: currysrc_org.eclipse, guavalib, jopt-simple-4.9
+1 −1
Original line number Original line Diff line number Diff line
@@ -628,7 +628,7 @@ func addCommandForPyBinaryRunfilesDir(oldCommand string, zipperCommandPath, zipF
}
}


func isSymlinkAction(a action) bool {
func isSymlinkAction(a action) bool {
	return a.Mnemonic == "Symlink" || a.Mnemonic == "SolibSymlink"
	return a.Mnemonic == "Symlink" || a.Mnemonic == "SolibSymlink" || a.Mnemonic == "ExecutableSymlink"
}
}


func isTemplateExpandAction(a action) bool {
func isTemplateExpandAction(a action) bool {
+47 −1
Original line number Original line Diff line number Diff line
@@ -86,7 +86,7 @@ func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
	testCase := tc
	testCase := tc
	for i, tar := range testCase.targets {
	for i, tar := range testCase.targets {
		switch tar.typ {
		switch tar.typ {
		case "cc_binary", "proto_library", "cc_lite_proto_library":
		case "cc_binary", "proto_library", "cc_lite_proto_library", "genlex":
			tar.attrs["target_compatible_with"] = `select({
			tar.attrs["target_compatible_with"] = `select({
        "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
        "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
        "//conditions:default": [],
        "//conditions:default": [],
@@ -505,3 +505,49 @@ func TestCcBinaryStaticProto(t *testing.T) {
		},
		},
	})
	})
}
}

func TestCcBinaryConvertLex(t *testing.T) {
	runCcBinaryTests(t, ccBinaryBp2buildTestCase{
		description: `.l and .ll sources converted to .c and .cc`,
		blueprint: `
{rule_name} {
    name: "foo",
		srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
		lex: { flags: ["--foo_opt", "--bar_opt"] },
		include_build_directory: false,
}
`,
		targets: []testBazelTarget{
			{"genlex", "foo_genlex_l", attrNameToString{
				"srcs": `[
        "foo1.l",
        "foo2.l",
    ]`,
				"lexopts": `[
        "--foo_opt",
        "--bar_opt",
    ]`,
			}},
			{"genlex", "foo_genlex_ll", attrNameToString{
				"srcs": `[
        "bar1.ll",
        "bar2.ll",
    ]`,
				"lexopts": `[
        "--foo_opt",
        "--bar_opt",
    ]`,
			}},
			{"cc_binary", "foo", attrNameToString{
				"srcs": `[
        "bar.cc",
        ":foo_genlex_ll",
    ]`,
				"srcs_c": `[
        "foo.c",
        ":foo_genlex_l",
    ]`,
			}},
		},
	})
}
+48 −0
Original line number Original line Diff line number Diff line
@@ -2457,3 +2457,51 @@ func TestCcLibraryEscapeLdflags(t *testing.T) {
		}),
		}),
	})
	})
}
}

func TestCcLibraryConvertLex(t *testing.T) {
	runCcLibraryTestCase(t, bp2buildTestCase{
		moduleTypeUnderTest:        "cc_library",
		moduleTypeUnderTestFactory: cc.LibraryFactory,
		filesystem: map[string]string{
			"foo.c":   "",
			"bar.cc":  "",
			"foo1.l":  "",
			"bar1.ll": "",
			"foo2.l":  "",
			"bar2.ll": "",
		},
		blueprint: `cc_library {
	name: "foo_lib",
	srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
	lex: { flags: ["--foo_flags"] },
	include_build_directory: false,
	bazel_module: { bp2build_available: true },
}`,
		expectedBazelTargets: append([]string{
			makeBazelTarget("genlex", "foo_lib_genlex_l", attrNameToString{
				"srcs": `[
        "foo1.l",
        "foo2.l",
    ]`,
				"lexopts": `["--foo_flags"]`,
			}),
			makeBazelTarget("genlex", "foo_lib_genlex_ll", attrNameToString{
				"srcs": `[
        "bar1.ll",
        "bar2.ll",
    ]`,
				"lexopts": `["--foo_flags"]`,
			}),
		},
			makeCcLibraryTargets("foo_lib", attrNameToString{
				"srcs": `[
        "bar.cc",
        ":foo_lib_genlex_ll",
    ]`,
				"srcs_c": `[
        "foo.c",
        ":foo_lib_genlex_l",
    ]`,
			})...),
	})
}
+49 −0
Original line number Original line Diff line number Diff line
@@ -520,3 +520,52 @@ cc_library_shared {
		})},
		})},
	})
	})
}
}

func TestCcLibrarySharedConvertLex(t *testing.T) {
	runCcLibrarySharedTestCase(t, bp2buildTestCase{
		description:                "cc_library_shared with lex files",
		moduleTypeUnderTest:        "cc_library_shared",
		moduleTypeUnderTestFactory: cc.LibrarySharedFactory,
		filesystem: map[string]string{
			"foo.c":   "",
			"bar.cc":  "",
			"foo1.l":  "",
			"bar1.ll": "",
			"foo2.l":  "",
			"bar2.ll": "",
		},
		blueprint: `cc_library_shared {
	name: "foo_lib",
	srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
	lex: { flags: ["--foo_flags"] },
	include_build_directory: false,
	bazel_module: { bp2build_available: true },
}`,
		expectedBazelTargets: []string{
			makeBazelTarget("genlex", "foo_lib_genlex_l", attrNameToString{
				"srcs": `[
        "foo1.l",
        "foo2.l",
    ]`,
				"lexopts": `["--foo_flags"]`,
			}),
			makeBazelTarget("genlex", "foo_lib_genlex_ll", attrNameToString{
				"srcs": `[
        "bar1.ll",
        "bar2.ll",
    ]`,
				"lexopts": `["--foo_flags"]`,
			}),
			makeBazelTarget("cc_library_shared", "foo_lib", attrNameToString{
				"srcs": `[
        "bar.cc",
        ":foo_lib_genlex_ll",
    ]`,
				"srcs_c": `[
        "foo.c",
        ":foo_lib_genlex_l",
    ]`,
			}),
		},
	})
}
Loading