Skip to content

Commit e716474

Browse files
authored
Merge pull request #2 from uilianries/onetbb/2020_3_stdver
onetbb: Update import tools and fix linter errors
2 parents 791784e + 5822f1f commit e716474

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

recipes/onetbb/2020.x/conanfile.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
from conan.tools.microsoft import msvc_runtime_flag
2-
from conans import ConanFile, tools
3-
from conans.errors import ConanInvalidConfiguration, ConanException
1+
from conan import ConanFile
2+
from conan.tools.microsoft import msvc_runtime_flag, is_msvc
3+
from conan.tools.build import cross_building
4+
from conan.tools.files import get, replace_in_file, save, chdir, copy
5+
from conan.tools.scm import Version
6+
from conan.errors import ConanInvalidConfiguration, ConanException
7+
from conans import tools
48
import os
59
import textwrap
610

7-
required_conan_version = ">=1.43.0"
11+
required_conan_version = ">=1.47.0"
812

913

1014
class OneTBBConan(ConanFile):
@@ -41,10 +45,6 @@ def _source_subfolder(self):
4145
def _settings_build(self):
4246
return getattr(self, "settings_build", self.settings)
4347

44-
@property
45-
def _is_msvc(self):
46-
return str(self.settings.compiler) in ["Visual Studio", "msvc"]
47-
4848
@property
4949
def _is_clanglc(self):
5050
return self.settings.os == "Windows" and self.settings.compiler == "clang"
@@ -66,10 +66,10 @@ def configure(self):
6666

6767
def validate(self):
6868
if self.settings.os == "Macos":
69-
if hasattr(self, "settings_build") and tools.cross_building(self):
69+
if hasattr(self, "settings_build") and cross_building(self):
7070
# See logs from https://github.com/conan-io/conan-center-index/pull/8454
7171
raise ConanInvalidConfiguration("Cross building on Macos is not yet supported. Contributions are welcome")
72-
if self.settings.compiler == "apple-clang" and tools.Version(self.settings.compiler.version) < "8.0":
72+
if self.settings.compiler == "apple-clang" and Version(self.settings.compiler.version) < "8.0":
7373
raise ConanInvalidConfiguration("%s %s couldn't be built by apple-clang < 8.0" % (self.name, self.version))
7474
if not self.options.shared:
7575
self.output.warn("oneTBB strongly discourages usage of static linkage")
@@ -88,7 +88,7 @@ def build_requirements(self):
8888
self.build_requires("make/4.2.1")
8989

9090
def source(self):
91-
tools.get(**self.conan_data["sources"][self.version],
91+
get(self, **self.conan_data["sources"][self.version],
9292
strip_root=True, destination=self._source_subfolder)
9393

9494
def build(self):
@@ -100,14 +100,14 @@ def add_flag(name, value):
100100

101101
# Get the version of the current compiler instead of gcc
102102
linux_include = os.path.join(self._source_subfolder, "build", "linux.inc")
103-
tools.replace_in_file(linux_include, "shell gcc", "shell $(CC)")
104-
tools.replace_in_file(linux_include, "= gcc", "= $(CC)")
103+
replace_in_file(self, linux_include, "shell gcc", "shell $(CC)")
104+
replace_in_file(self, linux_include, "= gcc", "= $(CC)")
105105

106106
if self.version != "2019_u9" and self.settings.build_type == "Debug":
107-
tools.replace_in_file(os.path.join(self._source_subfolder, "Makefile"), "release", "debug")
107+
replace_in_file(self, os.path.join(self._source_subfolder, "Makefile"), "release", "debug")
108108

109109
if str(self._base_compiler) in ["Visual Studio", "msvc"]:
110-
tools.save(
110+
save(self,
111111
os.path.join(self._source_subfolder, "build", "big_iron_msvc.inc"),
112112
# copy of big_iron.inc adapted for MSVC
113113
textwrap.dedent("""\
@@ -211,7 +211,7 @@ def add_flag(name, value):
211211
if not make:
212212
raise ConanException("This package needs 'make' in the path to build")
213213

214-
with tools.chdir(self._source_subfolder):
214+
with chdir(self, self._source_subfolder):
215215
# intentionally not using AutoToolsBuildEnvironment for now - it's broken for clang-cl
216216
if self._is_clanglc:
217217
add_flag("CFLAGS", "-mrtm")
@@ -221,36 +221,35 @@ def add_flag(name, value):
221221
context = tools.no_op()
222222
if self.settings.compiler == "intel":
223223
context = tools.intel_compilervars(self)
224-
elif self._is_msvc:
224+
elif is_msvc(self):
225225
# intentionally not using vcvars for clang-cl yet
226226
context = tools.vcvars(self)
227227
with context:
228228
self.run("%s %s %s" % (make, extra, " ".join(targets)))
229229

230230
def package(self):
231-
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
232-
self.copy(pattern="*.h", dst="include", src="%s/include" % self._source_subfolder)
233-
self.copy(pattern="*", dst="include/tbb/compat", src="%s/include/tbb/compat" % self._source_subfolder)
234-
build_folder = "%s/build/" % self._source_subfolder
231+
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self._source_subfolder)
232+
copy(self, pattern="*.h", dst=os.path.join(self.package_folder, "include"), src=os.path.join(self._source_subfolder, "include"))
233+
copy(self, pattern="*", dst=os.path.join(self.package_folder, "include", "tbb", "compat"), src=os.path.join(self._source_subfolder, "include", "tbb", "compat"))
234+
build_folder = os.path.join(self._source_subfolder, "build")
235235
build_type = "debug" if self.settings.build_type == "Debug" else "release"
236-
self.copy(pattern="*%s*.lib" % build_type, dst="lib", src=build_folder, keep_path=False)
237-
self.copy(pattern="*%s*.a" % build_type, dst="lib", src=build_folder, keep_path=False)
238-
self.copy(pattern="*%s*.dll" % build_type, dst="bin", src=build_folder, keep_path=False)
239-
self.copy(pattern="*%s*.dylib" % build_type, dst="lib", src=build_folder, keep_path=False)
236+
copy(self, pattern=f"*{build_type}*.lib", dst=os.path.join(self.package_folder, "lib"), src=build_folder, keep_path=False)
237+
copy(self, pattern=f"*{build_type}*.a", dst=os.path.join(self.package_folder, "lib"), src=build_folder, keep_path=False)
238+
copy(self, pattern=f"*{build_type}*.dll", dst=os.path.join(self.package_folder, "bin"), src=build_folder, keep_path=False)
239+
copy(self, pattern=f"*{build_type}*.dylib", dst=os.path.join(self.package_folder, "lib"), src=build_folder, keep_path=False)
240240
# Copy also .dlls to lib folder so consumers can link against them directly when using MinGW
241241
if self.settings.os == "Windows" and self.settings.compiler == "gcc":
242-
self.copy("*%s*.dll" % build_type, dst="lib", src=build_folder, keep_path=False)
242+
copy(self, f"*{build_type}*.dll", dst=os.path.join(self.package_folder, "lib"), src=build_folder, keep_path=False)
243243

244244
if self.settings.os == "Linux":
245245
extension = "so"
246246
if self.options.shared:
247-
self.copy("*%s*.%s.*" % (build_type, extension), "lib", build_folder,
248-
keep_path=False)
247+
copy(self, f"*{build_type}*.{extension}.*", dst=os.path.join(self.package_folder, "lib"), src=build_folder, keep_path=False)
249248
outputlibdir = os.path.join(self.package_folder, "lib")
250-
os.chdir(outputlibdir)
251-
for fpath in os.listdir(outputlibdir):
252-
self.run("ln -s \"%s\" \"%s\"" %
253-
(fpath, fpath[0:fpath.rfind("." + extension) + len(extension) + 1]))
249+
with chdir(self, outputlibdir):
250+
for fpath in os.listdir(outputlibdir):
251+
filepath = fpath[0:fpath.rfind("." + extension) + len(extension) + 1]
252+
self.run(f'ln -s "{fpath}" "{filepath}"', run_environment=True)
254253

255254
def package_info(self):
256255
self.cpp_info.set_property("cmake_file_name", "TBB")

0 commit comments

Comments
 (0)