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

Test to show that a static-library recipe won't change its pkg_type when header_only option is used #17230

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions conans/model/pkg_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def deduce_from_options():
if conanfile_type is PackageType.UNKNOWN:
raise ConanException(f"{conanfile}: Package type is 'library',"
" but no 'shared' option declared")
elif any(option in conanfile.options for option in ["shared", "header_only"]):
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
conanfile.output.warning(f"{conanfile}: package_type '{conanfile_type}' is defined, "
"but 'shared' and/or 'header_only' options are present. "
"The package_type will have precedence over the options "
"regardless of their value.")
conanfile.package_type = conanfile_type
else: # automatic default detection with option shared/header-only
conanfile.package_type = deduce_from_options()
21 changes: 21 additions & 0 deletions test/integration/graph/core/test_auto_package_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import textwrap

import pytest

from conan.test.utils.tools import TestClient
Expand Down Expand Up @@ -36,10 +38,29 @@ def test_auto_package_type(conanfile):
c.run("graph info . --filter package_type")
assert "package_type: static-library" in c.out
c.run("graph info . --filter package_type -o shared=True")
assert "The package_type will have precedence over the options" not in c.out
assert "package_type: shared-library" in c.out
c.run("graph info . --filter package_type -o shared=True -o header_only=False")
assert "package_type: shared-library" in c.out
c.run("graph info . --filter package_type -o header_only=True")
assert "package_type: header-library" in c.out
c.run("graph info . --filter package_type -o header_only=True -o shared=False")
assert "package_type: header-library" in c.out

def test_package_type_and_header_library():
""" Show that forcing a package_type and header_only=True does not change the package_type"""
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
tc = TestClient(light=True)
tc.save({"conanfile.py": textwrap.dedent("""
from conan import ConanFile

class Pkg(ConanFile):
package_type = "static-library"
options = {"header_only": [True, False]}

""")})
tc.run("graph info . --filter package_type -o &:header_only=False")
assert "package_type: static-library" in tc.out
assert "The package_type will have precedence over the options" in tc.out
tc.run("graph info . --filter package_type -o &:header_only=True")
assert "package_type: static-library" in tc.out
assert "The package_type will have precedence over the options" in tc.out