Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / cython / rules.gni
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.
4
5 template("python_binary_module") {
6   # Only available on linux for now.
7   assert(is_linux)
8   assert(defined(invoker.sources))
9   assert(defined(invoker.python_base_module))
10
11   cython_root = "//third_party/cython"
12   cython_script = "$cython_root/src/cython.py"
13   cython_output = "${target_out_dir}/${target_name}.cc"
14
15   generator_target_name = target_name + "_cython_compiler"
16   shared_library_name = target_name + "_shared_library"
17   config_name = target_name + "_python_config"
18
19   if (is_linux) {
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
31   action(generator_target_name) {
32     visibility = target_visibility
33     script = cython_script
34     sources = invoker.sources
35     outputs = [ cython_output ]
36     args = [
37       "--cplus",
38       "-I", rebase_path("//", root_build_dir),
39       "-o", rebase_path(cython_output, root_build_dir),
40     ] + rebase_path(sources, root_build_dir)
41   }
42
43   config(config_name) {
44     visibility = target_visibility
45     python_flags = "//third_party/cython/python_flags.py"
46     include_dirs = exec_script(python_flags,
47                                [ "--gn", "--includes" ],
48                                "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) {
56       # Generated code includes static utility functions that often go unused.
57       cflags = [
58         "-Wno-unused-function",
59       ]
60     }
61   }
62
63   shared_library(shared_library_name) {
64     visibility = target_visibility
65     deps = [
66       ":$generator_target_name",
67     ]
68     if (defined(invoker.deps)) {
69       deps += invoker.deps
70     }
71     if (defined(invoker.datadeps)) {
72       datadeps = invoker.datadeps
73     }
74     sources = [ cython_output ]
75     if (defined(invoker.additional_sources)) {
76       sources += invoker.additional_sources
77     }
78     configs += [ ":$config_name" ]
79   }
80
81   copy(target_name) {
82     python_base_module = invoker.python_base_module
83     sources = [
84       "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_library_suffix}"
85     ]
86     outputs = [
87       "$root_out_dir/python/$python_base_module/${target_name}${python_module_suffix}"
88     ]
89     deps = [
90       ":$shared_library_name"
91     ]
92   }
93 }