Exemplo n.º 1
0
    def test_iter_source_nodes(self):
        r_files = set([op.join("src", "foo.c"),
            op.join("src", "bar.c"),
            op.join("src", "fubar.c"),
            op.join("foo", "__init__.py"),
            op.join("foo", "bar", "__init__.py"),
            "fu.py", "foo.1"])

        bento_info = """\
Name: foo

DataFiles: foo
    TargetDir: $sharedir
    Files: foo.1

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
    CompiledLibrary: fubar
        Sources: src/fubar.c
    Packages: foo, foo.bar
    Modules: fu
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        package = PackageDescription.from_string(bento_info)
        node_package = NodeRepresentation(self.top_node, self.top_node)
        node_package.update_package(package)

        files = set(n.path_from(self.top_node) for n in node_package.iter_source_nodes())
        self.assertEqual(files, r_files)
Exemplo n.º 2
0
class SdistContext(ContextWithBuildDirectory):
    def __init__(self, global_context, cmd_args, option_context, pkg,
                 run_node):
        super(SdistContext, self).__init__(global_context, cmd_args,
                                           option_context, pkg, run_node)
        self._meta = {}

        self._node_pkg = NodeRepresentation(run_node, self.top_node)
        self._node_pkg.update_package(pkg)

    def register_metadata(self, name, value):
        self._meta[name] = value

    def register_source_node(self, node, archive_name=None):
        """Register a node into the source distribution.

        archive_name is an optional string which will be used for the file name
        in the archive."""
        self._node_pkg._extra_source_nodes.append(node)
        if archive_name:
            self._node_pkg._aliased_source_nodes[node] = archive_name

    def configure(self):
        if self.pkg.meta_template_files:
            for template in self.pkg.meta_template_files:
                output = write_template(self.top_node, template, self.pkg,
                                        self._meta)
                self.register_source_node(output, output.bldpath())
Exemplo n.º 3
0
class SdistContext(CmdContext):
    def __init__(self, global_context, cmd_args, option_context, pkg, run_node):
        super(SdistContext, self).__init__(global_context, cmd_args, option_context, pkg, run_node)
        self._meta = {}

        self._node_pkg = NodeRepresentation(run_node, self.top_node)
        self._node_pkg.update_package(pkg)

    def register_metadata(self, name, value):
        self._meta[name] = value

    def register_source_node(self, node, archive_name=None):
        """Register a node into the source distribution.

        archive_name is an optional string which will be used for the file name
        in the archive."""
        self._node_pkg._extra_source_nodes.append(node)
        if archive_name:
            self._node_pkg._aliased_source_nodes[node] = archive_name

    def configure(self):
        if self.pkg.meta_template_files:
            for template in self.pkg.meta_template_files:
                output = write_template(self.top_node, template, self.pkg, self._meta)
                self.register_source_node(output, output.bldpath())
    def test_iter_source_nodes(self):
        r_files = set([
            op.join("src", "foo.c"),
            op.join("src", "bar.c"),
            op.join("src", "fubar.c"),
            op.join("foo", "__init__.py"),
            op.join("foo", "bar", "__init__.py"), "fu.py", "foo.1"
        ])

        bento_info = """\
Name: foo

DataFiles: foo
    TargetDir: $sharedir
    Files: foo.1

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
    CompiledLibrary: fubar
        Sources: src/fubar.c
    Packages: foo, foo.bar
    Modules: fu
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        package = PackageDescription.from_string(bento_info)
        node_package = NodeRepresentation(self.top_node, self.top_node)
        node_package.update_package(package)

        files = set(
            n.path_from(self.top_node)
            for n in node_package.iter_source_nodes())
        self.assertEqual(files, r_files)
Exemplo n.º 5
0
    def __init__(self, global_context, cmd_args, option_context, pkg,
                 run_node):
        super(SdistContext, self).__init__(global_context, cmd_args,
                                           option_context, pkg, run_node)
        self._meta = {}

        self._node_pkg = NodeRepresentation(run_node, self.top_node)
        self._node_pkg.update_package(pkg)
Exemplo n.º 6
0
    def _create_package_and_reference(self, bento_info, r_bento_info):
        pkg = PackageDescription.from_string(bento_info)
        node_pkg = NodeRepresentation(self.run_node, self.top_node)
        node_pkg.update_package(pkg)

        r_pkg = PackageDescription.from_string(r_bento_info)
        r_node_pkg = NodeRepresentation(self.run_node, self.top_node)
        r_node_pkg.update_package(r_pkg)

        return node_pkg, r_node_pkg
Exemplo n.º 7
0
    def __init__(self, global_context, cmd_args, option_context, pkg, run_node):
        super(SdistContext, self).__init__(global_context, cmd_args, option_context, pkg, run_node)

        self._node_pkg = NodeRepresentation(run_node, self.top_node)
        self._node_pkg.update_package(pkg)

        if self.pkg.meta_template_file:
            output = write_template(self.top_node, pkg)
            self.register_source_node(output, output.bldpath())
Exemplo n.º 8
0
    def __init__(self, global_context, cmd_argv, options_context, pkg, run_node):
        super(BuildContext, self).__init__(global_context, cmd_argv, options_context, pkg, run_node)
        self.builder_registry = BuilderRegistry()
        self.section_writer = SectionWriter()

        o, a = self.options_context.parser.parse_args(cmd_argv)
        if o.inplace:
            self.inplace = True
        else:
            self.inplace = False
        # Builders signature:
        #   - first argument: name, str. Name of the entity to be built
        #   - second argument: object. Value returned by
        #   NodePackage.iter_category for this category

        # TODO: # Refactor builders so that they directoy register outputs
        # instead of returning stuff to be registered (to allow for "delayed"
        # registration)
        def data_section_builder(name, section):
            return name, section.nodes, section.ref_node, section.target_dir

        def package_builder(name, nodes):
            return name, nodes, self.top_node, "$sitedir"

        def module_builder(name, node):
            return name, [node], self.top_node, "$sitedir"

        def script_builder(name, executable):
            scripts_node = self.build_node.make_node("scripts-%s" % sys.version[:3])
            scripts_node.mkdir()
            if sys.platform == "win32":
                nodes = create_win32_script(name, executable, scripts_node)
            else:
                nodes = create_posix_script(name, executable, scripts_node)
            return name, nodes, scripts_node, "$bindir"

        self.builder_registry.register_category("datafiles", data_section_builder)
        self.builder_registry.register_category("packages", package_builder)
        self.builder_registry.register_category("modules", module_builder)
        self.builder_registry.register_category("scripts", script_builder)

        self._node_pkg = NodeRepresentation(run_node, self.top_node)
        self._node_pkg.update_package(pkg)

        categories = (("packages", "pythonfiles"), ("modules", "pythonfiles"), ("datafiles", "datafiles"),
                      ("scripts", "executables"), ("extensions", "extensions"),
                      ("compiled_libraries", "compiled_libraries"))
        self.outputs_registry = OutputRegistry(categories)

        self.isection_registry = ISectionRegistry()
        self.isection_registry.register_category("extensions", _generic_iregistrer)
        self.isection_registry.register_category("compiled_libraries", _generic_iregistrer)
        self.isection_registry.register_category("packages", _generic_iregistrer)
        self.isection_registry.register_category("modules", _generic_iregistrer)
        self.isection_registry.register_category("datafiles", _generic_iregistrer)
        self.isection_registry.register_category("scripts", _generic_iregistrer)
Exemplo n.º 9
0
    def test_sources_glob(self):
        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/*.c
"""
        pkg = PackageDescription.from_string(bento_info)
        node_pkg = NodeRepresentation(self.top_node, self.top_node)
        node_pkg.update_package(pkg)

        extensions = dict(node_pkg.iter_category("extensions"))
        self.assertEqual(len(extensions), 1)
        self.assertEqual(len(extensions["_foo"].nodes), 2)
    def test_sources_glob(self):
        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/*.c
"""
        pkg = PackageDescription.from_string(bento_info)
        node_pkg = NodeRepresentation(self.top_node, self.top_node)
        node_pkg.update_package(pkg)

        extensions = dict(node_pkg.iter_category("extensions"))
        self.assertEqual(len(extensions), 1)
        self.assertEqual(len(extensions["_foo"].nodes), 2)
Exemplo n.º 11
0
    def _create_package_and_reference(self, bento_info, r_bento_info):
        pkg = PackageDescription.from_string(bento_info)
        node_pkg = NodeRepresentation(self.run_node, self.top_node)
        node_pkg.update_package(pkg)

        r_pkg = PackageDescription.from_string(r_bento_info)
        r_node_pkg = NodeRepresentation(self.run_node, self.top_node)
        r_node_pkg.update_package(r_pkg)

        return node_pkg, r_node_pkg
Exemplo n.º 12
0
    def __init__(self, global_context, command_argv, options_context, pkg,
                 run_node):
        super(BuildContext, self).__init__(global_context, command_argv,
                                           options_context, pkg, run_node)
        self.builder_registry = BuilderRegistry()
        self.section_writer = SectionWriter()

        o, a = self.options_context.parser.parse_args(command_argv)
        if o.inplace:
            self.inplace = True
        else:
            self.inplace = False
        # Builders signature:
        #   - first argument: name, str. Name of the entity to be built
        #   - second argument: object. Value returned by
        #   NodePackage.iter_category for this category

        # TODO: # Refactor builders so that they directoy register outputs
        # instead of returning stuff to be registered (to allow for "delayed"
        # registration)
        def data_section_builder(name, section):
            return name, section.nodes, section.ref_node, section.target_dir

        def package_builder(name, node_py_package):
            return name, node_py_package.nodes, self.top_or_sub_directory_node, "$sitedir"

        def module_builder(name, node):
            return name, [node], self.top_or_sub_directory_node, "$sitedir"

        def script_builder(name, executable):
            scripts_node = self.build_node.make_node("scripts-%s" %
                                                     sys.version[:3])
            scripts_node.mkdir()
            if sys.platform == "win32":
                nodes = create_win32_script(name, executable, scripts_node)
            else:
                nodes = create_posix_script(name, executable, scripts_node)
            return name, nodes, scripts_node, "$bindir"

        self.builder_registry.register_category("datafiles",
                                                data_section_builder)
        self.builder_registry.register_category("packages", package_builder)
        self.builder_registry.register_category("modules", module_builder)
        self.builder_registry.register_category("scripts", script_builder)

        if self.pkg.sub_directory is not None:
            sub_directory_node = self.top_node.find_node(
                self.pkg.sub_directory)
        else:
            sub_directory_node = None
        self._node_pkg = NodeRepresentation(run_node, self.top_node,
                                            sub_directory_node)
        self._node_pkg.update_package(pkg)

        categories = (("packages", "pythonfiles"), ("modules", "pythonfiles"),
                      ("datafiles", "datafiles"), ("scripts", "executables"),
                      ("extensions", "extensions"), ("compiled_libraries",
                                                     "compiled_libraries"))
        self.outputs_registry = OutputRegistry(categories)

        self.isection_registry = ISectionRegistry()
        self.isection_registry.register_category("extensions",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("compiled_libraries",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("packages",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("modules",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("datafiles",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("scripts",
                                                 _generic_iregistrer)

        self._current_default_section = 0

        self._meta = {}
Exemplo n.º 13
0
class BuildContext(ContextWithBuildDirectory):
    def __init__(self, global_context, command_argv, options_context, pkg,
                 run_node):
        super(BuildContext, self).__init__(global_context, command_argv,
                                           options_context, pkg, run_node)
        self.builder_registry = BuilderRegistry()
        self.section_writer = SectionWriter()

        o, a = self.options_context.parser.parse_args(command_argv)
        if o.inplace:
            self.inplace = True
        else:
            self.inplace = False
        # Builders signature:
        #   - first argument: name, str. Name of the entity to be built
        #   - second argument: object. Value returned by
        #   NodePackage.iter_category for this category

        # TODO: # Refactor builders so that they directoy register outputs
        # instead of returning stuff to be registered (to allow for "delayed"
        # registration)
        def data_section_builder(name, section):
            return name, section.nodes, section.ref_node, section.target_dir

        def package_builder(name, node_py_package):
            return name, node_py_package.nodes, self.top_or_sub_directory_node, "$sitedir"

        def module_builder(name, node):
            return name, [node], self.top_or_sub_directory_node, "$sitedir"

        def script_builder(name, executable):
            scripts_node = self.build_node.make_node("scripts-%s" %
                                                     sys.version[:3])
            scripts_node.mkdir()
            if sys.platform == "win32":
                nodes = create_win32_script(name, executable, scripts_node)
            else:
                nodes = create_posix_script(name, executable, scripts_node)
            return name, nodes, scripts_node, "$bindir"

        self.builder_registry.register_category("datafiles",
                                                data_section_builder)
        self.builder_registry.register_category("packages", package_builder)
        self.builder_registry.register_category("modules", module_builder)
        self.builder_registry.register_category("scripts", script_builder)

        if self.pkg.sub_directory is not None:
            sub_directory_node = self.top_node.find_node(
                self.pkg.sub_directory)
        else:
            sub_directory_node = None
        self._node_pkg = NodeRepresentation(run_node, self.top_node,
                                            sub_directory_node)
        self._node_pkg.update_package(pkg)

        categories = (("packages", "pythonfiles"), ("modules", "pythonfiles"),
                      ("datafiles", "datafiles"), ("scripts", "executables"),
                      ("extensions", "extensions"), ("compiled_libraries",
                                                     "compiled_libraries"))
        self.outputs_registry = OutputRegistry(categories)

        self.isection_registry = ISectionRegistry()
        self.isection_registry.register_category("extensions",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("compiled_libraries",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("packages",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("modules",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("datafiles",
                                                 _generic_iregistrer)
        self.isection_registry.register_category("scripts",
                                                 _generic_iregistrer)

        self._current_default_section = 0

        self._meta = {}

    def register_metadata(self, name, value):
        self._meta[name] = value

    def register_category(self, category_name, category_type="pythonfiles"):
        self.outputs_registry.register_category(category_name, category_type)
        self.isection_registry.register_category(category_name,
                                                 _generic_iregistrer)

    def register_outputs_simple(self,
                                nodes,
                                from_node=None,
                                target_dir='$sitedir'):
        category_name = "hook_registered"
        section_name = "hook_registered%d" % self._current_default_section

        if not category_name in self.outputs_registry.categories:
            self.register_category(category_name)
        self.register_outputs(category_name, section_name, nodes, from_node,
                              target_dir)

        self._current_default_section += 1

    def register_outputs(self,
                         category_name,
                         section_name,
                         nodes,
                         from_node=None,
                         target_dir="$sitedir"):
        if from_node is None:
            from_node = self.build_node
        self.outputs_registry.register_outputs(category_name, section_name,
                                               nodes, from_node, target_dir)

    def _compute_extension_name(self, extension_name):
        if self.local_node is None:
            raise ValueError("Forgot to call pre_recurse ?")
        if self.local_node != self.top_node:
            parent = self.local_node.srcpath().split(os.path.sep)
            return ".".join(parent + [extension_name])
        else:
            return extension_name

    def register_builder(self, extension_name, builder):
        full_name = self._compute_extension_name(extension_name)
        self.builder_registry.register_callback("extensions", full_name,
                                                builder)

    def default_builder(self, extension, **kw):
        return self.builder_registry.default_callback("extensions", extension,
                                                      **kw)

    def tweak_extension(self, extension_name, **kw):
        def _builder(extension):
            return self.default_builder(extension, **kw)

        full_name = self._compute_extension_name(extension_name)
        return self.builder_registry.register_callback("extensions", full_name,
                                                       _builder)

    def tweak_library(self, lib_name, **kw):
        def _builder(lib_name):
            return self.default_library_builder(lib_name, **kw)

        full_name = self._compute_extension_name(lib_name)
        return self.builder_registry.register_callback("compiled_libraries",
                                                       full_name, _builder)

    def default_library_builder(self, library, **kw):
        return self.builder_registry.default_callback("compiled_libraries",
                                                      library, **kw)

    def disable_extension(self, extension_name):
        def nobuild(extension):
            pass

        self.register_builder(extension_name, nobuild)

    def register_compiled_library_builder(self, clib_name, builder):
        full_name = self._compute_extension_name(clib_name)
        self.builder_registry.register_callback("compiled_libraries",
                                                full_name, builder)

    def compile(self):
        for category in ("packages", "modules", "datafiles"):
            for name, value in self._node_pkg.iter_category(category):
                builder = self.builder_registry.builder(category, name)
                name, nodes, from_node, target_dir = builder(name, value)
                self.outputs_registry.register_outputs(category, name, nodes,
                                                       from_node, target_dir)

        category = "scripts"
        for name, executable in self.pkg.executables.items():
            builder = self.builder_registry.builder(category, name)
            name, nodes, from_node, target_dir = builder(name, executable)
            self.outputs_registry.register_outputs(category, name, nodes,
                                                   from_node, target_dir)

        if self.pkg.config_py:
            content = _config_content(self.retrieve_configured_scheme())
            target_node = self.build_node.make_node(self.pkg.config_py)
            target_node.parent.mkdir()
            target_node.safe_write(content)
            self.outputs_registry.register_outputs("modules", "bento_config",
                                                   [target_node],
                                                   self.build_node, "$sitedir")

        if self.pkg.meta_template_files:
            target_nodes = []
            for template in self.pkg.meta_template_files:
                target_node = write_template(self.top_node, template, self.pkg,
                                             self._meta)
                target_nodes.append(target_node)
            self.outputs_registry.register_outputs("modules",
                                                   "meta_from_template",
                                                   target_nodes,
                                                   self.build_node, "$sitedir")

    def post_compile(self):
        # Do the output_registry -> installed sections registry convertion
        section_writer = self.section_writer

        for category, name, nodes, from_node, target_dir in self.outputs_registry.iter_over_category(
        ):
            installed_category = self.outputs_registry.installed_categories[
                category]
            if installed_category in section_writer.sections:
                sections = section_writer.sections[installed_category]
            else:
                sections = section_writer.sections[installed_category] = {}
            registrer = self.isection_registry.registrer(category, name)
            sections[name] = registrer(installed_category, name, nodes,
                                       from_node, target_dir)

        # FIXME: this is quite stupid.
        if self.inplace:
            scheme = self.retrieve_scheme()
            scheme["prefix"] = scheme["eprefix"] = self.run_node.abspath()
            scheme["sitedir"] = self.run_node.abspath()

            if self.pkg.config_py:
                target_node = self.build_node.find_node(self.pkg.config_py)
            else:
                target_node = None

            def _install_node(category, node, from_node, target_dir):
                installed_path = subst_vars(target_dir, scheme)
                target = os.path.join(installed_path,
                                      node.path_from(from_node))
                copy_installer(node.path_from(self.run_node), target, category)

            intree = (self.top_node == self.run_node)
            if intree:
                for category, name, nodes, from_node, target_dir in self.outputs_registry.iter_over_category(
                ):
                    for node in nodes:
                        if node != target_node and node.is_bld():
                            _install_node(category, node, from_node,
                                          target_dir)
            else:
                for category, name, nodes, from_node, target_dir in self.outputs_registry.iter_over_category(
                ):
                    for node in nodes:
                        if node != target_node:
                            _install_node(category, node, from_node,
                                          target_dir)
Exemplo n.º 14
0
class BuildContext(_ContextWithBuildDirectory):
    def __init__(self, cmd_argv, options_context, pkg, run_node):
        super(BuildContext, self).__init__(cmd_argv, options_context, pkg, run_node)
        self.builder_registry = BuilderRegistry()
        self.section_writer = SectionWriter()

        # Builders signature:
        #   - first argument: name, str. Name of the entity to be built
        #   - second argument: object. Value returned by
        #   NodePackage.iter_category for this category

        # TODO: # Refactor builders so that they directoy register outputs
        # instead of returning stuff to be registered (to allow for "delayed"
        # registration)
        def data_section_builder(name, section):
            return name, section.nodes, section.ref_node, section.target_dir

        def package_builder(name, nodes):
            return name, nodes, self.top_node, "$sitedir"

        def module_builder(name, node):
            return name, [node], self.top_node, "$sitedir"

        def script_builder(name, executable):
            scripts_node = self.build_node.make_node("scripts-%s" % sys.version[:3])
            scripts_node.mkdir()
            if sys.platform == "win32":
                nodes = create_win32_script(name, executable, scripts_node)
            else:
                nodes = create_posix_script(name, executable, scripts_node)
            return name, nodes, scripts_node, "$bindir"

        self.builder_registry.register_category("datafiles", data_section_builder)
        self.builder_registry.register_category("packages", package_builder)
        self.builder_registry.register_category("modules", module_builder)
        self.builder_registry.register_category("scripts", script_builder)

        self._node_pkg = NodeRepresentation(run_node, self.top_node)
        self._node_pkg.update_package(pkg)

        categories = (("packages", "pythonfiles"), ("modules", "pythonfiles"), ("datafiles", "datafiles"),
                      ("scripts", "executables"), ("extensions", "extensions"),
                      ("compiled_libraries", "compiled_libraries"))
        self.outputs_registry = OutputRegistry(categories)

        self.isection_registry = ISectionRegistry()
        self.isection_registry.register_category("extensions", _generic_iregistrer)
        self.isection_registry.register_category("compiled_libraries", _generic_iregistrer)
        self.isection_registry.register_category("packages", _generic_iregistrer)
        self.isection_registry.register_category("modules", _generic_iregistrer)
        self.isection_registry.register_category("datafiles", _generic_iregistrer)
        self.isection_registry.register_category("scripts", _generic_iregistrer)

    def register_category(self, category_name, category_type="pythonfiles"):
        self.outputs_registry.register_category(category_name, category_type)
        self.isection_registry.register_category(category_name, _generic_iregistrer)

    def register_outputs(self, category_name, section_name, nodes, from_node=None, target_dir="$sitedir"):
        if from_node is None:
            from_node = self.build_node
        self.outputs_registry.register_outputs(category_name, section_name, nodes, from_node, target_dir)

    def shutdown(self):
        CmdContext.shutdown(self)

    def _compute_extension_name(self, extension_name):
        if self.local_node is None:
            raise ValueError("Forgot to call pre_recurse ?")
        if self.local_node != self.top_node:
            parent = self.local_node.srcpath().split(os.path.sep)
            return ".".join(parent + [extension_name])
        else:
            return extension_name

    def register_builder(self, extension_name, builder):
        full_name = self._compute_extension_name(extension_name)
        self.builder_registry.register_callback("extensions", full_name, builder)

    def disable_extension(self, extension_name):
        def nobuild(extension):
            pass
        self.register_builder(extension_name, nobuild)

    def register_compiled_library_builder(self, clib_name, builder):
        relpos = self.local_node.path_from(self.top_node)
        full_name = os.path.join(relpos, clib_name).replace(os.sep, ".")
        self.builder_registry.register_callback("compiled_libraries", full_name, builder)

    def compile(self):
        for category in ("packages", "modules", "datafiles"):
            for name, value in self._node_pkg.iter_category(category):
                builder = self.builder_registry.builder(category, name)
                name, nodes, from_node, target_dir = builder(name, value)
                self.outputs_registry.register_outputs(category, name, nodes, from_node, target_dir)

        category = "scripts"
        for name, executable in self.pkg.executables.iteritems():
            builder = self.builder_registry.builder(category, name)
            name, nodes, from_node, target_dir = builder(name, executable)
            self.outputs_registry.register_outputs(category, name, nodes, from_node, target_dir)

        if self.pkg.config_py:
            content = _config_content(self.get_paths_scheme())
            target_node = self.build_node.make_node(self.pkg.config_py)
            target_node.parent.mkdir()
            target_node.safe_write(content)
            self.outputs_registry.register_outputs("modules", "bento_config", [target_node],
                                                   self.build_node, "$sitedir")

    def post_compile(self):
        # Do the output_registry -> installed sections registry convertion
        section_writer = self.section_writer

        for category, name, nodes, from_node, target_dir in self.outputs_registry.iter_over_category():
            installed_category = self.outputs_registry.installed_categories[category]
            if installed_category in section_writer.sections:
                sections = section_writer.sections[installed_category]
            else:
                sections = section_writer.sections[installed_category] = {}
            registrer = self.isection_registry.registrer(category, name)
            sections[name] = registrer(installed_category, name, nodes, from_node, target_dir)
Exemplo n.º 15
0
    def __init__(self, global_context, cmd_args, option_context, pkg, run_node):
        super(SdistContext, self).__init__(global_context, cmd_args, option_context, pkg, run_node)
        self._meta = {}

        self._node_pkg = NodeRepresentation(run_node, self.top_node)
        self._node_pkg.update_package(pkg)
Exemplo n.º 16
0
class BuildContext(ContextWithBuildDirectory):
    def __init__(self, global_context, command_argv, options_context, pkg, run_node):
        super(BuildContext, self).__init__(global_context, command_argv, options_context, pkg, run_node)
        self.builder_registry = BuilderRegistry()
        self.section_writer = SectionWriter()

        o, a = self.options_context.parser.parse_args(command_argv)
        if o.inplace:
            self.inplace = True
        else:
            self.inplace = False
        # Builders signature:
        #   - first argument: name, str. Name of the entity to be built
        #   - second argument: object. Value returned by
        #   NodePackage.iter_category for this category

        # TODO: # Refactor builders so that they directoy register outputs
        # instead of returning stuff to be registered (to allow for "delayed"
        # registration)
        def data_section_builder(name, section):
            return name, section.nodes, section.ref_node, section.target_dir

        def package_builder(name, node_py_package):
            return name, node_py_package.nodes, self.top_or_sub_directory_node, "$sitedir"

        def module_builder(name, node):
            return name, [node], self.top_or_sub_directory_node, "$sitedir"

        def script_builder(name, executable):
            scripts_node = self.build_node.make_node("scripts-%s" % sys.version[:3])
            scripts_node.mkdir()
            if sys.platform == "win32":
                nodes = create_win32_script(name, executable, scripts_node)
            else:
                nodes = create_posix_script(name, executable, scripts_node)
            return name, nodes, scripts_node, "$bindir"

        self.builder_registry.register_category("datafiles", data_section_builder)
        self.builder_registry.register_category("packages", package_builder)
        self.builder_registry.register_category("modules", module_builder)
        self.builder_registry.register_category("scripts", script_builder)

        if self.pkg.sub_directory is not None:
            sub_directory_node = self.top_node.find_node(self.pkg.sub_directory)
        else:
            sub_directory_node = None
        self._node_pkg = NodeRepresentation(run_node, self.top_node, sub_directory_node)
        self._node_pkg.update_package(pkg)

        categories = (("packages", "pythonfiles"), ("modules", "pythonfiles"), ("datafiles", "datafiles"),
                      ("scripts", "executables"), ("extensions", "extensions"),
                      ("compiled_libraries", "compiled_libraries"))
        self.outputs_registry = OutputRegistry(categories)

        self.isection_registry = ISectionRegistry()
        self.isection_registry.register_category("extensions", _generic_iregistrer)
        self.isection_registry.register_category("compiled_libraries", _generic_iregistrer)
        self.isection_registry.register_category("packages", _generic_iregistrer)
        self.isection_registry.register_category("modules", _generic_iregistrer)
        self.isection_registry.register_category("datafiles", _generic_iregistrer)
        self.isection_registry.register_category("scripts", _generic_iregistrer)

        self._current_default_section = 0

        self._meta = {}

    def register_metadata(self, name, value):
        self._meta[name] = value

    def register_category(self, category_name, category_type="pythonfiles"):
        self.outputs_registry.register_category(category_name, category_type)
        self.isection_registry.register_category(category_name, _generic_iregistrer)

    def register_outputs_simple(self, nodes, from_node=None, target_dir='$sitedir'):
        category_name = "hook_registered"
        section_name = "hook_registered%d" % self._current_default_section

        if not category_name in self.outputs_registry.categories:
            self.register_category(category_name)
        self.register_outputs(category_name, section_name, nodes, from_node, target_dir)

        self._current_default_section += 1

    def register_outputs(self, category_name, section_name, nodes, from_node=None, target_dir="$sitedir"):
        if from_node is None:
            from_node = self.build_node
        self.outputs_registry.register_outputs(category_name, section_name, nodes, from_node, target_dir)

    def _compute_extension_name(self, extension_name):
        if self.local_node is None:
            raise ValueError("Forgot to call pre_recurse ?")
        if self.local_node != self.top_node:
            parent = self.local_node.srcpath().split(os.path.sep)
            return ".".join(parent + [extension_name])
        else:
            return extension_name

    def register_builder(self, extension_name, builder):
        full_name = self._compute_extension_name(extension_name)
        self.builder_registry.register_callback("extensions", full_name, builder)

    def default_builder(self, extension, **kw):
        return self.builder_registry.default_callback(
                                        "extensions",
                                        extension,
                                        **kw)

    def tweak_extension(self, extension_name, **kw):
        def _builder(extension):
            return self.default_builder(extension, **kw)
        full_name = self._compute_extension_name(extension_name)
        return self.builder_registry.register_callback("extensions", full_name, _builder)

    def tweak_library(self, lib_name, **kw):
        def _builder(lib_name):
            return self.default_library_builder(lib_name, **kw)
        relpos = self.local_node.path_from(self.top_node)
        full_name = os.path.join(relpos, lib_name).replace(os.sep, ".")
        return self.builder_registry.register_callback("compiled_libraries", full_name, _builder)

    def default_library_builder(self, library, **kw):
        return self.builder_registry.default_callback(
                                        "compiled_libraries",
                                        library,
                                        **kw)

    def disable_extension(self, extension_name):
        def nobuild(extension):
            pass
        self.register_builder(extension_name, nobuild)

    def register_compiled_library_builder(self, clib_name, builder):
        relpos = self.local_node.path_from(self.top_node)
        full_name = os.path.join(relpos, clib_name).replace(os.sep, ".")
        self.builder_registry.register_callback("compiled_libraries", full_name, builder)

    def compile(self):
        for category in ("packages", "modules", "datafiles"):
            for name, value in self._node_pkg.iter_category(category):
                builder = self.builder_registry.builder(category, name)
                name, nodes, from_node, target_dir = builder(name, value)
                self.outputs_registry.register_outputs(category, name, nodes, from_node, target_dir)

        category = "scripts"
        for name, executable in self.pkg.executables.items():
            builder = self.builder_registry.builder(category, name)
            name, nodes, from_node, target_dir = builder(name, executable)
            self.outputs_registry.register_outputs(category, name, nodes, from_node, target_dir)

        if self.pkg.config_py:
            content = _config_content(self.retrieve_configured_scheme())
            target_node = self.build_node.make_node(self.pkg.config_py)
            target_node.parent.mkdir()
            target_node.safe_write(content)
            self.outputs_registry.register_outputs("modules", "bento_config", [target_node],
                                                   self.build_node, "$sitedir")

        if self.pkg.meta_template_files:
            target_nodes = []
            for template in self.pkg.meta_template_files:
                target_node = write_template(self.top_node, template, self.pkg, self._meta)
                target_nodes.append(target_node)
            self.outputs_registry.register_outputs("modules", "meta_from_template", target_nodes,
                                               self.build_node, "$sitedir")
    def post_compile(self):
        # Do the output_registry -> installed sections registry convertion
        section_writer = self.section_writer

        for category, name, nodes, from_node, target_dir in self.outputs_registry.iter_over_category():
            installed_category = self.outputs_registry.installed_categories[category]
            if installed_category in section_writer.sections:
                sections = section_writer.sections[installed_category]
            else:
                sections = section_writer.sections[installed_category] = {}
            registrer = self.isection_registry.registrer(category, name)
            sections[name] = registrer(installed_category, name, nodes, from_node, target_dir)

        # FIXME: this is quite stupid.
        if self.inplace:
            scheme = self.retrieve_scheme()
            scheme["prefix"] = scheme["eprefix"] = self.run_node.abspath()
            scheme["sitedir"] = self.run_node.abspath()

            if self.pkg.config_py:
                target_node = self.build_node.find_node(self.pkg.config_py)
            else:
                target_node = None

            def _install_node(category, node, from_node, target_dir):
                installed_path = subst_vars(target_dir, scheme)
                target = os.path.join(installed_path, node.path_from(from_node))
                copy_installer(node.path_from(self.run_node), target, category)

            intree = (self.top_node == self.run_node)
            if intree:
                for category, name, nodes, from_node, target_dir in self.outputs_registry.iter_over_category():
                    for node in nodes:
                        if node != target_node and node.is_bld():
                            _install_node(category, node, from_node, target_dir)
            else:
                for category, name, nodes, from_node, target_dir in self.outputs_registry.iter_over_category():
                    for node in nodes:
                        if node != target_node:
                            _install_node(category, node, from_node, target_dir)