2017-08-25 06:46:16 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2019-05-03 18:14:27 +01:00
|
|
|
import contextlib
|
2020-01-23 20:09:48 +00:00
|
|
|
from distutils import log
|
2019-04-03 19:33:37 +01:00
|
|
|
from distutils.dir_util import mkpath
|
|
|
|
from distutils.file_util import copy_file
|
2019-11-15 21:28:47 +00:00
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
import re
|
2020-01-23 20:09:48 +00:00
|
|
|
import pkg_resources
|
2018-04-07 18:42:48 +01:00
|
|
|
from setuptools import setup, find_packages
|
2020-01-24 23:24:50 +00:00
|
|
|
from setuptools.command.build_ext import build_ext as _build_ext
|
|
|
|
from setuptools.command.egg_info import egg_info as _egg_info
|
2019-11-15 21:28:47 +00:00
|
|
|
from setuptools.extension import Extension
|
2020-01-24 01:54:46 +00:00
|
|
|
import shlex
|
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 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
|
|
|
|
|
|
|
|
2020-01-24 23:24:50 +00:00
|
|
|
class build_ext(_build_ext):
|
2019-04-03 19:33:37 +01:00
|
|
|
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-09-04 22:40:47 +01:00
|
|
|
def _run_autoreconf(self, dir):
|
|
|
|
makefile_in = os.path.join(dir, "Makefile.in")
|
2019-05-03 18:14:27 +01:00
|
|
|
if not os.path.exists(makefile_in):
|
|
|
|
try:
|
2019-09-04 22:40:47 +01:00
|
|
|
subprocess.check_call(["autoreconf", "-i", dir])
|
2019-05-03 18:14:27 +01:00
|
|
|
except Exception:
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
|
|
|
os.remove(makefile_in)
|
|
|
|
raise
|
|
|
|
|
2019-09-04 22:40:47 +01:00
|
|
|
def _run_configure(self):
|
2019-04-03 19:33:37 +01:00
|
|
|
mkpath(self.build_temp)
|
2019-05-03 18:14:27 +01:00
|
|
|
makefile = os.path.join(self.build_temp, "Makefile")
|
|
|
|
if not os.path.exists(makefile):
|
2019-04-03 19:33:37 +01:00
|
|
|
args = [
|
|
|
|
os.path.relpath("libdrgn/configure", self.build_temp),
|
|
|
|
"--disable-static",
|
|
|
|
"--with-python=" + sys.executable,
|
|
|
|
]
|
2020-01-24 01:54:46 +00:00
|
|
|
try:
|
|
|
|
args.extend(shlex.split(os.environ["CONFIGURE_FLAGS"]))
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2019-05-03 18:14:27 +01:00
|
|
|
try:
|
|
|
|
subprocess.check_call(args, cwd=self.build_temp)
|
|
|
|
except Exception:
|
|
|
|
with contextlib.suppress(FileNotFoundError):
|
|
|
|
os.remove(makefile)
|
|
|
|
raise
|
2019-04-03 19:33:37 +01:00
|
|
|
|
2019-09-04 22:40:47 +01:00
|
|
|
def _run_make(self):
|
|
|
|
args = ["make", "-C", self.build_temp]
|
2019-04-03 19:33:37 +01:00
|
|
|
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-09-04 22:40:47 +01:00
|
|
|
def run(self):
|
|
|
|
self._run_autoreconf("libdrgn")
|
|
|
|
self._run_autoreconf("libdrgn/elfutils")
|
|
|
|
self._run_configure()
|
|
|
|
self._run_make()
|
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
so = os.path.join(self.build_temp, ".libs/_drgn.so")
|
|
|
|
if self.inplace:
|
2019-09-06 20:25:59 +01:00
|
|
|
copy_file(so, self.get_ext_fullpath("_drgn"), update=True)
|
|
|
|
old_inplace, self.inplace = self.inplace, 0
|
2019-04-03 19:33:37 +01:00
|
|
|
build_path = self.get_ext_fullpath("_drgn")
|
|
|
|
mkpath(os.path.dirname(build_path))
|
2019-09-06 20:25:59 +01:00
|
|
|
copy_file(so, build_path, update=True)
|
|
|
|
self.inplace = old_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-09-04 01:07:37 +01:00
|
|
|
def get_source_files(self):
|
|
|
|
if os.path.exists(".git"):
|
|
|
|
args = ["git", "ls-files", "-z", "libdrgn"]
|
|
|
|
return [
|
|
|
|
os.fsdecode(path)
|
|
|
|
for path in subprocess.check_output(args).split(b"\0")
|
|
|
|
if path
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
# If this is a source distribution, then setuptools will get the
|
|
|
|
# list of sources that was included in the tarball.
|
|
|
|
return []
|
2017-08-29 05:16:43 +01:00
|
|
|
|
|
|
|
|
2019-11-15 21:28:47 +00:00
|
|
|
# Work around pypa/setuptools#436.
|
2020-01-24 23:24:50 +00:00
|
|
|
class egg_info(_egg_info):
|
2019-11-15 21:28:47 +00:00
|
|
|
def run(self):
|
|
|
|
if os.path.exists(".git"):
|
|
|
|
try:
|
|
|
|
os.remove(os.path.join(self.egg_info, "SOURCES.txt"))
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
super().run()
|
|
|
|
|
|
|
|
|
2020-01-23 20:09:48 +00:00
|
|
|
def get_version():
|
|
|
|
if not os.path.exists(".git"):
|
|
|
|
# If this is a source distribution, get the version from the egg
|
|
|
|
# metadata.
|
|
|
|
return pkg_resources.get_distribution("drgn").version
|
|
|
|
|
|
|
|
with open("libdrgn/configure.ac", "r") as f:
|
|
|
|
version = re.search(r"AC_INIT\(\[drgn\], \[([^]]*)\]", f.read()).group(1)
|
|
|
|
|
|
|
|
dirty = bool(
|
|
|
|
subprocess.check_output(
|
|
|
|
["git", "status", "-uno", "--porcelain"],
|
|
|
|
# Use the environment variable instead of --no-optional-locks to
|
|
|
|
# support Git < 2.14.
|
|
|
|
env={**os.environ, "GIT_OPTIONAL_LOCKS": "0"},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
count = int(
|
|
|
|
subprocess.check_output(
|
|
|
|
["git", "rev-list", "--count", f"v{version}.."],
|
|
|
|
stderr=subprocess.DEVNULL,
|
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
log.warn("warning: v%s tag not found", version)
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
if count == 0:
|
|
|
|
if dirty:
|
|
|
|
version += "+dirty"
|
|
|
|
return version
|
|
|
|
|
|
|
|
commit = subprocess.check_output(
|
|
|
|
["git", "rev-parse", "--short", "HEAD"], universal_newlines=True
|
|
|
|
).strip()
|
|
|
|
version += f".dev{count}+{commit}"
|
|
|
|
if dirty:
|
|
|
|
version += ".dirty"
|
|
|
|
return version
|
|
|
|
|
|
|
|
|
2020-01-11 01:14:52 +00:00
|
|
|
with open("README.rst", "r") as f:
|
|
|
|
long_description = f.read()
|
|
|
|
|
2019-04-03 19:33:37 +01:00
|
|
|
|
|
|
|
setup(
|
|
|
|
name="drgn",
|
2020-01-23 20:09:48 +00:00
|
|
|
version=get_version(),
|
2019-04-03 19:33:37 +01:00
|
|
|
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=[])],
|
2020-01-24 23:24:50 +00:00
|
|
|
cmdclass={"build_ext": build_ext, "egg_info": egg_info},
|
2019-04-03 19:33:37 +01:00
|
|
|
entry_points={"console_scripts": ["drgn=drgn.internal.cli:main"],},
|
2020-01-11 01:14:52 +00:00
|
|
|
python_requires=">=3.6",
|
2019-04-03 19:33:37 +01:00
|
|
|
author="Omar Sandoval",
|
|
|
|
author_email="osandov@osandov.com",
|
|
|
|
description="Scriptable debugger library",
|
2020-01-11 01:14:52 +00:00
|
|
|
long_description=long_description,
|
|
|
|
long_description_content_type="text/x-rst",
|
2019-04-03 19:33:37 +01:00
|
|
|
url="https://github.com/osandov/drgn",
|
2020-01-11 01:14:52 +00:00
|
|
|
project_urls={
|
|
|
|
"Bug Tracker": "https://github.com/osandov/drgn/issues",
|
|
|
|
"Documentation": "https://drgn.readthedocs.io",
|
|
|
|
},
|
|
|
|
license="GPL-3.0+",
|
|
|
|
classifiers=[
|
|
|
|
"Development Status :: 3 - Alpha",
|
|
|
|
"Environment :: Console",
|
|
|
|
"Intended Audience :: Developers",
|
|
|
|
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
|
|
|
"Operating System :: POSIX :: Linux",
|
|
|
|
"Programming Language :: Python :: 3",
|
|
|
|
"Topic :: Software Development :: Debuggers",
|
|
|
|
],
|
2019-04-03 19:33:37 +01:00
|
|
|
)
|