summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/ios/intent_definition.gni
blob: 259f287fc686a18c047d78b063be77205511871d (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
# Copyright 2020 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.

import("//build/config/ios/ios_sdk.gni")

# Template to compile an .intentdefinition file.
#
# Arguments
#
#   intent_file
#     path to .intentdefinition file that must be compiled
#
#   intent_names
#     list of string corresponding to the intent defined in intent_file;
#     must include all the intents as only the intents listed will be
#     compiled
#
#   developer_dir
#     (optional) path to developer_dir to use
#
template("intent_definition") {
  assert(defined(invoker.intent_file) && invoker.intent_file != "",
         "intent_file must be defined for $target_name")

  assert(defined(invoker.intent_names) && invoker.intent_names != [],
         "intent_names must be defined for $target_name")

  assert(xcode_version_int >= 1140,
         "intent_definition requires Xcode 11.4 or higher")

  _compile_intent_target = "${target_name}_compile_intent"
  _compile_intent_output =
      "$target_gen_dir/" + get_path_info(invoker.intent_file, "file")

  action(_compile_intent_target) {
    script = "//build/apple/xcrun.py"
    inputs = [ invoker.intent_file ]
    outputs = [ _compile_intent_output ]
    args = [
      "intentbuilderc",
      "compile",
      "-input",
      rebase_path(invoker.intent_file, root_build_dir),
      "-output",
      rebase_path(target_gen_dir, root_build_dir),
    ]

    if (defined(invoker.developer_dir)) {
      args += [
        "--developer-dir",
        rebase_path(invoker.developer_dir, root_build_dir),
      ]
    }
  }

  _compile_intent_bundle = "${target_name}_compile_intent_bundle"
  bundle_data(_compile_intent_bundle) {
    sources = [ _compile_intent_output ]
    outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
    public_deps = [ ":$_compile_intent_target" ]
  }

  _generate_source_target = "${target_name}_generate_source"
  _generate_source_output = []
  foreach(_intent, invoker.intent_names) {
    _generate_source_output += [
      "$target_gen_dir/$_intent.h",
      "$target_gen_dir/$_intent.m",
    ]
  }

  action(_generate_source_target) {
    script = "//build/apple/xcrun.py"
    inputs = [ invoker.intent_file ]
    outputs = _generate_source_output
    args = [
      "intentbuilderc",
      "generate",
      "-input",
      rebase_path(invoker.intent_file, root_build_dir),
      "-output",
      rebase_path(target_gen_dir, root_build_dir),
      "-language",
      "Objective-C",
    ]

    if (defined(invoker.developer_dir)) {
      args += [
        "--developer-dir",
        rebase_path(invoker.developer_dir, root_build_dir),
      ]
    }
  }

  source_set(target_name) {
    forward_variables_from(invoker,
                           "*",
                           [
                             "developer_dir",
                             "intent_file",
                             "intent_names",
                             "sources",
                           ])

    if (!defined(deps)) {
      deps = []
    }
    if (!defined(frameworks)) {
      frameworks = []
    }

    sources = _generate_source_output
    configs += [ "//build/config/compiler:enable_arc" ]
    deps += [
      ":$_compile_intent_bundle",
      ":$_generate_source_target",
    ]
    frameworks += [ "Intents.framework" ]
  }
}