Ejemplo n.º 1
0
 def clean_cache(self):
     p = util.get_cache_path()
     if os.path.exists(p): shutil.rmtree(util.get_cache_path())
Ejemplo n.º 2
0
 def install(
     self,
     pb,
     test=False,
     test_all=False,
     generator=None,
     update=False,
     track=True,
     insecure=False,
     use_build_cache=False,
     recipe_deps_only=False
 ):
     pb = self.parse_pkg_build(pb)
     pkg_dir = self.get_package_directory(pb.to_fname())
     unlink_dir = self.get_unlink_directory(pb.to_fname())
     # If its been unlinked, then link it in
     if os.path.exists(unlink_dir):
         if update: shutil.rmtree(unlink_dir)
         else:
             self.link(pb)
             self.write_parent(pb, track=track)
             return "Linking package {}".format(pb.to_name())
     if os.path.exists(pkg_dir): 
         self.write_parent(pb, track=track)
         if update: self.remove(pb)
         else: return "Package {} already installed".format(pb.to_name())
     package_hash = self.hash_pkg(pb)
     self.log("package %s hash %s" % (pb.to_name(), package_hash))
     pkg_install_dir = self.get_package_directory(pb.to_fname(), 'install')
     if use_build_cache:
         install_dir = util.get_cache_path("builds", pb.to_name(), package_hash)
         util.mkdir(pkg_dir)
         os.symlink(install_dir, pkg_install_dir)
         self.log("using cached install dir '%s'" % install_dir)
     else:
         install_dir = pkg_install_dir
         self.log("using local install dir '%s'" % install_dir)
     build_needed = True
     if recipe_deps_only:
         self.install_deps(
             pb,
             test=test,
             test_all=test_all,
             generator=generator,
             insecure=insecure,
             use_build_cache=use_build_cache,
             recipe_deps_only=True
         )
         with util.cache_lock() as cache_lock:
             if not update and use_build_cache and os.path.exists(install_dir):
                 print("retreived Package {} from cache".format(pb.to_name()))
                 build_needed = False
     if build_needed:
         with self.create_builder(uuid.uuid4().hex, tmp=True) as builder:
             # Fetch package
             src_dir = builder.fetch(pb.pkg_src.url, pb.hash, (pb.cmake != None), insecure=insecure)
             # Install any dependencies first
             if not recipe_deps_only:
                 self.install_deps(
                     pb,
                     src_dir=src_dir,
                     test=test,
                     test_all=test_all,
                     generator=generator,
                     insecure=insecure,
                     use_build_cache=use_build_cache,
                     recipe_deps_only=False
                 )
             with util.cache_lock() as cache_lock:
                 if not update and use_build_cache and os.path.exists(install_dir):
                     print("retreived Package {} from cache".format(pb.to_name()))
                 else:
                     # Setup cmake file
                     if pb.cmake:
                         target = os.path.join(src_dir, 'CMakeLists.txt')
                         if os.path.exists(target):
                             os.rename(target, os.path.join(src_dir, builder.cmake_original_file))
                         shutil.copyfile(pb.cmake, target)
                     # Configure and build
                     dependents = self.get_dependents(pb, src_dir)
                     dep_install_paths = list([self.get_real_install_path(dep) for dep in dependents])
                     defines = list(pb.define or []) + [
                         "CMAKE_PREFIX_PATH=%s" % ";".join(
                             ['%s' % path for path in dep_install_paths + [self.prefix]]
                         )
                     ]
                     #defines.append("PKG_CONFIG_USE_CMAKE_PREFIX_PATH=ON")
                     #defines.append("CMAKE_FIND_USE_CMAKE_SYSTEM_PATH=OFF")
                     #defines.append("CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF")
                     pkg_config_paths = list(
                         filter(
                             os.path.exists,
                             sum(
                                 [
                                     [
                                         os.path.join(path, "lib/pkgconfig"),
                                         os.path.join(path, "lib64/pkgconfig"),
                                     ]
                                     for path in dep_install_paths
                                 ],
                                 []
                             )
                         )
                     )
                     bin_paths = list(
                         filter(
                             os.path.exists,
                             [
                                 os.path.join(path, "bin")
                                 for path in dep_install_paths
                             ]
                         )
                     ) + os.getenv("PATH", "").split(":")
                     configure_env = {
                         "PKG_CONFIG_LIBDIR":"/dev/null",
                         "PKG_CONFIG_PATH":":".join(pkg_config_paths),
                         "PATH":":".join(bin_paths),
                         "CFLAGS" : os.getenv("CFLAGS", ""),
                         "CXXFLAGS" : os.getenv("CXXFLAGS", "")
                     }
                     build_env = {
                         "PATH":":".join(bin_paths)
                     }
                     print("defines")
                     print(defines)
                     print("env")
                     print(configure_env)
                     print("build env")
                     print(build_env)
                     builder.configure(
                         src_dir,
                         defines=defines,
                         generator=generator,
                         install_prefix=install_dir,
                         test=test,
                         variant=pb.variant,
                         env=configure_env
                     )
                     builder.build(variant=pb.variant, env=build_env)
                     # Run tests if enabled
                     if test or test_all: builder.test(variant=pb.variant)
                     # Install
                     builder.build(target='install', variant=pb.variant, env=build_env)
                     if use_build_cache:
                         util.fix_cache_permissions_recursive(install_dir)
     if util.MERGE_INSTALLS:
         if util.USE_SYMLINKS: util.symlink_dir(install_dir, self.prefix)
         else: util.copy_dir(install_dir, self.prefix)
     self.write_parent(pb, track=track)
     return "Successfully installed {}".format(pb.to_name())