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

drop compat_app #12484

Merged
merged 2 commits into from
Nov 8, 2022
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
52 changes: 3 additions & 49 deletions conans/client/graph/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@
_default_compat = """\
# This file was generated by Conan. Remove this comment if you edit this file or Conan
# will destroy your changes.
from app_compat import app_compat
from cppstd_compat import cppstd_compat


def compatibility(conanfile):
if conanfile.package_type == "application":
return app_compat(conanfile)

configs = cppstd_compat(conanfile)
# TODO: Append more configurations for your custom compatibility rules
return configs
Expand Down Expand Up @@ -52,67 +48,25 @@ def cppstd_compat(conanfile):
"""


_default_app_compat = """\
# This file was generated by Conan. Remove this comment if you edit this file or Conan
# will destroy your changes.
from conan.tools.build import default_cppstd

def app_compat(conanfile):
# Will try to find a binary for the latest compiler version. In case it is not defined
# os, and arch should be at least defined.
os_ = conanfile.settings.get_safe("os")
arch = conanfile.settings.get_safe("arch")
if os_ is None or arch is None:
return

compiler = conanfile.settings.get_safe("compiler")
compiler = compiler or {"Windows": "msvc", "Macos": "apple-clang"}.get(os_, "gcc")
configuration = {"compiler": compiler}

compiler_version = conanfile.settings.get_safe("compiler.version")
if not compiler_version:
# Latest compiler version
definition = conanfile.settings.get_definition()
compiler_versions = definition["compiler"][compiler]["version"]
compiler_version = compiler_versions[-1] # Latest

configuration["compiler.version"] = compiler_version

build_type = conanfile.settings.get_safe("build_type")
configuration["build_type"] = build_type or "Release"

if compiler == "msvc":
runtime = conanfile.settings.get_safe("compiler.runtime")
if runtime is None:
configuration["compiler.runtime"] = "dynamic"
configuration["compiler.runtime_type"] = configuration["build_type"]

configuration["compiler.cppstd"] = conanfile.settings.get_safe("compiler.cppstd") or default_cppstd(conanfile, compiler, compiler_version)
return [{"settings": [(k, v) for k, v in configuration.items()]}]
"""


def get_binary_compatibility_file_paths(cache):
compatible_folder = os.path.join(cache.plugins_path, "compatibility")
compatibility_file = os.path.join(compatible_folder, "compatibility.py")
app_compat_file = os.path.join(compatible_folder, "app_compat.py")
cppstd_compat_file = os.path.join(compatible_folder, "cppstd_compat.py")
return compatibility_file, app_compat_file, cppstd_compat_file
return compatibility_file, cppstd_compat_file


def migrate_compatibility_files(cache):
from conans.client.migrations import update_file

compatibility_file, app_compat_file, cppstd_compat_file = get_binary_compatibility_file_paths(cache)
compatibility_file, cppstd_compat_file = get_binary_compatibility_file_paths(cache)
update_file(compatibility_file, _default_compat)
update_file(app_compat_file, _default_app_compat)
update_file(cppstd_compat_file, _default_cppstd_compat)


class BinaryCompatibility:

def __init__(self, cache):
compatibility_file, app_compat_file, cppstd_compat_file = get_binary_compatibility_file_paths(cache)
compatibility_file, cppstd_compat_file = get_binary_compatibility_file_paths(cache)
mod, _ = load_python_file(compatibility_file)
self._compatibility = mod.compatibility

Expand Down
70 changes: 0 additions & 70 deletions conans/test/integration/package_id/test_cache_compatibles.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,76 +132,6 @@ def validate(self):

class TestDefaultCompat:

def test_default_app_compat(self):
c = TestClient()
save(c.cache.default_profile_path, "")
conanfile = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
name = "app"
version = "1.0"
package_type = "application"
settings = "os", "arch", "compiler", "build_type"
""")
c.save({"conanfile.py": conanfile, "profile_build": "[settings]\nos=Windows\narch=x86_64"})
os_ = "Windows"
build_type = "Release"
arch = "x86_64"
compiler = "msvc"
version = "193" # This is latest
cppstd = "14"
runtime = "dynamic"

c.run(f"create . -s os={os_} -s arch={arch} -s build_type={build_type} "
f"-s compiler={compiler} "
f"-s compiler.version={version} -s compiler.cppstd={cppstd} "
f"-s compiler.runtime={runtime} -pr:b=profile_build")
package_id = c.created_package_id("app/1.0")
c.run(f"install --requires=app/1.0@ -s os={os_} -s arch={arch} -pr:b=profile_build")
assert "app/1.0: Main binary package 'e340edd75790e7156c595edebd3d98b10a2e091e' missing."\
f"Using compatible package '{package_id}'"

def test_default_app_compat_c(self):
c = TestClient()
save(c.cache.default_profile_path, "")
conanfile = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
name = "app"
version = "1.0"
package_type = "application"
settings = "os", "arch", "compiler", "build_type"

def package_id(self):
try: # This might not be defined if compiler=None
del self.info.settings.compiler.cppstd
except:
pass
""")
c.save({"conanfile.py": conanfile, "profile_build": "[settings]\nos=Windows\narch=x86_64"})
os_ = "Windows"
build_type = "Release"
arch = "x86_64"
compiler = "msvc"
version = "193"
cppstd = "14"
runtime = "dynamic"
c.run(f"create . -s os={os_} -s arch={arch} -s build_type={build_type} "
f"-s compiler={compiler} "
f"-s compiler.version={version} -s compiler.cppstd={cppstd} "
f"-s compiler.runtime={runtime} -pr:b=profile_build")
package_id1 = c.created_package_id("app/1.0")
c.run(f"create . -s os={os_} -s arch={arch} -s build_type={build_type} "
f"-s compiler={compiler} "
f"-s compiler.version={version} -s compiler.cppstd=17 "
f"-s compiler.runtime={runtime} -pr:b=profile_build")
package_id2 = c.created_package_id("app/1.0")
assert package_id1 == package_id2 # It does not depend on 'compiler.cppstd'

c.run(f"install --requires=app/1.0@ -s os={os_} -s arch={arch} -pr:b=profile_build")
assert "app/1.0: Main binary package 'e340edd75790e7156c595edebd3d98b10a2e091e' missing."\
f"Using compatible package '{package_id1}'"

def test_default_cppstd_compatibility(self):
c = TestClient()
save(c.cache.default_profile_path, "")
Expand Down
3 changes: 1 addition & 2 deletions conans/test/integration/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
@pytest.mark.parametrize(["plugin_path", "string_replace", "new_string"],
[("profile.py", "msvc", "EME_ESE_VC"),
("compatibility/compatibility.py", "conanfile", "conian_file"),
("compatibility/cppstd_compat.py", "conanfile", "conian_file"),
("compatibility/app_compat.py", "conanfile", "conian_file")])
("compatibility/cppstd_compat.py", "conanfile", "conian_file")])
def test_migration_profile_checker_plugin(plugin_path, string_replace, new_string):
t = TestClient()
# Any command generates the profile and compatibility plugin files
Expand Down