David Cournapeau | 3763b57 | 2011-08-27 22:25:14 | [diff] [blame] | 1 | """ |
David Cournapeau | da2af08 | 2011-09-08 15:31:12 | [diff] [blame] | 2 | See BENTO_BUILD.txt. |
David Cournapeau | 3763b57 | 2011-08-27 22:25:14 | [diff] [blame] | 3 | |
| 4 | Caveats: |
| 5 | |
| 6 | - no automatic detection for BLAS/LAPACK/etc... You need to set it up |
| 7 | manually for now (except on Mac OS X and Debian/Ubuntu). The upside is |
| 8 | that it is extremely easy to do so |
| 9 | - bento is still in flux, and some things may changes between releases. |
David Cournapeau | 3763b57 | 2011-08-27 22:25:14 | [diff] [blame] | 10 | """ |
| 11 | |
David Cournapeau | 7847043 | 2011-05-30 00:10:35 | [diff] [blame] | 12 | import os |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 13 | import sys |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 14 | import subprocess |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 15 | |
David Cournapeau | 0c7af4b | 2011-03-07 00:30:42 | [diff] [blame] | 16 | # Ugly but necessary hack: import numpy here so that wscript in sub directories |
| 17 | # will see this numpy and not an already installed one |
| 18 | import __builtin__ |
| 19 | __builtin__.__NUMPY_SETUP__ = True |
| 20 | |
Ralf Gommers | 3d431ab | 2013-05-04 17:28:09 | [diff] [blame] | 21 | import waflib |
| 22 | |
| 23 | from numpy.distutils.conv_template \ |
| 24 | import \ |
| 25 | process_str as process_c_str |
| 26 | |
David Cournapeau | a52f88f | 2011-04-06 00:18:04 | [diff] [blame] | 27 | from bento.commands import hooks |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 28 | from bento.utils.utils \ |
| 29 | import \ |
| 30 | cmd_is_runnable |
David Cournapeau | 20825a9 | 2012-09-09 16:53:22 | [diff] [blame] | 31 | from bento.backends.waf_backend \ |
| 32 | import \ |
| 33 | WAF_TOOLDIR |
David Cournapeau | fd9ee73 | 2012-10-09 21:10:54 | [diff] [blame] | 34 | from bento.backends.waf_tools \ |
| 35 | import \ |
| 36 | blas_lapack |
David Cournapeau | aa7e9bd | 2011-03-15 15:39:15 | [diff] [blame] | 37 | |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 38 | sys.path.insert(0, os.getcwd()) |
| 39 | try: |
| 40 | _SETUP_PY = __import__("setup") |
| 41 | finally: |
| 42 | sys.path.pop(0) |
| 43 | |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 44 | def compute_git_revision(top_node): |
| 45 | git_repo_node = top_node.find_node(".git") |
| 46 | if git_repo_node and cmd_is_runnable(["git", "--version"]): |
| 47 | s = subprocess.Popen(["git", "rev-parse", "HEAD"], |
| 48 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=top_node.abspath()) |
| 49 | out = s.communicate()[0] |
| 50 | return out.decode().strip() |
| 51 | else: |
| 52 | return "" |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 53 | |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 54 | def _register_metadata(context): |
| 55 | git_revision = compute_git_revision(context.top_node) |
| 56 | full_version = context.pkg.version |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 57 | if not _SETUP_PY.ISRELEASED: |
| 58 | full_version += '.dev-' + git_revision[:7] |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 59 | |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 60 | context.register_metadata("git_revision", git_revision) |
| 61 | context.register_metadata("is_released", _SETUP_PY.ISRELEASED) |
| 62 | context.register_metadata("full_version", full_version) |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 63 | |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 64 | def _generate_cython(): |
| 65 | print("Cythonizing sources") |
| 66 | cwd = os.path.abspath(os.path.dirname(__file__)) |
| 67 | p = subprocess.call([sys.executable, |
| 68 | os.path.join(cwd, 'tools', 'cythonize.py'), |
| 69 | 'numpy'], |
| 70 | cwd=cwd) |
| 71 | if p != 0: |
| 72 | raise RuntimeError("Running cythonize failed!") |
| 73 | |
David Cournapeau | 87295b3 | 2012-05-31 09:25:20 | [diff] [blame] | 74 | @hooks.post_configure |
| 75 | def post_configure(context): |
David Cournapeau | 3cb783e | 2012-04-16 18:31:44 | [diff] [blame] | 76 | conf = context.waf_context |
David Cournapeau | 3cb783e | 2012-04-16 18:31:44 | [diff] [blame] | 77 | if conf.env["CC_NAME"] == "gcc": |
| 78 | conf.env.CFLAGS_PYEXT.append("-Wfatal-errors") |
David Cournapeau | 20825a9 | 2012-09-09 16:53:22 | [diff] [blame] | 79 | |
| 80 | conf.load("arch", tooldir=[WAF_TOOLDIR]) |
| 81 | if sys.platform == "darwin": |
| 82 | conf.env["MACOSX_DEPLOYMENT_TARGET"] = "10.4" |
| 83 | conf.check_cc_default_arch() |
| 84 | archs = [conf.env.DEFAULT_CC_ARCH] |
| 85 | conf.env.ARCH = archs |
| 86 | |
David Cournapeau | fd9ee73 | 2012-10-09 21:10:54 | [diff] [blame] | 87 | blas_lapack.check_blas_lapack(context) |
David Cournapeau | 3cb783e | 2012-04-16 18:31:44 | [diff] [blame] | 88 | |
Julian Taylor | c9fd634 | 2014-04-05 11:13:13 | [diff] [blame] | 89 | _generate_cython() |
| 90 | |
David Cournapeau | 0d8b636 | 2011-06-14 23:40:26 | [diff] [blame] | 91 | @hooks.pre_build |
David Cournapeau | a52f88f | 2011-04-06 00:18:04 | [diff] [blame] | 92 | def pre_build(context): |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 93 | _register_metadata(context) |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 94 | |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 95 | @hooks.pre_sdist |
| 96 | def pre_sdist(context): |
| 97 | _register_metadata(context) |
David Cournapeau | eed2372 | 2012-09-09 21:19:05 | [diff] [blame] | 98 | |
| 99 | @hooks.options |
| 100 | def options(global_context): |
David Cournapeau | fd9ee73 | 2012-10-09 21:10:54 | [diff] [blame] | 101 | blas_lapack.add_options(global_context) |
Ralf Gommers | 3d431ab | 2013-05-04 17:28:09 | [diff] [blame] | 102 | |
| 103 | |
| 104 | class CTemplateTask(waflib.Task.Task): |
| 105 | color = 'BLUE' |
| 106 | before = ['c'] |
| 107 | def run(self): |
| 108 | s = self.inputs[0] |
| 109 | cnt = s.read() |
| 110 | writestr = process_c_str(cnt) |
| 111 | o = self.outputs[0] |
| 112 | o.write(writestr) |
| 113 | |
| 114 | @waflib.TaskGen.extension(".src") |
| 115 | def c_template(self, node): |
| 116 | outs = [] |
| 117 | outs.append(node.change_ext("")) |
| 118 | |
| 119 | tsk = self.create_task('CTemplateTask', node, outs) |
Ralf Gommers | 55c76f6 | 2013-12-08 15:16:11 | [diff] [blame] | 120 | if "c" in self.features and not node.name[-6:] == (".h.src"): |
Ralf Gommers | 3d431ab | 2013-05-04 17:28:09 | [diff] [blame] | 121 | self.source.append(outs[0]) |