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