Commit d6d05d02 by plusvic

Allow passing custom build options to the “build” command.

After commit eba22f3e you couldn’t  pass options like —dynamic-linking and—enable-profiling to the build command anymore. Those options were accepted by the build_ext command instead. With this change you can pass the options to both build and build_ext.
parent eaba8c1a
......@@ -14,6 +14,7 @@
# limitations under the License.
#
from distutils.command.build import build
from distutils.command.build_ext import build_ext
from setuptools import setup, Command, Extension
from codecs import open
......@@ -29,6 +30,21 @@ import tempfile
import shutil
import subprocess
OPTIONS = [
('dynamic-linking', None, 'link dynamically against libyara'),
('enable-cuckoo', None, 'enable "cuckoo" module'),
('enable-magic', None, 'enable "magic" module'),
('enable-profiling', None, 'enable profiling features')]
BOOLEAN_OPTIONS = [
'dynamic-linking',
'enable-cuckoo',
'enable-magic',
'enable-profiling']
@contextlib.contextmanager
def muted(*streams):
"""A context manager to redirect stdout and/or stderr to /dev/null.
......@@ -66,16 +82,29 @@ def has_function(function_name, libraries=None):
return result
class BuildCommand(build_ext):
class BuildCommand(build):
user_options = build.user_options + OPTIONS
boolean_options = build.boolean_options + BOOLEAN_OPTIONS
def initialize_options(self):
build.initialize_options(self)
self.dynamic_linking = None
self.enable_magic = None
self.enable_cuckoo = None
self.enable_profiling = None
def finalize_options(self):
build.finalize_options(self)
user_options = build_ext.user_options + [
('dynamic-linking', None,'link dynamically against libyara'),
('enable-cuckoo', None,'enable "cuckoo" module'),
('enable-magic', None,'enable "magic" module'),
('enable-profiling', None,'enable profiling features')]
boolean_options = build_ext.boolean_options + [
'dynamic-linking', 'enable-cuckoo', 'enable-magic', 'enable-profiling']
class BuildExtCommand(build_ext):
user_options = build_ext.user_options + OPTIONS
boolean_options = build_ext.boolean_options + BOOLEAN_OPTIONS
def initialize_options(self):
......@@ -88,6 +117,16 @@ class BuildCommand(build_ext):
def finalize_options(self):
build_ext.finalize_options(self)
# If the build_ext command was invoked by the build command, take the
# values for these options from the build command.
self.set_undefined_options('build',
('dynamic_linking', 'dynamic_linking'),
('enable_magic', 'enable_magic'),
('enable_cuckoo', 'enable_cuckoo'),
('enable_profiling', 'enable_profiling'))
if self.enable_magic and self.dynamic_linking:
raise distutils.errors.DistutilsOptionError(
'--enable-magic can''t be used with --dynamic-linking')
......@@ -194,8 +233,8 @@ class UpdateCommand(Command):
subprocess.check_call(['git', 'submodule', 'update'])
subprocess.check_call(['git', 'reset', '--hard'], cwd='yara')
subprocess.check_call(['git', 'clean', '-x', '-f', '-d'],
cwd='yara')
subprocess.check_call(['git', 'clean', '-x', '-f', '-d'], cwd='yara')
subprocess.check_call(['git', 'checkout', 'master'], cwd='yara')
subprocess.check_call(['git', 'pull'], cwd='yara')
subprocess.check_call(['git', 'fetch', '--tags'], cwd='yara')
......@@ -221,7 +260,8 @@ setup(
url='https://github.com/VirusTotal/yara-python',
zip_safe=False,
cmdclass={
'build_ext': BuildCommand,
'build': BuildCommand,
'build_ext': BuildExtCommand,
'update': UpdateCommand},
ext_modules=[Extension(
name='yara',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment