File: BUILD.gn

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 (121 lines) | stat: -rw-r--r-- 3,404 bytes parent folder | download | duplicates (10)
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 2022 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/closure_compiler/closure_args.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/typescript/ts_library.gni")
import("//ui/webui/resources/tools/generate_grd.gni")

assert(is_chromeos, "Desk API is ChromeOS only.")

resources_grd_file = "$target_gen_dir/resources.grd"

ts_files = [
  "background.ts",
  "background_main.ts",
  "desk_api_impl.ts",
  "message_type.ts",
  "notification_api_impl.ts",
  "service_worker.ts",
]

type_files = [
  "chrome_type_extension.d.ts",
  "desk_api_types.d.ts",
  "types.d.ts",
]

# Copy definition files to output folder, so they can import relatively the
# generated definitions.
copy("copy_definition") {
  sources = type_files
  outputs = [ "$target_gen_dir/{{source_target_relative}}" ]
}

copy("copy_src") {
  sources = ts_files
  outputs = [ "$target_gen_dir/{{source_file_part}}" ]
}

ts_library("build_ts") {
  deps = []
  extra_deps = [
    ":copy_definition",
    ":copy_src",
  ]

  # Using custom config to turn off useDefineForClassFields TS compiler flag
  # which is necessary for the js_binary() call below to work. An alternative
  # workaround would be to set TS compiler's `target` flag to 'es2021' or
  # earlier.
  tsconfig_base = "tsconfig_base.json"
  root_dir = "$target_gen_dir"
  out_dir = "$target_gen_dir/tsc"
  in_files = ts_files
  definitions = [
    "$target_gen_dir/chrome_type_extension.d.ts",
    "$target_gen_dir/desk_api_types.d.ts",
    "$target_gen_dir/types.d.ts",
    "//tools/typescript/definitions/chrome_event.d.ts",
    "//tools/typescript/definitions/notifications.d.ts",
    "//tools/typescript/definitions/runtime.d.ts",
    "//tools/typescript/definitions/tabs.d.ts",
  ]
}

js_library("js_from_ts") {
  sources = []
  foreach(_t, ts_files) {
    sources += [ "$target_gen_dir/tsc/" + string_replace(_t, ".ts", ".js") ]
  }
  extra_deps = [ ":build_ts" ]
}

# Generate a bundle that contains all external dependencies and source used by
# the extension.
js_binary("generate_desk_api_bundle") {
  deps = [ ":js_from_ts" ]
  sources = [ "$externs_path/chrome_extensions.js" ]
  outputs = [ "${target_gen_dir}/desk_api_bundle.js" ]
  closure_flags = default_closure_args + [
                    "generate_exports=true",
                    "jscomp_warning=checkTypes",
                    "jscomp_warning=deprecatedAnnotations",
                    "jscomp_warning=deprecated",
                  ]
}

generate_grd("build_grd") {
  deps = [
    ":build_ts",
    ":generate_desk_api_bundle",
  ]
  input_files = [
    "index.html",
    "templates_icon.png",
  ]
  input_files_base_dir = rebase_path(".", "//")
  manifest_files =
      filter_include(get_target_outputs(":generate_desk_api_bundle"),
                     [ "*_manifest.json" ])

  grd_prefix = "desk_api"
  out_grd = resources_grd_file
}

grit("resources") {
  # These arguments are needed since the grd is generated at build time.
  enable_input_discovery_for_gn_analyze = false
  source = resources_grd_file
  deps = [ ":build_grd" ]

  outputs = [
    "grit/desk_api_resources.h",
    "grit/desk_api_resources_map.cc",
    "grit/desk_api_resources_map.h",
    "desk_api_resources.pak",
  ]
  output_dir = "$root_gen_dir/chrome"
}