Merge "Support source code cross-referencing for C++ and Java"
This commit is contained in:
@@ -221,6 +221,17 @@ var (
|
||||
Rspfile: "$out.rsp",
|
||||
RspfileContent: "$in",
|
||||
})
|
||||
|
||||
_ = pctx.SourcePathVariable("cxxExtractor",
|
||||
"prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/cxx_extractor")
|
||||
_ = pctx.VariableFunc("kytheCorpus",
|
||||
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() })
|
||||
kytheExtract = pctx.StaticRule("kythe",
|
||||
blueprint.RuleParams{
|
||||
Command: "rm -f $out && KYTHE_CORPUS=${kytheCorpus} KYTHE_OUTPUT_FILE=$out $cxxExtractor $cFlags $in ",
|
||||
CommandDeps: []string{"$cxxExtractor"},
|
||||
},
|
||||
"cFlags")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -257,6 +268,7 @@ type builderFlags struct {
|
||||
tidy bool
|
||||
coverage bool
|
||||
sAbiDump bool
|
||||
emitXrefs bool
|
||||
|
||||
systemIncludeFlags string
|
||||
|
||||
@@ -281,6 +293,7 @@ type Objects struct {
|
||||
tidyFiles android.Paths
|
||||
coverageFiles android.Paths
|
||||
sAbiDumpFiles android.Paths
|
||||
kytheFiles android.Paths
|
||||
}
|
||||
|
||||
func (a Objects) Copy() Objects {
|
||||
@@ -289,6 +302,7 @@ func (a Objects) Copy() Objects {
|
||||
tidyFiles: append(android.Paths{}, a.tidyFiles...),
|
||||
coverageFiles: append(android.Paths{}, a.coverageFiles...),
|
||||
sAbiDumpFiles: append(android.Paths{}, a.sAbiDumpFiles...),
|
||||
kytheFiles: append(android.Paths{}, a.kytheFiles...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,6 +312,7 @@ func (a Objects) Append(b Objects) Objects {
|
||||
tidyFiles: append(a.tidyFiles, b.tidyFiles...),
|
||||
coverageFiles: append(a.coverageFiles, b.coverageFiles...),
|
||||
sAbiDumpFiles: append(a.sAbiDumpFiles, b.sAbiDumpFiles...),
|
||||
kytheFiles: append(a.kytheFiles, b.kytheFiles...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,6 +329,10 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
||||
if flags.coverage {
|
||||
coverageFiles = make(android.Paths, 0, len(srcFiles))
|
||||
}
|
||||
var kytheFiles android.Paths
|
||||
if flags.emitXrefs {
|
||||
kytheFiles = make(android.Paths, 0, len(srcFiles))
|
||||
}
|
||||
|
||||
commonFlags := strings.Join([]string{
|
||||
flags.globalFlags,
|
||||
@@ -401,6 +420,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
||||
coverage := flags.coverage
|
||||
dump := flags.sAbiDump
|
||||
rule := cc
|
||||
emitXref := flags.emitXrefs
|
||||
|
||||
switch srcFile.Ext() {
|
||||
case ".s":
|
||||
@@ -412,6 +432,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
||||
tidy = false
|
||||
coverage = false
|
||||
dump = false
|
||||
emitXref = false
|
||||
case ".c":
|
||||
ccCmd = "clang"
|
||||
moduleCflags = cflags
|
||||
@@ -450,6 +471,22 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
||||
},
|
||||
})
|
||||
|
||||
if emitXref {
|
||||
kytheFile := android.ObjPathWithExt(ctx, subdir, srcFile, "kzip")
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: kytheExtract,
|
||||
Description: "Xref C++ extractor " + srcFile.Rel(),
|
||||
Output: kytheFile,
|
||||
Input: srcFile,
|
||||
Implicits: cFlagsDeps,
|
||||
OrderOnly: pathDeps,
|
||||
Args: map[string]string{
|
||||
"cFlags": moduleCflags,
|
||||
},
|
||||
})
|
||||
kytheFiles = append(kytheFiles, kytheFile)
|
||||
}
|
||||
|
||||
if tidy {
|
||||
tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy")
|
||||
tidyFiles = append(tidyFiles, tidyFile)
|
||||
@@ -493,6 +530,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
||||
tidyFiles: tidyFiles,
|
||||
coverageFiles: coverageFiles,
|
||||
sAbiDumpFiles: sAbiDumpFiles,
|
||||
kytheFiles: kytheFiles,
|
||||
}
|
||||
}
|
||||
|
||||
|
39
cc/cc.go
39
cc/cc.go
@@ -77,6 +77,7 @@ func init() {
|
||||
ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
|
||||
})
|
||||
|
||||
android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
|
||||
pctx.Import("android/soong/cc/config")
|
||||
}
|
||||
|
||||
@@ -162,6 +163,7 @@ type Flags struct {
|
||||
Tidy bool
|
||||
Coverage bool
|
||||
SAbiDump bool
|
||||
EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
|
||||
|
||||
RequiredInstructionSet string
|
||||
DynamicLinker string
|
||||
@@ -346,6 +348,10 @@ type dependencyTag struct {
|
||||
explicitlyVersioned bool
|
||||
}
|
||||
|
||||
type xref interface {
|
||||
XrefCcFiles() android.Paths
|
||||
}
|
||||
|
||||
var (
|
||||
sharedDepTag = dependencyTag{name: "shared", library: true}
|
||||
sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
|
||||
@@ -427,6 +433,8 @@ type Module struct {
|
||||
staticVariant *Module
|
||||
|
||||
makeLinkType string
|
||||
// Kythe (source file indexer) paths for this compilation module
|
||||
kytheFiles android.Paths
|
||||
}
|
||||
|
||||
func (c *Module) OutputFile() android.OptionalPath {
|
||||
@@ -657,6 +665,10 @@ func installToBootstrap(name string, config android.Config) bool {
|
||||
return isBionic(name)
|
||||
}
|
||||
|
||||
func (c *Module) XrefCcFiles() android.Paths {
|
||||
return c.kytheFiles
|
||||
}
|
||||
|
||||
type baseModuleContext struct {
|
||||
android.BaseModuleContext
|
||||
moduleContextImpl
|
||||
@@ -995,6 +1007,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
|
||||
flags := Flags{
|
||||
Toolchain: c.toolchain(ctx),
|
||||
EmitXrefs: ctx.Config().EmitXrefRules(),
|
||||
}
|
||||
if c.compiler != nil {
|
||||
flags = c.compiler.compilerFlags(ctx, flags, deps)
|
||||
@@ -1060,6 +1073,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
c.kytheFiles = objs.kytheFiles
|
||||
}
|
||||
|
||||
if c.linker != nil {
|
||||
@@ -2366,6 +2380,31 @@ func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
|
||||
return ctx.Config().PlatformSdkVersion()
|
||||
}
|
||||
|
||||
func kytheExtractAllFactory() android.Singleton {
|
||||
return &kytheExtractAllSingleton{}
|
||||
}
|
||||
|
||||
type kytheExtractAllSingleton struct {
|
||||
}
|
||||
|
||||
func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
var xrefTargets android.Paths
|
||||
ctx.VisitAllModules(func(module android.Module) {
|
||||
if ccModule, ok := module.(xref); ok {
|
||||
xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
|
||||
}
|
||||
})
|
||||
// TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
|
||||
if len(xrefTargets) > 0 {
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: blueprint.Phony,
|
||||
Output: android.PathForPhony(ctx, "xref_cxx"),
|
||||
Inputs: xrefTargets,
|
||||
//Default: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var Bool = proptools.Bool
|
||||
var BoolDefault = proptools.BoolDefault
|
||||
var BoolPtr = proptools.BoolPtr
|
||||
|
@@ -74,6 +74,7 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
||||
coverage: in.Coverage,
|
||||
tidy: in.Tidy,
|
||||
sAbiDump: in.SAbiDump,
|
||||
emitXrefs: in.EmitXrefs,
|
||||
|
||||
systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
|
||||
|
||||
|
Reference in New Issue
Block a user