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
diff --git a/cc/gen.go b/cc/gen.go
index 487f662..29a2bb2 100644
--- a/cc/gen.go
+++ b/cc/gen.go
@@ -19,6 +19,8 @@
// functions.
import (
+ "path/filepath"
+
"github.com/google/blueprint"
"android/soong/android"
@@ -30,6 +32,7 @@
pctx.SourcePathVariable("yaccDataDir", "prebuilts/build-tools/common/bison")
pctx.HostBinToolVariable("aidlCmd", "aidl-cpp")
+ pctx.HostBinToolVariable("syspropCmd", "sysprop_cpp")
}
var (
@@ -55,6 +58,13 @@
},
"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 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 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 @@
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)
}
}