12
12
from urlparse import urlparse
13
13
except ImportError :
14
14
from urllib .parse import urlparse
15
- from pythonforandroid .logger import (logger , info , warning , shprint , info_main )
15
+ from pythonforandroid .logger import (logger , info , warning , error , shprint , info_main )
16
16
from pythonforandroid .util import (urlretrieve , current_directory , ensure_dir )
17
17
18
18
# this import is necessary to keep imp.load_source from complaining :)
@@ -563,6 +563,13 @@ def clean_build(self, arch=None):
563
563
warning (('Attempted to clean build for {} but build '
564
564
'did not exist' ).format (self .name ))
565
565
566
+ def install_libs (self , arch , lib , * libs ):
567
+ libs_dir = self .ctx .get_libs_dir (arch .arch )
568
+ shprint (sh .cp , '-t' , libs_dir , lib , * libs )
569
+
570
+ def has_libs (self , arch , * libs ):
571
+ return all (map (lambda l : self .ctx .has_lib (arch .arch , l ), libs ))
572
+
566
573
@classmethod
567
574
def recipe_dirs (cls , ctx ):
568
575
return [ctx .local_recipes ,
@@ -694,21 +701,44 @@ class PythonRecipe(Recipe):
694
701
call_hostpython_via_targetpython is False.
695
702
'''
696
703
704
+ install_in_targetpython = True
705
+ '''If True, installs the module in the targetpython installation dir.
706
+ This is almost always what you want to do.'''
707
+
697
708
setup_extra_args = []
698
709
'''List of extra arugments to pass to setup.py'''
699
710
711
+ @property
712
+ def real_hostpython_location (self ):
713
+ if 'hostpython2' in self .ctx .build_order :
714
+ return join (
715
+ Recipe .get_recipe ('hostpython2' , self .ctx ).get_build_dir (),
716
+ 'hostpython' )
717
+ else :
718
+ python_recipe = self .ctx .python_recipe
719
+ return 'python{}' .format (python_recipe .version )
720
+
700
721
@property
701
722
def hostpython_location (self ):
702
723
if not self .call_hostpython_via_targetpython :
703
- if 'hostpython2' in self .ctx .build_order :
704
- return join (
705
- Recipe .get_recipe ('hostpython2' , self .ctx ).get_build_dir (),
706
- 'hostpython' )
707
- else :
708
- python_recipe = self .ctx .python_recipe
709
- return 'python{}' .format (python_recipe .version )
724
+ return self .real_hostpython_location
710
725
return self .ctx .hostpython
711
726
727
+ def get_recipe_env (self , arch = None , with_flags_in_cc = True ):
728
+ env = super (PythonRecipe , self ).get_recipe_env (arch , with_flags_in_cc )
729
+ if not self .call_hostpython_via_targetpython :
730
+ hppath = []
731
+ hppath .append (join (dirname (self .hostpython_location ), 'Lib' ))
732
+ hppath .append (join (hppath [0 ], 'site-packages' ))
733
+ builddir = join (dirname (self .hostpython_location ), 'build' )
734
+ hppath += [join (builddir , d ) for d in listdir (builddir )
735
+ if isdir (join (builddir , d ))]
736
+ if 'PYTHONPATH' in env :
737
+ env ['PYTHONPATH' ] = ':' .join (hppath + [env ['PYTHONPATH' ]])
738
+ else :
739
+ env ['PYTHONPATH' ] = ':' .join (hppath )
740
+ return env
741
+
712
742
def should_build (self , arch ):
713
743
print ('name is' , self .site_packages_name , type (self ))
714
744
name = self .site_packages_name
@@ -738,7 +768,6 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
738
768
info ('Installing {} into site-packages' .format (self .name ))
739
769
740
770
with current_directory (self .get_build_dir (arch .arch )):
741
- # hostpython = sh.Command(self.ctx.hostpython)
742
771
hostpython = sh .Command (self .hostpython_location )
743
772
# hostpython = sh.Command('python3.5')
744
773
@@ -784,10 +813,20 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
784
813
785
814
# If asked, also install in the hostpython build dir
786
815
if self .install_in_hostpython :
787
- shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
788
- '--root={}' .format (dirname (self .hostpython_location )),
789
- '--install-lib=Lib/site-packages' ,
790
- _env = env , * self .setup_extra_args )
816
+ self .install_hostpython_package (arch )
817
+
818
+ def get_hostrecipe_env (self , arch ):
819
+ env = environ .copy ()
820
+ env ['PYTHONPATH' ] = join (dirname (self .real_hostpython_location ), 'Lib' , 'site-packages' )
821
+ return env
822
+
823
+ def install_hostpython_package (self , arch ):
824
+ env = self .get_hostrecipe_env (arch )
825
+ real_hostpython = sh .Command (self .real_hostpython_location )
826
+ shprint (real_hostpython , 'setup.py' , 'install' , '-O2' ,
827
+ '--root={}' .format (dirname (self .real_hostpython_location )),
828
+ '--install-lib=Lib/site-packages' ,
829
+ _env = env , * self .setup_extra_args )
791
830
792
831
793
832
class CompiledComponentsPythonRecipe (PythonRecipe ):
@@ -809,22 +848,27 @@ def build_compiled_components(self, arch):
809
848
env = self .get_recipe_env (arch )
810
849
with current_directory (self .get_build_dir (arch .arch )):
811
850
hostpython = sh .Command (self .hostpython_location )
812
- if self .call_hostpython_via_targetpython :
813
- shprint (hostpython , 'setup.py' , self .build_cmd , '-v' ,
814
- _env = env , * self .setup_extra_args )
815
- else :
816
- hppath = join (dirname (self .hostpython_location ), 'Lib' ,
817
- 'site-packages' )
818
- if 'PYTHONPATH' in env :
819
- env ['PYTHONPATH' ] = hppath + ':' + env ['PYTHONPATH' ]
820
- else :
821
- env ['PYTHONPATH' ] = hppath
822
- shprint (hostpython , 'setup.py' , self .build_cmd , '-v' , _env = env ,
823
- * self .setup_extra_args )
851
+ if self .install_in_hostpython :
852
+ shprint (hostpython , 'setup.py' , 'clean' , '--all' , _env = env )
853
+ shprint (hostpython , 'setup.py' , self .build_cmd , '-v' ,
854
+ _env = env , * self .setup_extra_args )
824
855
build_dir = glob .glob ('build/lib.*' )[0 ]
825
856
shprint (sh .find , build_dir , '-name' , '"*.o"' , '-exec' ,
826
857
env ['STRIP' ], '{}' , ';' , _env = env )
827
858
859
+ def install_hostpython_package (self , arch ):
860
+ env = self .get_hostrecipe_env (arch )
861
+ self .rebuild_compiled_components (arch , env )
862
+ super (CompiledComponentsPythonRecipe , self ).install_hostpython_package (arch )
863
+
864
+ def rebuild_compiled_components (self , arch , env ):
865
+ info ('Rebuilding compiled components in {}' .format (self .name ))
866
+
867
+ hostpython = sh .Command (self .real_hostpython_location )
868
+ shprint (hostpython , 'setup.py' , 'clean' , '--all' , _env = env )
869
+ shprint (hostpython , 'setup.py' , self .build_cmd , '-v' , _env = env ,
870
+ * self .setup_extra_args )
871
+
828
872
829
873
class CythonRecipe (PythonRecipe ):
830
874
pre_build_ext = False
@@ -880,13 +924,15 @@ def build_cython_components(self, arch):
880
924
881
925
if manually_cythonise :
882
926
info ('Running cython where appropriate' )
883
- if self .ctx .python_recipe .from_crystax :
884
- shprint (sh .find , self .get_build_dir (arch .arch ), '-iname' , '*.pyx' ,
885
- '-exec' , 'cython' , '{}' , ';' )
886
- # AND: Need to choose cython version more carefully
887
- else :
888
- shprint (sh .find , self .get_build_dir (arch .arch ), '-iname' , '*.pyx' ,
889
- '-exec' , self .ctx .cython , '{}' , ';' , _env = env )
927
+ cyenv = env .copy ()
928
+ if 'CYTHONPATH' in cyenv :
929
+ cyenv ['PYTHONPATH' ] = cyenv ['CYTHONPATH' ]
930
+ elif 'PYTHONPATH' in cyenv :
931
+ del cyenv ['PYTHONPATH' ]
932
+ cython = 'cython' if self .ctx .python_recipe .from_crystax else self .ctx .cython
933
+ cython_cmd = 'find "{}" -iname *.pyx | xargs "{}"' .format (
934
+ self .get_build_dir (arch .arch ), cython )
935
+ shprint (sh .sh , '-c' , cython_cmd , _env = cyenv )
890
936
info ('ran cython' )
891
937
892
938
shprint (hostpython , 'setup.py' , 'build_ext' , '-v' , _env = env ,
@@ -900,7 +946,6 @@ def build_cython_components(self, arch):
900
946
shprint (sh .find , build_lib [0 ], '-name' , '*.o' , '-exec' ,
901
947
env ['STRIP' ], '{}' , ';' , _env = env )
902
948
print ('stripped!?' )
903
- # exit(1)
904
949
905
950
# def cythonize_file(self, filename):
906
951
# if filename.startswith(self.build_dir):
0 commit comments