summaryrefslogtreecommitdiffstats
path: root/build/config/BUILDCONFIG.gn
blob: c9ec4a2f858aa7bbdbebcd01cee2e842c504c228 (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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
# Copyright (c) 2013 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.

# =============================================================================
# BUILD FLAGS
# =============================================================================
#
# This block lists input arguments to the build, along with their default
# values. GN requires listing them explicitly so it can validate input and have
# a central place to manage the build flags.
#
# If a value is specified on the command line, it will overwrite the defaults
# given here, otherwise the default will be injected into the root scope.
#
# KEEP IN ALPHABETICAL ORDER and write a good description for everything.
# Use "is_*" names for intrinsic platform descriptions and build modes, and
# "use_*" names for optional features libraries, and configurations.
declare_args() {
  # How many symbols to include in the build. This affects the performance of
  # the build since the symbols are large and dealing with them is slow.
  #   2 means regular build with symbols.
  #   1 means minimal symbols, usually enough for backtraces only.
  #   0 means no symbols.
  #   -1 means auto-set (off in release, regular in debug).
  symbol_level = -1

  # Component build.
  is_component_build = false
  # Debug build.
  is_debug = true

  # Set to true when compiling with the Clang compiler. Typically this is used
  # to configure warnings.
  is_clang = (os == "mac" || os == "ios" || os == "linux" || os == "chromeos")

  # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally
  # we build 32-bit on Windows regardless of the current host OS bit depth.
  # Setting this flag will override this logic and generate 64-bit toolchains.
  #
  # Normally this would get set automatically when you specify a target using
  # the 64-bit toolchain. You can also set this on the command line to convert
  # the default toolchain to 64-bit.
  force_win64 = false

  # Selects the desired build flavor. Official builds get additional
  # processing to prepare for release. Normally you will want to develop and
  # test with this flag off.
  is_official_build = false

  # Select the desired branding flavor. False means normal Chromium branding,
  # true means official Google Chrome branding (requires extra Google-internal
  # resources).
  is_chrome_branded = false

  # Compile for Address Sanitizer to find memory bugs.
  is_asan = false

  # Compile for Leak Sanitizer to find leaks.
  is_lsan = false

  # Compile for Memory Sanitizer to find uninitialized reads.
  is_msan = false

  # Compile for Thread Sanitizer to find threading bugs.
  is_tsan = false

  if (os == "chromeos") {
    # Allows the target toolchain to be injected as arguments. This is needed
    # to support the CrOS build system which supports per-build-configuration
    # toolchains.
    cros_use_custom_toolchain = false
  }

  # TODO(cjhopman): Make target_arch work for all platforms.

  # Architecture of the target device. For Android builds, this will be equal to
  # the cpu_arch of the default toolchain. When checking the CPU architecture
  # for source files and build dependencies you should almost alway use cpu_arch
  # instead. cpu_arch is the architecture of the current toolchain and allows
  # cross-compiles (compiling the same target for multiple toolchains in the
  # same build) to work.
  target_arch = "arm"
}

# =============================================================================
# OS DEFINITIONS
# =============================================================================
#
# We set these various is_FOO booleans for convenience in writing OS-based
# conditions.
#
# - is_android, is_chromeos, is_ios, and is_win should be obvious.
# - is_mac is set only for desktop Mac. It is not set on iOS.
# - is_posix is true for mac and any Unix-like system (basically everything
#   except Windows).
# - is_linux is true for desktop Linux and ChromeOS, but not Android (which is
#   generally too different despite being based on the Linux kernel).
#
# Do not add more is_* variants here for random lesser-used Unix systems like
# aix or one of the BSDs. If you need to check these, just check the os value
# directly.

if (os == "win") {
  is_android = false
  is_chromeos = false
  is_ios = false
  is_linux = false
  is_mac = false
  is_nacl = false
  is_posix = false
  is_win = true
} else if (os == "mac") {
  is_android = false
  is_chromeos = false
  is_ios = false
  is_linux = false
  is_mac = true
  is_nacl = false
  is_posix = true
  is_win = false
} else if (os == "android") {
  is_android = true
  is_chromeos = false
  is_ios = false
  is_linux = false
  is_mac = false
  is_nacl = false
  is_posix = true
  is_win = false
} else if (os == "chromeos") {
  is_android = false
  is_chromeos = true
  is_ios = false
  is_linux = true
  is_mac = false
  is_nacl = false
  is_posix = true
  is_win = false
} else if (os == "nacl") {
  # os == "nacl" will be passed by the nacl toolchain definition. It is not
  # set by default or on the command line. We treat is as a Posix variant.
  is_android = false
  is_chromeos = false
  is_ios = false
  is_linux = false
  is_mac = false
  is_nacl = true
  is_posix = true
  is_win = false
} else if (os == "ios") {
  is_android = false
  is_chromeos = false
  is_ios = true
  is_linux = false
  is_mac = false
  is_nacl = false
  is_posix = true
  is_win = false
} else if (os == "linux") {
  is_android = false
  is_chromeos = false
  is_ios = false
  is_linux = true
  is_mac = false
  is_nacl = false
  is_posix = true
  is_win = false
}

is_desktop_linux = is_linux && !is_chromeos

# =============================================================================
# CPU ARCHITECTURE
# =============================================================================

if (is_win) {
  # Always use 32-bit on Windows, even when compiling on a 64-bit host OS,
  # unless the override flag is specified.
  if (force_win64) {
    cpu_arch = "x64"
  } else {
    cpu_arch = "x86"
  }
}

if (is_android) {
  # TODO(cjhopman): enable this assert once bots are updated to not set
  # cpu_arch.
  #assert(cpu_arch == build_cpu_arch, "Android device target architecture should
  #    be set with 'target_arch', not 'cpu_arch'")
  cpu_arch = target_arch
}

# =============================================================================
# SOURCES FILTERS
# =============================================================================
#
# These patterns filter out platform-specific files when assigning to the
# sources variable. The magic variable |sources_assignment_filter| is applied
# to each assignment or appending to the sources variable and matches are
# automatcally removed.
#
# Note that the patterns are NOT regular expressions. Only "*" and "\b" (path
# boundary = end of string or slash) are supported, and the entire string
# muct match the pattern (so you need "*.cc" to match all .cc files, for
# example).

# DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
# below.
sources_assignment_filter = []
if (!is_posix) {
  sources_assignment_filter += [
    "*_posix.h",
    "*_posix.cc",
    "*_posix_unittest.h",
    "*_posix_unittest.cc",
    "*\bposix/*",
  ]
}
if (!is_win) {
  sources_assignment_filter += [
    "*_win.cc",
    "*_win.h",
    "*_win_unittest.cc",
    "*\bwin/*",
    "*.rc",
  ]
}
if (!is_mac) {
  sources_assignment_filter += [
    "*_mac.h",
    "*_mac.cc",
    "*_mac.mm",
    "*_mac_unittest.h",
    "*_mac_unittest.cc",
    "*_mac_unittest.mm",
    "*\bmac/*",
    "*_cocoa.h",
    "*_cocoa.cc",
    "*_cocoa.mm",
    "*_cocoa_unittest.h",
    "*_cocoa_unittest.cc",
    "*_cocoa_unittest.mm",
    "*\bcocoa/*",
  ]
}
if (!is_ios) {
  sources_assignment_filter += [
    "*_ios.h",
    "*_ios.cc",
    "*_ios.mm",
    "*_ios_unittest.h",
    "*_ios_unittest.cc",
    "*_ios_unittest.mm",
    "*\bios/*",
  ]
}
if (!is_mac && !is_ios) {
  sources_assignment_filter += [
    "*.mm",
  ]
}
if (!is_linux) {
  sources_assignment_filter += [
    "*_linux.h",
    "*_linux.cc",
    "*_linux_unittest.h",
    "*_linux_unittest.cc",
    "*\blinux/*",
  ]
}
if (!is_android) {
  sources_assignment_filter += [
    "*_android.h",
    "*_android.cc",
    "*_android_unittest.h",
    "*_android_unittest.cc",
    "*\bandroid/*",
  ]
}
if (!is_chromeos) {
  sources_assignment_filter += [
    "*_chromeos.h",
    "*_chromeos.cc",
    "*_chromeos_unittest.h",
    "*_chromeos_unittest.cc",
    "*\bchromeos/*",
  ]
}
# DO NOT ADD MORE PATTERNS TO THIS LIST, see set_sources_assignment_filter call
# below.

# Actually save this list.
#
# These patterns are executed for every file in the source tree of every run.
# Therefore, adding more patterns slows down the build for everybody. We should
# only add automatic patterns for configurations affecting hundreds of files
# across many projects in the tree.
#
# Therefore, we only add rules to this list corresponding to platforms on the
# Chromium waterfall.  This is not for non-officially-supported platforms
# (FreeBSD, etc.) toolkits, (X11, GTK, etc.), or features. For these cases,
# write a conditional in the target to remove the file(s) from the list when
# your platform/toolkit/feature doesn't apply.
set_sources_assignment_filter(sources_assignment_filter)

# =============================================================================
# BUILD OPTIONS
# =============================================================================

# These Sanitizers all imply using the Clang compiler. On Windows they either
# don't work or work differently.
if (!is_clang && (is_asan || is_lsan || is_tsan || is_msan)) {
  is_clang = true
}

# =============================================================================
# TARGET DEFAULTS
# =============================================================================
#
# Set up the default configuration for every build target of the given type.
# The values configured here will be automatically set on the scope of the
# corresponding target. Target definitions can add or remove to the settings
# here as needed.

# Holds all configs used for making native executables and libraries, to avoid
# duplication in each target below.
_native_compiler_configs = [
  "//build/config:feature_flags",

  "//build/config/compiler:compiler",
  "//build/config/compiler:compiler_arm_fpu",
  "//build/config/compiler:chromium_code",
  "//build/config/compiler:default_include_dirs",
  "//build/config/compiler:default_warnings",
  "//build/config/compiler:no_rtti",
  "//build/config/compiler:runtime_library",
]
if (is_win) {
  _native_compiler_configs += [
    "//build/config/win:lean_and_mean",
    "//build/config/win:nominmax",
    "//build/config/win:sdk",
    "//build/config/win:unicode",
    "//build/config/win:winver",
  ]
}
if (is_posix) {
  _native_compiler_configs += [
    "//build/config/gcc:no_exceptions",
    "//build/config/gcc:symbol_visibility_hidden",
  ]
}

if (is_linux) {
  _native_compiler_configs += [ "//build/config/linux:sdk", ]
} else if (is_mac) {
  _native_compiler_configs += [ "//build/config/mac:sdk", ]
} else if (is_ios) {
  _native_compiler_configs += [ "//build/config/ios:sdk", ]
} else if (is_android) {
  _native_compiler_configs += [ "//build/config/android:sdk", ]
}

if (is_clang) {
  _native_compiler_configs += [
    "//build/config/clang:find_bad_constructs",
    "//build/config/clang:extra_warnings",
  ]
}

# Optimizations and debug checking.
if (is_debug) {
  _native_compiler_configs += [ "//build/config:debug" ]
  _default_optimization_config = "//build/config/compiler:no_optimize"
} else {
  _native_compiler_configs += [ "//build/config:release" ]
  _default_optimization_config = "//build/config/compiler:optimize"
}
_native_compiler_configs += [ _default_optimization_config ]

# If it wasn't manually set, set to an appropriate default.
if (symbol_level == -1) {
  # Linux is slowed by having symbols as part of the target binary, whereas
  # Mac and Windows have them separate, so in Release Linux, default them off.
  if (is_debug || !is_linux) {
    symbol_level = 2
  } else {
    symbol_level = 0
  }
}

# Symbol setup.
if (symbol_level == 2) {
  _default_symbols_config = "//build/config/compiler:symbols"
} else if (symbol_level == 1) {
  _default_symbols_config = "//build/config/compiler:minimal_symbols"
} else if (symbol_level == 0) {
  _default_symbols_config = "//build/config/compiler:no_symbols"
} else {
  assert(false, "Bad value for symbol_level.")
}
_native_compiler_configs += [ _default_symbols_config ]

# Windows linker setup for EXEs and DLLs.
if (is_win) {
  if (is_debug) {
    _default_incremental_linking_config =
      "//build/config/win:incremental_linking"
  } else {
    _default_incremental_linking_config =
      "//build/config/win:no_incremental_linking"
  }
  _windows_linker_configs = [
    _default_incremental_linking_config,
    "//build/config/win:sdk_link",
    "//build/config/win:common_linker_setup",
    # Default to console-mode apps. Most of our targets are tests and such
    # that shouldn't use the windows subsystem.
    "//build/config/win:console",
  ]
}

# Executable defaults.
_executable_configs = _native_compiler_configs + [
  "//build/config:default_libs",
]
if (is_win) {
  _executable_configs += _windows_linker_configs
} else if (is_mac) {
  _executable_configs += [
    "//build/config/mac:mac_dynamic_flags",
    "//build/config/mac:mac_executable_flags" ]
} else if (is_linux || is_android) {
  _executable_configs += [ "//build/config/gcc:executable_ldconfig" ]
  if (is_android) {
    _executable_configs += [ "//build/config/android:executable_config" ]
  }
}
set_defaults("executable") {
  configs = _executable_configs
}

# Static library defaults.
set_defaults("static_library") {
  configs = _native_compiler_configs
}

# Shared library defaults (also for components in component mode).
_shared_library_configs = _native_compiler_configs + [
  "//build/config:default_libs",
]
if (is_win) {
  _shared_library_configs += _windows_linker_configs
} else if (is_mac) {
  _shared_library_configs += [ "//build/config/mac:mac_dynamic_flags" ]
}
set_defaults("shared_library") {
  configs = _shared_library_configs
}
if (is_component_build) {
  set_defaults("component") {
    configs = _shared_library_configs
  }
}

# Source set defaults (also for components in non-component mode).
set_defaults("source_set") {
  configs = _native_compiler_configs
}
if (!is_component_build) {
  set_defaults("component") {
    configs = _native_compiler_configs
  }
}

# Test defaults.
set_defaults("test") {
  if (is_android) {
    configs = _shared_library_configs
  } else {
    configs = _executable_configs
  }
}


# ==============================================================================
# TOOLCHAIN SETUP
# ==============================================================================
#
# Here we set the default toolchain, as well as the variable host_toolchain
# which will identify the toolchain corresponding to the local system when
# doing cross-compiles. When not cross-compiling, this will be the same as the
# default toolchain.

if (is_win) {
  # TODO(brettw) name the toolchains the same as cpu_arch as with Linux below
  # to eliminate these conditionals.
  if (build_cpu_arch == "x64") {
    host_toolchain = "//build/toolchain/win:64"
  } else if (build_cpu_arch == "x86") {
    host_toolchain = "//build/toolchain/win:32"
  }

  if (cpu_arch == "x64") {
    set_default_toolchain("//build/toolchain/win:64")
  } else if (cpu_arch == "x86") {
    set_default_toolchain("//build/toolchain/win:32")
  }
} else if (is_android) {
  # Use clang for the x86/64 Linux host builds.
  if (build_cpu_arch == "x86" || build_cpu_arch == "x64") {
    host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
  } else {
    host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
  }
  set_default_toolchain("//build/toolchain/android:$cpu_arch")
} else if (is_linux) {
  if (is_clang) {
    host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
    set_default_toolchain("//build/toolchain/linux:clang_$cpu_arch")
  } else {
    host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
    set_default_toolchain("//build/toolchain/linux:$cpu_arch")
  }
  if (is_chromeos && cros_use_custom_toolchain) {
    set_default_toolchain("//build/toolchain/cros:target")
  }
} else if (is_mac) {
  host_toolchain = "//build/toolchain/mac:clang"
  set_default_toolchain(host_toolchain)
} else if (is_ios) {
  host_toolchain = "//build/toolchain/mac:host_clang"
  set_default_toolchain("//build/toolchain/mac:clang")
}

# ==============================================================================
# COMPONENT SETUP
# ==============================================================================

# TODO(brettw) erase this once the built-in "component" function is removed.
if (is_component_build) {
  component_mode = "shared_library"
} else {
  component_mode = "source_set"
}

template("component") {
  if (is_component_build) {
    shared_library(target_name) {
      # Configs will always be defined since we set_defaults for a component
      # above. We want to use those rather than whatever came with the nested
      # shared/static library inside the component.
      configs = []  # Prevent list overwriting warning.
      configs = invoker.configs

      # The sources assignment filter will have already been applied when the
      # code was originally executed. We don't want to apply it again, since
      # the original target may have override it for some assignments.
      set_sources_assignment_filter([])

      if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
      if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
      if (defined(invoker.cflags)) { cflags = invoker.cflags }
      if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
      if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
      if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
      if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
      if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
      if (defined(invoker.data)) { data = invoker.data }
      if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
      if (defined(invoker.defines)) { defines = invoker.defines }
      # All shared libraries must have the sanitizer deps to properly link in
      # asan mode (this target will be empty in other cases).
      if (defined(invoker.deps)) {
        deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
      } else {
        deps = [ "//build/config/sanitizers:deps" ]
      }
      if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
      if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
      if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
      if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
      if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
      if (defined(invoker.libs)) { libs = invoker.libs }
      if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
      if (defined(invoker.output_name)) { output_name = invoker.output_name }
      if (defined(invoker.public)) { public = invoker.public }
      if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
      if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
      if (defined(invoker.sources)) { sources = invoker.sources }
      if (defined(invoker.testonly)) { testonly = invoker.testonly }
      if (defined(invoker.visibility)) { visibility = invoker.visibility }
    }
  } else {
    source_set(target_name) {
      # See above.
      configs = []  # Prevent list overwriting warning.
      configs = invoker.configs

      # See above call.
      set_sources_assignment_filter([])

      if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
      if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
      if (defined(invoker.cflags)) { cflags = invoker.cflags }
      if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
      if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
      if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
      if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
      if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
      if (defined(invoker.data)) { data = invoker.data }
      if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
      if (defined(invoker.defines)) { defines = invoker.defines }
      if (defined(invoker.deps)) { deps = invoker.deps }
      if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
      if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
      if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
      if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
      if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
      if (defined(invoker.libs)) { libs = invoker.libs }
      if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
      if (defined(invoker.output_name)) { output_name = invoker.output_name }
      if (defined(invoker.public)) { public = invoker.public }
      if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
      if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
      if (defined(invoker.sources)) { sources = invoker.sources }
      if (defined(invoker.testonly)) { testonly = invoker.testonly }
      if (defined(invoker.visibility)) { visibility = invoker.visibility }
    }
  }
}

# ==============================================================================
# TEST SETUP
# ==============================================================================

# Define a test as an executable (or shared_library on Android) with the
# "testonly" flag set.
template("test") {
  if (is_android) {
    shared_library(target_name) {
      # Configs will always be defined since we set_defaults for a component
      # above. We want to use those rather than whatever came with the nested
      # shared/static library inside the component.
      configs = []  # Prevent list overwriting warning.
      configs = invoker.configs

      # See above call.
      set_sources_assignment_filter([])

      testonly = true

      if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
      if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
      if (defined(invoker.cflags)) { cflags = invoker.cflags }
      if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
      if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
      if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
      if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
      if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
      if (defined(invoker.data)) { data = invoker.data }
      if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
      if (defined(invoker.defines)) { defines = invoker.defines }
      if (defined(invoker.deps)) { deps = invoker.deps }
      if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
      if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
      if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
      if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
      if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
      if (defined(invoker.libs)) { libs = invoker.libs }
      if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
      if (defined(invoker.output_name)) { output_name = invoker.output_name }
      if (defined(invoker.public)) { public = invoker.public }
      if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
      if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
      if (defined(invoker.sources)) { sources = invoker.sources }
      if (defined(invoker.visibility)) { visibility = invoker.visibility }
    }
  } else {
    executable(target_name) {
      # See above.
      configs = []  # Prevent list overwriting warning.
      configs = invoker.configs

      # See above call.
      set_sources_assignment_filter([])

      testonly = true

      if (defined(invoker.all_dependent_configs)) { all_dependent_configs = invoker.all_dependent_configs }
      if (defined(invoker.allow_circular_includes_from)) { allow_circular_includes_from = invoker.allow_circular_includes_from }
      if (defined(invoker.cflags)) { cflags = invoker.cflags }
      if (defined(invoker.cflags_c)) { cflags_c = invoker.cflags_c }
      if (defined(invoker.cflags_cc)) { cflags_cc = invoker.cflags_cc }
      if (defined(invoker.cflags_objc)) { cflags_objc = invoker.cflags_objc }
      if (defined(invoker.cflags_objcc)) { cflags_objcc = invoker.cflags_objcc }
      if (defined(invoker.check_includes)) { check_includes = invoker.check_includes }
      if (defined(invoker.data)) { data = invoker.data }
      if (defined(invoker.datadeps)) { datadeps = invoker.datadeps }
      if (defined(invoker.defines)) { defines = invoker.defines }
      # All shared libraries must have the sanitizer deps to properly link in
      # asan mode (this target will be empty in other cases).
      if (defined(invoker.deps)) {
        deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
      } else {
        deps = [ "//build/config/sanitizers:deps" ]
      }
      if (defined(invoker.direct_dependent_configs)) { direct_dependent_configs = invoker.direct_dependent_configs }
      if (defined(invoker.forward_dependent_configs_from)) { forward_dependent_configs_from = invoker.forward_dependent_configs_from }
      if (defined(invoker.include_dirs)) { include_dirs = invoker.include_dirs }
      if (defined(invoker.ldflags)) { ldflags = invoker.ldflags }
      if (defined(invoker.lib_dirs)) { lib_dirs = invoker.lib_dirs }
      if (defined(invoker.libs)) { libs = invoker.libs }
      if (defined(invoker.output_extension)) { output_extension = invoker.output_extension }
      if (defined(invoker.output_name)) { output_name = invoker.output_name }
      if (defined(invoker.public)) { public = invoker.public }
      if (defined(invoker.public_configs)) { public_configs = invoker.public_configs }
      if (defined(invoker.public_deps)) { public_deps = invoker.public_deps }
      if (defined(invoker.sources)) { sources = invoker.sources }
      if (defined(invoker.visibility)) { visibility = invoker.visibility }
    }
  }
}