OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 template("python_binary_module_sources") { | 5 template("python_binary_source_set") { |
6 # Only available on linux for now. | 6 # Only available on linux for now. |
7 assert(is_linux) | 7 assert(is_linux) |
8 assert(defined(invoker.sources)) | 8 assert(defined(invoker.cython_sources) || defined(invoker.sources)) |
9 | 9 |
10 cython_root = "//third_party/cython" | |
11 cython_script = "$cython_root/src/cython.py" | |
12 cython_output = "${target_out_dir}/${target_name}.cc" | |
13 | |
14 generator_target_name = target_name + "_cython_compiler" | |
15 config_name = target_name + "_python_config" | 10 config_name = target_name + "_python_config" |
16 | 11 |
17 target_visibility = [ ":$target_name" ] | 12 target_visibility = [ ":$target_name" ] |
18 | 13 |
19 action(generator_target_name) { | 14 if (defined(invoker.cython_sources)) { |
20 visibility = target_visibility | 15 generator_target_name = target_name + "_cython_compiler" |
21 script = cython_script | 16 |
22 sources = invoker.sources | 17 cython_root = "//third_party/cython" |
23 outputs = [ | 18 cython_script = "$cython_root/src/cython.py" |
24 cython_output, | 19 cython_output = "${target_out_dir}/${target_name}.cc" |
25 ] | 20 |
26 args = [ | 21 action(generator_target_name) { |
27 "--cplus", | 22 visibility = target_visibility |
28 "-I", | 23 script = cython_script |
29 rebase_path("//", root_build_dir), | 24 sources = invoker.cython_sources |
30 "-o", | 25 outputs = [ |
31 rebase_path(cython_output, root_build_dir), | 26 cython_output, |
32 ] + rebase_path(sources, root_build_dir) | 27 ] |
| 28 args = [ |
| 29 "--cplus", |
| 30 "-I", |
| 31 rebase_path("//", root_build_dir), |
| 32 "-o", |
| 33 rebase_path(cython_output, root_build_dir), |
| 34 ] + rebase_path(sources, root_build_dir) |
| 35 } |
33 } | 36 } |
34 | 37 |
35 config(config_name) { | 38 config(config_name) { |
36 visibility = target_visibility | 39 visibility = target_visibility |
37 python_flags = "//third_party/cython/python_flags.py" | 40 python_flags = "//third_party/cython/python_flags.py" |
38 include_dirs = exec_script(python_flags, [ "--includes" ], "list lines") | 41 include_dirs = exec_script(python_flags, [ "--includes" ], "list lines") |
39 libs = exec_script(python_flags, [ "--libraries" ], "list lines") | 42 libs = exec_script(python_flags, [ "--libraries" ], "list lines") |
40 lib_dirs = exec_script(python_flags, [ "--library_dirs" ], "list lines") | 43 lib_dirs = exec_script(python_flags, [ "--library_dirs" ], "list lines") |
41 if (!is_win) { | 44 if (!is_win) { |
42 # Generated code includes static utility functions that often go unused. | 45 # Generated code includes static utility functions that often go unused. |
43 cflags = [ "-Wno-unused-function" ] | 46 cflags = [ "-Wno-unused-function" ] |
44 } | 47 } |
45 } | 48 } |
46 | 49 |
47 source_set(target_name) { | 50 source_set(target_name) { |
48 deps = [ | |
49 ":$generator_target_name", | |
50 ] | |
51 if (defined(invoker.visibility)) { | 51 if (defined(invoker.visibility)) { |
52 visibility = invoker.visibility | 52 visibility = invoker.visibility |
53 } | 53 } |
| 54 sources = [] |
| 55 if (defined(invoker.cython_sources)) { |
| 56 sources += [ cython_output ] |
| 57 } |
| 58 if (defined(invoker.sources)) { |
| 59 sources += invoker.sources |
| 60 } |
| 61 if (defined(invoker.configs)) { |
| 62 configs += invoker.configs |
| 63 } |
| 64 all_dependent_configs = [ ":$config_name" ] |
| 65 deps = [] |
| 66 if (defined(invoker.cython_sources)) { |
| 67 deps += [ ":$generator_target_name" ] |
| 68 } |
54 if (defined(invoker.deps)) { | 69 if (defined(invoker.deps)) { |
55 deps += invoker.deps | 70 deps += invoker.deps |
56 } | 71 } |
57 if (defined(invoker.datadeps)) { | 72 if (defined(invoker.datadeps)) { |
58 datadeps = invoker.datadeps | 73 datadeps = invoker.datadeps |
59 } | 74 } |
60 sources = [ | |
61 cython_output, | |
62 ] | |
63 if (defined(invoker.additional_sources)) { | |
64 sources += invoker.additional_sources | |
65 } | |
66 if (defined(invoker.configs)) { | |
67 configs += invoker.configs | |
68 } | |
69 all_dependent_configs = [ ":$config_name" ] | |
70 } | 75 } |
71 } | 76 } |
72 | 77 |
73 template("python_binary_module") { | 78 template("python_binary_module") { |
74 # Only available on linux for now. | 79 # Only available on linux for now. |
75 assert(is_linux) | 80 assert(is_linux) |
76 assert(defined(invoker.sources)) | 81 |
| 82 has_sources = defined(invoker.cython_sources) || defined(invoker.sources) |
| 83 |
| 84 assert(has_sources || defined(invoker.deps)) |
77 assert(defined(invoker.python_base_module)) | 85 assert(defined(invoker.python_base_module)) |
78 | 86 |
79 sources_target_name = target_name + "_cython_sources" | 87 sources_target_name = target_name + "_cython_sources" |
80 shared_library_name = target_name + "_shared_library" | 88 shared_library_name = target_name + "_shared_library" |
81 | 89 |
82 if (is_linux) { | 90 if (is_linux) { |
83 shared_library_prefix = "lib" | 91 shared_library_prefix = "lib" |
84 shared_library_suffix = ".so" | 92 shared_library_suffix = ".so" |
85 python_module_suffix = ".so" | 93 python_module_suffix = ".so" |
86 } | 94 } |
87 | 95 |
88 target_visibility = [ | 96 target_visibility = [ |
89 ":$sources_target_name", | 97 ":$sources_target_name", |
90 ":$shared_library_name", | 98 ":$shared_library_name", |
91 ":$target_name", | 99 ":$target_name", |
92 ] | 100 ] |
93 | 101 |
94 python_binary_module_sources(sources_target_name) { | 102 if (has_sources) { |
95 visibility = target_visibility | 103 python_binary_source_set(sources_target_name) { |
96 sources = invoker.sources | 104 visibility = target_visibility |
97 if (defined(invoker.configs)) { | 105 if (defined(invoker.cython_sources)) { |
98 configs = invoker.configs | 106 cython_sources = invoker.cython_sources |
| 107 } |
| 108 if (defined(invoker.sources)) { |
| 109 sources = invoker.sources |
| 110 } |
| 111 if (defined(invoker.configs)) { |
| 112 configs = invoker.configs |
| 113 } |
| 114 if (defined(invoker.deps)) { |
| 115 deps = invoker.deps |
| 116 } |
| 117 if (defined(invoker.datadeps)) { |
| 118 datadeps = invoker.datadeps |
| 119 } |
99 } | 120 } |
100 } | 121 } |
101 | 122 |
102 shared_library(shared_library_name) { | 123 shared_library(shared_library_name) { |
103 visibility = target_visibility | 124 visibility = target_visibility |
104 deps = [ | 125 if (defined(invoker.configs)) { |
105 ":$sources_target_name", | 126 configs += invoker.configs |
106 ] | 127 } |
| 128 deps = [] |
| 129 if (has_sources) { |
| 130 deps += [ ":$sources_target_name" ] |
| 131 } |
107 if (defined(invoker.deps)) { | 132 if (defined(invoker.deps)) { |
108 deps += invoker.deps | 133 deps += invoker.deps |
109 } | 134 } |
110 if (defined(invoker.datadeps)) { | 135 if (defined(invoker.datadeps)) { |
111 datadeps = invoker.datadeps | 136 datadeps = invoker.datadeps |
112 } | 137 } |
113 if (defined(invoker.additional_sources)) { | |
114 sources = invoker.additional_sources | |
115 } | |
116 if (defined(invoker.configs)) { | |
117 configs += invoker.configs | |
118 } | |
119 } | 138 } |
120 | 139 |
121 copy(target_name) { | 140 copy(target_name) { |
122 python_base_module = invoker.python_base_module | 141 python_base_module = invoker.python_base_module |
123 sources = [ | 142 sources = [ |
124 "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_libr
ary_suffix}", | 143 "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_libr
ary_suffix}", |
125 ] | 144 ] |
126 outputs = [ | 145 outputs = [ |
127 "$root_out_dir/python/$python_base_module/${target_name}${python_module_su
ffix}", | 146 "$root_out_dir/python/$python_base_module/${target_name}${python_module_su
ffix}", |
128 ] | 147 ] |
129 deps = [ | 148 deps = [ |
130 ":$shared_library_name", | 149 ":$shared_library_name", |
131 ] | 150 ] |
132 } | 151 } |
133 } | 152 } |
OLD | NEW |