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

Commit d5781347 authored by Dan Willemsen's avatar Dan Willemsen
Browse files

Export cc_library_headers as BUILD_HEADER_LIBRARY

And support the reverse translation in androidmk.

Test: Use a cc_library_headers using LOCAL_HEADER_LIBRARIES in make
Test: androidmk with LOCAL_HEADER_LIBRARIES
Test: androidmk with soong's Android-*.mk file for BUILD_HEADER_LIBRARIES
Change-Id: I17adedb62151f62e67e2168b09ad87f1d5648df6
parent 44988795
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ var standardProperties = map[string]struct {
	"LOCAL_STATIC_LIBRARIES":              {"static_libs", bpparser.ListType},
	"LOCAL_WHOLE_STATIC_LIBRARIES":        {"whole_static_libs", bpparser.ListType},
	"LOCAL_SYSTEM_SHARED_LIBRARIES":       {"system_shared_libs", bpparser.ListType},
	"LOCAL_HEADER_LIBRARIES":              {"header_libs", bpparser.ListType},
	"LOCAL_ASFLAGS":                       {"asflags", bpparser.ListType},
	"LOCAL_CLANG_ASFLAGS":                 {"clang_asflags", bpparser.ListType},
	"LOCAL_CFLAGS":                        {"cflags", bpparser.ListType},
@@ -572,6 +573,7 @@ var moduleTypes = map[string]string{
	"BUILD_STATIC_LIBRARY":        "cc_library_static",
	"BUILD_HOST_SHARED_LIBRARY":   "cc_library_host_shared",
	"BUILD_HOST_STATIC_LIBRARY":   "cc_library_host_static",
	"BUILD_HEADER_LIBRARY":        "cc_library_headers",
	"BUILD_EXECUTABLE":            "cc_binary",
	"BUILD_HOST_EXECUTABLE":       "cc_binary_host",
	"BUILD_NATIVE_TEST":           "cc_test",
+45 −12
Original line number Diff line number Diff line
@@ -81,18 +81,7 @@ func (c *Module) AndroidMk() (ret android.AndroidMkData, err error) {
}

func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
	if library.shared() {
		ctx.subAndroidMk(ret, &library.stripper)
		ctx.subAndroidMk(ret, &library.relocationPacker)
	}

	if library.static() || library.header() {
		ret.Class = "STATIC_LIBRARIES"
	} else if library.shared() {
		ret.Class = "SHARED_LIBRARIES"
	}

	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
	writeExportedIncludes := func(w io.Writer) {
		var exportedIncludes []string
		for _, flag := range library.exportedFlags() {
			if strings.HasPrefix(flag, "-I") {
@@ -106,6 +95,50 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
		if len(exportedIncludeDeps) > 0 {
			fmt.Fprintln(w, "LOCAL_EXPORT_C_INCLUDE_DEPS :=", strings.Join(exportedIncludeDeps.Strings(), " "))
		}
	}

	if library.static() {
		ret.Class = "STATIC_LIBRARIES"
	} else if library.shared() {
		ctx.subAndroidMk(ret, &library.stripper)
		ctx.subAndroidMk(ret, &library.relocationPacker)

		ret.Class = "SHARED_LIBRARIES"
	} else if library.header() {
		ret.Custom = func(w io.Writer, name, prefix, moduleDir string) error {
			fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
			fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
			fmt.Fprintln(w, "LOCAL_MODULE :=", name)

			archStr := ctx.Target().Arch.ArchType.String()
			var host bool
			switch ctx.Target().Os.Class {
			case android.Host:
				fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH := ", archStr)
				host = true
			case android.HostCross:
				fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH := ", archStr)
				host = true
			case android.Device:
				fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH := ", archStr)
			}

			if host {
				fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", ctx.Target().Os.String())
				fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
			}

			writeExportedIncludes(w)
			fmt.Fprintln(w, "include $(BUILD_HEADER_LIBRARY)")

			return nil
		}

		return
	}

	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
		writeExportedIncludes(w)

		fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+outputFile.Ext())