17
17
import importlib
18
18
import io
19
19
import json
20
+ import glob
20
21
import shutil
21
22
import fnmatch
22
23
import re
@@ -61,6 +62,24 @@ def get_directory(filename):
61
62
return basename (filename [:- 4 ])
62
63
print ('Unknown file extension for {}' .format (filename ))
63
64
exit (1 )
65
+
66
+ def which (program , path_env ):
67
+ import os
68
+ def is_exe (fpath ):
69
+ return os .path .isfile (fpath ) and os .access (fpath , os .X_OK )
70
+
71
+ fpath , fname = os .path .split (program )
72
+ if fpath :
73
+ if is_exe (program ):
74
+ return program
75
+ else :
76
+ for path in path_env .split (os .pathsep ):
77
+ path = path .strip ('"' )
78
+ exe_file = os .path .join (path , program )
79
+ if is_exe (exe_file ):
80
+ return exe_file
81
+
82
+ return None
64
83
65
84
66
85
import contextlib
@@ -538,11 +557,17 @@ def prepare_build_dir(self):
538
557
def prepare_dist_dir (self , name ):
539
558
self .dist_dir = join (self .ctx .dist_dir , name + '_' +
540
559
self .bootstrap_template_dir )
541
- shprint (sh .cp , '-r' ,
542
- join (self .ctx .root_dir ,
543
- 'bootstrap_templates' ,
544
- self .bootstrap_template_dir ),
545
- self .dist_dir )
560
+ # shprint(sh.cp, '-r',
561
+ # join(self.ctx.root_dir,
562
+ # 'bootstrap_templates',
563
+ # self.bootstrap_template_dir),
564
+ # self.dist_dir)
565
+ ensure_dir (self .dist_dir )
566
+
567
+ def run_distribute (self ):
568
+ print ('Running distribute' )
569
+ print ('Default bootstrap being used doesn\' t know how to distribute...failing.' )
570
+ exit (1 )
546
571
547
572
548
573
class PygameBootstrap (Bootstrap ):
@@ -551,6 +576,96 @@ class PygameBootstrap(Bootstrap):
551
576
recipe_depends = ['hostpython2' , 'python2' , 'pyjnius' , 'sdl' , 'pygame' ,
552
577
'android' , 'kivy' ]
553
578
579
+ def run_distribute (self ):
580
+ print ('Running distribute!' )
581
+
582
+ src_path = join (self .ctx .root_dir , 'bootstrap_templates' ,
583
+ self .bootstrap_template_dir )
584
+
585
+ with current_directory (self .dist_dir ):
586
+
587
+ print ('Creating initial layout' )
588
+ for dirname in ('assets' , 'bin' , 'private' , 'res' , 'templates' ):
589
+ if not exists (dirname ):
590
+ shprint (sh .mkdir , dirname )
591
+
592
+ print ('Copying default files' )
593
+ shprint (sh .cp , '-a' , join (src_path , 'default.properties' ), '.' )
594
+ shprint (sh .cp , '-a' , join (src_path , 'local.properties' ), '.' )
595
+ shprint (sh .cp , '-a' , join (src_path , 'build.py' ), '.' )
596
+ shprint (sh .cp , '-a' , join (src_path , 'buildlib' ), '.' )
597
+ shprint (sh .cp , '-a' , join (src_path , 'src' ), '.' )
598
+ shprint (sh .cp , '-a' , join (src_path , 'templates' ), '.' )
599
+ shprint (sh .cp , '-a' , join (src_path , 'res' ), '.' )
600
+ shprint (sh .cp , '-a' , join (src_path , 'blacklist.txt' ), '.' )
601
+ shprint (sh .cp , '-a' , join (src_path , 'whitelist.txt' ), '.' )
602
+
603
+ print ('Copying python distribution' )
604
+ hostpython = sh .Command (self .ctx .hostpython )
605
+ shprint (hostpython , '-OO' , '-m' , 'compileall' , join (self .ctx .build_dir , 'python-install' ))
606
+ if not exists ('python-install' ):
607
+ shprint (sh .cp , '-a' , join (self .ctx .build_dir , 'python-install' ), '.' )
608
+
609
+ print ('Copying libs' )
610
+ # AND: Hardcoding armeabi - naughty!
611
+ shprint (sh .mkdir , '-p' , join ('libs' , 'armeabi' ))
612
+ for lib in glob .glob (join (self .ctx .libs_dir , '*' )):
613
+ shprint (sh .cp , '-a' , lib , join ('libs' , 'armeabi' ))
614
+
615
+ print ('Copying java files' )
616
23D3
+ for filename in glob .glob (join (self .ctx .build_dir , 'java' , '*' )):
617
+ shprint (sh .cp , '-a' , filename , 'src' )
618
+
619
+ print ('Filling private directory' )
620
+ if not exists (join ('private' , 'lib' )):
621
+ shprint (sh .cp , '-a' , join ('python-install' , 'lib' ), 'private' )
622
+ shprint (sh .mkdir , '-p' , join ('private' , 'include' , 'python2.7' ))
623
+
624
+ # AND: Copylibs stuff should go here
625
+ shprint (sh .mv , join ('libs' , 'armeabi' , 'libpymodules.so' ), 'private/' )
626
+ shprint (sh .cp , join ('python-install' , 'include' , 'python2.7' , 'pyconfig.h' ), join ('private' , 'include' , 'python2.7/' ))
627
+
628
+ print ('Remove some unwanted files' )
629
+ shprint (sh .rm , '-f' , join ('private' , 'lib' , 'libpython2.7.so' ))
630
+ shprint (sh .rm , '-rf' , join ('private' , 'lib' , 'pkgconfig' ))
631
+
632
+ with current_directory (join (self .dist_dir , 'private' , 'lib' , 'python2.7' )):
633
+ # shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
634
+ removes = []
635
+ for dirname , something , filens in walk ('.' ):
636
+ for filename in filens :
637
+ for suffix in ('py' , 'pyc' , 'so.o' , 'so.a' , 'so.libs' ):
638
+ if filename .endswith (suffix ):
639
+ removes .append (filename )
640
+ shprint (sh .rm , '-f' , * removes )
641
+
642
+ print ('Deleting some other stuff not used on android' )
643
+ # To quote the original distribute.sh, 'well...'
644
+ shprint (sh .rm , '-rf' , 'ctypes' )
645
+ shprint (sh .rm , '-rf' , 'lib2to3' )
646
+ shprint (sh .rm , '-rf' , 'idlelib' )
647
+ for filename in glob .glob ('config/libpython*.a' ):
648
+ shprint (sh .rm , '-f' , filename )
649
+ shprint (sh .rm , '-rf' , 'config/python.o' )
650
+ shprint (sh .rm , '-rf' , 'lib-dynload/_ctypes_test.so' )
651
+ shprint (sh .rm , '-rf' , 'lib-dynloat/_testcapi.so' )
652
+
653
+
654
+ print ('Stripping libraries' )
655
+ env = ArchAndroid (self .ctx ).get_env ()
656
+ print ('env is' , env )
657
+ strip = which ('arm-linux-androideabi-strip' , env ['PATH' ])
658
+ if strip is None :
659
+ print ('Can\' t find strip in PATH...' )
660
+ strip = sh .Command (strip )
661
+ filens = shprint (sh .find , join (self .dist_dir , 'private' ), join (self .dist_dir , 'libs' ),
662
+ '-iname' , '*.so' , _env = env ).stdout
663
+ for filen in filens .split ('\n ' ):
664
+ try :
665
+ shprint (strip , filen , _env = env )
666
+ except sh .ErrorReturnCode_1 :
667
+ print ('Something went wrong with strip...not sure if this is important.' )
668
+
554
669
555
670
556
671
class Recipe (object ):
@@ -1472,6 +1587,8 @@ def create_android_project(self):
1472
1587
1473
1588
run_pymodules_install ([])
1474
1589
1590
+ ctx .bootstrap .run_distribute ()
1591
+
1475
1592
print ('Done building recipes, exiting for now.' )
1476
1593
return
1477
1594
0 commit comments