1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 template("python_binary_source_set") {
6 # Only available on linux for now.
8 assert(defined(invoker.cython_sources) || defined(invoker.sources))
10 config_name = target_name + "_python_config"
12 target_visibility = [ ":$target_name" ]
14 if (defined(invoker.cython_sources)) {
15 generator_target_name = target_name + "_cython_compiler"
17 cython_root = "//third_party/cython"
18 cython_script = "$cython_root/src/cython.py"
19 cython_output = "${target_out_dir}/${target_name}.cc"
21 action(generator_target_name) {
22 visibility = target_visibility
23 script = cython_script
24 sources = invoker.cython_sources
31 rebase_path("//", root_build_dir),
33 rebase_path(target_gen_dir, root_build_dir),
35 rebase_path(cython_output, root_build_dir),
36 ] + rebase_path(sources, root_build_dir)
41 visibility = target_visibility
42 python_flags = "//third_party/cython/python_flags.py"
43 include_dirs = exec_script(python_flags, [ "--includes" ], "list lines")
44 libs = exec_script(python_flags, [ "--libraries" ], "list lines")
45 lib_dirs = exec_script(python_flags, [ "--library_dirs" ], "list lines")
47 # Generated code includes static utility functions that often go unused.
48 cflags = [ "-Wno-unused-function" ]
52 source_set(target_name) {
53 if (defined(invoker.visibility)) {
54 visibility = invoker.visibility
57 if (defined(invoker.cython_sources)) {
58 sources += [ cython_output ]
60 if (defined(invoker.sources)) {
61 sources += invoker.sources
63 if (defined(invoker.configs)) {
64 configs += invoker.configs
66 all_dependent_configs = [ ":$config_name" ]
68 if (defined(invoker.cython_sources)) {
69 deps += [ ":$generator_target_name" ]
71 if (defined(invoker.deps)) {
74 if (defined(invoker.datadeps)) {
75 datadeps = invoker.datadeps
80 template("python_binary_module") {
81 # Only available on linux for now.
84 has_sources = defined(invoker.cython_sources) || defined(invoker.sources)
86 assert(has_sources || defined(invoker.deps))
88 !defined(invoker.python_base_module) || invoker.python_base_module != "")
90 sources_target_name = target_name + "_cython_sources"
91 shared_library_name = target_name + "_shared_library"
94 shared_library_prefix = "lib"
95 shared_library_suffix = ".so"
96 python_module_suffix = ".so"
100 ":$sources_target_name",
101 ":$shared_library_name",
106 python_binary_source_set(sources_target_name) {
107 visibility = target_visibility
108 if (defined(invoker.cython_sources)) {
109 cython_sources = invoker.cython_sources
111 if (defined(invoker.sources)) {
112 sources = invoker.sources
114 if (defined(invoker.configs)) {
115 configs = invoker.configs
117 if (defined(invoker.deps)) {
120 if (defined(invoker.datadeps)) {
121 datadeps = invoker.datadeps
126 shared_library(shared_library_name) {
127 visibility = target_visibility
128 if (defined(invoker.configs)) {
129 configs += invoker.configs
133 deps += [ ":$sources_target_name" ]
135 if (defined(invoker.deps)) {
138 if (defined(invoker.datadeps)) {
139 datadeps = invoker.datadeps
144 if (defined(invoker.python_base_module)) {
145 python_base_module = invoker.python_base_module
146 output = "$root_out_dir/python/$python_base_module/${target_name}${python_module_suffix}"
148 output = "$root_out_dir/python/${target_name}${python_module_suffix}"
152 "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_library_suffix}",
158 ":$shared_library_name",