cc_fuzz: add "data" field

"data" field specifies data dependencies that will be installed in
fuzzer's output directory.

"data" behaves similar to "corpus", except "data" preserves directory
structure, e.g.

    data: ["foo/bar.txt"]

is installed into

    $OUT/data/fuzz/<arch>/<target>/data/foo/bar.txt

Test: build a fuzzer with data depenency, check data is installed
correctly
Change-Id: Ia1255026278435181b6d93f91f8f9ad39c96d07f
This commit is contained in:
Tri Vo
2019-11-27 13:45:45 -08:00
parent af7c2fcb71
commit ad172d88b6
2 changed files with 34 additions and 0 deletions

View File

@@ -49,6 +49,9 @@ type FuzzProperties struct {
// Optional list of seed files to be installed to the fuzz target's output
// directory.
Corpus []string `android:"path"`
// Optional list of data files to be installed to the fuzz target's output
// directory. Directory structure relative to the module is preserved.
Data []string `android:"path"`
// Optional dictionary to be installed to the fuzz target's output directory.
Dictionary *string `android:"path"`
// Config for running the target on fuzzing infrastructure.
@@ -81,6 +84,8 @@ type fuzzBinary struct {
corpus android.Paths
corpusIntermediateDir android.Path
config android.Path
data android.Paths
dataIntermediateDir android.Path
installedSharedDeps []string
}
@@ -210,6 +215,17 @@ func (fuzz *fuzzBinary) install(ctx ModuleContext, file android.Path) {
builder.Build(pctx, ctx, "copy_corpus", "copy corpus")
fuzz.corpusIntermediateDir = intermediateDir
fuzz.data = android.PathsForModuleSrc(ctx, fuzz.Properties.Data)
builder = android.NewRuleBuilder()
intermediateDir = android.PathForModuleOut(ctx, "data")
for _, entry := range fuzz.data {
builder.Command().Text("cp").
Input(entry).
Output(intermediateDir.Join(ctx, entry.Rel()))
}
builder.Build(pctx, ctx, "copy_data", "copy data")
fuzz.dataIntermediateDir = intermediateDir
if fuzz.Properties.Dictionary != nil {
fuzz.dictionary = android.PathForModuleSrc(ctx, *fuzz.Properties.Dictionary)
if fuzz.dictionary.Ext() != ".dict" {
@@ -377,6 +393,19 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
files = append(files, fileToZip{corpusZip, ""})
}
// Package the data into a zipfile.
if fuzzModule.data != nil {
dataZip := archDir.Join(ctx, module.Name()+"_data.zip")
command := builder.Command().BuiltTool(ctx, "soong_zip").
FlagWithOutput("-o ", dataZip)
for _, f := range fuzzModule.data {
intermediateDir := strings.TrimSuffix(f.String(), f.Rel())
command.FlagWithArg("-C ", intermediateDir)
command.FlagWithInput("-f ", f)
}
files = append(files, fileToZip{dataZip, ""})
}
// Find and mark all the transiently-dependent shared libraries for
// packaging.
for _, library := range sharedLibraries {