def __init__(self, name, version, source_info): self.source_info = source_info self.cache_dir = config.global_config().src_cache_dir() self.build_dir = config.global_config().build_dir() self.dest_dir = os.path.join(self.build_dir, "{0}-{1}".format(name, version)) self.url = source_info["url"]
def cmd_list(package_name, category=None): bundle = LibBundle() bundle.load(config.global_config().current_bundle()) files = bundle.list_files(package_name, category) for n in files: print(n)
def __init__(self, bundle): self._bundle = bundle self._context = BuildContext(bundle.path, bundle.toolchain, bundle.arch) self.hooks = Enum("pre_build","post_build", "post_install") self._hook_functions = {self.hooks.pre_build:set(), self.hooks.post_build:set(), self.hooks.post_install:set()} build_dir = os.path.join(config.global_config().workspace_dir(), "build_{0}_{1}".format(bundle.toolchain, bundle.arch)) config.global_config().set("Paths", "build", build_dir) if not os.path.isdir(build_dir): os.mkdir(build_dir) self._context.build_dir = build_dir
def __init__(self, bundle_path, toolchain, arch): self.bundle_path = bundle_path self.toolchain = toolchain self.arch = arch self.os_name = config.os_name() self.env = env.env self.workspace_dir = config.global_config().workspace_dir() self.install_dir = os.path.join(self.workspace_dir, "tmp_install")
def cmd_new(path, toolchain, arch): fpath = path.format(p=config.os_name(), t=toolchain, a=arch) if fpath.split(os.sep)[0] == fpath: fpath = os.path.join(config.global_config().root_dir(), fpath) bundle = LibBundle() bundle.create(fpath, config.os_name(), toolchain, arch) cmd_set(fpath)
def setup_env(toolchain, arch): """Set up environment for specified toolchain""" global env env = os.environ.copy() #set PATH to minimum to control exactly what software is found. path = "" if os_name() == "win": path = "C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;" elif os_name() == "mac": path = "/usr/bin:/bin:/usr/sbin:/sbin:" if global_config().current_bundle(): path = os.path.join(global_config().current_bundle(), "bin") + os.pathsep + path env["CMAKE_PREFIX_PATH"] = global_config().current_bundle() env["PATH"] = path if toolchain.startswith("vc"): setup_env_vc(toolchain[2:], arch)
def cmd_info(): bundle = LibBundle() bundle.load(config.global_config().current_bundle()) print("Bundle: " + bundle.path) print("Toolchain: " + bundle.toolchain) print("Architecture: " + bundle.arch) print("\nInstalled:") for info in sorted(bundle.list_installed()): print("{0:<15}{1:<10}".format(info[0], info[1]))
def cmd_archive(path=None): if path is None: path = os.path.dirname(config.global_config().current_bundle()) bundle_name = os.path.basename(config.global_config().current_bundle()) archive_path = os.path.join(path, bundle_name) if config.os_name() == "win": try: system.run_cmd("7z", ["a", "-r", archive_path + ".7z", config.global_config().current_bundle()]) except exceptions.CalledProcessError as e: if e.returncode != 1: raise else: system.run_cmd("zip", ["-r", archive_path + ".zip", config.global_config().current_bundle()])
def cmd_set_formula_path(path, append=False): if append: old_value = config.global_config().get("Paths", "formula_dirs") if not old_value.endswith(os.pathsep): old_value += os.pathsep config.global_config().set("Paths", "formula_dirs", old_value + path) else: config.global_config().set("Paths", "formula_dirs", path) config.global_config().write()
def cmd_install(formula_spec, options): bundle = LibBundle() bundle.load(config.global_config().current_bundle()) builder = FormulaBuilder(bundle) if options.interactive: def _start_shell(): print("Type 'exit' to continue with the installation, 'exit 1' to abort") try: system.shell() except exceptions.CalledProcessError: raise exceptions.AbortOperation builder.add_hook(builder.hooks.pre_build, _start_shell) try: builder.install(formula_spec, options) except exceptions.AbortOperation: print("Installation Aborted")
def on_formula_path(parser, options, args): if not args: print(config.global_config().get("Paths", "formula_dirs")) else: commands.cmd_set_formula_path(args[0], options.append)
def adjust_config_by_options(config, options): for name in ('debug_info_level', 'native_builder'): value = getattr(options, name, None) if value: config.global_config(**{name: value})
def _install(self, formula_name, **kwargs): formula = formulamanager.get(formula_name, self._context) formula_options = {} force_install = False clean_src = False if kwargs.has_key("formula_options"): formula_options = kwargs["formula_options"] if kwargs.has_key("variant"): formula_options["variant"] = kwargs["variant"] if kwargs.has_key("force"): force_install = kwargs["force"] if kwargs.has_key("clean_src"): clean_src = kwargs["clean_src"] formula.set_options(formula_options) if not formula.is_kit and (force_install or not self._bundle.is_installed(formula.name)): if clean_src: build_src_dir = os.path.join(self._context.build_dir, "{0}-{1}".format(formula.name, formula.version)) if os.path.exists(build_src_dir): fileutils.remove(build_src_dir) src_dir = sourcemanager.get_source(config.global_config().build_dir(), formula.name, formula.version, formula.source) old_cwd = os.getcwd() os.chdir(src_dir) if formula.patches: path1 = os.path.join(formula.dir, "patches", formula.name) if formula.dir.endswith(config.os_name()): path2 = os.path.normpath(os.path.join(formula.dir, "..", "patches", formula.name)) else: path2 = os.path.join(formula.dir, config.os_name(), "patches", formula.name) patch_dirs = [path1, path2] sourcemanager.patch_source(formula.patches, patch_dirs, src_dir) #make sure we have clean install dir for each formula if os.path.exists(self._context.install_dir): fileutils.remove(self._context.install_dir) try: os.mkdir(self._context.install_dir) except OSError: #On Windows, it is sometimes necessary to wait a little after deleting a #directory before creating it again time.sleep(0.01) os.mkdir(self._context.install_dir) self._call_hook_functions(self.hooks.pre_build) logging.getLogger().info("Building {0}...".format(formula.name)) fileset = formula.build() self._call_hook_functions(self.hooks.post_build) logging.getLogger().info("Done") logging.getLogger().info("Installing {0}...".format(formula.name)) self._bundle.install(formula.name, formula.version, formula.depends_on.keys(), fileset, force_install) self._call_hook_functions(self.hooks.post_install) logging.getLogger().info("Done") os.chdir(old_cwd)
import os import imp import logging import config from formula import Formula import exceptions _formula_cache = {} _default_search_path = [os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "Formula"))] _default_search_path.append(os.path.join(_default_search_path[0], config.os_name())) _default_search_path.extend(config.global_config().formula_dirs()) def _find_formula(name): """Find the location of a formula file or kit""" path = None for p in _default_search_path: kit = os.path.join(p, name) formula = os.path.join(p, name, ".py") if os.path.exists(kit) or os.path.exists(formula): path = p break if path is None: raise exceptions.FileNotFoundError("No formula named " + name) return path def _validate(formula, toolchain, arch):
def cmd_uninstall(package_name, keep_dependent=False): bundle = LibBundle() bundle.load(config.global_config().current_bundle()) builder = FormulaBuilder(bundle) builder.uninstall(package_name, keep_dependent)
def cmd_set(path): #raises an exception if path is not a valid bundle bundle = LibBundle().load(path) config.global_config().set("Bundle", "path", path) config.global_config().write()