diff --git a/cc/androidmk.go b/cc/androidmk.go index ff181d80e..c1225bc16 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -317,6 +317,11 @@ func (fuzz *fuzzBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkDa 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 c2b0ff4bb..0d3cc7430 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -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 {