# Path: kiwixbuild/utils.py
# COLORS = {
#     'OK': '\033[92m',
#     'WARNING': '\033[93m',
#     'NEEDED': '\033[93m',
#     'SKIP': '\033[34m',
#     'ERROR': '\033[91m',
#     '': '\033[0m',
# }
# REMOTE_PREFIX = 'http://mirror.download.kiwix.org/dev/'
# def which(name):
# def xrun_find(name):
#     def __getattr__(self, name):
# def DefaultEnv():
# def remove_duplicates(iterable, key_function=None):
# def get_sha256(path):
# def colorize(text, color=None):
# def print_progress(progress):
# def add_execution_right(file_path):
# def copy_tree(src, dst, post_copy_function=None):
# def download_remote(what, where):
#     def __init__(self, msg=""):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __new__(cls, name, sha256, url=None):
#     def __init__(self, command_name, log_file, force_native_build):
#     def try_skip(self, path, extra_name=""):
#     def _finalise(self):
# def extract_archive(archive_path, dest_dir, topdir=None, name=None):
# def run_command(command, cwd, context, *, env=None, input=None):
# class Defaultdict(defaultdict):
# class BaseCommandResult(Exception):
# class SkipCommand(BaseCommandResult):
# class WarningMessage(BaseCommandResult):
# class StopBuild(BaseCommandResult):
# class Remotefile(namedtuple('Remotefile', ('name', 'sha256', 'url'))):
# class Context:
# 
# Path: kiwixbuild/versions.py

# 
# Path: kiwixbuild/_global.py
# def neutralEnv(what):
#     return getattr(_neutralEnv, what)
# 
# def option(what):
#     return getattr(_options, what)
# 
# def get_target_step(key, default_context=None):
#     if isinstance(key, tuple):
#         context, target = key
#     else:
#         context, target = default_context, key
#     return _target_steps[(context, target)]


import subprocess
import os
import shutil
import time
from kiwixbuild.utils import pj, Context, SkipCommand, WarningMessage, extract_archive, Defaultdict, StopBuild, run_command, colorize
from kiwixbuild.versions import main_project_versions, base_deps_versions
from kiwixbuild._global import neutralEnv, option, get_target_step
        return neutralEnv('log_dir')

    def _patch(self, context):
        context.try_skip(self.source_path)
        for p in self.patches:
            with open(pj(SCRIPT_DIR, 'patches', p), 'r') as patch_input:
                run_command("patch -p1", self.source_path, context, input=patch_input.read())

    def command(self, name, function, *args):
        print("  {} {} : ".format(name, self.name), end="", flush=True)
        log = pj(self._log_dir, 'cmd_{}_{}.log'.format(name, self.name))
        context = Context(name, log, True)
        try:
            start_time = time.time()
            ret = function(*args, context=context)
            context._finalise()
            duration = time.time() - start_time
            print(colorize("OK"), "({:.1f}s)".format(duration))
            return ret
        except WarningMessage as e:
            print(e)
        except SkipCommand as e:
            print(e)
        except subprocess.CalledProcessError:
            print(colorize("ERROR"))
            try:
                with open(log, 'r') as f:
                    print(f.read())
            except:
                pass

# Path: kiwixbuild/utils.py
# COLORS = {
#     'OK': '\033[92m',
#     'WARNING': '\033[93m',
#     'NEEDED': '\033[93m',
#     'SKIP': '\033[34m',
#     'ERROR': '\033[91m',
#     '': '\033[0m',
# }
# REMOTE_PREFIX = 'http://mirror.download.kiwix.org/dev/'
# def which(name):
# def xrun_find(name):
#     def __getattr__(self, name):
# def DefaultEnv():
# def remove_duplicates(iterable, key_function=None):
# def get_sha256(path):
# def colorize(text, color=None):
# def print_progress(progress):
# def add_execution_right(file_path):
# def copy_tree(src, dst, post_copy_function=None):
# def download_remote(what, where):
#     def __init__(self, msg=""):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def __new__(cls, name, sha256, url=None):
#     def __init__(self, command_name, log_file, force_native_build):
#     def try_skip(self, path, extra_name=""):
#     def _finalise(self):
# def extract_archive(archive_path, dest_dir, topdir=None, name=None):
# def run_command(command, cwd, context, *, env=None, input=None):
# class Defaultdict(defaultdict):
# class BaseCommandResult(Exception):
# class SkipCommand(BaseCommandResult):
# class WarningMessage(BaseCommandResult):
# class StopBuild(BaseCommandResult):
# class Remotefile(namedtuple('Remotefile', ('name', 'sha256', 'url'))):
# class Context:
# 
# Path: kiwixbuild/versions.py

# 
# Path: kiwixbuild/_global.py
# def neutralEnv(what):
#     return getattr(_neutralEnv, what)
# 
# def option(what):
#     return getattr(_options, what)
# 
# def get_target_step(key, default_context=None):
#     if isinstance(key, tuple):
#         context, target = key
#     else:
#         context, target = default_context, key
#     return _target_steps[(context, target)]


# Path: kiwixbuild/dependencies/base.py
import subprocess
import os
import shutil
import time
from kiwixbuild.utils import pj, Context, SkipCommand, WarningMessage, extract_archive, Defaultdict, StopBuild, run_command, colorize
from kiwixbuild.versions import main_project_versions, base_deps_versions
from kiwixbuild._global import neutralEnv, option, get_target_step

        return neutralEnv('log_dir')

    def _patch(self, context):
        context.try_skip(self.source_path)
        for p in self.patches:
            with open(pj(SCRIPT_DIR, 'patches', p), 'r') as patch_input:
                run_command("patch -p1", self.source_path, context, input=patch_input.read())

    def command(self, name, function, *args):
        print("  {} {} : ".format(name, self.name), end="", flush=True)
        log = pj(self._log_dir, 'cmd_{}_{}.log'.format(name, self.name))
        context = Context(name, log, True)
        try:
            start_time = time.time()
            ret = function(*args, context=context)
            context._finalise()
            duration = time.time() - start_time
            print(colorize("OK"), "({:.1f}s)".format(duration))
            return ret
        except WarningMessage as e:
            print(e)
        except SkipCommand as e:
            print(e)
        except subprocess.CalledProcessError:
            print(colorize("ERROR"))
            try:
                with open(log, 'r') as f:
                    print(f.read())
            except:
                pass

            raise StopBuild()