Example #1
0
def parse_specifier(formula_spec):
    """Return the name and location of the formula specified by formula_spec.

    formula_spec can be:
        - a path to the formula file or kit (if it is a relative path, it must 
          have at least one slash)
        - <kit name>.<formula name> to specify a formula located inside a kit
        - a formula name
    """
    formula_name = ""
    search_path = []
    
    if formula_spec.count(os.sep):
        #formula_spec is a path
        search_path.append(os.path.dirname(formula_spec))
        formula_name = os.path.splitext(os.path.basename(formula_spec))[0]
    elif formula_spec.count(".") == 1 and not formula_spec.count(os.sep):
        #formula_spec is in the form: <kit name>.<formula name>
        kit_name, formula_name = formula_spec.split(".")
        path = _find_formula(kit_name)
        search_path.append(os.path.join(path, kit_name))
        search_path.append(os.path.join(path, kit_name, config.os_name()))
    else:
        #formula_spec is just the formula name
        formula_name = formula_spec
        path = _find_formula(formula_name)
        search_path.append(path)
        formula_path = os.path.join(path, formula_name)
        if os.path.isdir(formula_path):
            #add kit directories as well
            search_path.append(formula_path)
            search_path.append(os.path.join(formula_path, config.os_name()))
    
    return formula_name, search_path
Example #2
0
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)
Example #3
0
def run_cmd(name, args=[], silent=False, ignore_errors=False):
    """
    Run an executable file.
    Like a normal shell, name can be a path or a command that can be found by searching PATH.
    Special characters in args are escaped by the subprocess module
    If silent is true, output is dumped to devnull
    """
    if os.path.isfile(name):
        file_path = name
    else:
        if not _commands.has_key(name):
            if os_name() == "win" and not os.path.splitext(name)[1]:
                name = name + ".exe"
            file_path = find_cmd(name, env.env["PATH"])
            _commands[name] = file_path
        else:
            file_path = _commands[name]
            
    cmd_line = [file_path] + args
    
    try:
        if silent:
            with open(os.devnull, 'wb') as devnull:
                subprocess.check_call(cmd_line, stdout=devnull,
                                      stderr=devnull, env=env.env)
        else:
            subprocess.check_call(cmd_line, env=env.env)
    except subprocess.CalledProcessError as e:
        if not ignore_errors:
            raise exceptions.CalledProcessError(e.returncode, e.cmd)
Example #4
0
 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")
Example #5
0
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)
Example #6
0
def extract(filepath, dest, verbose=False):
    """
    Extract an archive using the appropriate system commands
    """
    args_7z = ["x", "-y", "-o" + dest]
    
    try:
        if os.path.splitext(filepath)[0].endswith(".tar") or filepath.endswith(".tgz"):
            if os_name() == "win":
                run_cmd("7z", args_7z + [filepath], not verbose)

                tar_filepath = os.path.join(dest, os.listdir(dest)[0])
                run_cmd("7z", args_7z + [tar_filepath], not verbose)
                
                fileutils.remove(tar_filepath)
            else:
                flags = "-x"
                if verbose:
                    flags = "-xv"
                
                run_cmd("tar", [flags, "-f", filepath, "-C", dest])
        
        elif filepath.endswith(".zip"):
            if os_name() == "win":
                run_cmd("7z", args_7z + [filepath], not verbose)
            else:
                flags = ""
                if not verbose:
                    flags = "-qq"
                
                run_cmd("unzip", [flags, filepath, "-d", dest])
        else:
            #for all other types (example .7z) try 7z
            
            run_cmd("7z", args_7z + [filepath], not verbose)

            
    except exceptions.CommandNotFoundError:
        #change message
        raise exceptions.CommandNotFoundError("Could not find a program for extracting file (unzip, tar, 7z)")
Example #7
0
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()])
Example #8
0
def shell(args=[]):
    if os_name() == "win":
        run_cmd("cmd", args)
    else:
        run_cmd("bash", args)
Example #9
0
 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)
Example #10
0
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):