Skip to content

Commit

Permalink
PyPANDA: update setup scripts to use debian package instead of self-i…
Browse files Browse the repository at this point in the history
…nstalling
  • Loading branch information
Andrew Fasano committed Dec 19, 2023
1 parent 9a7209f commit 3840250
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 57 deletions.
11 changes: 10 additions & 1 deletion panda/python/core/pandare/panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,16 @@ def __init__(self, arch="i386", mem="128M",
if libpanda_path:
environ["PANDA_LIB"] = self.libpanda_path = libpanda_path
else:
self.libpanda_path = pjoin(self.get_build_dir(), "{0}-softmmu/libpanda-{0}.so".format(self.arch_name))
build_dir = self.get_build_dir()
lib_paths = ["libpanda-{0}.so".format(self.arch_name), "{0}-softmmu/libpanda-{0}.so".format(self.arch_name)]
# Select the first path that exists - we'll have libpanda-{arch}.so for a system install versus arch-softmmu/libpanda-arch.so for a build
for p in lib_paths:
if isfile(pjoin(build_dir, p)):
self.libpanda_path = pjoin(build_dir, p)
break
else:
raise RuntimeError("Couldn't find libpanda-{0}.so in {1} (in either root or {0}-libpanda directory)".format(self.arch_name, build_dir))

self.panda = self.libpanda_path # Necessary for realpath to work inside core-panda, may cause issues?

self.ffi = self._do_types_import()
Expand Down
10 changes: 9 additions & 1 deletion panda/python/core/pandare/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,20 @@ def _find_build_dir(arch_name, find_executable=False):
'''
Internal function to return the build directory for the specified architecture
'''

system_build = "/usr/local/bin/"
python_package = pjoin(*[dirname(__file__), "data"])
local_build = realpath(pjoin(dirname(__file__), "../../../../build"))


arch_dir = f"{arch_name}-softmmu"
file_name = f"panda-system-{arch_name}" if find_executable else \
f"libpanda-{arch_name}.so"
pot_paths = [pjoin(python_package, arch_dir), pjoin(local_build, arch_dir)]

# system path could have panda-system-X or libpanda-X.so. Others would have an arch_name - softmmu directory
pot_paths = [system_build,
pjoin(python_package, arch_dir),
pjoin(local_build, arch_dir)]

if find_executable and 'PATH' in environ:
# If we're looking for the panda executable, also search the user's path
Expand Down
73 changes: 18 additions & 55 deletions panda/python/core/setup.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/env python
# Install with python setup.py (develop|install)

from setuptools import setup, find_packages
from setuptools.command.install import install as install_orig
from setuptools.command.develop import develop as develop_orig
from setuptools.dist import Distribution
from subprocess import check_output
import shutil

import os
import shutil
################################################
# 1) Copy panda object files: libpanda-XYZ.so, #
# pc-bios/*, all .so files for plugins, #
# pypanda's include directory, llvm-helpers #
################################################
arches = ['arm', 'aarch64', 'i386', 'x86_64', 'ppc', 'mips', 'mipsel', 'mips64']

# Check for PANDA binaries in /usr/local/bin/ or in our build directory
#panda_binaries = ['/usr/local/bin/panda-system-{arch}' for arch in arches]
# Do we actually care at this point?

root_dir = os.path.join(*[os.path.dirname(__file__), "..", "..", ".."]) # panda-git/ root dir

Expand All @@ -28,16 +27,9 @@ def copy_objs():
build_root = os.path.join(root_dir, "build")

if os.path.isdir(lib_dir):
assert('panda' in lib_dir), "Refusing to rm -rf directory without 'panda' in it"
shutil.rmtree(lib_dir)
os.mkdir(lib_dir)

# Copy bios directory
biosdir = os.path.join(root_dir, "pc-bios")
if not os.path.isdir(biosdir):
raise RuntimeError(f"Could not find PC-bios directory at {biosdir}")
shutil.copytree(biosdir, lib_dir+"/pc-bios")

# Copy pypanda's include directory (different than core panda's) into a datadir
pypanda_inc = os.path.join(*[root_dir, "panda", "python", "core", "pandare", "include"])
if not os.path.isdir(pypanda_inc):
Expand All @@ -47,21 +39,18 @@ def copy_objs():
shutil.rmtree(pypanda_inc_dest)
shutil.copytree(pypanda_inc, pypanda_inc_dest)

# For each arch, copy llvm-helpers
# XXX Should these be in standard panda deb?
# What actually uses these? Taint? Disabling for now
'''
# Check if we have llvm-support
with open(os.path.join(*[build_root, 'config-host.mak']), 'r') as cfg:
llvm_enabled = True if 'CONFIG_LLVM=y' in cfg.read() else False
# For each arch, copy library, plugins, plog_pb2.py and llvm-helpers
arches = ['arm', 'aarch64', 'i386', 'x86_64', 'ppc', 'mips', 'mipsel', 'mips64']
if pypi_build:
# Nobody really wants mips32 anymore, shrink our distribution size by dropping
arches = ['arm', 'aarch64', 'i386', 'x86_64', 'ppc', 'mips64']

for arch in arches:
libname = "libpanda-"+arch+".so"
softmmu = arch+"-softmmu"
path = os.path.join(*[build_root, softmmu, libname])
plugindir = os.path.join(*[build_root, softmmu, "panda", "plugins"])
llvm1 = os.path.join(*[build_root, softmmu, "llvm-helpers.bc1"])
llvm2 = os.path.join(*[build_root, softmmu, f"llvm-helpers-{arch}.bc"])
Expand All @@ -71,25 +60,10 @@ def copy_objs():
continue
os.mkdir(os.path.join(lib_dir, softmmu))

new_plugindir = os.path.join(lib_dir, softmmu, "panda/plugins")
os.mkdir(os.path.dirname(new_plugindir)) # When we copy the whole tree, it will make the plugins directory

shutil.copy( path, os.path.join(lib_dir, softmmu))
if llvm_enabled:
shutil.copy( llvm1, os.path.join(lib_dir, softmmu))
shutil.copy( llvm2, os.path.join(lib_dir, softmmu))

shutil.copytree(plugindir, new_plugindir, ignore=shutil.ignore_patterns('*.o', '*.d'))

# Strip libpandas and plugins to save space (Need <100mb for pypi)
if pypi_build:
check_output(f"find {lib_dir} -type f -executable -exec strip {{}} \;", shell=True)


#########################
# 3) Build the package #
#########################
'''

from setuptools.command.install import install as install_orig
from setuptools.command.develop import develop as develop_orig
Expand All @@ -100,11 +74,6 @@ class custom_develop(develop_orig):
2) Running regular setup tools logic
'''
def run(self):
# Delete pandare/data in the case of `setup.py develop`
# Don't copy objects, use them in the current path
if os.path.isdir(lib_dir):
assert('panda' in lib_dir), "Refusing to rm -rf directory without 'panda' in it"
shutil.rmtree(lib_dir)
from create_panda_datatypes import main as create_datatypes
create_datatypes(install=False)
super().run()
Expand All @@ -114,18 +83,16 @@ class custom_install(install_orig):
We're going to install to the system. Two possible states to handle
1) Running from within the panda repo with panda built - need to create_datatypes
2) Running from a python sdist where all the files are already prepared
Install to the system by:
1) Creating datatype files for an install
2) Copying objects into local module
3) Running regular setup tools logic
'''
def run(self):
try:
from create_panda_datatypes import main as create_datatypes
# If we can do the import, we're in the panda repo
create_datatypes(install=True)
copy_objs()

except ImportError:
# Import failed, we're either in a python sdist or something has gone very wrong
assert(os.path.isfile("pandare/include/panda_datatypes.h")), \
"panda_datatypes.h missing and can't be generated"
assert(os.path.isfile("pandare/autogen/panda_datatypes.py")), \
Expand All @@ -140,22 +107,18 @@ def run(self):
long_description = fh.read()

setup(name='pandare',
version='0.1.1.6',
version='0.1.2.0',
description='Python Interface to PANDA',
long_description=long_description,
long_description_content_type="text/markdown",
author='Andrew Fasano, Luke Craig, and Tim Leek',
author_email='[email protected]',
url='https://github.com/panda-re/panda/',
packages=find_packages(),
package_data = { 'pandare': ['data/**/*', # Copy everything (fails?)
'data/*-softmmu/libpanda-*.so', # Libpandas
'data/*-softmmu/llvm-helpers*.bc*', # Llvm-helpers
'data/*-softmmu/panda/plugins/*', # All plugins
'data/*-softmmu/panda/plugins/**/*',# All plugin files
package_data = { 'pandare': [ \
'data/*-softmmu/llvm-helpers*.bc*', # LLVM Helpers
'data/pypanda/include/*.h', # Includes files
'data/pypanda/include/*.h', # Includes files
'data/pc-bios/*', # BIOSes
'data/pc-bios/**/*', # Keymaps
'qcows.json' # Generic Images
]},
install_requires=[ 'cffi>=1.14.3', 'colorama'],
Expand Down

0 comments on commit 3840250

Please sign in to comment.