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

Commit 9fa7e806 authored by Rashed Abdel-Tawab's avatar Rashed Abdel-Tawab Committed by Rashed Abdel-Tawab
Browse files

lineage: Dynamically generate kernel headers using lineage generator

Add a soong vendor plugin for kernel config variables so we can use
these in go.

Change-Id: Id31f2be8fcc5aba2d965dbe815edaaf1d28279c6
parent 80381b73
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -19,6 +19,28 @@ bootstrap_go_package {
    ],
    srcs: [
        "generator/generator.go",
        "generator/variables.go",
    ],
    pluginFor: ["soong_build"],
}

lineage_generator {
    name: "generated_kernel_includes",

    // The headers make command
    cmd: "make $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_SOURCE) O=$(genDir) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) headers_install",

    // Directories that can be imported by a cc_* module generated_headers property
    export_include_dirs: ["usr/include"],

    // Sources for dependency tracking
    dep_root: "$(TARGET_KERNEL_SOURCE)",
    dep_files: [ "Makefile", "include/**/*", "arch/$(KERNEL_ARCH)/include/**/*"],
}

cc_library_headers {
    name: "generated_kernel_headers",
    generated_headers: ["generated_kernel_includes"],
    export_generated_headers: ["generated_kernel_includes"],
    vendor_available: true,
}
+4 −1
Original line number Diff line number Diff line
@@ -213,10 +213,13 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	depRoot := String(g.properties.Dep_root)
	if depRoot == "" {
		depRoot = ctx.ModuleDir()
	} else {
		depRoot = lineageExpandVariables(ctx, depRoot)
	}

	// Glob dep_files property
	for _, dep_file := range g.properties.Dep_files {
		dep_file = lineageExpandVariables(ctx, dep_file)
		globPath := filepath.Join(depRoot, dep_file)
		paths, err := ctx.GlobWithDeps(globPath, nil)
		if err != nil {
@@ -228,7 +231,7 @@ func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		}
	}

	cmd := String(g.properties.Cmd)
	cmd := lineageExpandVariables(ctx, String(g.properties.Cmd))

	rawCommand, err := android.Expand(cmd, func(name string) (string, error) {
		switch name {
+28 −0
Original line number Diff line number Diff line
package generator

import (
	"fmt"

	"android/soong/android"
)

func lineageExpandVariables(ctx android.ModuleContext, in string) string {
	lineageVars := ctx.Config().VendorConfig("lineageVarsPlugin")

	out, err := android.Expand(in, func(name string) (string, error) {
		if lineageVars.IsSet(name) {
			return lineageVars.String(name), nil
		}
		// This variable is not for us, restore what the original
		// variable string will have looked like for an Expand
		// that comes later.
		return fmt.Sprintf("$(%s)", name), nil
	})

	if err != nil {
		ctx.PropertyErrorf("%s: %s", in, err.Error())
		return ""
	}

	return out
}
+2 −0
Original line number Diff line number Diff line
@@ -8,3 +8,5 @@ include vendor/lineage/config/BoardConfigKernel.mk
ifeq ($(BOARD_USES_QCOM_HARDWARE),true)
include vendor/lineage/config/BoardConfigQcom.mk
endif

include vendor/lineage/config/BoardConfigSoong.mk
+22 −0
Original line number Diff line number Diff line
# Add variables that we wish to make available to soong here.
EXPORT_TO_SOONG := \
    KERNEL_ARCH \
    KERNEL_CROSS_COMPILE \
    KERNEL_MAKE_FLAGS \
    TARGET_KERNEL_CONFIG \
    TARGET_KERNEL_SOURCE

# Setup SOONG_CONFIG_* vars to export the vars listed above.
# Documentation here:
# https://github.com/LineageOS/android_build_soong/commit/8328367c44085b948c003116c0ed74a047237a69

SOONG_CONFIG_NAMESPACES += lineageVarsPlugin

SOONG_CONFIG_lineageVarsPlugin :=

define addVar
  SOONG_CONFIG_lineageVarsPlugin += $(1)
  SOONG_CONFIG_lineageVarsPlugin_$(1) := $$(subst ",\",$$($1))
endef

$(foreach v,$(EXPORT_TO_SOONG),$(eval $(call addVar,$(v))))