Chromium Code Reviews| Index: mojo/public/python/rules.gni |
| diff --git a/mojo/public/python/rules.gni b/mojo/public/python/rules.gni |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a79e7352be245381f21eedf511f48fde5be496cf |
| --- /dev/null |
| +++ b/mojo/public/python/rules.gni |
| @@ -0,0 +1,125 @@ |
| +# Copyright 2015 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. |
| + |
| +# Rules to generate python packaged applications for Mojo |
| + |
| +import("../mojo_sdk.gni") |
| + |
| +template("python_package") { |
| + action(target_name) { |
| + script = rebase_path("mojo/public/tools/gn/zip.py", ".", mojo_root) |
| + |
| + inputs = invoker.sources |
| + |
| + deps = [] |
| + zip_inputs = [] |
| + |
| + if (defined(invoker.mojom_deps)) { |
| + foreach(d, invoker.mojom_deps) { |
| + # Resolve the name, so that a target //mojo/something becomes |
| + # //mojo/something:something and we can append "_python" to get the |
| + # python dependency name. |
| + full_name = get_label_info(d, "label_no_toolchain") |
| + dep_name = get_label_info(d, "name") |
| + dep_target_out_dir = get_label_info(d, "target_out_dir") |
| + deps += [ "${full_name}_python" ] |
| + zip_inputs += [ "$dep_target_out_dir/$dep_name.pyzip" ] |
| + } |
| + } |
| + |
| + if (defined(invoker.deps)) { |
| + deps += invoker.deps |
| + foreach(d, invoker.deps) { |
| + dep_name = get_label_info(d, "name") |
| + dep_target_out_dir = get_label_info(d, "target_out_dir") |
| + zip_inputs += [ "$dep_target_out_dir/$dep_name.pyzip" ] |
| + } |
| + } |
| + |
| + if (defined(invoker.datadeps)) { |
| + datadeps = invoker.datadeps |
| + } |
| + |
| + output = "$target_out_dir/$target_name.pyzip" |
| + outputs = [ |
| + output, |
| + ] |
| + |
| + rebase_base_dir = |
| + rebase_path(get_label_info(":$target_name", "dir"), root_build_dir) |
| + rebase_inputs = rebase_path(inputs, root_build_dir) |
| + rebase_zip_inputs = rebase_path(zip_inputs, root_build_dir) |
| + rebase_output = rebase_path(output, root_build_dir) |
| + args = [ |
| + "--base-dir=$rebase_base_dir", |
| + "--inputs=$rebase_inputs", |
| + "--zip-inputs=$rebase_zip_inputs", |
| + "--output=$rebase_output", |
| + ] |
| + } |
| +} |
| + |
| +# Use this template to generate a .mojo python application. One of the source |
| +# files should be named __mojo__.py and contain a MojoMain function as the |
| +# entry point. Dependencies of python_packaged_application targets should be |
| +# either mojom targets (and specified using the mojom_deps variable) or |
| +# python_package targets. |
|
qsr
2015/01/12 17:37:45
I wonder if we need mojom_deps. With your changes,
etiennej
2015/01/14 00:54:04
Done.
|
| +template("python_packaged_application") { |
| + package_name = "${target_name}_package" |
| + package_output = "$target_out_dir/$package_name.pyzip" |
| + |
| + if (defined(invoker.output_name)) { |
| + mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo" |
| + } else { |
| + mojo_output = "$root_out_dir/" + target_name + ".mojo" |
| + } |
| + |
| + python_package(package_name) { |
| + sources = invoker.sources |
| + if (defined(invoker.deps)) { |
| + deps = invoker.deps |
| + } |
| + if (defined(invoker.mojom_deps)) { |
| + mojom_deps = invoker.mojom_deps |
| + } |
| + if (defined(invoker.datadeps)) { |
| + datadeps = invoker.datadeps |
| + } |
| + } |
| + |
| + action(target_name) { |
| + script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root) |
| + |
| + input = package_output |
| + inputs = [ |
| + input, |
| + ] |
| + |
| + output = mojo_output |
| + outputs = [ |
| + output, |
| + ] |
| + |
| + deps = [ |
| + ":$package_name", |
| + ] |
| + if (defined(invoker.deps)) { |
| + deps += invoker.deps |
| + } |
| + if (defined(invoker.mojom_deps)) { |
| + deps += invoker.mojom_deps |
| + } |
| + if (defined(invoker.datadeps)) { |
| + datadeps = invoker.datadeps |
| + } |
| + |
| + rebase_input = rebase_path(input, root_build_dir) |
| + rebase_output = rebase_path(output, root_build_dir) |
| + args = [ |
| + "--input=$rebase_input", |
| + "--output=$rebase_output", |
| + "--line=#!mojo:py_content_handler", |
| + ] |
| + } |
| +} |