def _run_configure(self, bentos, bscripts=None, configure_argv=None, build_argv=None): from bento.backends.waf_backend import make_stream_logger from bento.backends.waf_backend import WafBackend top_node = self.top_node bento_info = bentos["bento.info"] package = PackageDescription.from_string(bento_info) package_options = PackageOptions.from_string(bento_info) create_fake_package_from_bento_info(top_node, bento_info) top_node.make_node("bento.info").safe_write(bento_info) global_context = create_global_context(package, package_options, WafBackend()) conf, configure = prepare_command(global_context, "configure", configure_argv, package, top_node) run_command_in_context(conf, configure) bld, build = prepare_command(global_context, "build", build_argv, package, top_node) bld.waf_context.logger = make_stream_logger("build", cStringIO()) return conf, configure, bld, build
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_template_filling(self): bento_info = """\ Name: foo Version: 1.0 MetaTemplateFiles: release.py.in Library: Modules: fubar """ archive_list = [ op.join("foo-1.0", f) for f in ["fubar.py", "release.py.in", "release.py", "PKG_INFO"] ] template = self.top_node.make_node("release.py.in") template.write("""\ NAME = $NAME VERSION = $VERSION """) create_fake_package_from_bento_info(self.top_node, bento_info) package = PackageDescription.from_string(bento_info) sdist = SdistCommand() opts = OptionsContext.from_command(sdist) cmd_argv = ["--output-file=foo.zip", "--format=zip"] context = SdistContext(None, cmd_argv, opts, package, self.run_node) run_command_in_context(context, sdist) self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
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 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_extra_source_registration(self): bento_info = """\ Name: foo Version: 1.0 Library: Modules: fubar """ archive_list = [ op.join("foo-1.0", f) for f in ["fubar.py", "yeah.info", "PKG_INFO"] ] extra_node = self.top_node.make_node("yeah.info") extra_node.write("") create_fake_package_from_bento_info(self.top_node, bento_info) package = PackageDescription.from_string(bento_info) sdist = SdistCommand() opts = OptionsContext.from_command(sdist) cmd_argv = ["--output-file=foo.zip", "--format=zip"] context = SdistContext(None, cmd_argv, opts, package, self.run_node) context.register_source_node(self.top_node.find_node("yeah.info")) run_command_in_context(context, sdist) self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
def test_simple_package(self): bento_info = """\ Name: foo Version: 1.0 ExtraSourceFiles: yeah.info Library: Packages: foo, foo.bar Modules: fubar """ archive_list = [ op.join("foo-1.0", f) for f in [ "yeah.info", "PKG_INFO", op.join("foo", "__init__.py"), op.join("foo", "bar", "__init__.py"), "fubar.py" ] ] create_fake_package_from_bento_info(self.top_node, bento_info) package = PackageDescription.from_string(bento_info) sdist = SdistCommand() opts = OptionsContext.from_command(sdist) cmd_argv = ["--output-file=foo.zip", "--format=zip"] context = SdistContext(None, cmd_argv, opts, package, self.run_node) run_command_in_context(context, sdist) self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
def _run_configure_and_build(self, bento_info, install_prefix): top_node = self.top_node create_fake_package_from_bento_info(top_node, bento_info) context = GlobalContext(None) options = PackageOptions.from_string(bento_info) context.register_package_options(options) cmd_argv = [ "--prefix=%s" % install_prefix, "--exec-prefix=%s" % install_prefix ] conf, configure = prepare_configure(top_node, bento_info, ConfigureYakuContext, cmd_argv) context.register_command("configure", configure) options_context = OptionsContext.from_command(configure) if not context.is_options_context_registered("configure"): context.register_options_context("configure", options_context) context.save_command_argv("configure", cmd_argv) run_command_in_context(conf, configure) bld, build = prepare_build(top_node, bento_info) run_command_in_context(bld, build) return context, conf, configure, bld, build
def test_simple(self): root = self.root run_node = root.find_node(self.d) conf, configure = prepare_configure(run_node, BENTO_INFO, ConfigureYakuContext) run_command_in_context(conf, configure)
def test_simple_package(self): bento_info = """\ Name: foo Version: 1.0 ExtraSourceFiles: yeah.info Library: Packages: foo, foo.bar Modules: fubar """ archive_list = [op.join("foo-1.0", f) for f in ["yeah.info", op.join("foo", "__init__.py"), op.join("foo", "bar", "__init__.py"), "fubar.py"]] create_fake_package_from_bento_info(self.top_node, bento_info) package = PackageDescription.from_string(bento_info) sdist = SdistCommand() opts = OptionsContext.from_command(sdist) cmd_argv = ["--output-file=foo.zip", "--format=zip"] context = SdistContext(None, cmd_argv, opts, package, self.run_node) run_command_in_context(context, sdist) self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
def test_template_filling(self): bento_info = """\ Name: foo Version: 1.0 MetaTemplateFile: release.py.in Library: Modules: fubar """ archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "release.py.in", "release.py"]] template = self.top_node.make_node("release.py.in") template.write("""\ NAME = $NAME VERSION = $VERSION """) create_fake_package_from_bento_info(self.top_node, bento_info) package = PackageDescription.from_string(bento_info) sdist = SdistCommand() opts = OptionsContext.from_command(sdist) cmd_argv = ["--output-file=foo.zip", "--format=zip"] context = SdistContext(None, cmd_argv, opts, package, self.run_node) run_command_in_context(context, sdist) self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
def test_extra_source_registration(self): bento_info = """\ Name: foo Version: 1.0 Library: Modules: fubar """ archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "yeah.info"]] extra_node = self.top_node.make_node("yeah.info") extra_node.write("") create_fake_package_from_bento_info(self.top_node, bento_info) package = PackageDescription.from_string(bento_info) sdist = SdistCommand() opts = OptionsContext.from_command(sdist) cmd_argv = ["--output-file=foo.zip", "--format=zip"] context = SdistContext(None, cmd_argv, opts, package, self.run_node) context.register_source_node(self.top_node.find_node("yeah.info")) run_command_in_context(context, sdist) self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
def _run_configure_and_build(self, bento_info, install_prefix): top_node = self.top_node create_fake_package_from_bento_info(top_node, bento_info) context = GlobalContext(None) options = PackageOptions.from_string(bento_info) context.register_package_options(options) cmd_argv = ["--prefix=%s" % install_prefix, "--exec-prefix=%s" % install_prefix] conf, configure = prepare_configure(top_node, bento_info, ConfigureYakuContext, cmd_argv) context.register_command("configure", configure) options_context = OptionsContext.from_command(configure) if not context.is_options_context_registered("configure"): context.register_options_context("configure", options_context) context.save_command_argv("configure", cmd_argv) run_command_in_context(conf, configure) bld, build = prepare_build(top_node, bento_info) run_command_in_context(bld, build) return context, conf, configure, bld, build
def _run_configure_and_build(self, bentos, bscripts=None, configure_argv=None, build_argv=None): conf, configure, bld, build = self._run_configure( bentos, bscripts, configure_argv, build_argv) run_command_in_context(bld, build) return conf, configure, bld, build
def _run_configure(self, bentos, bscripts=None, configure_argv=None, build_argv=None): top_node = self.top_node create_fake_package_from_bento_infos(top_node, bentos, bscripts) conf, configure = prepare_configure(top_node, bentos["bento.info"], self._configure_context) run_command_in_context(conf, configure) bld, build = prepare_build(top_node, bentos["bento.info"], self._build_context, build_argv) return conf, configure, bld, build
def test_simple_distutils(self): top_node = self.top_node create_fake_package_from_bento_info(top_node, BENTO_INFO_WITH_EXT) conf, configure = prepare_configure(top_node, BENTO_INFO_WITH_EXT, DistutilsConfigureContext) run_command_in_context(conf, configure) build = BuildCommand() opts = OptionsContext.from_command(build) bld = DistutilsBuildContext(None, [], opts, conf.pkg, top_node) run_command_in_context(bld, build)
def _test_run(self, bento_info): install_prefix = tempfile.mkdtemp() try: context, conf, configure, bld, build = self._run_configure_and_build(bento_info, install_prefix) install = InstallCommand() opts = OptionsContext.from_command(install) inst = ContextWithBuildDirectory(context, [], opts, conf.pkg, self.top_node) run_command_in_context(inst, install) finally: shutil.rmtree(install_prefix)
def _test_installed_sections(self, bento_infos, r_sections): create_fake_package_from_bento_infos(self.top_node, bento_infos) conf, configure = prepare_configure(self.run_node, bento_infos["bento.info"]) run_command_in_context(conf, configure) bld, build = prepare_build(self.top_node, bento_infos["bento.info"]) run_command_in_context(bld, build) sections = bld.section_writer.sections self.assertEqual(comparable_installed_sections(sections), comparable_installed_sections(r_sections))
def test_flags(self): bento_info = """\ Name: foo Flag: floupi Description: some floupi flag Default: true """ run_node = self.root.find_node(self.d) conf, configure = prepare_configure(run_node, bento_info, ConfigureYakuContext, ["--floupi=false"]) run_command_in_context(conf, configure)
def test_simple(self): help = HelpCommand() options = OptionsContext() for option in HelpCommand.common_options: options.add_option(option) global_context = GlobalContext(None, commands_registry=self.registry, options_registry=self.options_registry) pkg = PackageDescription() context = HelpContext(global_context, [], options, pkg, self.run_node) run_command_in_context(context, help)
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
def _test_installed_sections(self, bento_info, r_sections): create_fake_package_from_bento_info(self.top_node, bento_info) conf, configure = prepare_configure(self.run_node, bento_info) run_command_in_context(conf, configure) bld, build = prepare_build(self.top_node, bento_info) run_command_in_context(bld, build) sections = bld.section_writer.sections self.assertEqual(comparable_installed_sections(sections), comparable_installed_sections(r_sections))
def _test_dry_run(self, bento_info): install_prefix = tempfile.mkdtemp() try: context, conf, configure, bld, build = self._run_configure_and_build( bento_info, install_prefix) install = InstallCommand() opts = OptionsContext.from_command(install) inst = ContextWithBuildDirectory(context, ["--list-files"], opts, conf.pkg, self.top_node) run_command_in_context(inst, install) finally: shutil.rmtree(install_prefix)
def _execute_build(self, bento_info): create_fake_package_from_bento_info(self.top_node, bento_info) # FIXME: this should be done automatically in create_fake_package_from_bento_info self.top_node.make_node("bento.info").safe_write(bento_info) package = PackageDescription.from_string(bento_info) package_options = PackageOptions.from_string(bento_info) global_context = create_global_context(package, package_options, YakuBackend()) conf, configure = prepare_command(global_context, "configure", [], package, self.run_node) run_command_in_context(conf, configure) bld, build = prepare_command(global_context, "build", [], package, self.run_node) run_command_in_context(bld, build) return bld
def test_simple(self): n = self.top_node.make_node("doc/conf.py") n.parent.mkdir() n.write("") n = self.top_node.make_node("doc/contents.rst") n.write("") bento_info = "Name: foo" package = PackageDescription.from_string(bento_info) sphinx = SphinxCommand() opts = OptionsContext.from_command(sphinx) context = ContextWithBuildDirectory(None, [], opts, package, self.run_node) run_command_in_context(context, sphinx)
def test_simple_waf(self): from bento.backends.waf_backend import make_stream_logger from bento.backends.waf_backend import WafBackend top_node = self.top_node package = PackageDescription.from_string(BENTO_INFO_WITH_EXT) package_options = PackageOptions.from_string(BENTO_INFO_WITH_EXT) create_fake_package_from_bento_info(top_node, BENTO_INFO_WITH_EXT) top_node.make_node("bento.info").safe_write(BENTO_INFO_WITH_EXT) global_context = create_global_context(package, package_options, WafBackend()) conf, configure = prepare_command(global_context, "configure", [], package, top_node) run_command_in_context(conf, configure) bld, build = prepare_command(global_context, "build", [], package, top_node) bld.waf_context.logger = make_stream_logger("build", cStringIO()) run_command_in_context(bld, build)
def _run_configure_and_build(self, bentos, bscripts=None, configure_argv=None, build_argv=None): conf, configure, bld, build = self._run_configure(bentos, bscripts, configure_argv, build_argv) run_command_in_context(bld, build) return conf, configure, bld, build