blob: 54b06ab650091c7238d0e9d8c844fcf714449f27 [file] [log] [blame]
Samuel Huang06f1ae92018-03-13 18:19:34 +00001# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Calder Kitagawaf1724dd2018-05-08 15:08:31 +00005import("//build/buildflag_header.gni")
Samuel Huang06f1ae92018-03-13 18:19:34 +00006import("//chrome/process_version_rc_template.gni")
Samuel Huang06f1ae92018-03-13 18:19:34 +00007import("//testing/test.gni")
8
Calder Kitagawaf1724dd2018-05-08 15:08:31 +00009buildflag_header("buildflags") {
10 header = "buildflags.h"
11
12 # Disable DEX on Windows Official Builds.
13 _enable_dex = !(is_win && is_official_build)
Etienne Pierre-doraye57c4e62018-08-10 17:44:37 +000014 _enable_elf = true
Calder Kitagawaf1724dd2018-05-08 15:08:31 +000015 _enable_win = true
Calder Kitagawa0d7a2512018-05-23 17:30:51 +000016
17 # Disable ZTF (Zucchini Text Format) on official builds it is for testing only.
18 _enable_ztf = !is_official_build
Calder Kitagawaf1724dd2018-05-08 15:08:31 +000019 flags = [
20 "ENABLE_DEX=$_enable_dex",
Etienne Pierre-doraye57c4e62018-08-10 17:44:37 +000021 "ENABLE_ELF=$_enable_elf",
Calder Kitagawaf1724dd2018-05-08 15:08:31 +000022 "ENABLE_WIN=$_enable_win",
Calder Kitagawa0d7a2512018-05-23 17:30:51 +000023 "ENABLE_ZTF=$_enable_ztf",
Calder Kitagawaf1724dd2018-05-08 15:08:31 +000024 ]
25}
26
Samuel Huang06f1ae92018-03-13 18:19:34 +000027static_library("zucchini_lib") {
28 sources = [
29 "abs32_utils.cc",
30 "abs32_utils.h",
31 "address_translator.cc",
32 "address_translator.h",
33 "algorithm.h",
Samuel Huang65b242d2019-01-11 20:00:13 +000034 "arm_utils.cc",
35 "arm_utils.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000036 "binary_data_histogram.cc",
37 "binary_data_histogram.h",
38 "buffer_sink.cc",
39 "buffer_sink.h",
40 "buffer_source.cc",
41 "buffer_source.h",
42 "buffer_view.h",
43 "crc32.cc",
44 "crc32.h",
45 "disassembler.cc",
46 "disassembler.h",
Etienne Pierre-Dorayfff1ca32018-03-29 13:33:46 +000047 "disassembler_dex.cc",
48 "disassembler_dex.h",
Etienne Pierre-doraye57c4e62018-08-10 17:44:37 +000049 "disassembler_elf.cc",
50 "disassembler_elf.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000051 "disassembler_no_op.cc",
52 "disassembler_no_op.h",
53 "disassembler_win32.cc",
54 "disassembler_win32.h",
Calder Kitagawa0d7a2512018-05-23 17:30:51 +000055 "disassembler_ztf.cc",
56 "disassembler_ztf.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000057 "element_detection.cc",
58 "element_detection.h",
59 "encoded_view.cc",
60 "encoded_view.h",
61 "ensemble_matcher.cc",
62 "ensemble_matcher.h",
63 "equivalence_map.cc",
64 "equivalence_map.h",
65 "heuristic_ensemble_matcher.cc",
66 "heuristic_ensemble_matcher.h",
67 "image_index.cc",
68 "image_index.h",
69 "image_utils.h",
Samuel Huang6951a282018-04-30 22:47:52 +000070 "imposed_ensemble_matcher.cc",
71 "imposed_ensemble_matcher.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000072 "io_utils.cc",
73 "io_utils.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000074 "patch_reader.cc",
75 "patch_reader.h",
76 "patch_utils.h",
77 "patch_writer.cc",
78 "patch_writer.h",
Samuel Huang451ff5d2018-04-20 17:40:00 +000079 "reference_bytes_mixer.cc",
80 "reference_bytes_mixer.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000081 "reference_set.cc",
82 "reference_set.h",
83 "rel32_finder.cc",
84 "rel32_finder.h",
85 "rel32_utils.cc",
86 "rel32_utils.h",
Etienne Pierre-Doraya88cad02018-07-25 20:16:02 +000087 "reloc_elf.cc",
88 "reloc_elf.h",
Etienne Pierre-dorayae27d8e2018-07-24 15:42:33 +000089 "reloc_win32.cc",
90 "reloc_win32.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000091 "suffix_array.h",
92 "target_pool.cc",
93 "target_pool.h",
94 "targets_affinity.cc",
95 "targets_affinity.h",
Etienne Pierre-Dorayfff1ca32018-03-29 13:33:46 +000096 "type_dex.h",
Etienne Pierre-Doraya88cad02018-07-25 20:16:02 +000097 "type_elf.h",
Samuel Huang06f1ae92018-03-13 18:19:34 +000098 "type_win_pe.h",
99 "typed_value.h",
100 "zucchini.h",
101 "zucchini_apply.cc",
102 "zucchini_apply.h",
103 "zucchini_gen.cc",
104 "zucchini_gen.h",
105 "zucchini_tools.cc",
106 "zucchini_tools.h",
107 ]
108
109 deps = [
Calder Kitagawaf1724dd2018-05-08 15:08:31 +0000110 ":buildflags",
Samuel Huang06f1ae92018-03-13 18:19:34 +0000111 "//base",
112 ]
113}
114
115static_library("zucchini_io") {
116 sources = [
117 "mapped_file.cc",
118 "mapped_file.h",
119 "zucchini_integration.cc",
120 "zucchini_integration.h",
121 ]
122
123 deps = [
124 ":zucchini_lib",
125 "//base",
126 ]
127}
128
129executable("zucchini") {
130 sources = [
131 "main_utils.cc",
132 "main_utils.h",
133 "zucchini_commands.cc",
134 "zucchini_commands.h",
135 "zucchini_main.cc",
136 ]
137
138 deps = [
139 ":zucchini_io",
140 ":zucchini_lib",
141 "//base",
Samuel Huang06f1ae92018-03-13 18:19:34 +0000142 ]
143
144 if (is_win) {
145 deps += [ ":zucchini_exe_version" ]
146 }
147}
148
149if (is_win) {
150 process_version_rc_template("zucchini_exe_version") {
151 template_file = "zucchini_exe_version.rc.version"
152 output = "$target_gen_dir/zucchini_exe_version.rc"
153 }
154}
155
Samuel Huang06f1ae92018-03-13 18:19:34 +0000156test("zucchini_unittests") {
157 sources = [
158 "abs32_utils_unittest.cc",
159 "address_translator_unittest.cc",
160 "algorithm_unittest.cc",
Samuel Huang65b242d2019-01-11 20:00:13 +0000161 "arm_utils_unittest.cc",
Samuel Huang06f1ae92018-03-13 18:19:34 +0000162 "binary_data_histogram_unittest.cc",
163 "buffer_sink_unittest.cc",
164 "buffer_source_unittest.cc",
165 "buffer_view_unittest.cc",
166 "crc32_unittest.cc",
Samuel Huanga8a2a942018-04-09 15:18:17 +0000167 "disassembler_dex_unittest.cc",
Etienne Pierre-doraye57c4e62018-08-10 17:44:37 +0000168 "disassembler_elf_unittest.cc",
Calder Kitagawa0d7a2512018-05-23 17:30:51 +0000169 "disassembler_ztf_unittest.cc",
Samuel Huang06f1ae92018-03-13 18:19:34 +0000170 "element_detection_unittest.cc",
171 "encoded_view_unittest.cc",
172 "equivalence_map_unittest.cc",
173 "image_index_unittest.cc",
174 "image_utils_unittest.cc",
Samuel Huang6951a282018-04-30 22:47:52 +0000175 "imposed_ensemble_matcher_unittest.cc",
Samuel Huang06f1ae92018-03-13 18:19:34 +0000176 "io_utils_unittest.cc",
Samuel Huang06f1ae92018-03-13 18:19:34 +0000177 "mapped_file_unittest.cc",
178 "patch_read_write_unittest.cc",
179 "patch_utils_unittest.cc",
180 "reference_set_unittest.cc",
181 "rel32_finder_unittest.cc",
182 "rel32_utils_unittest.cc",
Etienne Pierre-Doraya88cad02018-07-25 20:16:02 +0000183 "reloc_elf_unittest.cc",
Etienne Pierre-dorayae27d8e2018-07-24 15:42:33 +0000184 "reloc_win32_unittest.cc",
Samuel Huang06f1ae92018-03-13 18:19:34 +0000185 "suffix_array_unittest.cc",
186 "target_pool_unittest.cc",
187 "targets_affinity_unittest.cc",
188 "test_disassembler.cc",
189 "test_disassembler.h",
190 "test_reference_reader.cc",
191 "test_reference_reader.h",
192 "test_utils.cc",
193 "test_utils.h",
194 "typed_value_unittest.cc",
195 "zucchini_apply_unittest.cc",
196 "zucchini_gen_unittest.cc",
197 ]
198
199 deps = [
200 ":zucchini_io",
201 ":zucchini_lib",
202 "//base",
203 "//base/test:run_all_unittests",
204 "//base/test:test_support",
205 "//testing/gtest",
206 ]
207}
208
209test("zucchini_integration_test") {
Nico Weber1940ec92020-01-13 18:48:21 +0000210 sources = [ "integration_test.cc" ]
Samuel Huang06f1ae92018-03-13 18:19:34 +0000211
212 deps = [
213 ":zucchini_lib",
214 "//base",
215 "//base/test:run_all_unittests",
216 "//base/test:test_support",
217 "//testing/gtest",
218 ]
Richard Townsend80851dc2020-03-18 20:12:36 +0000219
220 data = [ "testdata" ]
Samuel Huang06f1ae92018-03-13 18:19:34 +0000221}
Calder Kitagawaa401b7e2018-04-24 20:35:27 +0000222
223# Group to build and depend on all the Zucchini related fuzzers.
224group("zucchini_fuzzers") {
225 testonly = true
226 deps = [
Calder Kitagawa9ee7e432018-07-03 14:30:05 +0000227 "//components/zucchini/fuzzers:zucchini_disassembler_dex_fuzzer",
Calder Kitagawaa401b7e2018-04-24 20:35:27 +0000228 "//components/zucchini/fuzzers:zucchini_disassembler_win32_fuzzer",
229 "//components/zucchini/fuzzers:zucchini_patch_fuzzer",
230 ]
Calder Kitagawa11c1b2a2018-05-09 19:51:14 +0000231
232 # Ensure protoc is available.
Calder Kitagawac4290b52018-05-24 21:36:47 +0000233 # Disabled on Windows due to crbug/844826.
234 if (current_toolchain == host_toolchain && !is_win) {
Calder Kitagawa1bed19c2018-05-17 21:07:49 +0000235 deps += [
Calder Kitagawa806fa632018-05-28 14:30:21 +0000236 "//components/zucchini/fuzzers:zucchini_apply_fuzzer",
Calder Kitagawa61784802018-07-03 14:25:19 +0000237 "//components/zucchini/fuzzers:zucchini_imposed_ensemble_matcher_fuzzer",
Calder Kitagawa1bed19c2018-05-17 21:07:49 +0000238 "//components/zucchini/fuzzers:zucchini_raw_gen_fuzzer",
Calder Kitagawa75569ad2018-05-25 19:49:43 +0000239 "//components/zucchini/fuzzers:zucchini_ztf_gen_fuzzer",
Calder Kitagawa1bed19c2018-05-17 21:07:49 +0000240 ]
Calder Kitagawa11c1b2a2018-05-09 19:51:14 +0000241 }
Calder Kitagawaa401b7e2018-04-24 20:35:27 +0000242}