summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/config/ios/asset_catalog.gni
blob: 84dd92cce20976293794b629d3990bfdcd788ff5 (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
# Copyright 2017 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")

# This template declares a bundle_data target that references an asset
# catalog so that it is compiled to the asset catalog of the generated
# bundle.
#
# The create_bundle target requires that all asset catalogs are part of an
# .xcasset bundle. This requirement comes from actool that only receives
# the path to the .xcasset bundle directory and not to the individual
# .imageset directories.
#
# The requirement is a bit problematic as it prevents compiling only a
# subset of the asset catakig that are contained in a .xcasset. This template
# fixes that by instead copying the content of the asset catalog to temporary
# .xcasset directory (below $root_out_dir) and defining a bundle_data
# target that refers to those copies (this is efficient as the "copy" is
# implemented by hardlinking if possible on macOS).
#
# Since the create_data target will only refer to the .xcasset directory
# and additional "action" target that runs a dummy script is defined. It
# does nothing but pretends to generate the .xcassets directory (while
# it is really created as a side-effect of the "copy" step). This allows
# to workaround the check in "gn" that all inputs below $root_out_dir have
# to be outputs of another target with a public dependency path.
#
# This template also ensures that the file are only copied once when the
# build targets multiple architectures at the same time (aka "fat build").
#
# Arguments
#
#     sources:
#       required, list of strings, paths to the file contained in the
#       asset catalog directory; this must contain the Contents.json file
#       and all the image referenced by it (not enforced by the template).
#
#     asset_type:
#       required, string, type of the asset catalog, that is the extension
#       of the directory containing the images and the Contents.json file.
#
template("asset_catalog") {
  assert(defined(invoker.sources) && invoker.sources != [],
         "sources must be defined and not empty for $target_name")

  assert(defined(invoker.asset_type) && invoker.asset_type != "",
         "asset_type must be defined and not empty for $target_name")

  if (is_fat_secondary_toolchain) {
    group(target_name) {
      public_deps = [ ":$target_name($primary_fat_toolchain_name)" ]
    }
  } else {
    _copy_target_name = target_name + "__copy"
    _data_target_name = target_name

    _sources = invoker.sources
    _outputs = []

    # The compilation of resources into Assets.car is enabled automatically
    # by the "create_bundle" target if any of the "bundle_data" sources's
    # path is in a .xcassets directory and matches one of the know asset
    # catalog type.
    _xcassets_dir = "$target_gen_dir/${target_name}.xcassets"
    _output_dir = "$_xcassets_dir/" +
                  get_path_info(get_path_info(_sources[0], "dir"), "file")

    foreach(_source, invoker.sources) {
      _dir = get_path_info(_source, "dir")
      _outputs += [ "$_output_dir/" + get_path_info(_source, "file") ]

      assert(get_path_info(_dir, "extension") == invoker.asset_type,
             "$_source dirname must have .${invoker.asset_type} extension")
    }

    action(_copy_target_name) {
      # Forward "deps", "public_deps" and "testonly" in case some of the
      # source files are generated.
      forward_variables_from(invoker,
                             [
                               "deps",
                               "public_deps",
                               "testonly",
                             ])

      script = "//build/config/ios/hardlink.py"

      visibility = [ ":$_data_target_name" ]
      sources = _sources
      outputs = _outputs + [ _xcassets_dir ]

      args = [
        rebase_path(get_path_info(_sources[0], "dir"), root_build_dir),
        rebase_path(_output_dir, root_build_dir),
      ]
    }

    bundle_data(_data_target_name) {
      forward_variables_from(invoker,
                             "*",
                             [
                               "deps",
                               "outputs",
                               "public_deps",
                               "sources",
                             ])

      sources = _outputs
      outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
      public_deps = [ ":$_copy_target_name" ]
    }
  }
}

# Those templates are specialisation of the asset_catalog template for known
# types of asset catalog types (imageset, launchimage, appiconset).
#
# Arguments
#
#     sources:
#       required, list of strings, paths to the file contained in the
#       asset catalog directory; this must contain the Contents.json file
#       and all the image referenced by it (not enforced by the template).
#
template("appiconset") {
  asset_catalog(target_name) {
    forward_variables_from(invoker, "*", [ "asset_type" ])
    asset_type = "appiconset"
  }
}
template("colorset") {
  asset_catalog(target_name) {
    forward_variables_from(invoker, "*", [ "asset_type" ])
    asset_type = "colorset"
  }
}
template("imageset") {
  asset_catalog(target_name) {
    forward_variables_from(invoker, "*", [ "asset_type" ])
    asset_type = "imageset"
  }
}
template("launchimage") {
  asset_catalog(target_name) {
    forward_variables_from(invoker, "*", [ "asset_type" ])
    asset_type = "launchimage"
  }
}