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

Feature/conan v2 error #8399

Merged
merged 14 commits into from Jan 27, 2021
6 changes: 2 additions & 4 deletions conan/tools/cmake/cmake.py
Expand Up @@ -10,7 +10,7 @@
from conans.client.tools.oss import cpu_count, args_to_string
from conans.errors import ConanException
from conans.model.version import Version
from conans.util.conan_v2_mode import conan_v2_behavior
from conans.util.conan_v2_mode import conan_v2_error
from conans.util.files import mkdir


Expand Down Expand Up @@ -101,9 +101,7 @@ def _build(self, build_type=None, target=None):
"single-config build systems")

bt = build_type or self._conanfile.settings.get_safe("build_type")
if not bt:
conan_v2_behavior("build_type setting should be defined.",
v1_behavior=self._conanfile.output.warn)
conan_v2_error("build_type setting should be defined.", not bt)

if bt and self._is_multiconfiguration:
build_config = "--config %s" % bt
Expand Down
8 changes: 1 addition & 7 deletions conans/client/api/conan_api.py
@@ -1,5 +1,4 @@
import os
import sys
import time

from tqdm import tqdm
Expand All @@ -10,11 +9,9 @@
from conans.client.migrations import ClientMigrator
from conans.client.tools.env import environment_append
from conans.client.userio import UserIO
from conans.errors import NoRemoteAvailable, ConanException
from conans.errors import NoRemoteAvailable
from conans.model.version import Version
from conans.paths import get_conan_user_home
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.env_reader import get_env
from conans.util.files import exception_message_safe


Expand Down Expand Up @@ -55,9 +52,6 @@ def __init__(self, cache_folder=None, quiet=True, user_io=None, http_requester=N
# Migration system
migrator = ClientMigrator(self.cache_folder, Version(client_version), self.out)
migrator.migrate()
if not get_env(CONAN_V2_MODE_ENVVAR, False):
# FIXME Remove in Conan 2.0
sys.path.append(os.path.join(self.cache_folder, "python"))

@api_method
def user_list(self, remote_name=None):
Expand Down
10 changes: 3 additions & 7 deletions conans/client/build/autotools_environment.py
Expand Up @@ -18,7 +18,7 @@
from conans.client.tools.win import unix_path
from conans.errors import ConanException
from conans.model.build_info import DEFAULT_BIN, DEFAULT_INCLUDE, DEFAULT_LIB, DEFAULT_SHARE
from conans.util.conan_v2_mode import conan_v2_behavior
from conans.util.conan_v2_mode import conan_v2_error
from conans.util.files import get_abs_path


Expand Down Expand Up @@ -49,9 +49,7 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False):
self._build_type = conanfile.settings.get_safe("build_type")

self._compiler = conanfile.settings.get_safe("compiler")
if not self._compiler:
conan_v2_behavior("compiler setting should be defined.",
v1_behavior=self._conanfile.output.warn)
conan_v2_error("compiler setting should be defined.", not self._compiler)

self._compiler_version = conanfile.settings.get_safe("compiler.version")
self._compiler_runtime = conanfile.settings.get_safe("compiler.runtime")
Expand Down Expand Up @@ -235,9 +233,7 @@ def _is_flag_in_args(varname, args):
def make(self, args="", make_program=None, target=None, vars=None):
if not self._conanfile.should_build:
return
if not self._build_type:
conan_v2_behavior("build_type setting should be defined.",
v1_behavior=self._conanfile.output.warn)
conan_v2_error("build_type setting should be defined.", not self._build_type)
make_program = os.getenv("CONAN_MAKE_PROGRAM") or make_program or "make"
with environment_append(vars or self.vars):
str_args = args_to_string(args)
Expand Down
10 changes: 3 additions & 7 deletions conans/client/build/cmake.py
Expand Up @@ -19,7 +19,7 @@
from conans.client.tools.oss import cpu_count, args_to_string
from conans.errors import ConanException
from conans.model.version import Version
from conans.util.conan_v2_mode import conan_v2_behavior
from conans.util.conan_v2_mode import conan_v2_error
from conans.util.config_parser import get_bool_from_text
from conans.util.files import mkdir, get_abs_path, walk, decode_text
from conans.util.runners import version_runner
Expand Down Expand Up @@ -258,9 +258,7 @@ def get_dir(folder, origin):

def _run(self, command):
compiler = self._settings.get_safe("compiler")
if not compiler:
conan_v2_behavior("compiler setting should be defined.",
v1_behavior=self._conanfile.output.warn)
conan_v2_error("compiler setting should be defined.", not compiler)
the_os = self._settings.get_safe("os")
is_clangcl = the_os == "Windows" and compiler == "clang"
is_msvc = compiler == "Visual Studio"
Expand Down Expand Up @@ -323,9 +321,7 @@ def configure(self, args=None, defs=None, source_dir=None, build_dir=None,
def build(self, args=None, build_dir=None, target=None):
if not self._conanfile.should_build:
return
if not self._build_type:
conan_v2_behavior("build_type setting should be defined.",
v1_behavior=self._conanfile.output.warn)
conan_v2_error("build_type setting should be defined.", not self._build_type)
self._build(args, build_dir, target)

def _build(self, args=None, build_dir=None, target=None):
Expand Down
10 changes: 3 additions & 7 deletions conans/client/build/meson.py
Expand Up @@ -11,7 +11,7 @@
from conans.errors import ConanException
from conans.model.build_info import DEFAULT_BIN, DEFAULT_INCLUDE, DEFAULT_LIB
from conans.model.version import Version
from conans.util.conan_v2_mode import conan_v2_behavior
from conans.util.conan_v2_mode import conan_v2_error
from conans.util.files import decode_text, get_abs_path, mkdir
from conans.util.runners import version_runner

Expand All @@ -32,9 +32,7 @@ def __init__(self, conanfile, backend=None, build_type=None, append_vcvars=False
self._os = self._ss("os")

self._compiler = self._ss("compiler")
if not self._compiler:
conan_v2_behavior("compiler setting should be defined.",
v1_behavior=self._conanfile.output.warn)
conan_v2_error("compiler setting should be defined.", not self._compiler)

self._compiler_version = self._ss("compiler.version")

Expand Down Expand Up @@ -214,9 +212,7 @@ def _run_meson_command(self, subcommand=None, args=None, build_dir=None):
def build(self, args=None, build_dir=None, targets=None):
if not self._conanfile.should_build:
return
if not self._build_type:
conan_v2_behavior("build_type setting should be defined.",
v1_behavior=self._conanfile.output.warn)
conan_v2_error("build_type setting should be defined.", not self._build_type)
self._run_ninja_targets(args=args, build_dir=build_dir, targets=targets)

def install(self, args=None, build_dir=None):
Expand Down
13 changes: 6 additions & 7 deletions conans/client/conan_api.py
Expand Up @@ -63,8 +63,7 @@
from conans.search.search import search_recipes
from conans.tools import set_global_instances
from conans.unicode import get_cwd
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.env_reader import get_env
from conans.util.conan_v2_mode import conan_v2_error
from conans.util.files import exception_message_safe, mkdir, save_files, load, save
from conans.util.log import configure_logger
from conans.util.tracer import log_command, log_exception
Expand Down Expand Up @@ -237,9 +236,9 @@ def __init__(self, cache_folder=None, output=None, user_io=None, http_requester=
migrator = ClientMigrator(self.cache_folder, Version(client_version), self.out)
migrator.migrate()
check_required_conan_version(self.cache_folder, self.out)
if not get_env(CONAN_V2_MODE_ENVVAR, False):
# FIXME Remove in Conan 2.0
sys.path.append(os.path.join(self.cache_folder, "python"))
python_folder = os.path.join(self.cache_folder, "python")
conan_v2_error("Using code from cache/python not allowed", os.path.isdir(python_folder))
sys.path.append(python_folder)

def create_app(self, quiet_output=None):
self.app = ConanApp(self.cache_folder, self.user_io, self.http_requester,
Expand Down Expand Up @@ -295,8 +294,8 @@ def inspect(self, path, attributes, remote_name=None):
conanfile_path, _, _, ref = result
conanfile = self.app.loader.load_basic(conanfile_path)
conanfile.name = ref.name
conanfile.version = str(ref.version) \
if os.environ.get(CONAN_V2_MODE_ENVVAR, False) else ref.version
# FIXME: Conan 2.0, this should be a string, not a Version object
conanfile.version = ref.version

result = OrderedDict()
if not attributes:
Expand Down
35 changes: 3 additions & 32 deletions conans/client/conanfile/configure.py
@@ -1,7 +1,6 @@
from conans.errors import (conanfile_exception_formatter, ConanInvalidConfiguration)
from conans.errors import conanfile_exception_formatter
from conans.model.conan_file import get_env_context_manager
from conans.util.conan_v2_mode import conan_v2_behavior, CONAN_V2_MODE_ENVVAR
from conans.util.env_reader import get_env
from conans.util.conan_v2_mode import conan_v2_error
from conans.util.misc import make_tuple


Expand All @@ -11,9 +10,7 @@ def run_configure_method(conanfile, down_options, down_ref, ref):
# Avoid extra time manipulating the sys.path for python
with get_env_context_manager(conanfile, without_python=True):
if hasattr(conanfile, "config"):
conan_v2_behavior("config() has been deprecated. "
"Use config_options() and configure()",
v1_behavior=conanfile.output.warn)
conan_v2_error("config() has been deprecated. Use config_options() and configure()")
with conanfile_exception_formatter(str(conanfile), "config"):
conanfile.config()

Expand All @@ -34,36 +31,10 @@ def run_configure_method(conanfile, down_options, down_ref, ref):
# Recipe provides its own name if nothing else is defined
conanfile.provides = make_tuple(conanfile.provides or conanfile.name)

_validate_fpic(conanfile)

if conanfile.deprecated:
from six import string_types
message = "Recipe '%s' is deprecated" % conanfile.display_name
if isinstance(conanfile.deprecated, string_types):
message += " in favor of '%s'" % conanfile.deprecated
message += ". Please, consider changing your requirements."
conanfile.output.warn(message)


def _validate_fpic(conanfile):
v2_mode = get_env(CONAN_V2_MODE_ENVVAR, False)
# FIXME: The toolchain() has dissapeared, but now it is integrated with generators.
# FIXME: Not sure this check should be here, this could raise before the graph is fully evaluated
toolchain = hasattr(conanfile, "toolchain")

if not (toolchain or v2_mode):
return
fpic = conanfile.options.get_safe("fPIC")
if fpic is None:
return
os_ = conanfile.settings.get_safe("os")
if os_ and "Windows" in os_:
if v2_mode:
raise ConanInvalidConfiguration("fPIC option defined for Windows")
conanfile.output.error("fPIC option defined for Windows")
return
shared = conanfile.options.get_safe("shared")
if shared:
if v2_mode:
raise ConanInvalidConfiguration("fPIC option defined for a shared library")
conanfile.output.error("fPIC option defined for a shared library")
22 changes: 6 additions & 16 deletions conans/client/conf/__init__.py
Expand Up @@ -8,7 +8,6 @@
from conans.errors import ConanException
from conans.model.env_info import unquote
from conans.paths import DEFAULT_PROFILE_NAME, conan_expand_user, CACERT_FILE
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.dates import timedelta_from_text
from conans.util.env_reader import get_env
from conans.util.files import load
Expand Down Expand Up @@ -128,15 +127,13 @@

build_type: [None, Debug, Release, RelWithDebInfo, MinSizeRel]

{% if not conan_v2 %}

cppstd: [None, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20] # Deprecated, use compiler.cppstd
{% endif %}
"""))


def get_default_settings_yml(force_v1=False):
conan_v2 = not force_v1 and os.environ.get(CONAN_V2_MODE_ENVVAR, False)
return _t_default_settings_yml.render(conan_v2=conan_v2)
def get_default_settings_yml():
return _t_default_settings_yml.render()


_t_default_client_conf = Template(textwrap.dedent("""
Expand Down Expand Up @@ -193,9 +190,6 @@ def get_default_settings_yml(force_v1=False):

# cacert_path # environment CONAN_CACERT_PATH
# scm_to_conandata # environment CONAN_SCM_TO_CONANDATA
{% if conan_v2 %}
revisions_enabled = 1
{% endif %}

# config_install_interval = 1h
# required_conan_version = >=1.26
Expand All @@ -221,18 +215,14 @@ def get_default_settings_yml(force_v1=False):
# You can skip the proxy for the matching (fnmatch) urls (comma-separated)
# no_proxy_match = *bintray.com*, https://myserver.*

{% if not conan_v2 %}{# no hooks by default in Conan v2 #}
[hooks] # environment CONAN_HOOKS
attribute_checker
{% endif %}

# Default settings now declared in the default profile
"""))


def get_default_client_conf(force_v1=False):
conan_v2 = not force_v1 and os.environ.get(CONAN_V2_MODE_ENVVAR, False)
return _t_default_client_conf.render(conan_v2=conan_v2, default_profile=DEFAULT_PROFILE_NAME)
return _t_default_client_conf.render(default_profile=DEFAULT_PROFILE_NAME)


class ConanClientConfigParser(ConfigParser, object):
Expand Down Expand Up @@ -444,7 +434,7 @@ def revisions_enabled(self):
revisions_enabled = self.get_item("general.revisions_enabled")
return revisions_enabled.lower() in ("1", "true")
except ConanException:
return True if os.environ.get(CONAN_V2_MODE_ENVVAR, False) else False
return False

@property
def parallel_download(self):
Expand Down Expand Up @@ -474,7 +464,7 @@ def scm_to_conandata(self):
scm_to_conandata = self.get_item("general.scm_to_conandata")
return scm_to_conandata.lower() in ("1", "true")
except ConanException:
return True if os.environ.get(CONAN_V2_MODE_ENVVAR, False) else False
return False

@property
def default_package_id_mode(self):
Expand Down
9 changes: 4 additions & 5 deletions conans/client/graph/python_requires.py
Expand Up @@ -7,8 +7,7 @@
from conans.errors import ConanException, NotFoundException
from conans.model.ref import ConanFileReference
from conans.model.requires import Requirement
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.conan_v2_mode import conan_v2_behavior
from conans.util.conan_v2_mode import conan_v2_error

PythonRequire = namedtuple("PythonRequire", ["ref", "module", "conanfile",
"exports_folder", "exports_sources_folder"])
Expand Down Expand Up @@ -135,8 +134,8 @@ def _load_pyreq_conanfile(self, loader, lock_python_requires, ref):
conanfile, module = loader.load_basic_module(path, lock_python_requires, user=new_ref.user,
channel=new_ref.channel)
conanfile.name = new_ref.name
conanfile.version = str(new_ref.version) \
if os.environ.get(CONAN_V2_MODE_ENVVAR, False) else new_ref.version
# FIXME Conan 2.0 version should be a string, not a Version object
conanfile.version = new_ref.version

if getattr(conanfile, "alias", None):
ref = ConanFileReference.loads(conanfile.alias)
Expand Down Expand Up @@ -203,7 +202,7 @@ def _look_for_require(self, reference):
return python_require

def __call__(self, reference):
conan_v2_behavior("Old syntax for python_requires is deprecated")
conan_v2_error("Old syntax for python_requires is deprecated")
if not self.valid:
raise ConanException("Invalid use of python_requires(%s)" % reference)
try:
Expand Down
4 changes: 1 addition & 3 deletions conans/client/installer.py
Expand Up @@ -31,7 +31,6 @@
from conans.model.user_info import DepsUserInfo
from conans.model.user_info import UserInfo
from conans.paths import BUILD_INFO, CONANINFO, RUN_LOG_NAME
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.env_reader import get_env
from conans.util.files import clean_dirty, is_dirty, make_read_only, mkdir, rmdir, save, set_dirty
from conans.util.log import logger
Expand Down Expand Up @@ -613,9 +612,8 @@ def _call_package_info(self, conanfile, package_folder, ref):
conanfile.cpp_info.public_deps = public_deps
# Once the node is build, execute package info, so it has access to the
# package folder and artifacts
conan_v2 = get_env(CONAN_V2_MODE_ENVVAR, False)
# Minimal pythonpath, not the whole context, make it 50% slower
with pythonpath(conanfile) if not conan_v2 else no_op():
with pythonpath(conanfile):
memsharded marked this conversation as resolved.
Show resolved Hide resolved
with tools.chdir(package_folder):
with conanfile_exception_formatter(str(conanfile), "package_info"):
conanfile.package_folder = package_folder
Expand Down
8 changes: 3 additions & 5 deletions conans/client/loader.py
Expand Up @@ -18,7 +18,6 @@
from conans.model.ref import ConanFileReference
from conans.model.settings import Settings
from conans.paths import DATA_YML
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
from conans.util.files import load


Expand Down Expand Up @@ -161,8 +160,7 @@ def load_export(self, conanfile_path, name, version, user, channel, lock_python_
if not conanfile.version:
raise ConanException("conanfile didn't specify version")

if os.environ.get(CONAN_V2_MODE_ENVVAR, False):
conanfile.version = str(conanfile.version)
# FIXME Conan 2.0, conanfile.version should be a string, not a version object

ref = ConanFileReference(conanfile.name, conanfile.version, user, channel)
conanfile.display_name = str(ref)
Expand Down Expand Up @@ -236,8 +234,8 @@ def load_conanfile(self, conanfile_path, profile, ref, lock_python_requires=None
raise ConanException("%s: Cannot load recipe.\n%s" % (str(ref), str(e)))

conanfile.name = ref.name
conanfile.version = str(ref.version) \
if os.environ.get(CONAN_V2_MODE_ENVVAR, False) else ref.version
# FIXME Conan 2.0, version should be a string not a Version object
conanfile.version = ref.version

if profile.dev_reference and profile.dev_reference == ref:
conanfile.develop = True
Expand Down