|
5 | 5 | import distutils.cmd |
6 | 6 | import distutils.log |
7 | 7 | import distutils.sysconfig |
8 | | -import os |
9 | 8 | import os.path |
10 | 9 | import platform |
11 | 10 | import shutil |
| 11 | +import subprocess |
12 | 12 | import sys |
13 | 13 | import tempfile |
14 | 14 |
|
15 | 15 | from setuptools import Extension, setup |
16 | 16 |
|
17 | 17 | LIBSASS_SOURCE_DIR = os.path.join('libsass', 'src') |
18 | 18 |
|
19 | | -if not os.path.isfile(os.path.join('libsass', 'Makefile')) and \ |
20 | | - os.path.isdir('.git'): |
| 19 | +if ( |
| 20 | + not os.path.isfile(os.path.join('libsass', 'Makefile')) and |
| 21 | + os.path.isdir('.git') |
| 22 | +): |
21 | 23 | print(file=sys.stderr) |
22 | | - print('You seem to miss initializing submodules; ' |
23 | | - 'try the following command', file=sys.stderr) |
| 24 | + print('Missing the libsass sumbodule. Try:', file=sys.stderr) |
24 | 25 | print(' git submodule update --init', file=sys.stderr) |
25 | 26 | print(file=sys.stderr) |
26 | 27 | exit(1) |
27 | 28 |
|
| 29 | + |
| 30 | +# Determine the libsass version from the git checkout |
| 31 | +if os.path.exists(os.path.join('libsass', '.git')): |
| 32 | + proc = subprocess.Popen( |
| 33 | + ( |
| 34 | + 'git', '-C', 'libsass', 'describe', |
| 35 | + '--abbrev=4', '--dirty', '--always', '--tags', |
| 36 | + ), |
| 37 | + stdout=subprocess.PIPE, |
| 38 | + ) |
| 39 | + out, _ = proc.communicate() |
| 40 | + assert not proc.returncode, proc.returncode |
| 41 | + with open('.libsass-upstream-version', 'wb') as libsass_version_file: |
| 42 | + libsass_version_file.write(out) |
| 43 | + |
| 44 | +# The version file should always exist at this point |
| 45 | +with open('.libsass-upstream-version', 'rb') as libsass_version_file: |
| 46 | + libsass_version = libsass_version_file.read().decode('UTF-8').strip() |
| 47 | + if sys.platform == 'win32': |
| 48 | + # This looks wrong, but is required for some reason :( |
| 49 | + version_define = r'/DLIBSASS_VERSION="\"{0}\""'.format(libsass_version) |
| 50 | + else: |
| 51 | + version_define = '-DLIBSASS_VERSION="{0}"'.format(libsass_version) |
| 52 | + |
28 | 53 | sources = ['pysass.cpp'] |
29 | 54 | headers = [] |
30 | 55 | for directory in ( |
@@ -89,9 +114,7 @@ def customize_compiler(compiler): |
89 | 114 | compiler.linker_so[0] = os.environ['CXX'] |
90 | 115 | return compiler |
91 | 116 | distutils.sysconfig.customize_compiler = customize_compiler |
92 | | - flags.extend([ |
93 | | - '-stdlib=libc++', |
94 | | - ]) |
| 117 | + flags.append('-stdlib=libc++') |
95 | 118 | if platform.system() == 'Darwin': |
96 | 119 | flags.append('-mmacosx-version-min=10.7',) |
97 | 120 | if tuple(map(int, platform.mac_ver()[0].split('.'))) >= (10, 9): |
@@ -134,10 +157,9 @@ def restore_cencode(): |
134 | 157 | sass_extension = Extension( |
135 | 158 | '_sass', |
136 | 159 | sources, |
137 | | - library_dirs=[os.path.join('.', 'libsass', 'src')], |
138 | 160 | include_dirs=[os.path.join('.', 'libsass', 'include')], |
139 | 161 | depends=headers, |
140 | | - extra_compile_args=flags, |
| 162 | + extra_compile_args=flags + [version_define], |
141 | 163 | extra_link_args=link_flags, |
142 | 164 | ) |
143 | 165 |
|
|
0 commit comments