Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implements attribute in ConanFile to provide opt-in automatic management of some options and settings. #14320

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conans/client/conanfile/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def run_configure_method(conanfile, down_options, profile_options, ref):
if hasattr(conanfile, "config_options"):
with conanfile_exception_formatter(conanfile, "config_options"):
conanfile.config_options()
else:
elif conanfile.activate_default_behaviors:
Copy link
Member

@memsharded memsharded Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't love the name, but challenging to find a better one. Some ideas:

  • auto_configuration = True
  • manage_options = True
  • auto_manage_library_type_configuration = True
  • auto_manage_library_configuration = True
  • auto_library_configuration = True
  • library_type_defaults = True

Generic list of things?

  • auto_manage = ["library_type_configuration", "app_type_configuration"]

  • auto_manage = ["library_configuration", "app_configuration"]

  • auto = ["library_configuration", "app_configuration"]

  • policies = ["auto_shared_fpic", "auto_header_only", "auto_cmake"]

  • auto_manage = ["shared_fpic", "header_only"]

  • rules, auto, defaults, implicits, auto_behaviors, mods, builtins, mixin, recipe_auto, recipe_defaults, config_templates

  • implements = ["auto_shared_fpic", "cmake_template"]

  • applies = [

  • sidecar = ["auto_shared_fpic", ]

  • recipe_presets = [

  • salt_and_pepper = ["auto_shared_fpic"

  • pre-cooked = ["auto_shared_

build_policy = "missing", upload_policy = "skip"

The language case would be a different one most likely:

  • languages = "C", "C++", "fortran"

Maybe "configuration" and "options" should be in the var name?

FINAL DECISION:

  • implements = ["auto_shared_fpic", "auto_header_only"]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. We should think of another shorter one if possible.

default_config_options(conanfile)

# Assign only the current package options values, but none of the dependencies
Expand All @@ -20,7 +20,7 @@ def run_configure_method(conanfile, down_options, profile_options, ref):
if hasattr(conanfile, "configure"):
with conanfile_exception_formatter(conanfile, "configure"):
conanfile.configure()
else:
elif conanfile.activate_default_behaviors:
default_configure(conanfile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default_configure(conanfile)
if ... => auto_shared_fpic_configure(conanfile)
if ... => auto_header_only_configure(conanfile)


self_options, up_options = conanfile.options.get_upstream_options(down_options, ref,
Expand Down
2 changes: 1 addition & 1 deletion conans/client/graph/compute_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ def run_validate_package_id(conanfile):
with conanfile_exception_formatter(conanfile, "package_id"):
with conanfile_remove_attr(conanfile, ['cpp_info', 'settings', 'options'], "package_id"):
conanfile.package_id()
else:
elif conanfile.activate_default_behaviors:
default_package_id(conanfile)
conanfile.info.validate()
2 changes: 2 additions & 0 deletions conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ConanFile:
default_options = None
package_type = None

activate_default_behaviors = False

provides = None
deprecated = None

Expand Down
2 changes: 2 additions & 0 deletions conans/test/functional/toolchains/cmake/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class App(ConanFile):
generators = "CMakeDeps"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
activate_default_behaviors = True

def generate(self):
tc = CMakeToolchain(self)
Expand Down Expand Up @@ -395,6 +396,7 @@ def test_toolchain_linux(self, build_type, cppstd, arch, libcxx, shared):
"CMAKE_EXE_LINKER_FLAGS": arch_str,
"COMPILE_DEFINITIONS": defines,
# fPIC is managed automatically depending on the shared option value
# if activate_default_behaviors=True
"CMAKE_POSITION_INDEPENDENT_CODE": "ON" if not shared else ""
}

Expand Down
10 changes: 7 additions & 3 deletions conans/test/integration/options/test_configure_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ConfigureOptionsTest(unittest.TestCase):
])
def test_methods_not_defined(self, settings_os, shared, fpic, header_only, result):
"""
Test that options are managed automatically when methods config_otpions and configure are not
defined.
Test that options are managed automatically when methods config_options and configure are not
defined and activate_default_behaviors=True.
Check that header only package gets its unique package ID.
"""
client = TestClient()
Expand All @@ -39,6 +39,7 @@ class Pkg(ConanFile):
settings = "os", "compiler", "arch", "build_type"
options = {{"shared": [True, False], "fPIC": [True, False], "header_only": [True, False]}}
default_options = {{"shared": {shared}, "fPIC": {fpic}, "header_only": {header_only}}}
activate_default_behaviors = True

def build(self):
shared = self.options.get_safe("shared")
Expand Down Expand Up @@ -73,7 +74,7 @@ def build(self):
])
def test_optout(self, settings_os, shared, fpic, header_only, result):
"""
Test that options are not managed automatically when methods are defined.
Test that options are not managed automatically when methods are defined even if activate_default_behaviors=True.
Check that header only package gets its unique package ID.
"""
client = TestClient()
Expand All @@ -84,6 +85,7 @@ class Pkg(ConanFile):
settings = "os", "compiler", "arch", "build_type"
options = {{"shared": [True, False], "fPIC": [True, False], "header_only": [True, False]}}
default_options = {{"shared": {shared}, "fPIC": {fpic}, "header_only": {header_only}}}
activate_default_behaviors = True

def config_options(self):
pass
Expand Down Expand Up @@ -131,6 +133,7 @@ class Pkg(ConanFile):
settings = "os", "compiler", "arch", "build_type"
options = {{"shared": [True, False], "fPIC": [True, False], "header_only": [True, False]}}
default_options = {{"shared": {shared}, "fPIC": {fpic}, "header_only": {header_only}}}
activate_default_behaviors = True

def config_options(self):
default_config_options(self)
Expand Down Expand Up @@ -162,6 +165,7 @@ def test_header_package_type_pid(self):
class Pkg(ConanFile):
settings = "os", "compiler", "arch", "build_type"
package_type = "header-library"
activate_default_behaviors = True

""")
client.save({"conanfile.py": conanfile})
Expand Down
4 changes: 2 additions & 2 deletions conans/test/integration/package_id/test_default_package_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_default_package_id_options(typedep, typeconsumer, different_id):
"""
c = TestClient()
dep = GenConanfile("dep", "0.1").with_option("myopt", [True, False]) \
.with_package_type(typedep)
.with_package_type(typedep).with_class_attribute("activate_default_behaviors=True")
consumer = GenConanfile("consumer", "0.1").with_requires("dep/0.1")\
.with_package_type(typeconsumer)
.with_package_type(typeconsumer).with_class_attribute("activate_default_behaviors=True")

c.save({"dep/conanfile.py": dep,
"consumer/conanfile.py": consumer})
Expand Down