33import os
44import sys
55import shutil
6+ import argparse
67if sys .version_info [0 ] < 3 :
78 raise RuntimeError ('Requires python3' )
89
1415# those include files. See panda/include/panda/README.pypanda for
1516# so proscriptions wrt those headers we use here. They need to be kept
1617# fairly clean if we are to be able to make sense of them with this script
17- # which isn't terriby clever.
18+ # which isn't terribly clever.
1819
19- # Also copy all of the generated plog_pb2.py's into pandare/plog_pb/
20+ # Also copy all the generated plog_pb2.py's into pandare/plog_pb/
2021# XXX: WIP if we do this this file should be renamed
2122root_dir = os .path .join (* [os .path .dirname (__file__ ), ".." , ".." , ".." ]) # panda-git/ root dir
2223build_root = os .path .join (root_dir , "build" )
2324lib_dir = os .path .join ("pandare" , "data" )
2425
25- for arch in ['arm' , 'aarch64' , 'i386' , 'x86_64' , 'ppc' , 'mips' , 'mipsel' , 'mips64' ]:
26+ arches = ['arm' , 'aarch64' , 'i386' , 'x86_64' , 'ppc' , 'mips' , 'mipsel' , 'mips64' , 'mips64el' ]
27+ for arch in arches :
2628 softmmu = arch + "-softmmu"
2729 plog = os .path .join (* [build_root , softmmu , "plog_pb2.py" ])
2830 if os .path .isfile (plog ):
@@ -187,17 +189,12 @@ def include_this(pdth, fn):
187189 pdth .write (line )
188190 pn += 1
189191
190- def compile (arch , bits , pypanda_headers , install , static_inc ):
191- #from ..ffi_importer import ffi
192+ def compile (arch , bits , pypanda_headers , include_dir ):
192193 from cffi import FFI
193194 ffi = FFI ()
194195
195196 ffi .set_source (f"panda_{ arch } _{ bits } " , None )
196- if install :
197- import os
198- include_dir = os .path .abspath (os .path .join (* [os .path .dirname (__file__ ), "pandare" , "include" ]))
199- else :
200- include_dir = static_inc
197+
201198
202199 def define_clean_header (ffi , fname ):
203200 '''Convenience function to pull in headers from file in C'''
@@ -325,7 +322,7 @@ def expand_ppp_def(line):
325322 ffi .compile (verbose = True ,debug = True ,tmpdir = './pandare/autogen' )
326323
327324
328- def main (install = False , recompile = True ):
325+ def main (recompile = True ):
329326 '''
330327 Copy and reformat panda header files into the autogen directory
331328
@@ -338,8 +335,6 @@ def main(install=False,recompile=True):
338335 # out pypanda bits to go in INCLUDE_DIR files
339336 plugin_dirs = os .listdir (PLUGINS_DIR )
340337
341- INCLUDE_DIR_PYP_INSTALL = 'os.path.abspath(os.path.join(*[os.path.dirname(__file__), "..", "..", "pandare", "data", "pypanda", "include"]))' # ... /python3.6/site-packages/panda/data/pypanda/include/
342-
343338 # We want the various cpu_loop_... functions
344339 create_pypanda_header ("%s/exec/exec-all.h" % INCLUDE_DIR_CORE )
345340
@@ -631,7 +626,7 @@ def exception(self):
631626
632627 for arch in arches :
633628 print ("Compiling headers for:" , arch )
634- compile (arch [0 ], arch [1 ], pypanda_headers , install , INCLUDE_DIR_PYP )
629+ compile (arch [0 ], arch [1 ], pypanda_headers , INCLUDE_DIR_PYP )
635630
636631 #ps = (
637632 # Process(target=compile, args=(arch[0], arch[1], pypanda_headers, install, INCLUDE_DIR_PYP))
@@ -641,5 +636,68 @@ def exception(self):
641636 #[p.join() for p in ps]
642637
643638
639+ # Check for PANDA binaries in /usr/local/bin/ or in our build directory
640+ # panda_binaries = ['/usr/local/bin/panda-system-{arch}' for arch in arches]
641+ # Do we actually care at this point?
642+ def copy_objs ():
643+ '''
644+ Run to copy objects into a (local and temporary) python module before installing to the system.
645+ Shouldn't be run if you're just installing in develop mode
646+ '''
647+ print ("Copying objects into pandare/data/pypanda/include" )
648+ if os .path .isdir (lib_dir ):
649+ shutil .rmtree (lib_dir )
650+ os .mkdir (lib_dir )
651+
652+ # Copy pypanda's include directory (different than core panda's) into a datadir
653+ pypanda_inc = os .path .join (* [root_dir , "panda" , "python" , "core" , "pandare" , "include" ])
654+ if not os .path .isdir (pypanda_inc ):
655+ raise RuntimeError (f"Could not find pypanda include directory at { pypanda_inc } " )
656+ pypanda_inc_dest = os .path .join (* ["pandare" , "data" , "pypanda" , "include" ])
657+ if os .path .isdir (pypanda_inc_dest ):
658+ shutil .rmtree (pypanda_inc_dest )
659+ shutil .copytree (pypanda_inc , pypanda_inc_dest )
660+
661+ # For each arch, copy llvm-helpers
662+ # XXX Should these be in standard panda deb?
663+ # What actually uses these? Taint? Disabling for now
664+ '''
665+ # Check if we have llvm-support
666+ with open(os.path.join(*[build_root, 'config-host.mak']), 'r') as cfg:
667+ llvm_enabled = True if 'CONFIG_LLVM=y' in cfg.read() else False
668+
669+ for arch in arches:
670+ libname = "libpanda-"+arch+".so"
671+ softmmu = arch+"-softmmu"
672+ path = os.path.join(*[build_root, softmmu, libname])
673+ llvm1 = os.path.join(*[build_root, softmmu, "llvm-helpers.bc1"])
674+ llvm2 = os.path.join(*[build_root, softmmu, f"llvm-helpers-{arch}.bc"])
675+
676+ if os.path.isfile(path) is False:
677+ print(("Missing file {} - did you run build.sh from panda/build directory?\n "
678+ "Skipping building pypanda for {}").format(path, arch))
679+ continue
680+
681+ os.mkdir(os.path.join(lib_dir, softmmu))
682+ if llvm_enabled:
683+ shutil.copy( llvm1, os.path.join(lib_dir, softmmu))
684+ shutil.copy( llvm2, os.path.join(lib_dir, softmmu))
685+ '''
686+
687+
644688if __name__ == '__main__' :
689+ parser = argparse .ArgumentParser (prog = 'A python script to populate panda/autogen folder '
690+ 'and prep for PyPanda wheel installation' )
691+ parser .add_argument ('--install' , '-i' , dest = 'install' , action = 'store_true' ,
692+ help = 'If set, this means update pandare folder for installation' )
693+ parser .add_argument ('--recompile' , '-r' , dest = 'recompile' , action = 'store_true' ,
694+ help = 'If set, recompile the headers with cffi' )
695+ args = parser .parse_args ()
696+ """
697+ Install as a local module (not to system) by
698+ 1) Creating datatype files for local-use
699+ 2) Running regular setup tools logic
700+ """
645701 main ()
702+ if args .install :
703+ copy_objs ()
0 commit comments