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
diff --git a/cc/androidmk.go b/cc/androidmk.go
index ff181d8..c1225bc 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -317,6 +317,11 @@
filepath.Dir(fuzz.corpusIntermediateDir.String())+":corpus/"+d.Base())
}
+ for _, d := range fuzz.data {
+ fuzzFiles = append(fuzzFiles,
+ filepath.Dir(fuzz.dataIntermediateDir.String())+":data/"+d.Rel())
+ }
+
if fuzz.dictionary != nil {
fuzzFiles = append(fuzzFiles,
filepath.Dir(fuzz.dictionary.String())+":"+fuzz.dictionary.Base())
diff --git a/cc/fuzz.go b/cc/fuzz.go
index c2b0ff4..0d3cc74 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -49,6 +49,9 @@
// 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 @@
corpus android.Paths
corpusIntermediateDir android.Path
config android.Path
+ data android.Paths
+ dataIntermediateDir android.Path
installedSharedDeps []string
}
@@ -210,6 +215,17 @@
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 @@
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 {