# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]
# 
# Path: bento/installed_package_description.py
# class InstalledSection(object):
#     @classmethod
#     def from_source_target_directories(cls, category, name, source_dir, target_dir, files):
#         files = [(f, f) for f in files]
#         return cls(category, name, source_dir, target_dir, files)
# 
#     def __init__(self, category, name, srcdir, target, files):
#         self.category = category
#         self.name = name
#         if os.sep != "/":
#             self.source_dir = bento.utils.path.normalize_path(srcdir)
#             self.target_dir = bento.utils.path.normalize_path(target)
#             self.files = [(bento.utils.path.normalize_path(f), bento.utils.path.normalize_path(g)) for f, g in files]
#         else:
#             self.source_dir = srcdir
#             self.target_dir = target
#             self.files = files
# 
#     def __repr__(self):
#         ret = """\
# InstalledSection(%(category)s,
#     %(name)s,
#     %(source_dir)s,
#     %(target_dir)s,
#     %(files)s)""" % {"name": self.name, "category": self.category,
#             "source_dir": self.source_dir, "target_dir": self.target_dir,
#             "files": self.files}
#         return ret
# 
#     def __eq__(self, other):
#         return self.category == other.category and \
#                 self.name == other.name and \
#                 self.source_dir == other.source_dir and \
#                 self.target_dir == other.target_dir and \
#                 self.files == other.files


import os
import errno
import bento.errors
        import distutils.errors
        import distutils.errors
from bento.utils.utils \
    import \
        extract_exception
from bento.compat.api \
    import \
        relpath
from bento.installed_package_description \
    import \
        InstalledSection
from bento.errors \
    import \
        CommandExecutionFailure
    from distutils.extension import Extension as DistExtension
        from distutils.dist import Distribution
        from distutils import log

    def build_compiled_library(self, library):

        bld_cmd = self.clib_bld_cmd
        compiler = bld_cmd.compiler
        base, filename = os.path.split(self._compiled_library_filename(library.name, compiler))
        old_build_clib = bld_cmd.build_clib
        if base:
            # workaround for a distutils issue: distutils put all C libraries
            # in the same directory, and we cannot control the output directory
            # from the name - we need to hack build_clib directory
            bld_cmd.build_clib = os.path.join(old_build_clib, base)
        try:
            try:
                # workaround for yet another bug in distutils: distutils fucks up when
                # building a static library if the target alread exists on at least mac
                # os x.
                target = os.path.join(old_build_clib, base, filename)
                try:
                    os.remove(target)
                except OSError:
                    e = extract_exception()
                    if e.errno != errno.ENOENT:
                        raise
                build_info = {"sources": library.sources,
                        "include_dirs": library.include_dirs}
                bld_cmd.build_libraries([(library.name, build_info)])

                return [relpath(target, self._build_base)]
            except distutils.errors.DistutilsError:

# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]
# 
# Path: bento/installed_package_description.py
# class InstalledSection(object):
#     @classmethod
#     def from_source_target_directories(cls, category, name, source_dir, target_dir, files):
#         files = [(f, f) for f in files]
#         return cls(category, name, source_dir, target_dir, files)
# 
#     def __init__(self, category, name, srcdir, target, files):
#         self.category = category
#         self.name = name
#         if os.sep != "/":
#             self.source_dir = bento.utils.path.normalize_path(srcdir)
#             self.target_dir = bento.utils.path.normalize_path(target)
#             self.files = [(bento.utils.path.normalize_path(f), bento.utils.path.normalize_path(g)) for f, g in files]
#         else:
#             self.source_dir = srcdir
#             self.target_dir = target
#             self.files = files
# 
#     def __repr__(self):
#         ret = """\
# InstalledSection(%(category)s,
#     %(name)s,
#     %(source_dir)s,
#     %(target_dir)s,
#     %(files)s)""" % {"name": self.name, "category": self.category,
#             "source_dir": self.source_dir, "target_dir": self.target_dir,
#             "files": self.files}
#         return ret
# 
#     def __eq__(self, other):
#         return self.category == other.category and \
#                 self.name == other.name and \
#                 self.source_dir == other.source_dir and \
#                 self.target_dir == other.target_dir and \
#                 self.files == other.files


# Path: bento/commands/build_distutils.py
import os
import errno
import bento.errors
        import distutils.errors
        import distutils.errors
from bento.utils.utils \
    import \
        extract_exception
from bento.compat.api \
    import \
        relpath
from bento.installed_package_description \
    import \
        InstalledSection
from bento.errors \
    import \
        CommandExecutionFailure
    from distutils.extension import Extension as DistExtension
        from distutils.dist import Distribution
        from distutils import log


    def build_compiled_library(self, library):

        bld_cmd = self.clib_bld_cmd
        compiler = bld_cmd.compiler
        base, filename = os.path.split(self._compiled_library_filename(library.name, compiler))
        old_build_clib = bld_cmd.build_clib
        if base:
            # workaround for a distutils issue: distutils put all C libraries
            # in the same directory, and we cannot control the output directory
            # from the name - we need to hack build_clib directory
            bld_cmd.build_clib = os.path.join(old_build_clib, base)
        try:
            try:
                # workaround for yet another bug in distutils: distutils fucks up when
                # building a static library if the target alread exists on at least mac
                # os x.
                target = os.path.join(old_build_clib, base, filename)
                try:
                    os.remove(target)
                except OSError:
                    e = extract_exception()
                    if e.errno != errno.ENOENT:
                        raise
                build_info = {"sources": library.sources,
                        "include_dirs": library.include_dirs}
                bld_cmd.build_libraries([(library.name, build_info)])

                return [relpath(target, self._build_base)]
            except distutils.errors.DistutilsError:

                e = extract_exception()