summaryrefslogtreecommitdiff
path: root/chromium/components/crash/core/app/BUILD.gn
blob: 8876246e763bdf1fa4d4d2eb7fbdd32be01d37bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# TODO(crbug.com/1226159): Complete crash reporting integration on Fuchsia.
assert(!is_fuchsia)

import("//components/gwp_asan/buildflags/buildflags.gni")

if (is_android) {
  import("//build/config/android/config.gni")
}

source_set("lib") {
  visibility = [
    ":*",
    "//components/crash/content/app:*",
  ]

  sources = [
    "crash_reporter_client.cc",
    "crash_reporter_client.h",
  ]

  deps = [
    "//base",
    "//build:branding_buildflags",
  ]
}

source_set("crashpad_handler_main") {
  sources = [ "crashpad_handler_main.cc" ]

  deps = [
    "//components/gwp_asan/buildflags",
    "//third_party/crashpad/crashpad/handler:handler",
  ]

  if (enable_gwp_asan) {
    deps += [ "//components/gwp_asan/crash_handler" ]
  }
}

static_library("app") {
  sources = [
    "client_upload_info.cc",
    "client_upload_info.h",
    "crash_export_thunks.h",
    "crash_switches.cc",
    "crash_switches.h",
    "crashpad.cc",
    "crashpad.h",
  ]

  if (is_linux || is_chromeos) {
    sources += [
      "breakpad_linux.cc",
      "breakpad_linux.h",
      "breakpad_linux_impl.h",
      "crashpad_linux.cc",
    ]
  }

  defines = [ "CRASH_IMPLEMENTATION" ]

  public_deps = [ ":lib" ]
  deps = [
    "//base",
    "//build:branding_buildflags",
    "//build:chromeos_buildflags",
    "//content/public/common:content_descriptors",
    "//third_party/crashpad/crashpad/client",
    "//third_party/crashpad/crashpad/util",
  ]

  if (is_ios) {
    deps -= [ "//content/public/common:content_descriptors" ]
  }

  if (is_android) {
    sources += [ "crashpad_android.cc" ]
    deps += [
      ":crashpad_handler_main",
      "//components/crash/android:jni_headers",
      "//third_party/crashpad/crashpad/handler",
      "//third_party/crashpad/crashpad/snapshot",
    ]
    libs = [ "log" ]
  }

  if (is_android || is_linux || is_chromeos) {
    deps += [
      "//base:base_static",
      "//components/crash/core/common",
      "//sandbox",
    ]
  }

  if (is_linux || is_chromeos) {
    deps += [ "//third_party/breakpad:client" ]
  }

  if (is_win) {
    sources += [
      "crashpad_win.cc",
      "dump_hung_process_with_ptype.cc",
      "dump_hung_process_with_ptype.h",
      "minidump_with_crashpad_info.cc",
      "minidump_with_crashpad_info.h",
    ]

    deps += [
      "//third_party/crashpad/crashpad/client",
      "//third_party/crashpad/crashpad/handler",
      "//third_party/crashpad/crashpad/minidump",
      "//third_party/crashpad/crashpad/util",
    ]
  }

  if (is_mac) {
    sources += [ "crashpad_mac.mm" ]
    deps += [
      "//third_party/crashpad/crashpad/minidump",
      "//third_party/crashpad/crashpad/snapshot",
    ]
  }

  if (is_ios) {
    sources += [ "crashpad_ios.mm" ]
    deps += [ "//third_party/crashpad/crashpad/minidump" ]
  }
}

if (is_win) {
  static_library("run_as_crashpad_handler") {
    sources = [
      "crash_switches.cc",
      "crash_switches.h",
      "fallback_crash_handler_launcher_win.cc",
      "fallback_crash_handler_launcher_win.h",
      "fallback_crash_handler_win.cc",
      "fallback_crash_handler_win.h",
      "fallback_crash_handling_win.cc",
      "fallback_crash_handling_win.h",
      "minidump_with_crashpad_info.cc",
      "minidump_with_crashpad_info.h",
      "run_as_crashpad_handler_win.cc",
      "run_as_crashpad_handler_win.h",
    ]

    deps = [
      "//base",
      "//build:chromeos_buildflags",
      "//components/gwp_asan/buildflags",
      "//third_party/crashpad/crashpad/client",
      "//third_party/crashpad/crashpad/handler",
      "//third_party/crashpad/crashpad/minidump",
      "//third_party/crashpad/crashpad/util",
    ]

    if (enable_gwp_asan) {
      deps += [ "//components/gwp_asan/crash_handler" ]
    }
  }

  # This source set contains the include file that declares the export thunks.
  # Any target that gets compiled into both test and release code needs to
  # depend on this for the include alone. The binary it's linked into then needs
  # to depend on either :crash_export_thunks or :test_support, or in the case of
  # release binaries, on //chrome_elf, which re-exports the thunks.
  source_set("crash_export_thunk_include") {
    sources = [ "crash_export_thunks.h" ]
  }

  # This source set contains a set of functions that allow using the crashpad
  # handler across a module boundary. The intent is for these functions to be
  # built into a dynamic library, which the user of the crashpad handler then
  # has a link-time dependency on. This will result in an import dependency
  # from the user to the dynamic library that will be bound at load time.
  # In a single-module project, this source set can alternatively be included in
  # the sole module, in which case the implementation will be bound at link
  # time.
  source_set("crash_export_thunks") {
    sources = [
      "crash_export_thunks.cc",
      "crash_export_thunks.h",
    ]

    deps = [
      ":app",
      "//base",
      "//third_party/crashpad/crashpad/client",
    ]
  }

  # This source set contains a set of test stubs for the functions above.
  # time.
  source_set("crash_export_stubs") {
    testonly = true

    sources = [
      "crash_export_stubs.cc",
      "crash_export_thunks.h",
    ]

    deps = [
      ":app",
      "//base",
    ]
  }
}

if (is_mac || is_android || is_linux || is_chromeos) {
  # We build a chromium-specific crashpad_handler executable so that we can
  # define custom UserStreamDataSources.
  executable("chrome_crashpad_handler") {
    sources = [ "chrome_crashpad_handler.cc" ]

    deps = [
      ":crashpad_handler_main",
      "//third_party/crashpad/crashpad/handler",
    ]

    if (is_mac && (is_component_build || is_asan)) {
      ldflags = [
        # The handler is in
        # Chromium.app/Contents/Frameworks/Chromium Framework.framework/Versions/A/Helpers/
        # or
        # Content Shell.app/Contents/Frameworks/Content Shell Framework.framework/Versions/C/Helpers/
        # so set rpath up to the base. This is the only case needed for is_asan.
        "-Wl,-rpath,@loader_path/../../../../../../..",

        # The handler can also be executed in an unbundled framework at
        # Chromium Framework.framework/Versions/A/Helpers/
        "-Wl,-rpath,@loader_path/../../../..",

        # The handler can be executed from headless_browsertests in Helpers/
        "-Wl,-rpath,@loader_path/..",
      ]
    }
  }
}

if (is_android) {
  # There is not any normal way to package native executables in an Android APK.
  # It is normal to package native code as a loadable module but Android's APK
  # installer will ignore files not named like a shared object, so give the
  # handler executable an acceptable name.
  copy("chrome_crashpad_handler_named_as_so") {
    deps = [ ":chrome_crashpad_handler" ]

    sources = [ "$root_out_dir/chrome_crashpad_handler" ]

    outputs = [ "$root_out_dir/libchrome_crashpad_handler.so" ]
  }
}

# This source set provides the functionality required for tests, which on Windows
# link the export thunks directly into the test binary.
source_set("test_support") {
  testonly = true

  deps = [ ":lib" ]

  if (is_win) {
    deps += [ ":crash_export_stubs" ]
  }
}

source_set("unit_tests") {
  testonly = true
  sources = []
  deps = [
    ":lib",
    "//base",
    "//base/test:test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]

  if (is_win) {
    sources += [
      "fallback_crash_handler_launcher_win_unittest.cc",
      "fallback_crash_handler_win_unittest.cc",
      "fallback_crash_handling_win_unittest.cc",
    ]
    deps += [
      ":run_as_crashpad_handler",
      "//third_party/breakpad:client",
      "//third_party/crashpad/crashpad/client:client",
      "//third_party/crashpad/crashpad/snapshot:snapshot",
      "//third_party/crashpad/crashpad/util",
    ]
  }
  if (is_ios) {
    configs += [ "//build/config/compiler:enable_arc" ]

    sources += [ "crashpad_ios_unittest.mm" ]
    deps += [
      ":app",
      "//components/crash/core/common:reporter_running_ios",
      "//third_party/crashpad/crashpad/client:common",
      "//third_party/crashpad/crashpad/test",
    ]
  }
}