2017-08-25 06:46:16 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2019-03-29 15:51:53 +00:00
|
|
|
import re
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
import os.path
|
2019-04-03 19:33:37 +01:00
|
|
|
from distutils.dir_util import mkpath
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
from distutils.errors import DistutilsSetupError
|
2019-04-03 19:33:37 +01:00
|
|
|
from distutils.file_util import copy_file
|
2018-04-07 18:42:48 +01:00
|
|
|
from setuptools import setup, find_packages
|
2017-08-29 05:16:43 +01:00
|
|
|
from setuptools.extension import Extension
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
from setuptools.command.sdist import sdist
|
|
|
|
import subprocess
|
2019-04-03 19:33:37 +01:00
|
|
|
import sys
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
class my_build_ext(build_ext):
|
|
|
|
user_options = [
|
|
|
|
('inplace', 'i', 'put compiled extension into the source directory'),
|
|
|
|
('parallel=', 'j', 'number of parallel build jobs'),
|
|
|
|
]
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
boolean_options = ['inplace']
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
help_options = []
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
def _run_autotools(self):
|
|
|
|
if not os.path.exists('libdrgn/configure'):
|
|
|
|
subprocess.check_call(['autoreconf', '-i', 'libdrgn'])
|
|
|
|
mkpath(self.build_temp)
|
|
|
|
if not os.path.exists(os.path.join(self.build_temp, 'Makefile')):
|
|
|
|
args = [
|
|
|
|
os.path.relpath('libdrgn/configure', self.build_temp),
|
|
|
|
'--disable-static', '--with-python=' + sys.executable,
|
|
|
|
]
|
|
|
|
subprocess.check_call(args, cwd=self.build_temp)
|
|
|
|
|
|
|
|
def get_source_files(self):
|
|
|
|
self._run_autotools()
|
|
|
|
args = ['make', '-C', self.build_temp, 'distfiles', '-s']
|
|
|
|
return [
|
|
|
|
os.path.normpath(os.path.join(self.build_temp, path)) for path in
|
|
|
|
subprocess.check_output(args, universal_newlines=True).splitlines()
|
|
|
|
]
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
|
|
|
def run(self):
|
2019-04-03 19:33:37 +01:00
|
|
|
self._run_autotools()
|
|
|
|
args = ['make', '-C', self.build_temp, '_drgn.la']
|
|
|
|
if self.parallel:
|
|
|
|
args.append(f'-j{self.parallel}')
|
|
|
|
subprocess.check_call(args)
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
so = os.path.join(self.build_temp, '.libs/_drgn.so')
|
|
|
|
if self.inplace:
|
|
|
|
copy_file(so, self.get_ext_fullpath('_drgn'))
|
|
|
|
self.inplace = 0
|
|
|
|
build_path = self.get_ext_fullpath('_drgn')
|
|
|
|
mkpath(os.path.dirname(build_path))
|
|
|
|
copy_file(so, build_path)
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class my_sdist(sdist):
|
|
|
|
user_options = sdist.user_options + [
|
|
|
|
('force', 'f',
|
|
|
|
'create the source distribution even if the repository is unclean'),
|
|
|
|
]
|
|
|
|
|
|
|
|
boolean_options = sdist.boolean_options + ['force']
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
super().initialize_options()
|
|
|
|
self.force = 0
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
# In order to avoid shipping a stale source distribution (e.g., due to
|
|
|
|
# pypa/setuptools#436 or the autotools output being out of date),
|
|
|
|
# require the repository to be clean (no unknown or ignored files).
|
|
|
|
# This check can be disabled with --force.
|
2019-04-11 23:51:20 +01:00
|
|
|
if (not self.force and subprocess.check_output(['git', 'clean', '-dnx'])):
|
Rewrite drgn core in C
The current mixed Python/C implementation works well, but it has a
couple of important limitations:
- It's too slow for some common use cases, like iterating over large
data structures.
- It can't be reused in utilities written in other languages.
This replaces the internals with a new library written in C, libdrgn. It
includes Python bindings with mostly the same public interface as
before, with some important improvements:
- Types are now represented by a single Type class rather than the messy
polymorphism in the Python implementation.
- Qualifiers are a bitmask instead of a set of strings.
- Bit fields are not considered a separate type.
- The lvalue/rvalue terminology is replaced with reference/value.
- Structure, union, and array values are better supported.
- Function objects are supported.
- Program distinguishes between lookups of variables, constants, and
functions.
The C rewrite is about 6x as fast as the original Python when using the
Python bindings, and about 8x when using the C API directly.
Currently, the exposed API in C is fairly conservative. In the future,
the memory reader, type index, and object index APIs will probably be
exposed for more flexibility.
2019-03-22 23:27:46 +00:00
|
|
|
raise DistutilsSetupError('repository has untracked or ignored files; '
|
|
|
|
'please run git clean -dfx or use --force')
|
|
|
|
super().run()
|
2017-08-29 05:16:43 +01:00
|
|
|
|
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
with open('libdrgn/drgn.h', 'r') as f:
|
|
|
|
drgn_h = f.read()
|
|
|
|
version_major = re.search('^#define DRGN_VERSION_MAJOR ([0-9])+$', drgn_h,
|
|
|
|
re.MULTILINE).group(1)
|
|
|
|
version_minor = re.search('^#define DRGN_VERSION_MINOR ([0-9])+$', drgn_h,
|
|
|
|
re.MULTILINE).group(1)
|
|
|
|
version_patch = re.search('^#define DRGN_VERSION_PATCH ([0-9])+$', drgn_h,
|
|
|
|
re.MULTILINE).group(1)
|
|
|
|
version = f'{version_major}.{version_minor}.{version_patch}'
|
|
|
|
|
|
|
|
setup(
|
|
|
|
name='drgn',
|
|
|
|
version=version,
|
|
|
|
packages=find_packages(exclude=['examples', 'scripts', 'tests']),
|
|
|
|
# This is here so that setuptools knows that we have an extension; it's
|
|
|
|
# actually built using autotools/make.
|
|
|
|
ext_modules=[Extension(name='_drgn', sources=[])],
|
|
|
|
cmdclass={
|
|
|
|
'build_ext': my_build_ext,
|
|
|
|
'sdist': my_sdist,
|
|
|
|
},
|
|
|
|
entry_points={
|
|
|
|
'console_scripts': ['drgn=drgn.internal.cli:main'],
|
|
|
|
},
|
|
|
|
author='Omar Sandoval',
|
|
|
|
author_email='osandov@osandov.com',
|
|
|
|
description='Scriptable debugger library',
|
|
|
|
license='GPL-3.0+',
|
|
|
|
url='https://github.com/osandov/drgn',
|
|
|
|
)
|