def test_extension_registration(self): top_node = self.top_node bento_info = """\ Name: foo Library: Extension: _foo Sources: src/foo.c Extension: _bar Sources: src/bar.c """ bentos = {"bento.info": bento_info} conf, configure, bld, build = self._run_configure(bentos) def pre_build(context): builder = self._builder_factory(context) context.register_builder("_bar", builder) pre_hook = PreHookWrapper(pre_build, "build", self.d) run_command_in_context(bld, build, pre_hooks=[pre_hook]) sections = bld.section_writer.sections["extensions"] self.failUnless(len(sections) == 2) self.failUnless(len(sections["_bar"].files) == 0)
def test_extension_tweak(self): bento_info = """\ Name: foo Library: Extension: _foo Sources: src/foo.c Extension: _bar Sources: src/bar.c """ bentos = {"bento.info": bento_info} conf, configure, bld, build = self._run_configure(bentos) # To check that include_dirs is passed along the slightly # over-engineered callchain, we wrap the default build with a function # that check the include_dirs is step up correctly. def pre_build(context): context.tweak_extension("_bar", include_dirs=["fubar"]) pre_hook = PreHookWrapper(pre_build, "build", self.d) old_default_builder = bld.default_builder try: def _builder_wrapper(extension, **kw): if extension.name == "_bar": self.assertTrue(kw.get("include_dirs", []) == ["fubar"]) return old_default_builder(extension, **kw) bld.default_builder = _builder_wrapper run_command_in_context(bld, build, pre_hooks=[pre_hook]) finally: bld.default_builder = old_default_builder sections = bld.section_writer.sections["extensions"] self.failUnless(len(sections) == 2)
def test_disable_extension(self): conf, configure, bld, build = self._run_configure({"bento.info": BENTO_INFO_WITH_EXT}) pre_hook = PreHookWrapper(lambda context: context.disable_extension("foo"), "build", self.d) run_command_in_context(bld, build, pre_hooks=[pre_hook]) assert "extensions" not in bld.section_writer.sections
def _run_build_with_pre_hook(self, hook_func): package = PackageDescription.from_string(BENTO_INFO) global_context = prepare_package(self.top_node, BENTO_INFO) conf, configure = prepare_command(global_context, "configure", [], package, self.top_node) run_command_in_context(conf, configure) pre_hook = PreHookWrapper(hook_func, self.build_node.path_from(self.top_node), self.top_node.abspath()) bld, build = prepare_command(global_context, "build", [], package, self.top_node) run_command_in_context(bld, build, pre_hooks=[pre_hook]) return bld