Beispiel #1
0
def get_cfg():
    ctx = ConfigureContext()
    if os.path.exists(CONFIG_CACHE):
        fid = open(CONFIG_CACHE)
        try:
            ctx.cache = load(fid)
        finally:
            fid.close()

    if os.path.exists(BUILD_CONFIG):
        fid = myopen(BUILD_CONFIG, "rb")
        try:
            load_tools(ctx, fid)
        finally:
            fid.close()

    if os.path.exists(DEFAULT_ENV):
        env = Environment()
        env.load(DEFAULT_ENV)
    else:
        env = Environment()
    if not env.has_key("BLDDIR"):
        env["BLDDIR"] = BUILD_DIR
    # FIXME: nothing to do here
    env["VERBOSE"] = False
    if "-v" in sys.argv:
        env["VERBOSE"] = True

    ctx.env = env
    ctx.log = myopen(os.path.join(env["BLDDIR"], "config.log"), "w")
    return ctx
Beispiel #2
0
def get_cfg():
    ctx = ConfigureContext()
    if os.path.exists(CONFIG_CACHE):
        fid = open(CONFIG_CACHE, "rb")
        try:
            ctx.cache = load(fid)
            ctx._stdout_cache = load(fid)
            ctx._cmd_cache = load(fid)
        finally:
            fid.close()

    # XXX: how to reload existing environment ?
    env = Environment()
    if not env.has_key("BLDDIR"):
        env["BLDDIR"] = BUILD_DIR
    # FIXME: nothing to do here
    env["VERBOSE"] = False
    if "-v" in sys.argv:
        env["VERBOSE"] = True
    env["ENV"] = {}

    srcnode, bldnode = create_top_nodes(
            os.path.abspath(os.getcwd()),
            os.path.abspath(env["BLDDIR"]))
    ctx.src_root = srcnode
    ctx.bld_root = bldnode

    ctx.env = env
    ctx.log = myopen(os.path.join(env["BLDDIR"], "config.log"), "w")
    return ctx
Beispiel #3
0
class BuildContext(object):
    def __init__(self):
        self.env = Environment()
        self.tools = []
        self.cache = {}
        self.builders = {}
        self.tasks = []

    def load(self):
        self.env = Environment()
        if os.path.exists(DEFAULT_ENV):
            self.env.load(DEFAULT_ENV)

        f = open(BUILD_CONFIG)
        try:
            load_tools(self, f)
        finally:
            f.close()

        if os.path.exists(BUILD_CACHE):
            fid = open(BUILD_CACHE, "rb")
            try:
                self.cache = load(fid)
            finally:
                fid.close()
        else:
            self.cache = {}

        srcnode, bldnode = create_top_nodes(
                os.path.abspath(os.getcwd()),
                os.path.abspath(self.env["BLDDIR"]))
        self.src_root = srcnode
        self.bld_root = bldnode

        fid = open(HOOK_DUMP, "rb")
        try:
            data = load(fid)
            yaku.task_manager.RULES_REGISTRY = data["extensions"]
            yaku.task_manager.FILES_REGISTRY = _hook_path_to_hook_id(srcnode, data["files"])
        finally:
            fid.close()

    def store(self):
        # Use rename to avoid corrupting the cache if interrupted
        tmp_fid = open(BUILD_CACHE + ".tmp", "wb")
        try:
            dump(self.cache, tmp_fid)
        finally:
            tmp_fid.close()
        rename(BUILD_CACHE + ".tmp", BUILD_CACHE)

    def set_stdout_cache(self, task, stdout):
        pass

    def set_cmd_cache(self, task, stdout):
        pass
Beispiel #4
0
    def load(self, src_path=None, build_path="build"):
        if src_path is None:
            src_path = os.getcwd()
        src_path = os.path.abspath(src_path)
        build_path = os.path.abspath(os.path.join(os.getcwd(), build_path))
        if not os.path.exists(build_path):
            raise IOError("%s not found (did you use different build_path for configure and build contexts ?)" \
                          % build_path)

        srcnode, bldnode = create_top_nodes(src_path, build_path)
        self.src_root = srcnode
        self.bld_root = bldnode
        self.path = srcnode

        self.env = Environment()
        default_env = bldnode.find_node(DEFAULT_ENV)
        if default_env:
            self.env.load(default_env.abspath())
        if not os.path.abspath(self.env["BLDDIR"]) == bldnode.abspath():
            raise ValueError("Gne ?")

        build_config = bldnode.find_node(BUILD_CONFIG)
        if build_config is None:
            raise IOError("Did not find %r in %r" %
                          (BUILD_CONFIG, bldnode.abspath()))
        else:
            f = open(build_config.abspath())
            try:
                load_tools(self, f)
            finally:
                f.close()

        build_cache = bldnode.find_node(BUILD_CACHE)
        if build_cache is not None:
            fid = open(build_cache.abspath(), "rb")
            try:
                self.cache = load(fid)
            finally:
                fid.close()
        else:
            self.cache = {}

        hook_dump = bldnode.find_node(HOOK_DUMP)
        fid = open(hook_dump.abspath(), "rb")
        try:
            data = load(fid)
            yaku.task_manager.RULES_REGISTRY = data["extensions"]
            yaku.task_manager.FILES_REGISTRY = _hook_path_to_hook_id(
                srcnode, data["files"])
        finally:
            fid.close()
Beispiel #5
0
    def __init__(self):
        self.env = Environment()
        self.tools = []
        self._tool_modules = {}
        self.builders = {}
        self.cache = {}
        self.conf_results = []
        self._configured = {}
        self._stdout_cache = {}
        self._cmd_cache = {}

        self.src_root = None
        self.bld_root = None
        self.path = None
Beispiel #6
0
def _setup_compiler(ctx, cc_type):
    old_env = ctx.env
    ctx.env = Environment()
    cc_env = None
    sys.path.insert(0, os.path.dirname(yaku.tools.__file__))
    try:
        try:
            mod = __import__(cc_type)
            mod.setup(ctx)
        except ImportError:
            raise RuntimeError("No tool %s is available (import failed)" \
                            % cc_type)

        # XXX: this is ugly - find a way to have tool-specific env...
        cc_env = ctx.env
    finally:
        sys.path.pop(0)
        ctx.env = old_env

    copied_values = [
        "CC", "CPPPATH_FMT", "LIBDIR_FMT", "LIB_FMT", "CC_OBJECT_FMT",
        "CC_TGT_F", "CC_SRC_F", "LINK_TGT_F", "LINK_SRC_F", "SHLINK"
    ]
    for k in copied_values:
        ctx.env["PYEXT_%s" % k] = cc_env[k]
    ctx.env.prextend("PYEXT_CPPPATH", cc_env["CPPPATH"])
    ctx.env.prextend("PYEXT_LIBDIR", cc_env["LIBDIR"])
Beispiel #7
0
    def __init__(self, name, bld, sources, target):
        self.bld = bld
        self.name = name
        self.sources = sources
        self.target = target

        self.env = Environment()
Beispiel #8
0
    def load(self):
        self.env = Environment()
        if os.path.exists(DEFAULT_ENV):
            self.env.load(DEFAULT_ENV)

        f = open(BUILD_CONFIG)
        try:
            load_tools(self, f)
        finally:
            f.close()

        if os.path.exists(BUILD_CACHE):
            fid = open(BUILD_CACHE, "rb")
            try:
                self.cache = load(fid)
            finally:
                fid.close()
        else:
            self.cache = {}

        srcnode, bldnode = create_top_nodes(
                os.path.abspath(os.getcwd()),
                os.path.abspath(self.env["BLDDIR"]))
        self.src_root = srcnode
        self.bld_root = bldnode

        fid = open(HOOK_DUMP, "rb")
        try:
            data = load(fid)
            yaku.task_manager.RULES_REGISTRY = data["extensions"]
            yaku.task_manager.FILES_REGISTRY = _hook_path_to_hook_id(srcnode, data["files"])
        finally:
            fid.close()
Beispiel #9
0
 def __init__(self):
     self.env = Environment()
     self.tools = []
     self._tool_modules = {}
     self.builders = {}
     self.cache = {}
     self.conf_results = []
     self._configured = {}
     self._stdout_cache = {}
     self._cmd_cache = {}
Beispiel #10
0
def setup_pyext_env(ctx, cc_type="default", use_distutils=True):
    pyenv = Environment()
    if use_distutils:
        if cc_type == "default":
            dist_env = get_configuration()
        else:
            dist_env = get_configuration(cc_type)
        for name, value in dist_env.items():
            pyenv["PYEXT_%s" % name] = value
        pyenv["PYEXT_FMT"] = "%%s%s" % dist_env["SO"]
        pyenv["PYEXT_CFLAGS"] = pyenv["PYEXT_BASE_CFLAGS"] + \
                pyenv["PYEXT_OPT"] + \
                pyenv["PYEXT_SHARED"]
        pyenv["PYEXT_SHLINKFLAGS"] = dist_env["LDFLAGS"]
    else:
        old_env = ctx.env
        ctx.env = Environment()
        cc_env = None
        sys.path.insert(0, os.path.dirname(yaku.tools.__file__))
        try:
            try:
                mod = __import__(cc_type)
                mod.setup(ctx)
            except ImportError:
                raise RuntimeError("No tool %s is available (import failed)" \
                                % cc_type)
            cc_env = ctx.env
        finally:
            sys.path.pop(0)
            ctx.env = old_env
        pyenv["PYEXT_CC"] = cc_env["CC"]
        pyenv["PYEXT_CFLAGS"] = cc_env["CFLAGS"]
        pyenv["PYEXT_LIBDIR"] = cc_env["LIBDIR"]
        pyenv["PYEXT_LIBS"] = cc_env["LIBS"]
        pyenv["PYEXT_FMT"] = "%s.so"
        pyenv["PYEXT_SHLINK"] = cc_env["MODLINK"]
        pyenv["PYEXT_SHLINKFLAGS"] = cc_env["MODLINKFLAGS"]
        pyenv["PYEXT_CPPPATH"] = cc_env["CPPPATH"]
        pyenv.append("PYEXT_CPPPATH", distutils.sysconfig.get_python_inc(), create=True)
        if sys.platform == "win32":
            pyenv.append("PYEXT_LIBDIR", os.path.join(sys.exec_prefix, "libs"))

    return pyenv
Beispiel #11
0
class BuildContext(object):
    def __init__(self):
        self.env = {}
        self.tools = []
        self.cache = {}
        self.builders = {}
        self.tasks = []

    def load(self):
        self.env = Environment()
        if os.path.exists(DEFAULT_ENV):
            self.env.load(DEFAULT_ENV)

        f = open(BUILD_CONFIG)
        try:
            load_tools(self, f)
        finally:
            f.close()

        if os.path.exists(BUILD_CACHE):
            fid = open(BUILD_CACHE, "rb")
            try:
                self.cache = load(fid)
            finally:
                fid.close()
        else:
            self.cache = {}

    def store(self):
        # Use rename to avoid corrupting the cache if interrupted
        tmp_fid = open(BUILD_CACHE + ".tmp", "w")
        try:
            dump(self.cache, tmp_fid)
        finally:
            tmp_fid.close()

        try:
            os.unlink(BUILD_CACHE)
        except OSError:
            pass
        os.rename(BUILD_CACHE + ".tmp", BUILD_CACHE)
Beispiel #12
0
def _setup_cxxcompiler(ctx, cxx_type):
    old_env = ctx.env
    ctx.env = Environment()
    sys.path.insert(0, os.path.dirname(yaku.tools.__file__))
    try:
        mod = __import__(cxx_type)
        mod.setup(ctx)
        cxx_env = ctx.env
    finally:
        sys.path.pop(0)
        ctx.env = old_env

    for k in ["CXX", "CXXFLAGS", "CXX_TGT_F", "CXX_SRC_F", "CXXSHLINK"]:
        ctx.env["PYEXT_%s" % k] = cxx_env[k]
Beispiel #13
0
    def load(self, src_path=None, build_path="build"):
        if src_path is None:
            src_path = os.getcwd()
        src_path = os.path.abspath(src_path)
        build_path = os.path.abspath(os.path.join(os.getcwd(), build_path))
        if not os.path.exists(build_path):
            raise IOError("%s not found (did you use different build_path for configure and build contexts ?)" \
                          % build_path)

        srcnode, bldnode = create_top_nodes(src_path, build_path)
        self.src_root = srcnode
        self.bld_root = bldnode
        self.path = srcnode

        self.env = Environment()
        default_env = bldnode.find_node(DEFAULT_ENV)
        if default_env:
            self.env.load(default_env.abspath())
        if not os.path.abspath(self.env["BLDDIR"]) == bldnode.abspath():
            raise ValueError("Gne ?")

        build_config = bldnode.find_node(BUILD_CONFIG)
        if build_config is None:
            raise IOError("Did not find %r in %r" % (BUILD_CONFIG, bldnode.abspath()))
        else:
            f = open(build_config.abspath())
            try:
                load_tools(self, f)
            finally:
                f.close()

        build_cache = bldnode.find_node(BUILD_CACHE)
        if build_cache is not None:
            fid = open(build_cache.abspath(), "rb")
            try:
                self.cache = load(fid)
            finally:
                fid.close()
        else:
            self.cache = {}

        hook_dump = bldnode.find_node(HOOK_DUMP)
        fid = open(hook_dump.abspath(), "rb")
        try:
            data = load(fid)
            yaku.task_manager.RULES_REGISTRY = data["extensions"]
            yaku.task_manager.FILES_REGISTRY = _hook_path_to_hook_id(srcnode, data["files"])
        finally:
            fid.close()
Beispiel #14
0
    def load(self):
        self.env = Environment()
        if os.path.exists(DEFAULT_ENV):
            self.env.load(DEFAULT_ENV)

        f = open(BUILD_CONFIG)
        try:
            load_tools(self, f)
        finally:
            f.close()

        if os.path.exists(BUILD_CACHE):
            fid = open(BUILD_CACHE, "rb")
            try:
                self.cache = load(fid)
            finally:
                fid.close()
        else:
            self.cache = {}
Beispiel #15
0
def setup_pyext_env(ctx, cc_type="default", use_distutils=True):
    pyenv = Environment()
    if use_distutils:
        if cc_type == "default":
            dist_env = get_configuration()
        else:
            dist_env = get_configuration(cc_type)
        print(dist_env)
        for name, value in list(dist_env.items()):
            pyenv["PYEXT_%s" % name] = value
        pyenv["PYEXT_CFLAGS"].extend(dist_env.get("SHARED", []))
        pyenv["PYEXT_FMT"] = "%%s%s" % dist_env["SO"]
        pyenv["PYEXT_SHLINKFLAGS"] = dist_env["LDFLAGS"]
    else:
        old_env = ctx.env
        ctx.env = Environment()
        cc_env = None
        sys.path.insert(0, os.path.dirname(yaku.tools.__file__))
        try:
            try:
                mod = __import__(cc_type)
                mod.setup(ctx)
            except ImportError:
                raise RuntimeError("No tool %s is available (import failed)" \
                                % cc_type)
            cc_env = ctx.env
        finally:
            sys.path.pop(0)
            ctx.env = old_env
        pyenv["PYEXT_CC"] = cc_env["CC"]
        pyenv["PYEXT_CFLAGS"] = cc_env["CFLAGS"]
        pyenv["PYEXT_LIBDIR"] = cc_env["LIBDIR"]
        pyenv["PYEXT_LIBS"] = cc_env["LIBS"]
        pyenv["PYEXT_FMT"] = "%s.so"
        pyenv["PYEXT_SHLINK"] = cc_env["MODLINK"]
        pyenv["PYEXT_SHLINKFLAGS"] = cc_env["MODLINKFLAGS"]
        pyenv["PYEXT_CPPPATH"] = cc_env["CPPPATH"]
        pyenv.append("PYEXT_CPPPATH",
                     distutils.sysconfig.get_python_inc(),
                     create=True)
        if sys.platform == "win32":
            pyenv.append("PYEXT_LIBDIR", os.path.join(sys.exec_prefix, "libs"))

    return pyenv
Beispiel #16
0
def get_cfg(src_path=None, build_path="build"):
    ctx = ConfigureContext()
    config_cache = os.path.join(build_path, CONFIG_CACHE)
    if os.path.exists(config_cache):
        fid = open(config_cache, "rb")
        try:
            ctx.cache = load(fid)
            ctx._stdout_cache = load(fid)
            ctx._cmd_cache = load(fid)
        finally:
            fid.close()

    # XXX: how to reload existing environment ?
    env = Environment()
    if not "BLDDIR" in env:
        env["BLDDIR"] = build_path
    # FIXME: nothing to do here
    env["VERBOSE"] = False
    if "-v" in sys.argv:
        env["VERBOSE"] = True
    # Keep this as is - we do want a dictionary for 'serialization', and python
    # 3 os.environ is an object instead of a dict
    env["ENV"] = dict([(k, v) for k, v in list(os.environ.items())])

    if src_path is None:
        src_path = os.getcwd()
    srcnode, bldnode = create_top_nodes(os.path.abspath(src_path),
                                        os.path.abspath(env["BLDDIR"]))
    ctx.src_root = srcnode
    ctx.bld_root = bldnode
    # src_root and bld_root never change, but path may. All source nodes are
    # created relatively to path (kinda 'virtual' cwd)
    ctx.path = srcnode

    ctx.env = env
    ctx.log = myopen(os.path.join(env["BLDDIR"], "config.log"), "w")
    return ctx
Beispiel #17
0
class ConfigureContext(object):
    def __init__(self):
        self.env = Environment()
        self.tools = []
        self._tool_modules = {}
        self.builders = {}
        self.cache = {}
        self.conf_results = []
        self._configured = {}
        self._stdout_cache = {}
        self._cmd_cache = {}

        self.src_root = None
        self.bld_root = None
        self.path = None

    def load_tool(self, tool, tooldir=None):
        _t = import_tools([tool], tooldir)
        self.tools.append({"tool": tool, "tooldir": tooldir})
        mod = _t[tool]
        self._tool_modules[tool] = mod
        if hasattr(mod, "get_builder"):
            self.builders[tool] = mod.get_builder(self)
        return mod

    def use_tools(self, tools, tooldir=None):
        ret = {}
        for t in tools:
            if t in self._tool_modules:
                _t = self._tool_modules[t]
            else:
                _t = self.load_tool(t, tooldir)
            ret[t] = _t
        self.setup_tools()
        return ret

    def setup_tools(self):
        for builder in self.builders.values():
            if not builder.configured:
               builder.configure()
               self._configured[builder] = True

    def store(self):
        default_env = self.bld_root.make_node(DEFAULT_ENV)
        self.env.store(default_env.abspath())

        self.log.close()

        config_cache = self.bld_root.make_node(CONFIG_CACHE)
        out = []
        out.append(dumps(self.cache))
        out.append(dumps(self._stdout_cache))
        out.append(dumps(self._cmd_cache))
        config_cache.write(join_bytes(out), flags="wb")

        build_config = self.bld_root.make_node(BUILD_CONFIG)
        build_config.write("%r\n" % self.tools)

        hook_dump = self.bld_root.make_node(HOOK_DUMP)
        s = dumps({"extensions": yaku.task_manager.RULES_REGISTRY,
                   "files": _hook_id_to_hook_path(yaku.task_manager.FILES_REGISTRY)})
        hook_dump.write(s, flags="wb")

    def start_message(self, msg):
        _OUTPUT.write(msg + "... ")
        self.log.write("=" * 79 + "\n")
        self.log.write("%s\n" % msg)

    def end_message(self, msg):
        _OUTPUT.write("%s\n" % msg)

    def fail_configuration(self, msg):
        msg = "%s\nPlease look at the configuration log %r" % (msg, self.log.name)
        self.log.flush()
        raise ConfigurationFailure(msg)

    def set_cmd_cache(self, task, cmd):
        self._cmd_cache[task.get_uid()] = cmd[:]

    def get_cmd(self, task):
        tid = task.get_uid()
        try:
            return self._cmd_cache[tid]
        except KeyError:
            raise UnknownTask

    def set_stdout_cache(self, task, stdout):
        self._stdout_cache[task.get_uid()] = stdout

    def get_stdout(self, task):
        tid = task.get_uid()
        try:
            return self._stdout_cache[tid]
        except KeyError:
            raise UnknownTask
Beispiel #18
0
class ConfigureContext(object):
    def __init__(self):
        self.env = Environment()
        self.tools = []
        self._tool_modules = {}
        self.builders = {}
        self.cache = {}
        self.conf_results = []
        self._configured = {}
        self._stdout_cache = {}
        self._cmd_cache = {}

    def load_tool(self, tool, tooldir=None):
        _t = import_tools([tool], tooldir)
        self.tools.append({"tool": tool, "tooldir": tooldir})
        mod = _t[tool]
        self._tool_modules[tool] = mod
        if hasattr(mod, "get_builder"):
            self.builders[tool] = mod.get_builder(self)
        return mod

    def use_tools(self, tools, tooldir=None):
        ret = {}
        for t in tools:
            if t in self._tool_modules:
                _t = self._tool_modules[t]
            else:
                _t = self.load_tool(t, tooldir)
            ret[t] = _t
        self.setup_tools()
        return ret

    def setup_tools(self):
        for builder in self.builders.values():
            if not builder.configured:
               builder.configure()
               self._configured[builder] = True

    def store(self):
        self.env.store(DEFAULT_ENV)

        self.log.close()
        fid = open(CONFIG_CACHE, "wb")
        try:
            dump(self.cache, fid)
            dump(self._stdout_cache, fid)
            dump(self._cmd_cache, fid)
        finally:
            fid.close()

        fid = myopen(BUILD_CONFIG, "w")
        try:
            fid.write("%r\n" % self.tools)
        finally:
            fid.close()

        fid = myopen(HOOK_DUMP, "wb")
        try:
            dump({"extensions": yaku.task_manager.RULES_REGISTRY,
                  "files": _hook_id_to_hook_path(yaku.task_manager.FILES_REGISTRY)},
                 fid)
        finally:
            fid.close()

    def start_message(self, msg):
        sys.stderr.write(msg + "... ")
        self.log.write("=" * 79 + "\n")
        self.log.write("%s\n" % msg)

    def end_message(self, msg):
        sys.stderr.write("%s\n" % msg)

    def set_cmd_cache(self, task, cmd):
        self._cmd_cache[task.get_uid()] = cmd[:]

    def get_cmd(self, task):
        tid = task.get_uid()
        try:
            return self._cmd_cache[tid]
        except KeyError:
            raise UnknownTask

    def set_stdout_cache(self, task, stdout):
        self._stdout_cache[task.get_uid()] = stdout

    def get_stdout(self, task):
        tid = task.get_uid()
        try:
            return self._stdout_cache[tid]
        except KeyError:
            raise UnknownTask
Beispiel #19
0
 def __init__(self):
     self.env = Environment()
     self.tools = []
     self.cache = {}
     self.builders = {}
     self.tasks = []
Beispiel #20
0
class ConfigureContext(object):
    def __init__(self):
        self.env = Environment()
        self.tools = []
        self._tool_modules = {}
        self.builders = {}
        self.cache = {}
        self.conf_results = []
        self._configured = {}
        self._stdout_cache = {}
        self._cmd_cache = {}

        self.src_root = None
        self.bld_root = None
        self.path = None

    def load_tool(self, tool, tooldir=None):
        _t = import_tools([tool], tooldir)
        self.tools.append({"tool": tool, "tooldir": tooldir})
        mod = _t[tool]
        self._tool_modules[tool] = mod
        if hasattr(mod, "get_builder"):
            self.builders[tool] = mod.get_builder(self)
        return mod

    def use_tools(self, tools, tooldir=None):
        ret = {}
        for t in tools:
            if t in self._tool_modules:
                _t = self._tool_modules[t]
            else:
                _t = self.load_tool(t, tooldir)
            ret[t] = _t
        self.setup_tools()
        return ret

    def setup_tools(self):
        for builder in self.builders.values():
            if not builder.configured:
                builder.configure()
                self._configured[builder] = True

    def store(self):
        default_env = self.bld_root.make_node(DEFAULT_ENV)
        self.env.store(default_env.abspath())

        self.log.close()

        config_cache = self.bld_root.make_node(CONFIG_CACHE)
        out = []
        out.append(dumps(self.cache))
        out.append(dumps(self._stdout_cache))
        out.append(dumps(self._cmd_cache))
        config_cache.write(join_bytes(out), flags="wb")

        build_config = self.bld_root.make_node(BUILD_CONFIG)
        build_config.write("%r\n" % self.tools)

        hook_dump = self.bld_root.make_node(HOOK_DUMP)
        s = dumps({
            "extensions":
            yaku.task_manager.RULES_REGISTRY,
            "files":
            _hook_id_to_hook_path(yaku.task_manager.FILES_REGISTRY)
        })
        hook_dump.write(s, flags="wb")

    def start_message(self, msg):
        _OUTPUT.write(msg + "... ")
        self.log.write("=" * 79 + "\n")
        self.log.write("%s\n" % msg)

    def end_message(self, msg):
        _OUTPUT.write("%s\n" % msg)

    def fail_configuration(self, msg):
        msg = "%s\nPlease look at the configuration log %r" % (msg,
                                                               self.log.name)
        self.log.flush()
        raise ConfigurationFailure(msg)

    def set_cmd_cache(self, task, cmd):
        self._cmd_cache[task.get_uid()] = cmd[:]

    def get_cmd(self, task):
        tid = task.get_uid()
        try:
            return self._cmd_cache[tid]
        except KeyError:
            raise UnknownTask

    def set_stdout_cache(self, task, stdout):
        self._stdout_cache[task.get_uid()] = stdout

    def get_stdout(self, task):
        tid = task.get_uid()
        try:
            return self._stdout_cache[tid]
        except KeyError:
            raise UnknownTask

    def try_command(self, cmd, cwd=None, env=None, kw=None):
        if cwd is None:
            cwd = self.bld_root.abspath()
        if kw is None:
            kw = {}
        if env is not None:
            kw["env"] = env

        def log_failure(succeed, explanation):
            if succeed:
                self.log.write("---> Succeeded !\n")
            else:
                self.log.write("---> Failure !\n")
                self.log.write("~~~~~~~~~~~~~~\n")
                self.log.write(explanation)
                self.log.write("~~~~~~~~~~~~~~\n")
            self.log.write("Command was:\n")
            self.log.write("%s\n" % cmd)
            self.log.write("\n")

        try:
            p = subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT,
                                 cwd=cwd,
                                 **kw)
            stdout = p.communicate()[0].decode("utf-8")
            log_failure(p.returncode == 0, stdout)
            if p.returncode:
                return False
            return True
        except OSError:
            e = get_exception()
            log_failure(False, str(e))
        except WindowsError:
            e = get_exception()
            log_failure(False, str(e))
        return False
Beispiel #21
0
class ConfigureContext(object):
    def __init__(self):
        self.env = Environment()
        self.tools = []
        self._tool_modules = {}
        self.builders = {}
        self.cache = {}
        self.conf_results = []
        self._configured = {}
        self._stdout_cache = {}
        self._cmd_cache = {}

        self.src_root = None
        self.bld_root = None
        self.path = None

    def load_tool(self, tool, tooldir=None):
        _t = import_tools([tool], tooldir)
        self.tools.append({"tool": tool, "tooldir": tooldir})
        mod = _t[tool]
        self._tool_modules[tool] = mod
        if hasattr(mod, "get_builder"):
            self.builders[tool] = mod.get_builder(self)
        return mod

    def use_tools(self, tools, tooldir=None):
        ret = {}
        for t in tools:
            if t in self._tool_modules:
                _t = self._tool_modules[t]
            else:
                _t = self.load_tool(t, tooldir)
            ret[t] = _t
        self.setup_tools()
        return ret

    def setup_tools(self):
        for builder in list(self.builders.values()):
            if not builder.configured:
                builder.configure()
                self._configured[builder] = True

    def store(self):
        default_env = self.bld_root.make_node(DEFAULT_ENV)
        self.env.store(default_env.abspath())

        self.log.close()

        config_cache = self.bld_root.make_node(CONFIG_CACHE)
        out = []
        out.append(dumps(self.cache))
        out.append(dumps(self._stdout_cache))
        out.append(dumps(self._cmd_cache))
        config_cache.write(join_bytes(out), flags="wb")

        build_config = self.bld_root.make_node(BUILD_CONFIG)
        build_config.write("%r\n" % self.tools)

        hook_dump = self.bld_root.make_node(HOOK_DUMP)
        s = dumps({
            "extensions":
            yaku.task_manager.RULES_REGISTRY,
            "files":
            _hook_id_to_hook_path(yaku.task_manager.FILES_REGISTRY)
        })
        hook_dump.write(s, flags="wb")

    def start_message(self, msg):
        _OUTPUT.write(msg + "... ")
        self.log.write("=" * 79 + "\n")
        self.log.write("%s\n" % msg)

    def end_message(self, msg):
        _OUTPUT.write("%s\n" % msg)

    def fail_configuration(self, msg):
        msg = "%s\nPlease look at the configuration log %r" % (msg,
                                                               self.log.name)
        self.log.flush()
        raise ConfigurationFailure(msg)

    def set_cmd_cache(self, task, cmd):
        self._cmd_cache[task.get_uid()] = cmd[:]

    def get_cmd(self, task):
        tid = task.get_uid()
        try:
            return self._cmd_cache[tid]
        except KeyError:
            raise UnknownTask

    def set_stdout_cache(self, task, stdout):
        self._stdout_cache[task.get_uid()] = stdout

    def get_stdout(self, task):
        tid = task.get_uid()
        try:
            return self._stdout_cache[tid]
        except KeyError:
            raise UnknownTask
Beispiel #22
0
class ConfigureContext(object):
    def __init__(self):
        self.env = Environment()
        self.tools = []
        self._tool_modules = {}
        self.builders = {}
        self.cache = {}
        self.conf_results = []
        self._configured = {}
        self._stdout_cache = {}
        self._cmd_cache = {}

        self.src_root = None
        self.bld_root = None
        self.path = None

    def load_tool(self, tool, tooldir=None):
        _t = import_tools([tool], tooldir)
        self.tools.append({"tool": tool, "tooldir": tooldir})
        mod = _t[tool]
        self._tool_modules[tool] = mod
        if hasattr(mod, "get_builder"):
            self.builders[tool] = mod.get_builder(self)
        return mod

    def use_tools(self, tools, tooldir=None):
        ret = {}
        for t in tools:
            if t in self._tool_modules:
                _t = self._tool_modules[t]
            else:
                _t = self.load_tool(t, tooldir)
            ret[t] = _t
        self.setup_tools()
        return ret

    def setup_tools(self):
        for builder in self.builders.values():
            if not builder.configured:
               builder.configure()
               self._configured[builder] = True

    def store(self):
        default_env = self.bld_root.make_node(DEFAULT_ENV)
        self.env.store(default_env.abspath())

        self.log.close()

        config_cache = self.bld_root.make_node(CONFIG_CACHE)
        out = []
        out.append(dumps(self.cache))
        out.append(dumps(self._stdout_cache))
        out.append(dumps(self._cmd_cache))
        config_cache.write(join_bytes(out), flags="wb")

        build_config = self.bld_root.make_node(BUILD_CONFIG)
        build_config.write("%r\n" % self.tools)

        hook_dump = self.bld_root.make_node(HOOK_DUMP)
        s = dumps({"extensions": yaku.task_manager.RULES_REGISTRY,
                   "files": _hook_id_to_hook_path(yaku.task_manager.FILES_REGISTRY)})
        hook_dump.write(s, flags="wb")

    def start_message(self, msg):
        _OUTPUT.write(msg + "... ")
        self.log.write("=" * 79 + "\n")
        self.log.write("%s\n" % msg)

    def end_message(self, msg):
        _OUTPUT.write("%s\n" % msg)

    def fail_configuration(self, msg):
        msg = "%s\nPlease look at the configuration log %r" % (msg, self.log.name)
        self.log.flush()
        raise ConfigurationFailure(msg)

    def set_cmd_cache(self, task, cmd):
        self._cmd_cache[task.get_uid()] = cmd[:]

    def get_cmd(self, task):
        tid = task.get_uid()
        try:
            return self._cmd_cache[tid]
        except KeyError:
            raise UnknownTask

    def set_stdout_cache(self, task, stdout):
        self._stdout_cache[task.get_uid()] = stdout

    def get_stdout(self, task):
        tid = task.get_uid()
        try:
            return self._stdout_cache[tid]
        except KeyError:
            raise UnknownTask

    def try_command(self, cmd, cwd=None, env=None, kw=None):
        if cwd is None:
            cwd = self.bld_root.abspath()
        if kw is None:
            kw = {}
        if env is not None:
            kw["env"] = env

        def log_failure(succeed, explanation):
            if succeed:
                self.log.write("---> Succeeded !\n")
            else:
                self.log.write("---> Failure !\n")
                self.log.write("~~~~~~~~~~~~~~\n")
                self.log.write(explanation)
                self.log.write("~~~~~~~~~~~~~~\n")
            self.log.write("Command was:\n")
            self.log.write("%s\n" % cmd)
            self.log.write("\n")

        try:
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT, cwd=cwd, **kw)
            stdout = p.communicate()[0].decode("utf-8")
            log_failure(p.returncode == 0, stdout)
            if p.returncode:
                return False
            return True
        except OSError:
            e = get_exception()
            log_failure(False, str(e))
        except WindowsError:
            e = get_exception()
            log_failure(False, str(e))
        return False
Beispiel #23
0
 def __init__(self):
     self.env = Environment()
     self.tools = []
     self.cache = {}
     self.builders = {}
     self.tasks = []