3
3
import os
4
4
import sys
5
5
import shutil
6
+ import argparse
6
7
if sys .version_info [0 ] < 3 :
7
8
raise RuntimeError ('Requires python3' )
8
9
14
15
# those include files. See panda/include/panda/README.pypanda for
15
16
# so proscriptions wrt those headers we use here. They need to be kept
16
17
# 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.
18
19
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/
20
21
# XXX: WIP if we do this this file should be renamed
21
22
root_dir = os .path .join (* [os .path .dirname (__file__ ), ".." , ".." , ".." ]) # panda-git/ root dir
22
23
build_root = os .path .join (root_dir , "build" )
23
24
lib_dir = os .path .join ("pandare" , "data" )
24
25
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 :
26
28
softmmu = arch + "-softmmu"
27
29
plog = os .path .join (* [build_root , softmmu , "plog_pb2.py" ])
28
30
if os .path .isfile (plog ):
@@ -187,17 +189,12 @@ def include_this(pdth, fn):
187
189
pdth .write (line )
188
190
pn += 1
189
191
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 ):
192
193
from cffi import FFI
193
194
ffi = FFI ()
194
195
195
196
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
+
201
198
202
199
def define_clean_header (ffi , fname ):
203
200
'''Convenience function to pull in headers from file in C'''
@@ -325,7 +322,7 @@ def expand_ppp_def(line):
325
322
ffi .compile (verbose = True ,debug = True ,tmpdir = './pandare/autogen' )
326
323
327
324
328
- def main (install = False , recompile = True ):
325
+ def main (recompile = True ):
329
326
'''
330
327
Copy and reformat panda header files into the autogen directory
331
328
@@ -338,8 +335,6 @@ def main(install=False,recompile=True):
338
335
# out pypanda bits to go in INCLUDE_DIR files
339
336
plugin_dirs = os .listdir (PLUGINS_DIR )
340
337
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
-
343
338
# We want the various cpu_loop_... functions
344
339
create_pypanda_header ("%s/exec/exec-all.h" % INCLUDE_DIR_CORE )
345
340
@@ -631,7 +626,7 @@ def exception(self):
631
626
632
627
for arch in arches :
633
628
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 )
635
630
636
631
#ps = (
637
632
# Process(target=compile, args=(arch[0], arch[1], pypanda_headers, install, INCLUDE_DIR_PYP))
@@ -641,5 +636,68 @@ def exception(self):
641
636
#[p.join() for p in ps]
642
637
643
638
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
+
644
688
if __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
+ """
645
701
main ()
702
+ if args .install :
703
+ copy_objs ()
0 commit comments