From 034bf82f268aac424a39f1d899a2ff9f8cfd7fd0 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 7 Jul 2020 15:44:19 +0200 Subject: [PATCH 1/4] add conan_v2_behavior --- conans/client/build/autotools_environment.py | 10 ++++++++++ conans/client/build/cmake.py | 7 +++++++ conans/client/build/cmake_toolchain_build_helper.py | 4 ++++ conans/client/build/meson.py | 10 ++++++++++ 4 files changed, 31 insertions(+) diff --git a/conans/client/build/autotools_environment.py b/conans/client/build/autotools_environment.py index 2f8cacb55ff..429b5787754 100644 --- a/conans/client/build/autotools_environment.py +++ b/conans/client/build/autotools_environment.py @@ -17,6 +17,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.files import get_abs_path @@ -40,8 +41,17 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False): self._os = conanfile.settings.get_safe("os") self._arch = conanfile.settings.get_safe("arch") self._os_target, self._arch_target = get_target_os_arch(conanfile) + self._build_type = conanfile.settings.get_safe("build_type") + if not self._build_type: + conan_v2_behavior("build_type setting should be defined.", + v1_behavior=self._conanfile.output.warn) + 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) + self._compiler_version = conanfile.settings.get_safe("compiler.version") self._compiler_runtime = conanfile.settings.get_safe("compiler.runtime") self._libcxx = conanfile.settings.get_safe("compiler.libcxx") diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index 557935ff082..24bbb190481 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -17,6 +17,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.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 @@ -77,6 +78,9 @@ def __init__(self, conanfile, generator=None, cmake_system_name=True, self._conanfile = conanfile self._settings = conanfile.settings self._build_type = build_type or conanfile.settings.get_safe("build_type") + if not self._build_type: + conan_v2_behavior("build_type setting should be defined.", + v1_behavior=self._conanfile.output.warn) self._cmake_program = os.getenv("CONAN_CMAKE_PROGRAM") or cmake_program or "cmake" self.generator_platform = generator_platform @@ -238,6 +242,9 @@ 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) the_os = self._settings.get_safe("os") is_clangcl = the_os == "Windows" and compiler == "clang" is_msvc = compiler == "Visual Studio" diff --git a/conans/client/build/cmake_toolchain_build_helper.py b/conans/client/build/cmake_toolchain_build_helper.py index 5ec3cde6119..b1a19c98702 100644 --- a/conans/client/build/cmake_toolchain_build_helper.py +++ b/conans/client/build/cmake_toolchain_build_helper.py @@ -9,6 +9,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.files import mkdir @@ -102,6 +103,9 @@ 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) if bt and self._is_multiconfiguration: build_config = "--config %s" % bt diff --git a/conans/client/build/meson.py b/conans/client/build/meson.py index a42543f348a..6316d873844 100644 --- a/conans/client/build/meson.py +++ b/conans/client/build/meson.py @@ -11,6 +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.files import decode_text, get_abs_path, mkdir from conans.util.runners import version_runner @@ -29,9 +30,18 @@ def __init__(self, conanfile, backend=None, build_type=None, append_vcvars=False self._append_vcvars = append_vcvars 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) + self._compiler_version = self._ss("compiler.version") + self._build_type = self._ss("build_type") + if not self._build_type: + conan_v2_behavior("build_type setting should be defined.", + v1_behavior=self._conanfile.output.warn) self.backend = backend or "ninja" # Other backends are poorly supported, not default other. From d56716e5fbf1284efcca58e7b0433f6e7df13197 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 7 Jul 2020 16:23:29 +0200 Subject: [PATCH 2/4] change case --- conans/client/build/autotools_environment.py | 2 +- conans/client/build/cmake.py | 2 +- conans/client/build/meson.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/conans/client/build/autotools_environment.py b/conans/client/build/autotools_environment.py index 429b5787754..e9e81befbbd 100644 --- a/conans/client/build/autotools_environment.py +++ b/conans/client/build/autotools_environment.py @@ -49,7 +49,7 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False): self._compiler = conanfile.settings.get_safe("compiler") if not self._compiler: - conan_v2_behavior("Compiler setting should be defined.", + conan_v2_behavior("compiler setting should be defined.", v1_behavior=self._conanfile.output.warn) self._compiler_version = conanfile.settings.get_safe("compiler.version") diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index 24bbb190481..8b31ecd76c5 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -243,7 +243,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.", + conan_v2_behavior("compiler setting should be defined.", v1_behavior=self._conanfile.output.warn) the_os = self._settings.get_safe("os") is_clangcl = the_os == "Windows" and compiler == "clang" diff --git a/conans/client/build/meson.py b/conans/client/build/meson.py index 6316d873844..716f8c93c79 100644 --- a/conans/client/build/meson.py +++ b/conans/client/build/meson.py @@ -33,7 +33,7 @@ def __init__(self, conanfile, backend=None, build_type=None, append_vcvars=False self._compiler = self._ss("compiler") if not self._compiler: - conan_v2_behavior("Compiler setting should be defined.", + conan_v2_behavior("compiler setting should be defined.", v1_behavior=self._conanfile.output.warn) self._compiler_version = self._ss("compiler.version") @@ -63,7 +63,7 @@ def __init__(self, conanfile, backend=None, build_type=None, append_vcvars=False '17': 'c++17', 'gnu17': 'gnu++17', '20': 'c++1z', 'gnu20': 'gnu++1z' } - + if cppstd: self.options['cpp_std'] = cppstd_conan2meson[cppstd] From aefd51e5d5e4ae0b507c6344eeea6e5c89c5a078 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 7 Jul 2020 17:35:49 +0200 Subject: [PATCH 3/4] add tests --- .../test/conan_v2/build_helpers/__init__.py | 0 .../test/conan_v2/build_helpers/autotools.py | 41 +++++++++++++++ conans/test/conan_v2/build_helpers/cmake.py | 50 +++++++++++++++++++ conans/test/conan_v2/build_helpers/meson.py | 35 +++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 conans/test/conan_v2/build_helpers/__init__.py create mode 100644 conans/test/conan_v2/build_helpers/autotools.py create mode 100644 conans/test/conan_v2/build_helpers/cmake.py create mode 100644 conans/test/conan_v2/build_helpers/meson.py diff --git a/conans/test/conan_v2/build_helpers/__init__.py b/conans/test/conan_v2/build_helpers/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/conans/test/conan_v2/build_helpers/autotools.py b/conans/test/conan_v2/build_helpers/autotools.py new file mode 100644 index 00000000000..691f5e18de4 --- /dev/null +++ b/conans/test/conan_v2/build_helpers/autotools.py @@ -0,0 +1,41 @@ +import textwrap +import platform +import unittest + +from conans.test.utils.conan_v2_tests import ConanV2ModeTestCase + + +class AutotoolsBuildHelperTestCase(ConanV2ModeTestCase): + + @unittest.skipUnless(platform.system() == "Linux", "Requires make") + def test_no_build_type(self): + t = self.get_client() + conanfile = textwrap.dedent(""" + from conans import ConanFile, AutoToolsBuildEnvironment + class Pkg(ConanFile): + settings = "os", "arch", "compiler" + def build(self): + autotools = AutoToolsBuildEnvironment(self) + autotools.configure() + autotools.make() + """) + t.save({"conanfile.py": conanfile}) + t.run("create . pkg/0.1@user/testing", assert_error=True) + self.assertIn("Conan v2 incompatible: build_type setting should be defined.", t.out) + + @unittest.skipUnless(platform.system() == "Linux", "Requires make") + def test_no_compiler(self): + t = self.get_client() + conanfile = textwrap.dedent(""" + from conans import ConanFile, AutoToolsBuildEnvironment + + class Pkg(ConanFile): + settings = "os", "arch", "build_type" + def build(self): + autotools = AutoToolsBuildEnvironment(self) + autotools.configure() + autotools.make() + """) + t.save({"conanfile.py": conanfile}) + t.run("create . pkg/0.1@user/testing", assert_error=True) + self.assertIn("Conan v2 incompatible: compiler setting should be defined.", t.out) diff --git a/conans/test/conan_v2/build_helpers/cmake.py b/conans/test/conan_v2/build_helpers/cmake.py new file mode 100644 index 00000000000..7de110bd67e --- /dev/null +++ b/conans/test/conan_v2/build_helpers/cmake.py @@ -0,0 +1,50 @@ +import textwrap + +from conans.test.utils.conan_v2_tests import ConanV2ModeTestCase + + +class CMakeBuildHelperTestCase(ConanV2ModeTestCase): + + def test_no_build_type(self): + t = self.get_client() + conanfile = textwrap.dedent(""" + from conans import ConanFile, CMake + class Pkg(ConanFile): + settings = "os", "arch", "compiler" + def build(self): + cmake = CMake(self) + cmake.build() + """) + t.save({"conanfile.py": conanfile}) + t.run("create . pkg/0.1@user/testing", assert_error=True) + self.assertIn("Conan v2 incompatible: build_type setting should be defined.", t.out) + + def test_no_compiler(self): + t = self.get_client() + conanfile = textwrap.dedent(""" + from conans import ConanFile, CMake + + class Pkg(ConanFile): + settings = "os", "arch", "build_type" + def build(self): + cmake = CMake(self) + cmake.build() + """) + t.save({"conanfile.py": conanfile}) + t.run("create . pkg/0.1@user/testing", assert_error=True) + self.assertIn("Conan v2 incompatible: compiler setting should be defined.", t.out) + + def test_toolchain_no_build_type(self): + t = self.get_client() + conanfile = textwrap.dedent(""" + from conans import ConanFile, CMake + class Pkg(ConanFile): + toolchain = "cmake" + + def build(self): + cmake = CMake(self) + cmake.build() + """) + t.save({"conanfile.py": conanfile}) + t.run("create . pkg/0.1@user/testing", assert_error=True) + self.assertIn("Conan v2 incompatible: build_type setting should be defined.", t.out) diff --git a/conans/test/conan_v2/build_helpers/meson.py b/conans/test/conan_v2/build_helpers/meson.py new file mode 100644 index 00000000000..9e202a67187 --- /dev/null +++ b/conans/test/conan_v2/build_helpers/meson.py @@ -0,0 +1,35 @@ +import textwrap +import platform +import unittest + +from conans.test.utils.conan_v2_tests import ConanV2ModeTestCase + + +class MesonBuildHelperTestCase(ConanV2ModeTestCase): + + def test_no_build_type(self): + t = self.get_client() + conanfile = textwrap.dedent(""" + from conans import ConanFile, Meson + class Pkg(ConanFile): + settings = "os", "arch", "compiler" + def build(self): + meson = Meson(self) + """) + t.save({"conanfile.py": conanfile}) + t.run("create . pkg/0.1@user/testing", assert_error=True) + self.assertIn("Conan v2 incompatible: build_type setting should be defined.", t.out) + + def test_no_compiler(self): + t = self.get_client() + conanfile = textwrap.dedent(""" + from conans import ConanFile, Meson + + class Pkg(ConanFile): + settings = "os", "arch", "build_type" + def build(self): + meson = Meson(self) + """) + t.save({"conanfile.py": conanfile}) + t.run("create . pkg/0.1@user/testing", assert_error=True) + self.assertIn("Conan v2 incompatible: compiler setting should be defined.", t.out) From 7e84aa1fe370bbd003235889de93345646868c1f Mon Sep 17 00:00:00 2001 From: czoido Date: Thu, 9 Jul 2020 17:09:02 +0200 Subject: [PATCH 4/4] move checks to build --- conans/client/build/autotools_environment.py | 6 +++--- conans/client/build/cmake.py | 6 +++--- conans/client/build/meson.py | 6 +++--- conans/test/conan_v2/build_helpers/meson.py | 2 ++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/conans/client/build/autotools_environment.py b/conans/client/build/autotools_environment.py index e9e81befbbd..b29b87dbe0c 100644 --- a/conans/client/build/autotools_environment.py +++ b/conans/client/build/autotools_environment.py @@ -43,9 +43,6 @@ def __init__(self, conanfile, win_bash=False, include_rpath_flags=False): self._os_target, self._arch_target = get_target_os_arch(conanfile) self._build_type = conanfile.settings.get_safe("build_type") - if not self._build_type: - conan_v2_behavior("build_type setting should be defined.", - v1_behavior=self._conanfile.output.warn) self._compiler = conanfile.settings.get_safe("compiler") if not self._compiler: @@ -233,6 +230,9 @@ 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) 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) diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index 8b31ecd76c5..3bdd69d26dd 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -78,9 +78,6 @@ def __init__(self, conanfile, generator=None, cmake_system_name=True, self._conanfile = conanfile self._settings = conanfile.settings self._build_type = build_type or conanfile.settings.get_safe("build_type") - if not self._build_type: - conan_v2_behavior("build_type setting should be defined.", - v1_behavior=self._conanfile.output.warn) self._cmake_program = os.getenv("CONAN_CMAKE_PROGRAM") or cmake_program or "cmake" self.generator_platform = generator_platform @@ -307,6 +304,9 @@ 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) self._build(args, build_dir, target) def _build(self, args=None, build_dir=None, target=None): diff --git a/conans/client/build/meson.py b/conans/client/build/meson.py index 716f8c93c79..4128837952b 100644 --- a/conans/client/build/meson.py +++ b/conans/client/build/meson.py @@ -39,9 +39,6 @@ def __init__(self, conanfile, backend=None, build_type=None, append_vcvars=False self._compiler_version = self._ss("compiler.version") self._build_type = self._ss("build_type") - if not self._build_type: - conan_v2_behavior("build_type setting should be defined.", - v1_behavior=self._conanfile.output.warn) self.backend = backend or "ninja" # Other backends are poorly supported, not default other. @@ -217,6 +214,9 @@ 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) self._run_ninja_targets(args=args, build_dir=build_dir, targets=targets) def install(self, args=None, build_dir=None): diff --git a/conans/test/conan_v2/build_helpers/meson.py b/conans/test/conan_v2/build_helpers/meson.py index 9e202a67187..7ddc83d644b 100644 --- a/conans/test/conan_v2/build_helpers/meson.py +++ b/conans/test/conan_v2/build_helpers/meson.py @@ -15,6 +15,7 @@ class Pkg(ConanFile): settings = "os", "arch", "compiler" def build(self): meson = Meson(self) + meson.build() """) t.save({"conanfile.py": conanfile}) t.run("create . pkg/0.1@user/testing", assert_error=True) @@ -29,6 +30,7 @@ class Pkg(ConanFile): settings = "os", "arch", "build_type" def build(self): meson = Meson(self) + meson.build() """) t.save({"conanfile.py": conanfile}) t.run("create . pkg/0.1@user/testing", assert_error=True)