| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import("//build/config/dcheck_always_on.gni") | 5 import("//build/config/dcheck_always_on.gni") |
| 6 import("//services/service_manager/public/constants.gni") |
| 6 | 7 |
| 7 # Used to produce a Service Manifest for a Service. | 8 # Used to produce a Service Manifest for a Service. |
| 8 # | 9 # |
| 9 # Service manifests may be subsequently aggregated into one or more catalog | |
| 10 # manifests (see //services/catalog/public/tools/catalog.gni). A catalog | |
| 11 # manifest provides the Service Manager at runtime with a static service layout | |
| 12 # configuration to dictate which services are supported by the runtime | |
| 13 # environment as well as how individual services may be launched and | |
| 14 # interconnected. | |
| 15 # | |
| 16 # Note that this target may be used to produce partial manifests, and partial | |
| 17 # manifests may be aggregated by using one service_manifest target as the | |
| 18 # |source_manifest| of another (see below.) | |
| 19 # | |
| 20 # Parameters: | 10 # Parameters: |
| 21 # | 11 # |
| 22 # source (optional**) | 12 # source |
| 23 # The manifest template for this service. Must be the name of a valid JSON | 13 # The manifest file template for this service, must be valid JSON with |
| 24 # file. | 14 # a valid 'url' key matching name. |
| 25 # | |
| 26 # source_manifest (optional**) | |
| 27 # The manifest template for this service. Must be the name of another | |
| 28 # service_manifest target. | |
| 29 # | |
| 30 # ** NOTE: Either |source| OR |source_manifest| MUST be specified. | |
| 31 # | |
| 32 # name (optional) | |
| 33 # The name of the service whose manifest is to be generated. A script | |
| 34 # validates that the value of this parameter matches the name set in the | |
| 35 # source manifest and raises an error if it does not match. | |
| 36 # | 15 # |
| 37 # overlays (optional) | 16 # overlays (optional) |
| 38 # A list of other manifest targets whose outputs should be overlayed onto | 17 # A list of partial manifests to overlay onto the source manifest before |
| 39 # the source manifest before emitting the final output. Overlays are | 18 # emitting the final output. Overlays are applied as the last step, after |
| 40 # applied in-order as the last step of output generation, after any | 19 # any packaged manifests are embedded. |
| 41 # |packaged_services| manifests are embedded. | 20 # |
| 21 # name |
| 22 # The host portion of the mojo: URL of the service. A script validates |
| 23 # that the value of this parameter matches the host name portion of the |
| 24 # 'url' property set in the manifest and throws a ValueError if they do |
| 25 # not. |
| 26 # |
| 27 # output_name (optional) |
| 28 # The name of the package to output. The default value is copied from |
| 29 # |name|. Note that this has no effect on the contents of the manifest, |
| 30 # but only determines the output subdirectory within ${out}/Packages. |
| 31 # |
| 32 # deps (optional) |
| 33 # An array of dependent instances of this template. This template enforces |
| 34 # that dependencies can only be instances of this template. |
| 42 # | 35 # |
| 43 # packaged_services (optional) | 36 # packaged_services (optional) |
| 44 # A list of other manifest targets whose outputs should be packaged | 37 # An array of names of the dependent services. |
| 45 # within this output manifest, specifically within a toplevel "services" | |
| 46 # list. | |
| 47 # | 38 # |
| 48 # Outputs: | 39 # Outputs: |
| 49 # | 40 # |
| 50 # An instantiation of this template produces a meta manifest from the source | 41 # An instantiation of this template produces in |
| 51 # template and the output manifests of all its |overlay| and | 42 # $outdir/<name>/manifest.json |
| 52 # |packaged_services|dependencies. The output file is always | 43 # a meta manifest from the source template and the output manifest of all |
| 53 # "$target_gen_dir/${target_name}.json". | 44 # dependent children. |
| 54 # | 45 # |
| 55 template("service_manifest") { | 46 template("service_manifest") { |
| 56 assert( | 47 assert(defined(invoker.source), |
| 57 defined(invoker.source) || defined(invoker.source_manifest), | 48 "\"source\" must be defined for the $target_name template") |
| 58 "\"source\" or \"source_manifest\" must be defined for the $target_name ta
rget") | 49 assert(defined(invoker.name), |
| 59 assert( | 50 "\"name\" must be defined for the $target_name template") |
| 60 !defined(invoker.source) || !defined(invoker.source_manifest), | 51 if (defined(invoker.deps)) { |
| 61 "Only one of \"source\" or \"source_manifest\" must be defined for the $ta
rget_name target") | 52 assert(defined(invoker.packaged_services) || defined(invoker.overlays), |
| 53 "\"deps\" implies that you also want \"packaged_services\" and/or" + |
| 54 "\"overlays\", but you have neither.") |
| 55 } |
| 56 if (defined(invoker.packaged_services)) { |
| 57 assert(defined(invoker.deps), |
| 58 "\"deps\" building the dependent packaged services must be " + |
| 59 "provided.") |
| 60 } |
| 62 | 61 |
| 63 action(target_name) { | 62 action(target_name) { |
| 64 script = | 63 script = |
| 65 "//services/service_manager/public/tools/manifest/manifest_collator.py" | 64 "//services/service_manager/public/tools/manifest/manifest_collator.py" |
| 66 | 65 |
| 66 name = invoker.name |
| 67 inputs = [ |
| 68 invoker.source, |
| 69 ] |
| 70 if (defined(invoker.overlays)) { |
| 71 inputs += invoker.overlays |
| 72 } |
| 73 |
| 74 if (defined(invoker.output_name)) { |
| 75 output = "$root_out_dir/$packages_directory/${invoker.output_name}/manifes
t.json" |
| 76 } else { |
| 77 output = "$root_out_dir/$packages_directory/$name/manifest.json" |
| 78 } |
| 79 outputs = [ |
| 80 output, |
| 81 ] |
| 82 |
| 83 rebase_parent = rebase_path(invoker.source, root_build_dir) |
| 84 rebase_output = rebase_path(output, root_build_dir) |
| 85 |
| 86 args = [ |
| 87 "--name=$name", |
| 88 "--parent=$rebase_parent", |
| 89 "--output=$rebase_output", |
| 90 ] |
| 91 |
| 92 if (is_debug || dcheck_always_on) { |
| 93 args += [ "--pretty" ] |
| 94 } |
| 95 |
| 96 if (defined(invoker.overlays)) { |
| 97 args += [ "--overlays" ] |
| 98 foreach(overlay_path, invoker.overlays) { |
| 99 args += [ rebase_path(overlay_path, root_build_dir) ] |
| 100 } |
| 101 } |
| 102 |
| 103 if (defined(invoker.packaged_services)) { |
| 104 args += [ "--packaged-services" ] |
| 105 foreach(name, invoker.packaged_services) { |
| 106 input = "$root_out_dir/$packages_directory/$name/manifest.json" |
| 107 inputs += [ input ] |
| 108 args += [ rebase_path(input, root_build_dir) ] |
| 109 } |
| 110 } |
| 67 deps = [] | 111 deps = [] |
| 112 data_deps = [] |
| 68 if (defined(invoker.deps)) { | 113 if (defined(invoker.deps)) { |
| 69 deps += invoker.deps | 114 deps += invoker.deps |
| 70 } | 115 data_deps += invoker.deps |
| 71 | 116 } |
| 72 if (defined(invoker.source)) { | 117 } |
| 73 source = invoker.source | 118 |
| 74 } else { | 119 all_deps = [] |
| 75 source_target_dir = | 120 if (defined(invoker.deps)) { |
| 76 get_label_info(invoker.source_manifest, "target_gen_dir") | 121 all_deps += invoker.deps |
| 77 source_target_name = get_label_info(invoker.source_manifest, "name") | 122 } |
| 78 source = "$source_target_dir/${source_target_name}.json" | 123 |
| 79 deps += [ invoker.source_manifest ] | 124 group("${target_name}__is_service_manifest_or_overlay") { |
| 80 } | 125 } |
| 126 |
| 127 # Explicitly ensure that all dependencies are service_manifest |
| 128 # or service_manifest_overlay targets themselves. |
| 129 group("${target_name}__check_deps_are_all_service_manifest") { |
| 130 deps = [] |
| 131 foreach(d, all_deps) { |
| 132 name = get_label_info(d, "label_no_toolchain") |
| 133 toolchain = get_label_info(d, "toolchain") |
| 134 deps += [ "${name}__is_service_manifest_or_overlay(${toolchain})" ] |
| 135 } |
| 136 } |
| 137 } |
| 138 |
| 139 # A simple derivative of the service_manifest template above. This allows for |
| 140 # embedding of packaged services into a manifest overlay. |
| 141 # |
| 142 # Parameters: |
| 143 # |
| 144 # source |
| 145 # The manifest overlay file to procss. |
| 146 # |
| 147 # overlays (optional) |
| 148 # A list of partial manifests to overlay onto the source manifest before |
| 149 # emitting the final output. Overlays are applied as the last step, after |
| 150 # any packaged manifests are embedded. |
| 151 # |
| 152 # output_name (optional) |
| 153 # The output name of the manifest. Defaults to the target name. |
| 154 # |
| 155 # deps (optional) |
| 156 # An array of the service_manifest targets this overlay depends on. |
| 157 # |
| 158 # packaged_services (optional) |
| 159 # An array of names of the services packaged into this overlay. |
| 160 # |
| 161 # Outputs: |
| 162 # |
| 163 # An instantiation of this template produces in |
| 164 # ${root_gen_dir}/${output_name}.json |
| 165 # |
| 166 template("service_manifest_overlay") { |
| 167 assert(defined(invoker.source), |
| 168 "\"source\" must be defined for the $target_name template") |
| 169 if (defined(invoker.deps)) { |
| 170 assert(defined(invoker.packaged_services) || defined(invoker.overlays), |
| 171 "\"deps\" implies that you also want \"packaged_services\" and/or" + |
| 172 "\"overlays\", but you have neither.") |
| 173 } |
| 174 if (defined(invoker.packaged_services)) { |
| 175 assert(defined(invoker.deps), |
| 176 "\"deps\" building the dependent packaged services must be " + |
| 177 "provided.") |
| 178 } |
| 179 |
| 180 action(target_name) { |
| 181 script = |
| 182 "//services/service_manager/public/tools/manifest/manifest_collator.py" |
| 183 |
| 81 inputs = [ | 184 inputs = [ |
| 82 source, | 185 invoker.source, |
| 83 ] | 186 ] |
| 84 | 187 if (defined(invoker.overlays)) { |
| 85 output = "$target_gen_dir/${target_name}.json" | 188 inputs += invoker.overlays |
| 189 } |
| 190 |
| 191 output_name = target_name |
| 192 if (defined(invoker.output_name)) { |
| 193 output_name = invoker.output_name |
| 194 } |
| 195 output = "${root_gen_dir}/${output_name}.json" |
| 196 |
| 86 outputs = [ | 197 outputs = [ |
| 87 output, | 198 output, |
| 88 ] | 199 ] |
| 89 | 200 |
| 90 rebase_parent = rebase_path(source, root_build_dir) | 201 rebase_parent = rebase_path(invoker.source, root_build_dir) |
| 91 rebase_output = rebase_path(output, root_build_dir) | 202 rebase_output = rebase_path(output, root_build_dir) |
| 92 | 203 |
| 93 args = [ | 204 args = [ |
| 94 "--parent=$rebase_parent", | 205 "--parent=$rebase_parent", |
| 95 "--output=$rebase_output", | 206 "--output=$rebase_output", |
| 96 ] | 207 ] |
| 97 | 208 |
| 98 if (defined(invoker.name)) { | |
| 99 args += [ | |
| 100 "--name", | |
| 101 invoker.name, | |
| 102 ] | |
| 103 } | |
| 104 | |
| 105 if (is_debug || dcheck_always_on) { | 209 if (is_debug || dcheck_always_on) { |
| 106 args += [ "--pretty" ] | 210 args += [ "--pretty" ] |
| 107 } | 211 } |
| 108 | 212 |
| 109 if (defined(invoker.overlays)) { | 213 if (defined(invoker.overlays)) { |
| 110 args += [ "--overlays" ] | 214 args += [ "--overlays" ] |
| 111 foreach(manifest_target, invoker.overlays) { | 215 foreach(overlay_path, invoker.overlays) { |
| 112 manifest_target_dir = get_label_info(manifest_target, "target_gen_dir") | 216 args += [ rebase_path(overlay_path, root_build_dir) ] |
| 113 manifest_target_name = get_label_info(manifest_target, "name") | |
| 114 manifest_filename = "$manifest_target_dir/${manifest_target_name}.json" | |
| 115 | |
| 116 inputs += [ manifest_filename ] | |
| 117 deps += [ manifest_target ] | |
| 118 args += [ rebase_path(manifest_filename, root_build_dir) ] | |
| 119 | |
| 120 # Ensure that each entry does in fact reference a manifest rule. | |
| 121 label_no_toolchain = | |
| 122 get_label_info(manifest_target, "label_no_toolchain") | |
| 123 toolchain = get_label_info(manifest_target, "toolchain") | |
| 124 deps += [ "${label_no_toolchain}__is_service_manifest(${toolchain})" ] | |
| 125 } | 217 } |
| 126 } | 218 } |
| 127 | 219 |
| 128 if (defined(invoker.packaged_services)) { | 220 if (defined(invoker.packaged_services)) { |
| 129 args += [ "--packaged-services" ] | 221 args += [ "--packaged-services" ] |
| 130 foreach(manifest_target, invoker.packaged_services) { | 222 foreach(name, invoker.packaged_services) { |
| 131 manifest_target_dir = get_label_info(manifest_target, "target_gen_dir") | 223 input = "$root_out_dir/$packages_directory/$name/manifest.json" |
| 132 manifest_target_name = get_label_info(manifest_target, "name") | 224 inputs += [ input ] |
| 133 manifest_filename = "$manifest_target_dir/${manifest_target_name}.json" | 225 args += [ rebase_path(input, root_build_dir) ] |
| 226 } |
| 227 } |
| 134 | 228 |
| 135 inputs += [ manifest_filename ] | 229 deps = [] |
| 136 deps += [ manifest_target ] | 230 data_deps = [] |
| 137 args += [ rebase_path(manifest_filename, root_build_dir) ] | 231 if (defined(invoker.deps)) { |
| 138 | 232 deps += invoker.deps |
| 139 # Ensure that each entry does in fact reference a manifest rule. | 233 data_deps += invoker.deps |
| 140 label_no_toolchain = | |
| 141 get_label_info(manifest_target, "label_no_toolchain") | |
| 142 toolchain = get_label_info(manifest_target, "toolchain") | |
| 143 deps += [ "${label_no_toolchain}__is_service_manifest(${toolchain})" ] | |
| 144 } | |
| 145 } | 234 } |
| 146 } | 235 } |
| 147 | 236 |
| 148 group("${target_name}__is_service_manifest") { | 237 group("${target_name}__is_service_manifest_or_overlay") { |
| 238 } |
| 239 |
| 240 # Explicitly ensure that all dependencies are service_manifest |
| 241 # or service_manifest_overlay targets themselves. |
| 242 group("${target_name}__check_deps_are_all_service_manifest") { |
| 243 deps = [] |
| 244 foreach(d, all_deps) { |
| 245 name = get_label_info(d, "label_no_toolchain") |
| 246 toolchain = get_label_info(d, "toolchain") |
| 247 deps += [ "${name}__is_service_manifest_or_overlay(${toolchain})" ] |
| 248 } |
| 149 } | 249 } |
| 150 } | 250 } |
| OLD | NEW |