File: fuzzable_proto_library.gni

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (81 lines) | stat: -rw-r--r-- 3,062 bytes parent folder | download | duplicates (5)
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
# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# A fuzzable_proto_library is a proto_library that is the same as any other in
# non-fuzzer builds (ie: use_libfuzzer=false). However, in fuzzer builds, the
# proto_library is built with the full protobuf runtime and any "optimize_for =
# LITE_RUNTIME" options are ignored. This is done because libprotobuf-mutator
# needs the full protobuf runtime, but proto_libraries shipped in Chrome must
# use the optimize for LITE_RUNTIME option which is incompatible with the full
# protobuf runtime. tl;dr: A fuzzable_proto_library is a proto_library that can
# be fuzzed with libprotobuf-mutator and shipped in Chrome.

import("//testing/libfuzzer/fuzzer_test.gni")
import("//third_party/protobuf/proto_library.gni")

# TODO(https://crbug.com/1197634): Fold this into proto_library.
template("fuzzable_proto_library") {
  # Only make the proto library fuzzable if we are doing a build that we can
  # use LPM on (i.e. libFuzzer not on Chrome OS).
  if (use_fuzzing_engine_with_lpm &&
      current_toolchain != "//build/toolchain/cros:target") {
    _proto_target_name = "${target_name}__proto"
    proto_library(_proto_target_name) {
      forward_variables_from(invoker, "*", [ "proto_library_deps" ])

      if (defined(invoker.proto_library_deps)) {
        if (!defined(deps)) {
          deps = []
        }
        deps += invoker.proto_library_deps
      }

      # Override LITE_RUNTIME settings in the protobuf files.
      cc_generator_options = "speed"
      extra_configs = [ "//third_party/protobuf:protobuf_config" ]
    }

    # These groups are required by proto_library template in proto_library.gni.
    group("${target_name}_input_group") {
      public_deps = [ ":${_proto_target_name}_input_group" ]
    }
    group("${target_name}_gen") {
      public_deps = [ ":${_proto_target_name}_gen" ]
    }

    # Inspired by proto_library.gni's handling of
    # component_build_force_source_set.
    if (defined(component_build_force_source_set) &&
        component_build_force_source_set && is_component_build) {
      link_target_type = "source_set"
    } else {
      link_target_type = "static_library"
    }

    # By making target a static_library or source_set, we can add protobuf_full
    # to public_deps.
    target(link_target_type, target_name) {
      if (defined(invoker.testonly)) {
        testonly = invoker.testonly
      }
      sources = [ "//third_party/libprotobuf-mutator/dummy.cc" ]
      public_deps = [
        ":$_proto_target_name",
        "//third_party/libprotobuf-mutator:protobuf_full",
      ]
    }
  } else {
    # fuzzable_proto_library should behave like a proto_library when
    # !use_libfuzzer.
    proto_library(target_name) {
      forward_variables_from(invoker, "*", [ "proto_library_deps" ])
      if (defined(invoker.proto_library_deps)) {
        if (!defined(deps)) {
          deps = []
        }
        deps += invoker.proto_library_deps
      }
    }
  }
}