def insert_python_site(self): try: import setuptools.version as stv except ImportError: return version = stv.__version__.split('.', 1) if len(version) < 1 or int(version[0]) < 49: return m.warning('detected setuptools >= 49.0.0, installing fallback site.py file. ' 'See https://github.com/pypa/setuptools/issues/2295') # Since python-setuptools 49.0.0, site.py is not installed by # easy_install/setup.py anymore which breaks python installs outside # the system prefix. # https://github.com/pypa/setuptools/issues/2295 # # Install the previously installed site.py ourselves as a workaround config = self.cookbook.get_config() py_prefix = sysconfig.get_path('purelib', vars={'base': ''}) # Must strip \/ to ensure that the path is relative py_prefix = PurePath(config.prefix) / PurePath(py_prefix.strip('\\/')) src_file = os.path.join(os.path.dirname(__file__), 'site-patch.py') shutil.copy(src_file, py_prefix / 'site.py')
def ls(self, path, detail=False, **kwargs): self._get_dirs() path = PurePath(path.strip("/")) paths = {} for p, f in self.dir_cache.items(): p = PurePath(p.strip("/")) root = p.parent if root == path: # file is in directory -> return file paths[str(p)] = f elif path in p.parents: # file is in subdirectory -> return first intermediate directory ppath = str(path / p.relative_to(path).parts[0]) paths[ppath] = { "name": ppath + "/", "size": 0, "type": "directory" } out = list(paths.values()) if detail: return out else: return list(sorted(f["name"] for f in out))
def get_env(self, prefix, libdir, py_prefix): # Get paths for environment variables includedir = os.path.join(prefix, 'include') bindir = os.path.join(prefix, 'bin') manpathdir = os.path.join(prefix, 'share', 'man') infopathdir = os.path.join(prefix, 'share', 'info') pkgconfigbin = os.path.join(self.build_tools_prefix, 'bin', 'pkg-config') pkgconfigdatadir = os.path.join(prefix, 'share', 'pkgconfig') pkgconfigdir = os.path.join(libdir, 'pkgconfig') typelibpath = os.path.join(libdir, 'girepository-1.0') xdgdatadir = os.path.join(prefix, 'share') xdgconfigdir = os.path.join(prefix, 'etc', 'xdg') xcursordir = os.path.join(prefix, 'share', 'icons') aclocaldir = os.path.join(prefix, 'share', 'aclocal') perlversionpath = os.path.join(libdir, 'perl5', 'site_perl', self._perl_version()) if self.target_platform == Platform.WINDOWS: # On windows even if perl version is 5.8.8, modules can be # installed in 5.8 perlversionpath = perlversionpath.rsplit('.', 1)[0] perl5lib = ':'.join([ to_unixpath(os.path.join(libdir, 'perl5')), to_unixpath(perlversionpath) ]) gstpluginpath = os.path.join(libdir, 'gstreamer-0.10') gstpluginpath10 = os.path.join(libdir, 'gstreamer-1.0') gstregistry = os.path.join('~', '.gstreamer-0.10', 'cerbero-registry-%s' % self.target_arch) gstregistry10 = os.path.join('~', '.cache', 'gstreamer-1.0', 'cerbero-registry-%s' % self.target_arch) gstregistry = os.path.expanduser(gstregistry) gstregistry10 = os.path.expanduser(gstregistry10) pypath = sysconfig.get_path('purelib', vars={'base': ''}) # Must strip \/ to ensure that the path is relative pypath = PurePath(pypath.strip('\\/')) # Starting with Python 3.7.1 on Windows, each PYTHONPATH must use the # native path separator and must end in a path separator. pythonpath = [ str(prefix / pypath) + os.sep, str(self.build_tools_prefix / pypath) + os.sep ] if self.platform == Platform.WINDOWS: # On Windows, pypath doesn't include Python version although some # packages (pycairo, gi, etc...) install themselves using Python # version scheme like on a posix system. # Let's add an extra path to PYTHONPATH for these libraries. pypath = sysconfig.get_path('purelib', 'posix_prefix', {'base': ''}) pypath = PurePath(pypath.strip('\\/')) pythonpath.append(str(prefix / pypath) + os.sep) # Ensure python paths exists because setup.py won't create them for path in pythonpath: if self.platform == Platform.WINDOWS: # pythonpaths start with 'Lib' on Windows, which is extremely # undesirable since our libdir is 'lib'. Windows APIs are # case-preserving case-insensitive. path = path.lower() self._create_path(path) pythonpath = os.pathsep.join(pythonpath) if self.platform == Platform.LINUX: xdgdatadir += ":/usr/share:/usr/local/share" ldflags = self.config_env.get('LDFLAGS', '') ldflags_libdir = '-L%s ' % libdir if ldflags_libdir not in ldflags: ldflags = self._join_values(ldflags, ldflags_libdir) path = self.config_env.get('PATH', None) path = self._join_path(os.path.join(self.build_tools_prefix, 'bin'), path) # Add the prefix bindir after the build-tools bindir so that on Windows # binaries are run with the same libraries that they are linked with. if bindir not in path and self.prefix_is_executable(): path = self._join_path(bindir, path) ld_library_path = os.path.join(self.build_tools_prefix, 'lib') if self.prefix_is_executable(): ld_library_path = self._join_path(libdir, ld_library_path) if self.extra_lib_path is not None: ld_library_path = self._join_path(ld_library_path, self.extra_lib_path) if self.toolchain_prefix is not None: ld_library_path = self._join_path( ld_library_path, os.path.join(self.toolchain_prefix, 'lib')) includedir = self._join_path( includedir, os.path.join(self.toolchain_prefix, 'include')) # Most of these variables are extracted from jhbuild env = { 'LD_LIBRARY_PATH': ld_library_path, 'LDFLAGS': ldflags, 'PATH': path, 'MANPATH': manpathdir, 'INFOPATH': infopathdir, 'PKG_CONFIG': pkgconfigbin, 'PKG_CONFIG_PATH': '%s' % pkgconfigdatadir, 'PKG_CONFIG_LIBDIR': '%s' % pkgconfigdir, 'GI_TYPELIB_PATH': typelibpath, 'XDG_DATA_DIRS': xdgdatadir, 'XDG_CONFIG_DIRS': xdgconfigdir, 'XCURSOR_PATH': xcursordir, 'ACLOCAL_FLAGS': '-I%s' % aclocaldir, 'ACLOCAL': "aclocal", 'PERL5LIB': perl5lib, 'GST_PLUGIN_PATH': gstpluginpath, 'GST_PLUGIN_PATH_1_0': gstpluginpath10, 'GST_REGISTRY': gstregistry, 'GST_REGISTRY_1_0': gstregistry10, 'PYTHONPATH': pythonpath, 'MONO_PATH': os.path.join(libdir, 'mono', '4.5'), 'MONO_GAC_PREFIX': prefix, 'GSTREAMER_ROOT': prefix, 'CERBERO_PREFIX': self.prefix, 'CERBERO_HOST_SOURCES': self.sources } # Some autotools recipes will call the native (non-cross) compiler to # build generators, and we don't want it to use these. We will set the # include paths using CFLAGS, etc, when cross-compiling. if not self.cross_compiling(): env['C_INCLUDE_PATH'] = includedir env['CPLUS_INCLUDE_PATH'] = includedir # On Windows, we have a toolchain env that we need to set, but only # when running as a shell if self.platform == Platform.WINDOWS and self.for_shell: if self.can_use_msvc(): toolchain_env = self.msvc_toolchain_env else: toolchain_env = self.mingw_toolchain_env env = self._merge_env(env, toolchain_env) # merge the config env with this new env # LDFLAGS and PATH were already merged above new_env = self._merge_env(self.config_env, env, override_env=('LDFLAGS', 'PATH')) if self.target_platform == Platform.WINDOWS and self.platform != Platform.WINDOWS: new_env = self.get_wine_runtime_env(prefix, new_env) return new_env
def get_env(self, prefix, libdir, py_prefix): # Get paths for environment variables includedir = os.path.join(prefix, 'include') bindir = os.path.join(prefix, 'bin') manpathdir = os.path.join(prefix, 'share', 'man') infopathdir = os.path.join(prefix, 'share', 'info') pkgconfigbin = os.path.join(self.build_tools_prefix, 'bin', 'pkg-config') pkgconfigdatadir = os.path.join(prefix, 'share', 'pkgconfig') pkgconfigdir = os.path.join(libdir, 'pkgconfig') typelibpath = os.path.join(libdir, 'girepository-1.0') xdgdatadir = os.path.join(prefix, 'share') xdgconfigdir = os.path.join(prefix, 'etc', 'xdg') xcursordir = os.path.join(prefix, 'share', 'icons') aclocaldir = os.path.join(prefix, 'share', 'aclocal') perlversionpath = os.path.join(libdir, 'perl5', 'site_perl', self._perl_version()) if self.target_platform == Platform.WINDOWS: # On windows even if perl version is 5.8.8, modules can be # installed in 5.8 perlversionpath = perlversionpath.rsplit('.', 1)[0] perl5lib = ':'.join([ to_unixpath(os.path.join(libdir, 'perl5')), to_unixpath(perlversionpath) ]) gstpluginpath = os.path.join(libdir, 'gstreamer-0.10') gstpluginpath10 = os.path.join(libdir, 'gstreamer-1.0') gstregistry = os.path.join('~', '.gstreamer-0.10', 'cerbero-registry-%s' % self.target_arch) gstregistry10 = os.path.join('~', '.cache', 'gstreamer-1.0', 'cerbero-registry-%s' % self.target_arch) gstregistry = os.path.expanduser(gstregistry) gstregistry10 = os.path.expanduser(gstregistry10) pypath = sysconfig.get_path('purelib', vars={'base': ''}) # Must strip \/ to ensure that the path is relative pypath = PurePath(pypath.strip('\\/')) # Starting with Python 3.7.1 on Windows, each PYTHONPATH must use the # native path separator and must end in a path separator. pythonpath = [ str(prefix / pypath) + os.sep, str(self.build_tools_prefix / pypath) + os.sep ] # Ensure python paths exists because setup.py won't create them for path in pythonpath: if self.platform == Platform.WINDOWS: # pythonpaths start with 'Lib' on Windows, which is extremely # undesirable since our libdir is 'lib'. Windows APIs are # case-preserving case-insensitive. path = path.lower() self._create_path(path) pythonpath = os.pathsep.join(pythonpath) if self.platform == Platform.LINUX: xdgdatadir += ":/usr/share:/usr/local/share" ldflags = '-L%s ' % libdir if ldflags not in os.environ.get('LDFLAGS', ''): ldflags += os.environ.get('LDFLAGS', '') path = os.environ.get('PATH', '') path = self._join_path(os.path.join(self.build_tools_prefix, 'bin'), path) # Add the prefix bindir after the build-tools bindir so that on Windows # binaries are run with the same libraries that they are linked with. if bindir not in path and self.prefix_is_executable(): path = self._join_path(bindir, path) if not self.cross_compiling(): ld_library_path = libdir else: ld_library_path = "" if self.extra_lib_path is not None: ld_library_path = self._join_path(ld_library_path, self.extra_lib_path) if self.toolchain_prefix is not None: ld_library_path = self._join_path( ld_library_path, os.path.join(self.toolchain_prefix, 'lib')) includedir = self._join_path( includedir, os.path.join(self.toolchain_prefix, 'include')) # Most of these variables are extracted from jhbuild env = { 'LD_LIBRARY_PATH': ld_library_path, 'LDFLAGS': ldflags, 'C_INCLUDE_PATH': includedir, 'CPLUS_INCLUDE_PATH': includedir, 'PATH': path, 'MANPATH': manpathdir, 'INFOPATH': infopathdir, 'PKG_CONFIG': pkgconfigbin, 'PKG_CONFIG_PATH': '%s' % pkgconfigdatadir, 'PKG_CONFIG_LIBDIR': '%s' % pkgconfigdir, 'GI_TYPELIB_PATH': typelibpath, 'XDG_DATA_DIRS': xdgdatadir, 'XDG_CONFIG_DIRS': xdgconfigdir, 'XCURSOR_PATH': xcursordir, 'ACLOCAL_FLAGS': '-I%s' % aclocaldir, 'ACLOCAL': "aclocal", 'PERL5LIB': perl5lib, 'GST_PLUGIN_PATH': gstpluginpath, 'GST_PLUGIN_PATH_1_0': gstpluginpath10, 'GST_REGISTRY': gstregistry, 'GST_REGISTRY_1_0': gstregistry10, 'PYTHONPATH': pythonpath, 'MONO_PATH': os.path.join(libdir, 'mono', '4.5'), 'MONO_GAC_PREFIX': prefix, 'GSTREAMER_ROOT': prefix } return env
def get_env(self, prefix, libdir, py_prefix): # Get paths for environment variables includedir = os.path.join(prefix, 'include') bindir = os.path.join(prefix, 'bin') manpathdir = os.path.join(prefix, 'share', 'man') infopathdir = os.path.join(prefix, 'share', 'info') pkgconfigbin = os.path.join(self.build_tools_prefix, 'bin', 'pkg-config') pkgconfigdatadir = os.path.join(prefix, 'share', 'pkgconfig') pkgconfigdir = os.path.join(libdir, 'pkgconfig') typelibpath = os.path.join(libdir, 'girepository-1.0') xdgdatadir = os.path.join(prefix, 'share') xdgconfigdir = os.path.join(prefix, 'etc', 'xdg') xcursordir = os.path.join(prefix, 'share', 'icons') aclocaldir = os.path.join(prefix, 'share', 'aclocal') perlversionpath = os.path.join(libdir, 'perl5', 'site_perl', self._perl_version()) if self.target_platform == Platform.WINDOWS: # On windows even if perl version is 5.8.8, modules can be # installed in 5.8 perlversionpath = perlversionpath.rsplit('.', 1)[0] perl5lib = ':'.join([ to_unixpath(os.path.join(libdir, 'perl5')), to_unixpath(perlversionpath) ]) gstpluginpath = os.path.join(libdir, 'gstreamer-0.10') gstpluginpath10 = os.path.join(libdir, 'gstreamer-1.0') gstregistry = os.path.join('~', '.gstreamer-0.10', 'cerbero-registry-%s' % self.target_arch) gstregistry10 = os.path.join('~', '.cache', 'gstreamer-1.0', 'cerbero-registry-%s' % self.target_arch) gstregistry = os.path.expanduser(gstregistry) gstregistry10 = os.path.expanduser(gstregistry10) pypath = sysconfig.get_path('purelib', vars={'base': ''}) # Must strip \/ to ensure that the path is relative pypath = PurePath(pypath.strip('\\/')) # Starting with Python 3.7.1 on Windows, each PYTHONPATH must use the # native path separator and must end in a path separator. pythonpath = [ str(prefix / pypath) + os.sep, str(self.build_tools_prefix / pypath) + os.sep ] if self.platform == Platform.WINDOWS: # On Windows, pypath doesn't include Python version although some # packages (pycairo, gi, etc...) install themselves using Python # version scheme like on a posix system. # Let's add an extra path to PYTHONPATH for these libraries. pypath = sysconfig.get_path('purelib', 'posix_prefix', {'base': ''}) pypath = PurePath(pypath.strip('\\/')) pythonpath.append(str(prefix / pypath) + os.sep) # Ensure python paths exists because setup.py won't create them for path in pythonpath: if self.platform == Platform.WINDOWS: # pythonpaths start with 'Lib' on Windows, which is extremely # undesirable since our libdir is 'lib'. Windows APIs are # case-preserving case-insensitive. path = path.lower() self._create_path(path) pythonpath = os.pathsep.join(pythonpath) if self.platform == Platform.LINUX: xdgdatadir += ":/usr/share:/usr/local/share" ldflags = '-L%s ' % libdir if ldflags not in self.config_env.get('LDFLAGS', ''): ldflags += self.config_env.get('LDFLAGS', '') path = self.config_env.get('PATH', None) path = self._join_path(os.path.join(self.build_tools_prefix, 'bin'), path) # Add the prefix bindir after the build-tools bindir so that on Windows # binaries are run with the same libraries that they are linked with. if bindir not in path and self.prefix_is_executable(): path = self._join_path(bindir, path) ld_library_path = self._join_path( os.path.join(self.build_tools_prefix, 'lib'), path) if not self.cross_compiling(): ld_library_path = self._join_path(ld_library_path, libdir) if self.extra_lib_path is not None: ld_library_path = self._join_path(ld_library_path, self.extra_lib_path) if self.toolchain_prefix is not None: ld_library_path = self._join_path( ld_library_path, os.path.join(self.toolchain_prefix, 'lib')) includedir = self._join_path( includedir, os.path.join(self.toolchain_prefix, 'include')) # Most of these variables are extracted from jhbuild env = { 'LD_LIBRARY_PATH': ld_library_path, 'LDFLAGS': ldflags, 'C_INCLUDE_PATH': includedir, 'CPLUS_INCLUDE_PATH': includedir, 'PATH': path, 'MANPATH': manpathdir, 'INFOPATH': infopathdir, 'PKG_CONFIG': pkgconfigbin, 'PKG_CONFIG_PATH': '%s' % pkgconfigdatadir, 'PKG_CONFIG_LIBDIR': '%s' % pkgconfigdir, 'GI_TYPELIB_PATH': typelibpath, 'XDG_DATA_DIRS': xdgdatadir, 'XDG_CONFIG_DIRS': xdgconfigdir, 'XCURSOR_PATH': xcursordir, 'ACLOCAL_FLAGS': '-I%s' % aclocaldir, 'ACLOCAL': "aclocal", 'PERL5LIB': perl5lib, 'GST_PLUGIN_PATH': gstpluginpath, 'GST_PLUGIN_PATH_1_0': gstpluginpath10, 'GST_REGISTRY': gstregistry, 'GST_REGISTRY_1_0': gstregistry10, 'PYTHONPATH': pythonpath, 'MONO_PATH': os.path.join(libdir, 'mono', '4.5'), 'MONO_GAC_PREFIX': prefix, 'GSTREAMER_ROOT': prefix, 'CERBERO_PREFIX': self.prefix } # merge the config env with this new env new_env = {} for k in env.keys(): if k not in self.config_env: new_env[k] = env[k] else: env_v = env[k] config_v = self.config_env[k] if env_v == config_v: new_env[k] = env_v elif k in ('LDFLAGS', 'PATH'): # handled above new_env[k] = env_v elif self._is_env_multipath_key(k): new_env[k] = self._join_path(env_v, config_v) else: raise FatalError( "Don't know how to combine the environment " "variable '%s' with values '%s' and '%s'" % (k, env_v, config_v)) for k in self.config_env.keys(): if k not in env: new_env[k] = self.config_env[k] return new_env