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

[conan_v2_mode] Fail if build_type or compiler is not defined for build helpers #7327

Merged
merged 4 commits into from Jul 9, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions conans/client/build/autotools_environment.py
Expand Up @@ -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


Expand All @@ -40,8 +41,14 @@ 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")

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")
Expand Down Expand Up @@ -223,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)
Expand Down
7 changes: 7 additions & 0 deletions conans/client/build/cmake.py
Expand Up @@ -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
Expand Down Expand Up @@ -238,6 +239,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"
Expand Down Expand Up @@ -300,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):
Expand Down
4 changes: 4 additions & 0 deletions conans/client/build/cmake_toolchain_build_helper.py
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion conans/client/build/meson.py
Expand Up @@ -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

Expand All @@ -29,8 +30,14 @@ 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")

self.backend = backend or "ninja" # Other backends are poorly supported, not default other.
Expand All @@ -53,7 +60,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]

Expand Down Expand Up @@ -207,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):
Expand Down
Empty file.
41 changes: 41 additions & 0 deletions 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)
50 changes: 50 additions & 0 deletions 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)
37 changes: 37 additions & 0 deletions conans/test/conan_v2/build_helpers/meson.py
@@ -0,0 +1,37 @@
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)
meson.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, Meson

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)
self.assertIn("Conan v2 incompatible: compiler setting should be defined.", t.out)