summaryrefslogtreecommitdiffstats
path: root/mojo/public/mojo_application_manifest.gni
blob: 5b6cefe1d74d4758b7736ce6345fd0a2935084b5 (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
# Copyright 2016 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.

# Used to produce a Mojo Application Manifest for an application.
#
# Parameters:
#
#   source
#       The manifest file template for this application, must be valid JSON with
#       a valid 'url' key matching application_name.
#
#   application_name
#       The host portion of the mojo: URL of the application. The script
#       validates that the value of this parameter matches the host name portion
#       of the 'url' property set in the manifest and throws a ValueError if
#       they do not.
#
#   deps (optional)
#       An array of dependent instances of this template. This template enforces
#       that dependencies can only be instances of this template.
#
#   packaged_applications (optional)
#       An array of application_names of the dependent applications.
#
#   type (default is mojo)
#       Possible values are 'mojo' and 'exe'. Default is 'mojo'.
#
# Outputs:
#
#   An instantiation of this template produces in
#       $outdir/<application_name>/manifest.json
#   a meta manifest from the source template and the output manifest of all
#   dependent children.
#
template("mojo_application_manifest") {
  assert(defined(invoker.source),
         "\"source\" must be defined for the $target_name template")
  assert(defined(invoker.application_name),
         "\"application_name\" must be defined for the $target_name template")
  if (defined(invoker.deps)) {
    assert(defined(invoker.packaged_applications),
           "\"packaged_applications\" listing the directory containing the " +
               "manifest.json of dependent applications must be provided.")
  }
  if (defined(invoker.packaged_applications)) {
    assert(defined(invoker.deps),
           "\"deps\" building the dependent packaged applications must be " +
               "provided.")
  }
  if (defined(invoker.type)) {
    assert(invoker.type == "mojo" || invoker.type == "exe",
           "\"type\" must be one of \"mojo\" or \"exe\".")
  }

  action(target_name) {
    script = "//mojo/public/tools/manifest/manifest_collator.py"

    type = "mojo"
    if (defined(invoker.type)) {
      type = invoker.type
    }

    application_name = invoker.application_name
    inputs = [
      invoker.source,
    ]

    if (type == "mojo") {
      output = "$root_out_dir/$application_name/manifest.json"
    } else {
      output = "$root_out_dir/${application_name}_manifest.json"
    }
    outputs = [
      output,
    ]

    rebase_parent = rebase_path(invoker.source, root_build_dir)
    rebase_output = rebase_path(output, root_build_dir)

    args = [
      "--application-name=$application_name",
      "--parent=$rebase_parent",
      "--output=$rebase_output",
    ]

    if (defined(invoker.packaged_applications)) {
      foreach(application_name, invoker.packaged_applications) {
        input = "$root_out_dir/$application_name/manifest.json"
        inputs += [ input ]
        args += [ rebase_path(input, root_build_dir) ]
      }
    }
    deps = []
    if (defined(invoker.deps)) {
      deps += invoker.deps
    }
  }

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

  group("${target_name}__is_mojo_application_manifest") {
  }

  # Explicitly ensure that all dependencies are mojo_application_manifest
  # targets themselves.
  group("${target_name}__check_deps_are_all_mojo_application_manifest") {
    deps = []
    foreach(d, all_deps) {
      name = get_label_info(d, "label_no_toolchain")
      toolchain = get_label_info(d, "toolchain")
      deps += [ "${name}__is_mojo_application_manifest(${toolchain})" ]
    }
  }
}