Merge "Package fuzz targets into zipfiles, then coalesce."

This commit is contained in:
Mitch Phillips 2019-11-14 18:37:48 +00:00 committed by Gerrit Code Review
commit ed0070d453

View file

@ -317,9 +317,10 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
return
}
// Discard vendor-NDK-linked modules, they're duplicates of fuzz targets
// we're going to package anyway.
if ccModule.UseVndk() || !ccModule.Enabled() {
// Discard vendor-NDK-linked + recovery modules, they're duplicates of
// fuzz targets we're going to package anyway.
if !ccModule.Enabled() || ccModule.Properties.PreventInstall ||
ccModule.UseVndk() || ccModule.InRecovery() {
return
}
@ -337,9 +338,23 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
sharedLibraries := make(map[string]android.Path)
collectAllSharedDependencies(module, sharedLibraries, ctx)
var files []fileToZip
builder := android.NewRuleBuilder()
// Package the corpora into a zipfile.
if fuzzModule.corpus != nil {
corpusZip := archDir.Join(ctx, module.Name()+"_seed_corpus.zip")
command := builder.Command().BuiltTool(ctx, "soong_zip").
Flag("-j").
FlagWithOutput("-o ", corpusZip)
command.FlagWithRspFileInputList("-l ", fuzzModule.corpus)
files = append(files, fileToZip{corpusZip, ""})
}
// Find and mark all the transiently-dependent shared libraries for
// packaging.
for _, library := range sharedLibraries {
archDirs[archDir] = append(archDirs[archDir],
fileToZip{library, ccModule.Name() + "/lib"})
files = append(files, fileToZip{library, "lib"})
if _, exists := archSharedLibraryDeps[archAndLibraryKey{archDir, library}]; exists {
continue
@ -360,26 +375,35 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
}
// The executable.
archDirs[archDir] = append(archDirs[archDir],
fileToZip{ccModule.UnstrippedOutputFile(), ccModule.Name()})
// The corpora.
for _, corpusEntry := range fuzzModule.corpus {
archDirs[archDir] = append(archDirs[archDir],
fileToZip{corpusEntry, ccModule.Name() + "/corpus"})
}
files = append(files, fileToZip{ccModule.UnstrippedOutputFile(), ""})
// The dictionary.
if fuzzModule.dictionary != nil {
archDirs[archDir] = append(archDirs[archDir],
fileToZip{fuzzModule.dictionary, ccModule.Name()})
files = append(files, fileToZip{fuzzModule.dictionary, ""})
}
// Additional fuzz config.
if fuzzModule.config != nil {
archDirs[archDir] = append(archDirs[archDir],
fileToZip{fuzzModule.config, ccModule.Name()})
files = append(files, fileToZip{fuzzModule.config, ""})
}
fuzzZip := archDir.Join(ctx, module.Name()+".zip")
command := builder.Command().BuiltTool(ctx, "soong_zip").
Flag("-j").
FlagWithOutput("-o ", fuzzZip)
for _, file := range files {
if file.DestinationPathPrefix != "" {
command.FlagWithArg("-P ", file.DestinationPathPrefix)
} else {
command.Flag("-P ''")
}
command.FlagWithInput("-f ", file.SourceFilePath)
}
builder.Build(pctx, ctx, "create-"+fuzzZip.String(),
"Package "+module.Name()+" for "+archString+"-"+hostOrTargetString)
archDirs[archDir] = append(archDirs[archDir], fileToZip{fuzzZip, ""})
})
for archDir, filesToZip := range archDirs {
@ -391,11 +415,16 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
command := builder.Command().BuiltTool(ctx, "soong_zip").
Flag("-j").
FlagWithOutput("-o ", outputFile)
FlagWithOutput("-o ", outputFile).
Flag("-L 0") // No need to try and re-compress the zipfiles.
for _, fileToZip := range filesToZip {
command.FlagWithArg("-P ", fileToZip.DestinationPathPrefix).
FlagWithInput("-f ", fileToZip.SourceFilePath)
if fileToZip.DestinationPathPrefix != "" {
command.FlagWithArg("-P ", fileToZip.DestinationPathPrefix)
} else {
command.Flag("-P ''")
}
command.FlagWithInput("-f ", fileToZip.SourceFilePath)
}
builder.Build(pctx, ctx, "create-fuzz-package-"+arch+"-"+hostOrTarget,