From bd9e19da3c7da3259772dfec77ab35649aea8e9c Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Sat, 12 Dec 2020 13:08:47 +0300 Subject: [PATCH] updated in accordance with the new pyreq API * Removed the decorator, because it's not applicable to new python_requires API. * Similarly removed private _Meta class, which was hacky anyway. * Removed automatic dependency on b2 package in development mode. * Updated tests. --- README.adoc | 64 ++++--------------- conanfile.py | 59 +---------------- test_package/build-targets/conanfile.py | 6 +- test_package/build_folder/conanfile.py | 6 +- test_package/conanfile.py | 9 ++- test_package/custom_b2_reference/conanfile.py | 22 ------- .../custom_build_requires/conanfile.py | 24 ------- test_package/default-properties/conanfile.py | 7 +- test_package/explicit_require_b2/conanfile.py | 14 ---- test_package/explicit_require_b2/jamroot.jam | 13 ---- test_package/explicit_require_b2/main.cpp | 9 --- test_package/free/conanfile.py | 6 +- test_package/minimal/conanfile.py | 6 +- test_package/modules/get_helper_package.py | 1 - test_package/options/conanfile.py | 6 +- test_package/pre-generated/conanfile.py | 6 +- test_package/preexisting-toolset/conanfile.py | 6 +- test_package/propagate-subdir/conanfile.py | 6 +- test_package/properties/conanfile.py | 16 ++--- test_package/source_folder/conanfile.py | 6 +- 20 files changed, 69 insertions(+), 223 deletions(-) delete mode 100644 test_package/custom_b2_reference/conanfile.py delete mode 100644 test_package/custom_build_requires/conanfile.py delete mode 100644 test_package/explicit_require_b2/conanfile.py delete mode 100644 test_package/explicit_require_b2/jamroot.jam delete mode 100644 test_package/explicit_require_b2/main.cpp diff --git a/README.adoc b/README.adoc index 4fc4083..66c615d 100644 --- a/README.adoc +++ b/README.adoc @@ -23,26 +23,24 @@ package: [source,python] ---- -from conans import python_requires -b2 = python_requires("b2-helper/[>=0.7.1]@grisumbras/stable") +class MyConan(ConanFile): + python_requires = "b2-helper/[>=0.7.1]@grisumbras/stable" ---- == Usage -=== Using decorator +=== Using mixin -The simplest way to use the package is via the class decorator +The simplest way to use the package is via the mixin class: [source,python] ---- -@b2.build_with_b2 class MyConan(ConanFile): - name = "..." - version = "..." - settings = "os", "arch", "compiler", "build_type" + python_requires = "b2-helper/[>=0.7.1]@grisumbras/stable" + python_requires_extend = "b2-helper.Mixin" ---- -The decorator provides default implementations for methods `build`, `package` +The mixin provides default implementations for methods `build`, `package` and `test`. In order for it to work without any customization, project's jamroot file should be in `conanfile.source_folder` and the project should require no configuration beyond toolset initialization. If customization is @@ -50,8 +48,9 @@ required, the `ConanFile` subclass should override method `b2_setup_builder`: [source,python] ---- -@b2.build_with_b2 class MyConan(ConanFile): + python_requires_extend = "b2-helper.Mixin" + def b2_setup_builder(self, builder): builder.source_folder = "src" builder.build_folder = "build" @@ -66,52 +65,15 @@ If you need to build specific targets, you can sepcify them via [source,python] ---- -@b2.build_with_b2 class MyConan1(ConanFile): - b2_build_targets = "foo" + python_requires_extend = "b2-helper.Mixin" + b2_build_targets = "foo" -@b2.build_with_b2 class MyConan2(ConanFile): - b2_build_targets = "foo", "bar" ----- - -By default the decorator adds a build requirement on Boost.Build -_in development mode_. If you wish to disable that set its keyword argument -`build_require_b2` to `False`: - -[source,python] ----- -@b2.build_with_b2(build_require_b2=False) -class MyConan(ConanFile): - ... + python_requires_extend = "b2-helper.Mixin" + b2_build_targets = "foo", "bar" ---- -Alternatively, if you want to use a specific version of Boost.Build, set that -keyword argument to a conan reference: - -[source,python] ----- -@b2.build_with_b2(build_require_b2="boost_build/4.0.0@mycompany/stable) -class MyConan(ConanFile): - ... ----- - -=== Using mixin - -Another convenient way to use the package is via a mixin class: - -[source,python] ----- -class MyConan(b2.Mixin, ConanFile): - name = "..." - version = "..." - settings = "os", "arch", "compiler", "build_type" ----- - -Using mixin is equivalent to using the class decorator. Note, that since -`ConanFile` class defines methods `build`, `package` and so on, it is important -to put the mixin before it in the base class list. - === Using helper The helper can be used by itself pretty much the same way as standard build diff --git a/conanfile.py b/conanfile.py index 0b3ad87..27d8f80 100644 --- a/conanfile.py +++ b/conanfile.py @@ -31,13 +31,6 @@ def package_info(self): self.info.header_only() -b2_reference = "b2/[>=4.0.0]" - - -def join_arguments(args): - return " ".join(filter(None, args)) - - def jamify(s): """ Convert a valid Python identifier to a string that follows Boost.Build @@ -640,12 +633,6 @@ def b2_setup_builder(self, builder): return builder - def build_requirements(self): - """Adds build requirement on b2 in development mode.""" - - if getattr(self, "_b2_reference", None) and self.develop: - self.build_requires(self._b2_reference) - def build(self): """Configures and builds default targets.""" @@ -791,6 +778,7 @@ def configure(self): file.write(" <%s>%s\n" % (k, path_escaped(v))) file.write(" ;\n") + def build(self, *targets): """ Run Boost.Build and build targets `targets` using the active options, @@ -842,49 +830,8 @@ def _build(self, targets): self.conanfile.run(join_arguments(args)) -def build_with_b2(wrapped=None, build_require_b2=True): - def helper(wrapped): - meta = metaclass(build_require_b2) - return six.add_metaclass(meta)(wrapped) - - if wrapped is None: - return helper - else: - return helper(wrapped) - - -def metaclass(build_require_b2=True): - if build_require_b2 and not isinstance(build_require_b2, six.string_types): - return _Meta - else: - class _MetaWithCustomRef(_Meta): - reference = build_require_b2 - return _MetaWithCustomRef - - -def _subclass_index(lst, cls): - index = [i for (i, base) in enumerate(lst) if issubclass(base, cls)] - if index: - return index[0] - else: - return -1 - - -class _Meta(type): - reference = b2_reference - - def __new__(cls, name, bases, namespace): - mixin_index = _subclass_index(bases, Mixin) - if mixin_index < 0: - cf_index = _subclass_index(bases, ConanFile) - if cf_index > -1: - bases = list(bases) - bases.insert(cf_index, Mixin) - bases = tuple(bases) - - namespace["_b2_reference"] = cls.reference - - return type.__new__(cls, name, bases, namespace) +def join_arguments(args): + return " ".join(filter(None, args)) def path_escaped(path): diff --git a/test_package/build-targets/conanfile.py b/test_package/build-targets/conanfile.py index 74480cd..2a6f941 100644 --- a/test_package/build-targets/conanfile.py +++ b/test_package/build-targets/conanfile.py @@ -9,11 +9,13 @@ ConanFile, tools, ) -from get_helper_package import b2 +from get_helper_package import package_ref -@b2.build_with_b2 class MyConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.jam", "*.cpp" b2_build_targets = "install1", "install2" diff --git a/test_package/build_folder/conanfile.py b/test_package/build_folder/conanfile.py index badfa57..538b236 100644 --- a/test_package/build_folder/conanfile.py +++ b/test_package/build_folder/conanfile.py @@ -5,12 +5,14 @@ from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref import os -@b2.build_with_b2 class B2ToolTestConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.cpp", "*.jam" def b2_setup_builder(self, builder): diff --git a/test_package/conanfile.py b/test_package/conanfile.py index f5b20c1..ab7f43f 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,3 +1,9 @@ +# Copyright (c) 2020 Dmitry Arkhipov +# +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) + + from conans import ( ConanFile, tools, @@ -8,9 +14,6 @@ class TestB2Helper(ConanFile): _tests = ( "minimal", - "explicit_require_b2", - "custom_build_requires", - "custom_b2_reference", "source_folder", "build_folder", "options", diff --git a/test_package/custom_b2_reference/conanfile.py b/test_package/custom_b2_reference/conanfile.py deleted file mode 100644 index c1cb33b..0000000 --- a/test_package/custom_b2_reference/conanfile.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2019 Dmitry Arkhipov -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) - - -from conans import ConanFile -from get_helper_package import b2 - - -@b2.build_with_b2(build_require_b2="boost_build/1.69.0@bincrafters/stable") -class MyConan(ConanFile): - def build_requirements(self): - super(MyConan, self).build_requirements() - b2_ref = str(self.build_requires["boost_build"]) - assert(b2_ref == "boost_build/1.69.0@bincrafters/stable") - - def build(self): - pass - - def package(self): - pass diff --git a/test_package/custom_build_requires/conanfile.py b/test_package/custom_build_requires/conanfile.py deleted file mode 100644 index f6c906a..0000000 --- a/test_package/custom_build_requires/conanfile.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2019 Dmitry Arkhipov -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) - - -from conans import ConanFile -from get_helper_package import b2 -import os - - -@b2.build_with_b2 -class MyConan(ConanFile): - exports_sources = "jamroot*", "*.cpp" - - def build_requirements(self): - f = open("marker", "w") - f.close() - - def build(self): - assert(os.path.exists(os.path.join("..", "..", "marker"))) - - def package(self): - pass diff --git a/test_package/default-properties/conanfile.py b/test_package/default-properties/conanfile.py index ae4f338..8522c09 100644 --- a/test_package/default-properties/conanfile.py +++ b/test_package/default-properties/conanfile.py @@ -5,11 +5,14 @@ from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref -@b2.build_with_b2 class B2ToolTestConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" + settings = "os", "compiler", "build_type", "arch", options = {"shared": [True, False]} default_options = {"shared": False} diff --git a/test_package/explicit_require_b2/conanfile.py b/test_package/explicit_require_b2/conanfile.py deleted file mode 100644 index 8723271..0000000 --- a/test_package/explicit_require_b2/conanfile.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2019 Dmitry Arkhipov -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) - - -import os -from conans import ConanFile -from get_helper_package import b2 - - -@b2.build_with_b2(build_require_b2=True) -class MyConan(ConanFile): - exports_sources = "jamroot*", "*.cpp" diff --git a/test_package/explicit_require_b2/jamroot.jam b/test_package/explicit_require_b2/jamroot.jam deleted file mode 100644 index 9ff872e..0000000 --- a/test_package/explicit_require_b2/jamroot.jam +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2019 Dmitry Arkhipov -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) - - -import package ; - -project my-project ; - -exe main : main.cpp ; -package.install install my-project : : main ; -explicit install ; diff --git a/test_package/explicit_require_b2/main.cpp b/test_package/explicit_require_b2/main.cpp deleted file mode 100644 index a135d6a..0000000 --- a/test_package/explicit_require_b2/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2019 Dmitry Arkhipov - * - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) - */ - - -int main() {} diff --git a/test_package/free/conanfile.py b/test_package/free/conanfile.py index a15baeb..ed4aed8 100644 --- a/test_package/free/conanfile.py +++ b/test_package/free/conanfile.py @@ -5,12 +5,14 @@ from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref import os -@b2.build_with_b2 class B2ToolTestConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.cpp", "*.hpp", "*.jam" def b2_setup_builder(self, builder): diff --git a/test_package/minimal/conanfile.py b/test_package/minimal/conanfile.py index 57c9996..07bf7ae 100644 --- a/test_package/minimal/conanfile.py +++ b/test_package/minimal/conanfile.py @@ -5,11 +5,13 @@ from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref -b2.build_with_b2 class MyConan(ConanFile): """This is pretty much the bare minimum package definition""" + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.jam", "*.cpp" diff --git a/test_package/modules/get_helper_package.py b/test_package/modules/get_helper_package.py index 9a00177..5363dae 100644 --- a/test_package/modules/get_helper_package.py +++ b/test_package/modules/get_helper_package.py @@ -9,4 +9,3 @@ package_ref = os.environ.get("PACKAGE_REFERENCE") -b2 = python_requires(package_ref) diff --git a/test_package/options/conanfile.py b/test_package/options/conanfile.py index f5e8c0c..fde6af0 100644 --- a/test_package/options/conanfile.py +++ b/test_package/options/conanfile.py @@ -5,11 +5,13 @@ from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref -@b2.build_with_b2 class B2ToolTestConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.cpp", "*.jam" def b2_setup_builder(self, builder): diff --git a/test_package/pre-generated/conanfile.py b/test_package/pre-generated/conanfile.py index f7aecd5..9b4e774 100644 --- a/test_package/pre-generated/conanfile.py +++ b/test_package/pre-generated/conanfile.py @@ -8,14 +8,16 @@ ConanFile, tools, ) -from get_helper_package import b2 +from get_helper_package import package_ref import os -@b2.build_with_b2 class MyConan(ConanFile): """This package bootstraps its own project-config.jam""" + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.bat", "*.sh", "*.jam", "*.cpp" def build(self): diff --git a/test_package/preexisting-toolset/conanfile.py b/test_package/preexisting-toolset/conanfile.py index b5950b8..8fcc19d 100644 --- a/test_package/preexisting-toolset/conanfile.py +++ b/test_package/preexisting-toolset/conanfile.py @@ -6,11 +6,13 @@ import os from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref -@b2.build_with_b2 class MyConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.jam" def b2_setup_builder(self, builder): diff --git a/test_package/propagate-subdir/conanfile.py b/test_package/propagate-subdir/conanfile.py index 733b27e..c22529d 100644 --- a/test_package/propagate-subdir/conanfile.py +++ b/test_package/propagate-subdir/conanfile.py @@ -5,11 +5,13 @@ from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref -@b2.build_with_b2 class B2ToolTestConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.cpp", "*.hpp", "*.jam" def b2_setup_builder(self, builder): diff --git a/test_package/properties/conanfile.py b/test_package/properties/conanfile.py index 90d1145..fdfccf3 100644 --- a/test_package/properties/conanfile.py +++ b/test_package/properties/conanfile.py @@ -8,28 +8,24 @@ ConanFile, tools, ) -from get_helper_package import b2 +from get_helper_package import package_ref import os -@b2.build_with_b2 class B2ToolTestConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "*.cpp", "*.jam" def b2_setup_builder(self, builder): ps = builder.properties ps.threading = "multi" ps.link = "shared" - return builder def package(self): super(B2ToolTestConan, self).package() - if tools.os_info.is_windows: - ext = ".exe" - else: - ext = "" - assert(os.path.exists( - os.path.join(self.package_folder, "bin", "main" + ext) - )) + exe = "main" + (".exe" if tools.os_info.is_windows else "") + assert(os.path.exists(os.path.join(self.package_folder, "bin", exe))) diff --git a/test_package/source_folder/conanfile.py b/test_package/source_folder/conanfile.py index ca2907c..3ff2971 100644 --- a/test_package/source_folder/conanfile.py +++ b/test_package/source_folder/conanfile.py @@ -5,11 +5,13 @@ from conans import ConanFile -from get_helper_package import b2 +from get_helper_package import package_ref -@b2.build_with_b2 class B2ToolTestConan(ConanFile): + build_requires = "b2/[*]" + python_requires = package_ref + python_requires_extend = "b2-helper.Mixin" exports_sources = "src/*" def b2_setup_builder(self, builder):