File: ts_library.gni

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (177 lines) | stat: -rw-r--r-- 5,157 bytes parent folder | download | duplicates (3)
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
# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//third_party/node/node.gni")

template("ts_library") {
  node(target_name) {
    script = "//tools/typescript/ts_library.py"

    forward_variables_from(invoker,
                           [
                             "deps",
                             "extra_deps",
                             "in_files",
                             "tsconfig_base",
                             "path_mappings_file",
                             "manifest_excludes",
                             "testonly",
                             "visibility",
                           ])

    inputs = [
      "//tools/typescript/path_utils.py",
      "//tools/typescript/tsconfig_base.json",
      "//tools/typescript/validate_tsconfig.py",
    ]
    outputs = [ "$target_gen_dir/tsconfig_$target_name.json" ]

    assert(defined(in_files) || defined(invoker.definitions))

    root_dir = "."
    if (defined(invoker.root_dir)) {
      root_dir = invoker.root_dir
    }

    out_dir = target_gen_dir
    if (defined(invoker.out_dir)) {
      out_dir = invoker.out_dir
    }

    composite = false
    if (defined(invoker.composite)) {
      composite = invoker.composite
    }

    if (defined(in_files)) {
      outputs += [ "$target_gen_dir/${target_name}_manifest.json" ]
      foreach(_source, in_files) {
        inputs += [ "$root_dir/$_source" ]
        _dirname =
            rebase_path(get_path_info(_source, "gen_dir"), target_gen_dir)
        _filename = get_path_info(_source, "name")
        outputs += [ "$out_dir/$_dirname/$_filename.js" ]

        if (composite) {
          outputs += [ "$out_dir/$_dirname/$_filename.d.ts" ]
        }
      }
    }

    args = [
      "--root_gen_dir",
      rebase_path(root_gen_dir, target_gen_dir),
      "--root_src_dir",
      rebase_path("//", target_gen_dir),

      "--root_dir",
      rebase_path(root_dir, root_build_dir),
      "--gen_dir",
      rebase_path(target_gen_dir, root_build_dir),
      "--out_dir",
      rebase_path(out_dir, root_build_dir),
      "--output_suffix",
      target_name,
    ]

    if (defined(in_files)) {
      args += [ "--in_files" ] + in_files
    }

    if (defined(path_mappings_file)) {
      args += [
        "--path_mappings_file",
        rebase_path(path_mappings_file, target_gen_dir),
      ]
      inputs += [ path_mappings_file ]
    }

    if (defined(manifest_excludes)) {
      assert(defined(in_files))
      args += [ "--manifest_excludes" ] + manifest_excludes
    }

    if (defined(invoker.definitions)) {
      inputs += invoker.definitions
      definitions = []
      foreach(_definition, invoker.definitions) {
        definitions += [ rebase_path(_definition, target_gen_dir) ]
      }
      args += [ "--definitions" ] + definitions
    }

    if (defined(deps)) {
      args += [ "--deps" ]
      foreach(dep, deps) {
        name = get_label_info(dep, "name")
        tsconfig_dep =
            get_label_info(dep, "target_gen_dir") + "/tsconfig_$name.json"
        inputs += [ tsconfig_dep ]
        args += [ rebase_path(tsconfig_dep, target_gen_dir) ]
      }
    }

    if (defined(tsconfig_base)) {
      inputs += [ tsconfig_base ]
      args += [
        "--tsconfig_base",
        rebase_path(tsconfig_base, target_gen_dir),
      ]
    }

    if (composite) {
      args += [ "--composite" ]
    }

    if (defined(invoker.enable_source_maps) && invoker.enable_source_maps) {
      args += [ "--enable_source_maps" ]
    }

    if (defined(extra_deps)) {
      # ts_library() targets are conventionally named with "build_ts" or
      # "library". These should always be listed in deps and not extra_deps
      foreach(_extra_dep, extra_deps) {
        assert(get_label_info(_extra_dep, "name") != "build_ts" &&
                   get_label_info(_extra_dep, "name") != "library",
               "Did you mean to list ${_extra_dep} in deps instead of " +
                   "extra_deps? extra_deps should not hold any ts_library() " +
                   "targets.")
      }
      if (!defined(deps)) {
        deps = []
      }
      deps += extra_deps
    }

    path_mappings = [
      "/tools/typescript/definitions/*|" +
          rebase_path("//tools/typescript/definitions/*", target_gen_dir),
      # NOTE: path_mappings corresponding to files generated by
      # other ts_library() deps are automatically inferred from |deps| in
      # path_mappings.py. Don't add any such mappings here.
    ]

    # The |platform| flag is used in path_mappings.py and validate_tsconfig.py,
    # to limit some logic to certain platforms, like preventing special iOS
    # exceptions being abused on other platforms.
    if (is_ios) {
      platform = "ios"
      args += [
        "--platform",
        platform,
      ]
    } else if (is_chromeos) {
      platform = "chromeos_ash"
      args += [
        "--platform",
        platform,
      ]
    }

    args += [ "--path_mappings" ] + path_mappings
    if (defined(invoker.path_mappings)) {
      args += invoker.path_mappings
    }
  }
}