Merge "Support source code cross-referencing for C++ and Java"
am: 247de68b89
Change-Id: I5284d9be9865e95671ce8ec1927f74059f7fdf44
This commit is contained in:
@@ -62,6 +62,37 @@ var (
|
||||
"javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir",
|
||||
"outDir", "annoDir", "javaVersion")
|
||||
|
||||
_ = pctx.VariableFunc("kytheCorpus",
|
||||
func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() })
|
||||
// Run it with -add-opens=java.base/java.nio=ALL-UNNAMED to avoid JDK9's warning about
|
||||
// "Illegal reflective access by com.google.protobuf.Utf8$UnsafeProcessor ...
|
||||
// to field java.nio.Buffer.address"
|
||||
kytheExtract = pctx.AndroidStaticRule("kythe",
|
||||
blueprint.RuleParams{
|
||||
Command: `${config.ZipSyncCmd} -d $srcJarDir ` +
|
||||
`-l $srcJarDir/list -f "*.java" $srcJars && ` +
|
||||
`( [ ! -s $srcJarDir/list -a ! -s $out.rsp ] || ` +
|
||||
`KYTHE_ROOT_DIRECTORY=. KYTHE_OUTPUT_FILE=$out ` +
|
||||
`KYTHE_CORPUS=${kytheCorpus} ` +
|
||||
`${config.SoongJavacWrapper} ${config.JavaCmd} ` +
|
||||
`--add-opens=java.base/java.nio=ALL-UNNAMED ` +
|
||||
`-jar ${config.JavaKytheExtractorJar} ` +
|
||||
`${config.JavacHeapFlags} ${config.CommonJdkFlags} ` +
|
||||
`$processorpath $processor $javacFlags $bootClasspath $classpath ` +
|
||||
`-source $javaVersion -target $javaVersion ` +
|
||||
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list)`,
|
||||
CommandDeps: []string{
|
||||
"${config.JavaCmd}",
|
||||
"${config.JavaKytheExtractorJar}",
|
||||
"${config.ZipSyncCmd}",
|
||||
},
|
||||
CommandOrderOnly: []string{"${config.SoongJavacWrapper}"},
|
||||
Rspfile: "$out.rsp",
|
||||
RspfileContent: "$in",
|
||||
},
|
||||
"javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir",
|
||||
"outDir", "annoDir", "javaVersion")
|
||||
|
||||
turbine = pctx.AndroidStaticRule("turbine",
|
||||
blueprint.RuleParams{
|
||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||
@@ -196,6 +227,61 @@ func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
"errorprone", "errorprone")
|
||||
}
|
||||
|
||||
// Emits the rule to generate Xref input file (.kzip file) for the given set of source files and source jars
|
||||
// to compile with given set of builder flags, etc.
|
||||
func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath,
|
||||
srcFiles, srcJars android.Paths,
|
||||
flags javaBuilderFlags, deps android.Paths,
|
||||
intermediatesDir string) {
|
||||
|
||||
deps = append(deps, srcJars...)
|
||||
|
||||
var bootClasspath string
|
||||
if flags.javaVersion == "1.9" {
|
||||
var systemModuleDeps android.Paths
|
||||
bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device())
|
||||
deps = append(deps, systemModuleDeps...)
|
||||
} else {
|
||||
deps = append(deps, flags.bootClasspath...)
|
||||
if len(flags.bootClasspath) == 0 && ctx.Device() {
|
||||
// explicitly specify -bootclasspath "" if the bootclasspath is empty to
|
||||
// ensure java does not fall back to the default bootclasspath.
|
||||
bootClasspath = `-bootclasspath ""`
|
||||
} else {
|
||||
bootClasspath = flags.bootClasspath.FormJavaClassPath("-bootclasspath")
|
||||
}
|
||||
}
|
||||
|
||||
deps = append(deps, flags.classpath...)
|
||||
deps = append(deps, flags.processorPath...)
|
||||
|
||||
processor := "-proc:none"
|
||||
if flags.processor != "" {
|
||||
processor = "-processor " + flags.processor
|
||||
}
|
||||
|
||||
ctx.Build(pctx,
|
||||
android.BuildParams{
|
||||
Rule: kytheExtract,
|
||||
Description: "Xref Java extractor",
|
||||
Output: xrefFile,
|
||||
Inputs: srcFiles,
|
||||
Implicits: deps,
|
||||
Args: map[string]string{
|
||||
"annoDir": android.PathForModuleOut(ctx, intermediatesDir, "anno").String(),
|
||||
"bootClasspath": bootClasspath,
|
||||
"classpath": flags.classpath.FormJavaClassPath("-classpath"),
|
||||
"javacFlags": flags.javacFlags,
|
||||
"javaVersion": flags.javaVersion,
|
||||
"outDir": android.PathForModuleOut(ctx, "javac", "classes.xref").String(),
|
||||
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
|
||||
"processor": processor,
|
||||
"srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, "srcjars.xref").String(),
|
||||
"srcJars": strings.Join(srcJars.Strings(), " "),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.WritablePath,
|
||||
srcFiles, srcJars android.Paths, flags javaBuilderFlags) {
|
||||
|
||||
|
@@ -95,6 +95,7 @@ func init() {
|
||||
pctx.SourcePathVariable("JlinkCmd", "${JavaToolchain}/jlink")
|
||||
pctx.SourcePathVariable("JmodCmd", "${JavaToolchain}/jmod")
|
||||
pctx.SourcePathVariable("JrtFsJar", "${JavaHome}/lib/jrt-fs.jar")
|
||||
pctx.SourcePathVariable("JavaKytheExtractorJar", "prebuilts/build-tools/common/framework/javac_extractor.jar")
|
||||
pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime")
|
||||
|
||||
pctx.SourcePathVariable("GenKotlinBuildFileCmd", "build/soong/scripts/gen-kotlin-build-file.sh")
|
||||
|
42
java/java.go
42
java/java.go
@@ -50,6 +50,7 @@ func init() {
|
||||
android.RegisterModuleType("dex_import", DexImportFactory)
|
||||
|
||||
android.RegisterSingletonType("logtags", LogtagsSingleton)
|
||||
android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
|
||||
}
|
||||
|
||||
// TODO:
|
||||
@@ -343,6 +344,9 @@ type Module struct {
|
||||
|
||||
hiddenAPI
|
||||
dexpreopter
|
||||
|
||||
// list of the xref extraction files
|
||||
kytheFiles android.Paths
|
||||
}
|
||||
|
||||
func (j *Module) OutputFiles(tag string) (android.Paths, error) {
|
||||
@@ -383,6 +387,10 @@ type SrcDependency interface {
|
||||
CompiledSrcJars() android.Paths
|
||||
}
|
||||
|
||||
type xref interface {
|
||||
XrefJavaFiles() android.Paths
|
||||
}
|
||||
|
||||
func (j *Module) CompiledSrcs() android.Paths {
|
||||
return j.compiledJavaSrcs
|
||||
}
|
||||
@@ -391,6 +399,10 @@ func (j *Module) CompiledSrcJars() android.Paths {
|
||||
return j.compiledSrcJars
|
||||
}
|
||||
|
||||
func (j *Module) XrefJavaFiles() android.Paths {
|
||||
return j.kytheFiles
|
||||
}
|
||||
|
||||
var _ SrcDependency = (*Module)(nil)
|
||||
|
||||
func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
|
||||
@@ -1139,6 +1151,12 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
TransformJavaToClasses(ctx, classes, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
|
||||
jars = append(jars, classes)
|
||||
}
|
||||
if ctx.Config().EmitXrefRules() {
|
||||
extractionFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".kzip")
|
||||
emitXrefRule(ctx, extractionFile, uniqueSrcFiles, srcJars, flags, extraJarDeps, "xref")
|
||||
j.kytheFiles = append(j.kytheFiles, extractionFile)
|
||||
|
||||
}
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -2213,6 +2231,30 @@ func DefaultsFactory(props ...interface{}) android.Module {
|
||||
return module
|
||||
}
|
||||
|
||||
func kytheExtractJavaFactory() android.Singleton {
|
||||
return &kytheExtractJavaSingleton{}
|
||||
}
|
||||
|
||||
type kytheExtractJavaSingleton struct {
|
||||
}
|
||||
|
||||
func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
||||
var xrefTargets android.Paths
|
||||
ctx.VisitAllModules(func(module android.Module) {
|
||||
if javaModule, ok := module.(xref); ok {
|
||||
xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
|
||||
}
|
||||
})
|
||||
// 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_java"),
|
||||
Inputs: xrefTargets,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var Bool = proptools.Bool
|
||||
var BoolDefault = proptools.BoolDefault
|
||||
var String = proptools.String
|
||||
|
Reference in New Issue
Block a user