diff options
author | qsr <qsr@chromium.org> | 2014-12-01 09:50:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-01 17:52:11 +0000 |
commit | 7c28a2158a62f2f025f91a13c19c104425e0c190 (patch) | |
tree | 1b1c4f61f446f0eceb31b4d829a40b1df7c6d251 /third_party/cython | |
parent | b8cdad5b22e2f574b5429877b76a3721a84487da (diff) | |
download | chromium_src-7c28a2158a62f2f025f91a13c19c104425e0c190.zip chromium_src-7c28a2158a62f2f025f91a13c19c104425e0c190.tar.gz chromium_src-7c28a2158a62f2f025f91a13c19c104425e0c190.tar.bz2 |
Update cython rules.
This allow to produce the source of a python module without creating the
shared library so that it can be embedded in another application.
R=sdefresne@chromium.org
Review URL: https://codereview.chromium.org/766193002
Cr-Commit-Position: refs/heads/master@{#306204}
Diffstat (limited to 'third_party/cython')
-rw-r--r-- | third_party/cython/cython_compiler.gypi | 64 | ||||
-rw-r--r-- | third_party/cython/python_flags.py | 15 | ||||
-rw-r--r-- | third_party/cython/rules.gni | 89 |
3 files changed, 60 insertions, 108 deletions
diff --git a/third_party/cython/cython_compiler.gypi b/third_party/cython/cython_compiler.gypi deleted file mode 100644 index ca974a2..0000000 --- a/third_party/cython/cython_compiler.gypi +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2014 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'variables': { - 'python_flags': '<(DEPTH)/third_party/cython/python_flags.py', - }, - 'conditions': [ - ['OS=="mac"', { - 'variables': { - 'module_prefix': '', - 'module_suffix': '.so', - }, - }, { - 'variables': { - 'module_prefix': '<(SHARED_LIB_PREFIX)', - 'module_suffix': '<(SHARED_LIB_SUFFIX)', - }, - }], - ], - 'type': 'loadable_module', - 'rules': [ - { - 'rule_name': '<(_target_name)_cython_compiler', - 'extension': 'pyx', - 'variables': { - 'cython_compiler': '<(DEPTH)/third_party/cython/src/cython.py', - }, - 'inputs': [ - '<(cython_compiler)', - ], - 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/cython/<(python_base_module)/<(RULE_INPUT_ROOT).cc', - ], - 'action': [ - 'python', '<(cython_compiler)', - '--cplus', - '-I<(DEPTH)', - '-o', '<@(_outputs)', - '<(RULE_INPUT_PATH)', - ], - 'message': 'Generating C++ source from <(RULE_INPUT_PATH)', - 'process_outputs_as_sources': 1, - } - ], - 'include_dirs': [ - '<!@(python <(python_flags) --includes)', - '<(DEPTH)', - ], - 'libraries': [ - '<!@(python <(python_flags) --libraries)', - ], - 'cflags': [ - '-Wno-unused-function', - ], - 'xcode_settings': { - 'WARNING_CFLAGS': [ '-Wno-unused-function' ], - }, - 'library_dirs': [ - '<!@(python <(python_flags) --library_dirs)', - ], - 'hard_dependency': 1, -} diff --git a/third_party/cython/python_flags.py b/third_party/cython/python_flags.py index b10aece..492c9a9 100644 --- a/third_party/cython/python_flags.py +++ b/third_party/cython/python_flags.py @@ -16,9 +16,6 @@ def main(): """ parser = argparse.ArgumentParser( description='Retrieves compilation options for python modules.') - parser.add_argument('--gn', - help='Returns all values in a format suitable for gn', - action='store_true') parser.add_argument('--libraries', help='Returns libraries', action='store_true') parser.add_argument('--includes', help='Returns includes', @@ -36,11 +33,6 @@ def main(): libraries = b.get_libraries(ext) if sys.platform == 'darwin': libraries.append('python%s' % sys.version[:3]) - if not opts.gn and sys.platform in ['darwin', 'linux2']: - # In case of GYP output for darwin and linux prefix all - # libraries (if there are any) so the result can be used as a - # compiler argument. GN handles platform-appropriate prefixing itself. - libraries = ['-l%s' % library for library in libraries] result.extend(libraries) if opts.includes: result = result + b.include_dirs @@ -48,11 +40,8 @@ def main(): if sys.platform == 'darwin': result.append('%s/lib' % sysconfig.get_config_vars('prefix')[0]) - if opts.gn: - for x in result: - print x - else: - print ''.join(['"%s"' % x for x in result]) + for x in result: + print x if __name__ == '__main__': main() diff --git a/third_party/cython/rules.gni b/third_party/cython/rules.gni index efd9ca3..1d2ccfb 100644 --- a/third_party/cython/rules.gni +++ b/third_party/cython/rules.gni @@ -2,31 +2,19 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -template("python_binary_module") { +template("python_binary_module_sources") { # Only available on linux for now. assert(is_linux) assert(defined(invoker.sources)) - assert(defined(invoker.python_base_module)) cython_root = "//third_party/cython" cython_script = "$cython_root/src/cython.py" cython_output = "${target_out_dir}/${target_name}.cc" generator_target_name = target_name + "_cython_compiler" - shared_library_name = target_name + "_shared_library" config_name = target_name + "_python_config" - if (is_linux) { - shared_library_prefix = "lib" - shared_library_suffix = ".so" - python_module_suffix = ".so" - } - - target_visibility = [ - ":$generator_target_name", - ":$shared_library_name", - ":$target_name", - ] + target_visibility = [ ":$target_name" ] action(generator_target_name) { visibility = target_visibility @@ -35,8 +23,10 @@ template("python_binary_module") { outputs = [ cython_output ] args = [ "--cplus", - "-I", rebase_path("//", root_build_dir), - "-o", rebase_path(cython_output, root_build_dir), + "-I", + rebase_path("//", root_build_dir), + "-o", + rebase_path(cython_output, root_build_dir), ] + rebase_path(sources, root_build_dir) } @@ -44,27 +34,25 @@ template("python_binary_module") { visibility = target_visibility python_flags = "//third_party/cython/python_flags.py" include_dirs = exec_script(python_flags, - [ "--gn", "--includes" ], + [ "--includes" ], "list lines") libs = exec_script(python_flags, - [ "--gn", "--libraries" ], + [ "--libraries" ], "list lines") lib_dirs = exec_script(python_flags, - [ "--gn", "--library_dirs" ], + [ "--library_dirs" ], "list lines") if (!is_win) { # Generated code includes static utility functions that often go unused. - cflags = [ - "-Wno-unused-function", - ] + cflags = [ "-Wno-unused-function" ] } } - shared_library(shared_library_name) { - visibility = target_visibility - deps = [ - ":$generator_target_name", - ] + source_set(target_name) { + deps = [ ":$generator_target_name" ] + if (defined(invoker.visibility)) { + visibility = invoker.visibility + } if (defined(invoker.deps)) { deps += invoker.deps } @@ -75,7 +63,48 @@ template("python_binary_module") { if (defined(invoker.additional_sources)) { sources += invoker.additional_sources } - configs += [ ":$config_name" ] + all_dependent_configs = [ ":$config_name" ] + } +} + +template("python_binary_module") { + # Only available on linux for now. + assert(is_linux) + assert(defined(invoker.sources)) + assert(defined(invoker.python_base_module)) + + sources_target_name = target_name + "_cython_sources" + shared_library_name = target_name + "_shared_library" + + if (is_linux) { + shared_library_prefix = "lib" + shared_library_suffix = ".so" + python_module_suffix = ".so" + } + + target_visibility = [ + ":$sources_target_name", + ":$shared_library_name", + ":$target_name", + ] + + python_binary_module_sources(sources_target_name) { + visibility = target_visibility + sources = invoker.sources + } + + shared_library(shared_library_name) { + visibility = target_visibility + deps = [ ":$sources_target_name" ] + if (defined(invoker.deps)) { + deps += invoker.deps + } + if (defined(invoker.datadeps)) { + datadeps = invoker.datadeps + } + if (defined(invoker.additional_sources)) { + sources = invoker.additional_sources + } if (defined(invoker.configs)) { configs += invoker.configs } @@ -89,8 +118,6 @@ template("python_binary_module") { outputs = [ "$root_out_dir/python/$python_base_module/${target_name}${python_module_suffix}" ] - deps = [ - ":$shared_library_name" - ] + deps = [ ":$shared_library_name" ] } } |