Skip to content

Commit 9d3af22

Browse files
authored
Test to show that a static-library recipe won't change its pkg_type when header_only option is used (#17230)
* Test to show that a static-library recipe won't change its pkg_type when header_only option is used * Add warning
1 parent 9a7684e commit 9d3af22

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

conans/model/pkg_type.py

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def deduce_from_options():
5858
if conanfile_type is PackageType.UNKNOWN:
5959
raise ConanException(f"{conanfile}: Package type is 'library',"
6060
" but no 'shared' option declared")
61+
elif any(option in conanfile.options for option in ["shared", "header_only"]):
62+
conanfile.output.warning(f"{conanfile}: package_type '{conanfile_type}' is defined, "
63+
"but 'shared' and/or 'header_only' options are present. "
64+
"The package_type will have precedence over the options "
65+
"regardless of their value.")
6166
conanfile.package_type = conanfile_type
6267
else: # automatic default detection with option shared/header-only
6368
conanfile.package_type = deduce_from_options()

test/integration/graph/core/test_auto_package_type.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import textwrap
2+
13
import pytest
24

35
from conan.test.utils.tools import TestClient
@@ -36,10 +38,29 @@ def test_auto_package_type(conanfile):
3638
c.run("graph info . --filter package_type")
3739
assert "package_type: static-library" in c.out
3840
c.run("graph info . --filter package_type -o shared=True")
41+
assert "The package_type will have precedence over the options" not in c.out
3942
assert "package_type: shared-library" in c.out
4043
c.run("graph info . --filter package_type -o shared=True -o header_only=False")
4144
assert "package_type: shared-library" in c.out
4245
c.run("graph info . --filter package_type -o header_only=True")
4346
assert "package_type: header-library" in c.out
4447
c.run("graph info . --filter package_type -o header_only=True -o shared=False")
4548
assert "package_type: header-library" in c.out
49+
50+
def test_package_type_and_header_library():
51+
""" Show that forcing a package_type and header_only=True does not change the package_type"""
52+
tc = TestClient(light=True)
53+
tc.save({"conanfile.py": textwrap.dedent("""
54+
from conan import ConanFile
55+
56+
class Pkg(ConanFile):
57+
package_type = "static-library"
58+
options = {"header_only": [True, False]}
59+
60+
""")})
61+
tc.run("graph info . --filter package_type -o &:header_only=False")
62+
assert "package_type: static-library" in tc.out
63+
assert "The package_type will have precedence over the options" in tc.out
64+
tc.run("graph info . --filter package_type -o &:header_only=True")
65+
assert "package_type: static-library" in tc.out
66+
assert "The package_type will have precedence over the options" in tc.out

0 commit comments

Comments
 (0)