summaryrefslogtreecommitdiffstats
path: root/mojo/public
diff options
context:
space:
mode:
authorben <ben@chromium.org>2016-02-03 16:21:58 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-04 00:23:02 +0000
commit1a84d01d89fe66d8d3eaedd531a37597cccd9362 (patch)
treef48b5d1d8036c4e46cacc88e30b26eb5404f46b7 /mojo/public
parent251f17f89408c04d2db6a970559b6999463c8a6e (diff)
downloadchromium_src-1a84d01d89fe66d8d3eaedd531a37597cccd9362.zip
chromium_src-1a84d01d89fe66d8d3eaedd531a37597cccd9362.tar.gz
chromium_src-1a84d01d89fe66d8d3eaedd531a37597cccd9362.tar.bz2
Add a rule for collating mojo application manifests.
Introduces a new GN template for generating a manifest. Instantiations of this template can define dependencies which are collated with the parent to produce a meta (package) manifest absorbing the dependencies manifests. R=rockot,jam http://crbug.com/575858 Review URL: https://codereview.chromium.org/1660243002 Cr-Commit-Position: refs/heads/master@{#373396}
Diffstat (limited to 'mojo/public')
-rw-r--r--mojo/public/mojo_application.gni14
-rw-r--r--mojo/public/mojo_application_manifest.gni97
-rwxr-xr-xmojo/public/tools/manifest/manifest_collator.py56
3 files changed, 153 insertions, 14 deletions
diff --git a/mojo/public/mojo_application.gni b/mojo/public/mojo_application.gni
index cd0e78e..70fc5f1d 100644
--- a/mojo/public/mojo_application.gni
+++ b/mojo/public/mojo_application.gni
@@ -39,20 +39,6 @@ template("mojo_native_application") {
}
mojo_deps += [ ":$copy_step_name" ]
}
- if (defined(invoker.manifest)) {
- copy_step_name = "${base_target_name}__copy_manifest"
- copy(copy_step_name) {
- sources = invoker.manifest
- outputs = [
- "${root_out_dir}/${base_target_name}/manifest.json",
- ]
- if (defined(invoker.testonly)) {
- testonly = invoker.testonly
- }
- deps = mojo_deps
- }
- mojo_deps += [ ":$copy_step_name" ]
- }
output = base_target_name + ".mojo"
library_target_name = base_target_name + "_library"
diff --git a/mojo/public/mojo_application_manifest.gni b/mojo/public/mojo_application_manifest.gni
new file mode 100644
index 0000000..1ba5c1e
--- /dev/null
+++ b/mojo/public/mojo_application_manifest.gni
@@ -0,0 +1,97 @@
+# 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.
+#
+# 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.")
+ }
+
+ action(target_name) {
+ script = "//mojo/public/tools/manifest/manifest_collator.py"
+
+ application_name = invoker.application_name
+ 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"
+ 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})" ]
+ }
+ }
+}
diff --git a/mojo/public/tools/manifest/manifest_collator.py b/mojo/public/tools/manifest/manifest_collator.py
new file mode 100755
index 0000000..7acc76b
--- /dev/null
+++ b/mojo/public/tools/manifest/manifest_collator.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+# 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.
+
+""" A collator for Mojo Application Manifests """
+
+import argparse
+import json
+import shutil
+import sys
+import urlparse
+
+def ParseJSONFile(filename):
+ with open(filename) as json_file:
+ try:
+ return json.load(json_file)
+ except ValueError:
+ print "%s is not a valid JSON document" % filename
+ return None
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Collate Mojo application manifests.")
+ parser.add_argument("--parent")
+ parser.add_argument("--output")
+ parser.add_argument("--application-name")
+ args, children = parser.parse_known_args()
+
+ parent = ParseJSONFile(args.parent)
+ if parent == None:
+ return 1
+
+ parsed = urlparse.urlparse(parent['url'])
+ if args.application_name != parsed.hostname:
+ raise ValueError("Application name '%s' specified in build file does not " \
+ "match application name '%s' specified in manifest." %
+ (args.application_name, parsed.hostname))
+
+ applications = []
+ for child in children:
+ application = ParseJSONFile(child)
+ if application == None:
+ return 1
+ applications.append(application)
+
+ if len(applications) > 0:
+ parent['applications'] = applications
+
+ with open(args.output, 'w') as output_file:
+ json.dump(parent, output_file)
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main())