blob: f72bfffd2e8150b26df8d705cc9d4a4ae897cc9c [file] [log] [blame]
Muhammad Haseeb Ahmadaa1d0cf2022-01-01 05:14:32 +00001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "github.com/google/blueprint/proptools"
19
20 "android/soong/android"
21 "android/soong/fuzz"
22)
23
24func init() {
25 RegisterJavaFuzzBuildComponents(android.InitRegistrationContext)
26}
27
28func RegisterJavaFuzzBuildComponents(ctx android.RegistrationContext) {
29 ctx.RegisterModuleType("java_fuzz_host", FuzzFactory)
30}
31
32type JavaFuzzLibrary struct {
33 Library
34 fuzzPackagedModule fuzz.FuzzPackagedModule
35}
36
37func (j *JavaFuzzLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
38 j.Library.GenerateAndroidBuildActions(ctx)
39
40 if j.fuzzPackagedModule.FuzzProperties.Corpus != nil {
41 j.fuzzPackagedModule.Corpus = android.PathsForModuleSrc(ctx, j.fuzzPackagedModule.FuzzProperties.Corpus)
42 }
43 if j.fuzzPackagedModule.FuzzProperties.Data != nil {
44 j.fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, j.fuzzPackagedModule.FuzzProperties.Data)
45 }
46 if j.fuzzPackagedModule.FuzzProperties.Dictionary != nil {
47 j.fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *j.fuzzPackagedModule.FuzzProperties.Dictionary)
48 }
49
50 if j.fuzzPackagedModule.FuzzProperties.Fuzz_config != nil {
51 configPath := android.PathForModuleOut(ctx, "config").Join(ctx, "config.json")
52 android.WriteFileRule(ctx, configPath, j.fuzzPackagedModule.FuzzProperties.Fuzz_config.String())
53 j.fuzzPackagedModule.Config = configPath
54 }
55}
56
57// java_fuzz builds and links sources into a `.jar` file for the host.
58//
59// By default, a java_fuzz produces a `.jar` file containing `.class` files.
60// This jar is not suitable for installing on a device.
61func FuzzFactory() android.Module {
62 module := &JavaFuzzLibrary{}
63
64 module.addHostProperties()
65 module.Module.properties.Installable = proptools.BoolPtr(false)
66 module.AddProperties(&module.fuzzPackagedModule.FuzzProperties)
67
68 module.initModuleAndImport(module)
69 android.InitSdkAwareModule(module)
70 InitJavaModule(module, android.HostSupported)
71 return module
72}