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 = [ | 51 deps = [] |
qsr
2014/12/12 09:09:54
Could you run gn format, I'm pretty sure deps shou
etiennej
2014/12/12 10:58:25
I do not mind moving it, but I ran gn format (both
qsr
2014/12/12 12:27:45
Hum, weird. Can you take a look at https://code.go
etiennej
2014/12/12 13:39:46
Made the fixes. I'll prepare a CL in chromium with
| |
49 ":$generator_target_name", | 52 if (defined(invoker.cython_sources)) { |
50 ] | 53 deps += [ ":$generator_target_name" ] |
54 } | |
51 if (defined(invoker.visibility)) { | 55 if (defined(invoker.visibility)) { |
52 visibility = invoker.visibility | 56 visibility = invoker.visibility |
53 } | 57 } |
54 if (defined(invoker.deps)) { | 58 if (defined(invoker.deps)) { |
55 deps += invoker.deps | 59 deps += invoker.deps |
56 } | 60 } |
57 if (defined(invoker.datadeps)) { | 61 if (defined(invoker.datadeps)) { |
58 datadeps = invoker.datadeps | 62 datadeps = invoker.datadeps |
59 } | 63 } |
60 sources = [ | 64 sources = [] |
61 cython_output, | 65 if (defined(invoker.cython_sources)) { |
62 ] | 66 sources += [ cython_output ] |
63 if (defined(invoker.additional_sources)) { | 67 } |
64 sources += invoker.additional_sources | 68 if (defined(invoker.sources)) { |
69 sources += invoker.sources | |
65 } | 70 } |
66 all_dependent_configs = [ ":$config_name" ] | 71 all_dependent_configs = [ ":$config_name" ] |
67 } | 72 } |
68 } | 73 } |
69 | 74 |
70 template("python_binary_module") { | 75 template("python_binary_module") { |
71 # Only available on linux for now. | 76 # Only available on linux for now. |
72 assert(is_linux) | 77 assert(is_linux) |
73 assert(defined(invoker.sources)) | 78 |
79 has_sources = defined(invoker.cython_sources) || defined(invoker.sources) | |
80 | |
81 assert(has_sources || defined(invoker.deps)) | |
74 assert(defined(invoker.python_base_module)) | 82 assert(defined(invoker.python_base_module)) |
75 | 83 |
76 sources_target_name = target_name + "_cython_sources" | 84 sources_target_name = target_name + "_cython_sources" |
77 shared_library_name = target_name + "_shared_library" | 85 shared_library_name = target_name + "_shared_library" |
78 | 86 |
79 if (is_linux) { | 87 if (is_linux) { |
80 shared_library_prefix = "lib" | 88 shared_library_prefix = "lib" |
81 shared_library_suffix = ".so" | 89 shared_library_suffix = ".so" |
82 python_module_suffix = ".so" | 90 python_module_suffix = ".so" |
83 } | 91 } |
84 | 92 |
85 target_visibility = [ | 93 target_visibility = [ |
86 ":$sources_target_name", | 94 ":$sources_target_name", |
87 ":$shared_library_name", | 95 ":$shared_library_name", |
88 ":$target_name", | 96 ":$target_name", |
89 ] | 97 ] |
90 | 98 |
91 python_binary_module_sources(sources_target_name) { | 99 if (has_sources) { |
92 visibility = target_visibility | 100 python_binary_source_set(sources_target_name) { |
93 sources = invoker.sources | 101 visibility = target_visibility |
102 if (defined(invoker.cython_sources)) { | |
103 cython_sources = invoker.cython_sources | |
104 } | |
105 if (defined(invoker.sources)) { | |
106 sources = invoker.sources | |
107 } | |
108 if (defined(invoker.deps)) { | |
109 deps = invoker.deps | |
110 } | |
111 if (defined(invoker.datadeps)) { | |
112 datadeps = invoker.datadeps | |
113 } | |
114 if (defined(invoker.configs)) { | |
115 configs = invoker.configs | |
116 } | |
117 } | |
94 } | 118 } |
95 | 119 |
96 shared_library(shared_library_name) { | 120 shared_library(shared_library_name) { |
97 visibility = target_visibility | 121 visibility = target_visibility |
98 deps = [ | 122 deps = [] |
99 ":$sources_target_name", | 123 if (has_sources) { |
100 ] | 124 deps += [ ":$sources_target_name" ] |
125 } | |
101 if (defined(invoker.deps)) { | 126 if (defined(invoker.deps)) { |
102 deps += invoker.deps | 127 deps += invoker.deps |
103 } | 128 } |
104 if (defined(invoker.datadeps)) { | 129 if (defined(invoker.datadeps)) { |
105 datadeps = invoker.datadeps | 130 datadeps = invoker.datadeps |
106 } | 131 } |
107 if (defined(invoker.additional_sources)) { | |
108 sources = invoker.additional_sources | |
109 } | |
110 if (defined(invoker.configs)) { | 132 if (defined(invoker.configs)) { |
111 configs += invoker.configs | 133 configs += invoker.configs |
112 } | 134 } |
113 } | 135 } |
114 | 136 |
115 copy(target_name) { | 137 copy(target_name) { |
116 python_base_module = invoker.python_base_module | 138 python_base_module = invoker.python_base_module |
117 sources = [ | 139 sources = [ |
118 "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_libr ary_suffix}", | 140 "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_libr ary_suffix}", |
119 ] | 141 ] |
120 outputs = [ | 142 outputs = [ |
121 "$root_out_dir/python/$python_base_module/${target_name}${python_module_su ffix}", | 143 "$root_out_dir/python/$python_base_module/${target_name}${python_module_su ffix}", |
122 ] | 144 ] |
123 deps = [ | 145 deps = [ |
124 ":$shared_library_name", | 146 ":$shared_library_name", |
125 ] | 147 ] |
126 } | 148 } |
127 } | 149 } |
OLD | NEW |