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 import("//build/toolchain/toolchain.gni")
7 template("python_binary_source_set") {
8 # Only available on linux for now.
10 assert(defined(invoker.cython_sources) || defined(invoker.sources))
12 config_name = target_name + "_python_config"
14 target_visibility = [ ":$target_name" ]
16 if (defined(invoker.cython_sources)) {
17 generator_target_name = target_name + "_cython_compiler"
19 cython_root = "//third_party/cython"
20 cython_script = "$cython_root/src/cython.py"
21 cython_output = "${target_out_dir}/${target_name}.cc"
23 action(generator_target_name) {
24 visibility = target_visibility
25 script = cython_script
26 sources = invoker.cython_sources
33 rebase_path("//", root_build_dir),
35 rebase_path(target_gen_dir, root_build_dir),
37 rebase_path(cython_output, root_build_dir),
38 ] + rebase_path(sources, root_build_dir)
43 visibility = target_visibility
44 python_flags = "//third_party/cython/python_flags.py"
45 include_dirs = exec_script(python_flags, [ "--includes" ], "list lines")
46 libs = exec_script(python_flags, [ "--libraries" ], "list lines")
47 lib_dirs = exec_script(python_flags, [ "--library_dirs" ], "list lines")
49 # Generated code includes static utility functions that often go unused.
50 cflags = [ "-Wno-unused-function" ]
54 source_set(target_name) {
55 if (defined(invoker.visibility)) {
56 visibility = invoker.visibility
59 if (defined(invoker.cython_sources)) {
60 sources += [ cython_output ]
62 if (defined(invoker.sources)) {
63 sources += invoker.sources
65 if (defined(invoker.configs)) {
66 configs += invoker.configs
68 all_dependent_configs = [ ":$config_name" ]
70 if (defined(invoker.cython_sources)) {
71 deps += [ ":$generator_target_name" ]
73 if (defined(invoker.deps)) {
76 if (defined(invoker.datadeps)) {
77 datadeps = invoker.datadeps
82 template("python_binary_module") {
83 # Only available on linux for now.
86 has_sources = defined(invoker.cython_sources) || defined(invoker.sources)
88 assert(has_sources || defined(invoker.deps))
90 !defined(invoker.python_base_module) || invoker.python_base_module != "")
92 sources_target_name = target_name + "_cython_sources"
93 shared_library_name = target_name + "_shared_library"
96 shared_library_prefix = "lib"
97 shared_library_suffix = ".so"
98 python_module_suffix = ".so"
101 target_visibility = [
102 ":$sources_target_name",
103 ":$shared_library_name",
108 python_binary_source_set(sources_target_name) {
109 visibility = target_visibility
110 if (defined(invoker.cython_sources)) {
111 cython_sources = invoker.cython_sources
113 if (defined(invoker.sources)) {
114 sources = invoker.sources
116 if (defined(invoker.configs)) {
117 configs = invoker.configs
119 if (defined(invoker.deps)) {
122 if (defined(invoker.datadeps)) {
123 datadeps = invoker.datadeps
128 shared_library(shared_library_name) {
129 visibility = target_visibility
130 if (defined(invoker.configs)) {
131 configs += invoker.configs
135 deps += [ ":$sources_target_name" ]
137 if (defined(invoker.deps)) {
140 if (defined(invoker.datadeps)) {
141 datadeps = invoker.datadeps
146 if (defined(invoker.python_base_module)) {
147 python_base_module = invoker.python_base_module
148 output = "$root_out_dir/python/$python_base_module/${target_name}${python_module_suffix}"
150 output = "$root_out_dir/python/${target_name}${python_module_suffix}"
154 "$root_shlib_dir/${shared_library_prefix}${shared_library_name}${shared_library_suffix}",
160 ":$shared_library_name",