From 4f645a2a7c7fc0a08fd13dd19e822f69d7d12191 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 8 Nov 2023 13:31:47 +0100 Subject: [PATCH] Removed useless extra_xxxx attrs --- conan/tools/google/toolchain.py | 21 +++---- .../toolchains/google/test_bazeltoolchain.py | 62 +++++++++++++++++++ 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/conan/tools/google/toolchain.py b/conan/tools/google/toolchain.py index 05a661a5b4b..4c051c4ecfe 100644 --- a/conan/tools/google/toolchain.py +++ b/conan/tools/google/toolchain.py @@ -46,7 +46,7 @@ class BazelToolchain: bazelrc_name = "conan_bzl.rc" bazelrc_config = "conan-config" - bazelrc_template = textwrap.dedent(""" + bazelrc_template = textwrap.dedent("""\ # Automatic bazelrc file created by Conan {% if copt %}build:conan-config {{copt}}{% endif %} {% if conlyopt %}build:conan-config {{conlyopt}}{% endif %} @@ -67,13 +67,6 @@ def __init__(self, conanfile, namespace=None): "deprecated as it's not used anymore.") check_using_build_profile(self._conanfile) - # Flags - # TODO: Should we read the buildenv to get flags? - self.extra_cxxflags = [] - self.extra_cflags = [] - self.extra_ldflags = [] - self.extra_defines = [] - # Bazel build parameters shared = self._conanfile.options.get_safe("shared") fpic = self._conanfile.options.get_safe("fPIC") @@ -113,13 +106,13 @@ def _filter_list_empty_fields(v): def cxxflags(self): ret = [self.cppstd] conf_flags = self._conanfile.conf.get("tools.build:cxxflags", default=[], check_type=list) - ret = ret + self.extra_cxxflags + conf_flags + ret = ret + self.cxxopt + conf_flags return self._filter_list_empty_fields(ret) @property def cflags(self): conf_flags = self._conanfile.conf.get("tools.build:cflags", default=[], check_type=list) - ret = self.extra_cflags + conf_flags + ret = self.conlyopt + conf_flags return self._filter_list_empty_fields(ret) @property @@ -130,15 +123,15 @@ def ldflags(self): check_type=list)) linker_scripts = self._conanfile.conf.get("tools.build:linker_scripts", default=[], check_type=list) conf_flags.extend(["-T'" + linker_script + "'" for linker_script in linker_scripts]) - ret = self.extra_ldflags + conf_flags + ret = self.linkopt + conf_flags return self._filter_list_empty_fields(ret) def _context(self): return { "copt": " ".join(f"--copt={flag}" for flag in self.copt), - "conlyopt": " ".join(f"--conlyopt={flag}" for flag in (self.conlyopt + self.cflags)), - "cxxopt": " ".join(f"--cxxopt={flag}" for flag in (self.cxxopt + self.cxxflags)), - "linkopt": " ".join(f"--linkopt={flag}" for flag in (self.linkopt + self.ldflags)), + "conlyopt": " ".join(f"--conlyopt={flag}" for flag in self.cflags), + "cxxopt": " ".join(f"--cxxopt={flag}" for flag in self.cxxflags), + "linkopt": " ".join(f"--linkopt={flag}" for flag in self.ldflags), "force_pic": self.force_pic, "dynamic_mode": self.dynamic_mode, "compilation_mode": self.compilation_mode, diff --git a/conans/test/integration/toolchains/google/test_bazeltoolchain.py b/conans/test/integration/toolchains/google/test_bazeltoolchain.py index 7dcf5d1b112..42fc6987eb4 100644 --- a/conans/test/integration/toolchains/google/test_bazeltoolchain.py +++ b/conans/test/integration/toolchains/google/test_bazeltoolchain.py @@ -109,3 +109,65 @@ def test_bazel_toolchain_and_cross_compilation(conanfile): c.run("install . -pr:b profile -pr:h profile_host") content = load(c, os.path.join(c.current_folder, "conan", BazelToolchain.bazelrc_name)) assert "build:conan-config --cpu=darwin_arm64" in content + + +def test_toolchain_attributes_and_conf_priority(): + """ + Tests that all the attributes are appearing correctly in the conan_bzl.rc even defining + some conf variables + """ + profile = textwrap.dedent(""" + [settings] + arch=x86_64 + build_type=Release + compiler=apple-clang + compiler.cppstd=gnu17 + compiler.libcxx=libc++ + compiler.version=13.0 + os=Macos + [conf] + tools.build:cxxflags=["--flag1"] + tools.build:cflags+=["--flag3"] + tools.build:sharedlinkflags+=["--linkflag5"] + tools.build:exelinkflags+=["--linkflag6"] + """) + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.google import BazelToolchain + class ExampleConanIntegration(ConanFile): + settings = "os", "arch", "build_type", "compiler" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + + def generate(self): + bz = BazelToolchain(self) + bz.copt = ["copt1"] + bz.conlyopt = ["conly1"] + bz.cxxopt = ["cxxopt1"] + bz.linkopt = ["linkopt1"] + bz.force_pic = True + bz.dynamic_mode = "auto" + bz.compilation_mode = "fastbuild" + bz.compiler = "gcc" + bz.cpu = "armv8" + bz.crosstool_top = "my_crosstool" + bz.generate() + """) + c = TestClient() + c.save({"conanfile.py": conanfile, + "profile": profile}) + c.run("install . -pr profile") + content = load(c, os.path.join(c.current_folder, BazelToolchain.bazelrc_name)) + expected = textwrap.dedent("""\ + # Automatic bazelrc file created by Conan + build:conan-config --copt=copt1 + build:conan-config --conlyopt=conly1 --conlyopt=--flag3 + build:conan-config --cxxopt=-std=gnu++17 --cxxopt=cxxopt1 --cxxopt=--flag1 + build:conan-config --linkopt=linkopt1 --linkopt=--linkflag5 --linkopt=--linkflag6 + build:conan-config --force_pic=True + build:conan-config --dynamic_mode=auto + build:conan-config --compilation_mode=fastbuild + build:conan-config --compiler=gcc + build:conan-config --cpu=armv8 + build:conan-config --crosstool_top=my_crosstool""") + assert expected == content