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

Commit 21f26907 authored by Inseob Kim's avatar Inseob Kim
Browse files

Add support for sysprop description files to c++

From now on, a c++ shared library can be built only with adding
".sysprop" description file to srcs. Sysprop library generator will
automatically generate a .cpp and .h files, and the header file will be
exposed to any clients linking against the shared library. For the full
schema of description file, see system/tools/sysprop/sysprop.proto.

Bug: 80125326
Test: 1) write a .sysprop description file.
2) create cc_library_shared and add description file to srcs.
3) create another module, link against library of 2), include generated
header, and access generated sysprop functions
4) see compile succeeded.

Change-Id: I95005a0724aeb8f11a856b7aee92787a16a5374d
parent 55e095b6
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -224,6 +224,10 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
		deps = protoDeps(ctx, deps, &compiler.Proto, Bool(compiler.Properties.Proto.Static))
	}

	if compiler.hasSrcExt(".sysprop") {
		deps.SharedLibs = append(deps.SharedLibs, "libbase")
	}

	if Bool(compiler.Properties.Openmp) {
		deps.StaticLibs = append(deps.StaticLibs, "libomp")
	}
@@ -489,6 +493,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
		flags = rsFlags(ctx, flags, &compiler.Properties)
	}

	if compiler.hasSrcExt(".sysprop") {
		flags.GlobalFlags = append(flags.GlobalFlags,
			"-I"+android.PathForModuleGen(ctx, "sysprop", "include").String())
	}

	if len(compiler.Properties.Srcs) > 0 {
		module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
		if inList("-Wno-error", flags.CFlags) || inList("-Wno-error", flags.CppFlags) {
+34 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package cc
// functions.

import (
	"path/filepath"

	"github.com/google/blueprint"

	"android/soong/android"
@@ -30,6 +32,7 @@ func init() {
	pctx.SourcePathVariable("yaccDataDir", "prebuilts/build-tools/common/bison")

	pctx.HostBinToolVariable("aidlCmd", "aidl-cpp")
	pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp")
}

var (
@@ -55,6 +58,13 @@ var (
		},
		"aidlFlags", "outDir")

	sysprop = pctx.AndroidStaticRule("sysprop",
		blueprint.RuleParams{
			Command:     "$syspropCmd --header-output-dir=$headerOutDir --source-output-dir=$srcOutDir --include-name=$includeName $in",
			CommandDeps: []string{"$syspropCmd"},
		},
		"headerOutDir", "srcOutDir", "includeName")

	windmc = pctx.AndroidStaticRule("windmc",
		blueprint.RuleParams{
			Command:     "$windmcCmd -r$$(dirname $out) -h$$(dirname $out) $in",
@@ -82,7 +92,6 @@ func genYacc(ctx android.ModuleContext, yaccFile android.Path, outFile android.M
}

func genAidl(ctx android.ModuleContext, aidlFile android.Path, outFile android.ModuleGenPath, aidlFlags string) android.Paths {

	ctx.Build(pctx, android.BuildParams{
		Rule:        aidl,
		Description: "aidl " + aidlFile.Rel(),
@@ -107,6 +116,26 @@ func genLex(ctx android.ModuleContext, lexFile android.Path, outFile android.Mod
	})
}

func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Path, android.Path) {
	headerFile := android.PathForModuleGen(ctx, "sysprop", "include", syspropFile.Rel()+".h")
	cppFile := android.PathForModuleGen(ctx, "sysprop", syspropFile.Rel()+".cpp")

	ctx.Build(pctx, android.BuildParams{
		Rule:           sysprop,
		Description:    "sysprop " + syspropFile.Rel(),
		Output:         cppFile,
		ImplicitOutput: headerFile,
		Input:          syspropFile,
		Args: map[string]string{
			"headerOutDir": filepath.Dir(headerFile.String()),
			"srcOutDir":    filepath.Dir(cppFile.String()),
			"includeName":  syspropFile.Rel() + ".h",
		},
	})

	return cppFile, headerFile
}

func genWinMsg(ctx android.ModuleContext, srcFile android.Path, flags builderFlags) (android.Path, android.Path) {
	headerFile := android.GenPathWithExt(ctx, "windmc", srcFile, "h")
	rcFile := android.GenPathWithExt(ctx, "windmc", srcFile, "rc")
@@ -169,6 +198,10 @@ func genSources(ctx android.ModuleContext, srcFiles android.Paths,
			rcFile, headerFile := genWinMsg(ctx, srcFile, buildFlags)
			srcFiles[i] = rcFile
			deps = append(deps, headerFile)
		case ".sysprop":
			cppFile, headerFile := genSysprop(ctx, srcFile)
			srcFiles[i] = cppFile
			deps = append(deps, headerFile)
		}
	}

+8 −0
Original line number Diff line number Diff line
@@ -678,6 +678,14 @@ func (library *libraryDecorator) link(ctx ModuleContext,
		}
	}

	if library.baseCompiler.hasSrcExt(".sysprop") {
		flags := []string{
			"-I" + android.PathForModuleGen(ctx, "sysprop", "include").String(),
		}
		library.reexportFlags(flags)
		library.reuseExportedFlags = append(library.reuseExportedFlags, flags...)
	}

	return out
}