def _create_cmake_module_variables(module_file): content = textwrap.dedent("""\ if(DEFINED OpenAL_FOUND) set(OPENAL_FOUND ${OpenAL_FOUND}) endif() if(DEFINED OpenAL_INCLUDE_DIR) set(OPENAL_INCLUDE_DIR ${OpenAL_INCLUDE_DIR}) endif() if(DEFINED OpenAL_LIBRARIES) set(OPENAL_LIBRARY ${OpenAL_LIBRARIES}) endif() if(DEFINED OpenAL_VERSION) set(OPENAL_VERSION_STRING ${OpenAL_VERSION}) endif() """) tools.save(module_file, content)
def build(self): shutil.copyfile(os.path.join(self.source_folder, "musl-cross-make", "litecross", "Makefile"), "Makefile") tools.save("config.mak", """ TARGET = {target} HOST = MUSL_SRCDIR = {sf}/musl-1.1.20 GCC_SRCDIR = {sf}/gcc-6.4.0 BINUTILS_SRCDIR = {sf}/binutils-2.27 GMP_SRCDIR = {sf}/gmp-6.1.1 MPC_SRCDIR = {sf}/mpc-1.0.3 MPFR_SRCDIR = {sf}/mpfr-3.1.4 LINUX_SRCDIR = {sf}/linux-4.4.10 """.format(target=self.options.target, sf=self.source_folder)) self.run("make all")
def _detect_compilers(self): tools.rmdir("detectdir") tools.mkdir("detectdir") with tools.chdir("detectdir"): tools.save("CMakeLists.txt", textwrap.dedent("""\ cmake_minimum_required(VERSION 2.8) project(test C CXX) message(STATUS "CC=${CMAKE_C_COMPILER}") message(STATUS "CXX=${CMAKE_CXX_COMPILER}") file(WRITE cc.txt "${CMAKE_C_COMPILER}") file(WRITE cxx.txt "${CMAKE_CXX_COMPILER}") """)) CMake(self).configure(source_folder="detectdir", build_folder="detectdir") cc = tools.load("cc.txt").strip() cxx = tools.load("cxx.txt").strip() return cc, cxx
def _create_cmake_module_variables(module_file): content = textwrap.dedent("""\ if(DEFINED Jasper_FOUND) set(JASPER_FOUND ${Jasper_FOUND}) endif() if(DEFINED Jasper_INCLUDE_DIR) set(JASPER_INCLUDE_DIR ${Jasper_INCLUDE_DIR}) endif() if(DEFINED Jasper_LIBRARIES) set(JASPER_LIBRARIES ${Jasper_LIBRARIES}) endif() if(DEFINED Jasper_VERSION) set(JASPER_VERSION_STRING ${Jasper_VERSION}) endif() """) tools.save(module_file, content)
def _build_msvc(self): target = "rasterlite_i.lib" if self.options.shared else "rasterlite.lib" optflags = ["-D_USE_MATH_DEFINES"] system_libs = [lib + ".lib" for lib in self.deps_cpp_info.system_libs] if self.options.shared: optflags.append("-DDLL_EXPORT") with tools.chdir(self._source_subfolder): tools.save(os.path.join("headers", "config.h"), "#define VERSION \"{}\"\n".format(self.version)) with tools.vcvars(self): with tools.environment_append( VisualStudioBuildEnvironment(self).vars): self.run( "nmake -f makefile.vc {} OPTFLAGS=\"{}\" SYSTEM_LIBS=\"{}\"" .format(target, " ".join(optflags), " ".join(system_libs)))
def _make(self): with tools.chdir(self._source_subfolder): # workaround for clang-cl not producing .pdb files if self._is_clangcl: tools.save("ossl_static.pdb", "") args = " ".join(self._configure_args) if self._use_nmake: self._replace_runtime_in_file( os.path.join("Configurations", "10-main.conf")) self.run("{perl} ./Configure {args}".format(perl=self._perl, args=args), win_bash=self._win_bash) self._run_make()
def test_conanfile(self): tools.save('conanfile.py', content=self.conanfile) output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[RECIPE METADATA] OK", output) self.assertIn("[HEADER ONLY] OK", output) self.assertIn("[NO COPY SOURCE] OK", output) self.assertIn("[FPIC OPTION] OK", output) self.assertIn("[FPIC MANAGEMENT] 'fPIC' option not found", output) self.assertIn("[VERSION RANGES] OK", output) self.assertIn("[LIBCXX] OK", output) self.assertIn("ERROR: [MATCHING CONFIGURATION] Empty package", output) self.assertIn( "ERROR: [PACKAGE LICENSE] No 'licenses' folder found in package", output) self.assertIn("[DEFAULT PACKAGE LAYOUT] OK", output) self.assertIn("[SHARED ARTIFACTS] OK", output)
def test_updated_project(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA_UPDATED) responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy/topics', json=_GITHUB_TOPICS_DATA_UPDATED) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy') responses.add( responses.PUT, 'https://api.github.com/repos/foobar/conan-dummy/topics') tools.save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn('pre_export(): The attributes are up-to-date.', output) self.assertIn('pre_export(): The topics are up-to-date.', output)
def test_auto_managed_subdirectory(self): conanfile = """from conans import ConanFile class Pkg(ConanFile): name = "lib" version = "1.0" settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False]} """ cwd = os.path.join(self.tmp_folder, "subdirectory") tools.save(os.path.join(cwd, "conanfile.py"), conanfile) self.packager = ConanMultiPackager(username="******", cwd=cwd) self.packager.add_common_builds() self.assertGreater(len(self.packager.items), 0) self.assertIn("lib:shared", self.packager.items[0].options)
def test_template(self): client = TestClient() template1 = textwrap.dedent(""" class {{package_name}}Conan(ConanFile): name = "{{name}}" version = "{{version}}" conan_version = "{{conan_version}}" """) save(os.path.join(client.cache_folder, "templates/mytemplate.py"), template1) client.run("new hello/0.1 --template=mytemplate.py") conanfile = client.load("conanfile.py") self.assertIn("class HelloConan(ConanFile):", conanfile) self.assertIn('name = "hello"', conanfile) self.assertIn('version = "0.1"', conanfile) self.assertIn('conan_version = "{}"'.format(client_version), conanfile)
def package(self): txt = tools.load(os.path.join(self._source_subfolder, "jam.c")) license_txt = txt[:txt.find("*/") + 3] tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), license_txt) if self.settings.os == "Windows": if self.settings.compiler == "Visual Studio": pass else: self.copy("*.exe", src=os.path.join(self._source_subfolder, "bin.nt"), dst=os.path.join(self.package_folder, "bin")) else: with tools.chdir(self._source_subfolder): autotools = self._configure_autotools() autotools.install()
def test_buildreq_toolsosinfo(self): tools.save( "conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): def build_requirements(self): if tools.os_info.is_windows and not tools.get_env("CONAN_BASH_PATH"): self.build_requires("msys2/cci.latest") """)) output = self.conan(["export", ".", "name/version@user/channel"]) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) self.assertIn( "Use of tools.os_info is forbidden in build_requirements", output) self.assertIn("conanfile.py:5 Build system dependent", output)
def test_conan_data(self): conanfile = textwrap.dedent(""" from conans import ConanFile class ExampleConan(ConanFile): def build(self): _ = self.conan_data["sources"][float(self.version)] """) tools.save('conanfile.py', content=conanfile) with environment_append({"CONAN_PYLINT_WERR": "1"}): output = self.conan(['export', '.', 'consumer/version@']) self.assertIn("pre_export(): Lint recipe", output) # Hook run without errors self.assertIn("pre_export(): Linter detected '0' errors", output) self.assertNotIn("no-member", output)
def test_config_platform(self): tools.save( "conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools import platform class AConan(ConanFile): def configure(self): if platform.system == "Windows": del self.options.fPIC """)) output = self.conan(["export", ".", "name/version@user/channel"]) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) self.assertIn("Use of platform is forbidden in configure", output) self.assertIn("conanfile.py:6 Build system dependent", output)
def test_validate_toolsosinfo(self): tools.save( "conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools from conans.errors import ConanInvalidConfiguration class AConan(ConanFile): def validate(self): if tools.os_info.is_windows: raise ConanInvalidConfiguration("I refuse to build on Windows") """)) output = self.conan(["export", ".", "name/version@user/channel"]) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) self.assertIn("Use of tools.os_info is forbidden in validate", output) self.assertIn("conanfile.py:6 Build system dependent", output)
def test_configopts_toolsosinfo(self): tools.save( "conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): def config_options(self): if tools.os_info.is_windows: del self.options.fPIC """)) output = self.conan(["export", ".", "name/version@user/channel"]) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) self.assertIn("Use of tools.os_info is forbidden in config_options", output) self.assertIn("conanfile.py:5 Build system dependent", output)
def _create_cmake_module_variables(module_file): content = textwrap.dedent("""\ if(DEFINED Freetype_FOUND) set(FREETYPE_FOUND ${Freetype_FOUND}) endif() if(DEFINED Freetype_INCLUDE_DIRS) set(FREETYPE_INCLUDE_DIRS ${Freetype_INCLUDE_DIRS}) endif() if(DEFINED Freetype_LIBRARIES) set(FREETYPE_LIBRARIES ${Freetype_LIBRARIES}) endif() if(DEFINED Freetype_VERSION) set(FREETYPE_VERSION_STRING ${Freetype_VERSION}) endif() """) tools.save(module_file, content)
def test_failed_attribute_update(self): responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA) responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy', status=500, json={"message": "Internal Server Error"}) tools.save('conanfile.py', content=self.conanfile_complete) output = self.conan(['export', '.', 'name/0.1.0@foobar/stable']) self.assertIn( 'pre_export(): WARN: The attributes description, homepage, name are outdated and they will be updated.', output) self.assertIn( 'pre_export(): ERROR: GitHub PATCH request failed with (500): {"message": "Internal Server Error"}.', output)
def test_unknown_subentry_sources(self): tools.save('conanfile.py', content=self.conanfile) conandata = textwrap.dedent(""" sources: "1.70.0": url: "url1.69.0" sha256: "sha1.69.0" other: "more_data" """) tools.save('conandata.yml', content=conandata) output = self.conan(['export', '.', 'name/1.70.0@jgsogo/test']) self.assertIn("ERROR: [CONANDATA.YML FORMAT (KB-H030)]", output) self.assertNotIn("First level entries", output) self.assertIn( "Additional entry ['other'] not allowed in 'sources':'1.70.0' of " "conandata.yml", output)
def test_req_toolsosinfo(self): tools.save( "conanfile.py", textwrap.dedent("""\ from conans import ConanFile, tools class AConan(ConanFile): def requirements(self): if tools.os_info.is_linux: self.requires("libalsa/1.2.4") """)) output = self.conan(["export", ".", "name/version@user/channel"]) self.assertIn("ERROR: [NO BUILD SYSTEM FUNCTIONS (KB-H061)]", output) self.assertIn("Use of tools.os_info is forbidden in requirements", output) self.assertIn("conanfile.py:5 Build system dependent", output)
def _patch_sources(self): for patch in self.conan_data.get("patches", {}).get(self.version, {}): tools.patch(**patch) # Workaround issue with empty sources for a CMake target flann_cpp_dir = os.path.join(self._source_subfolder, "src", "cpp") tools.save(os.path.join(flann_cpp_dir, "empty.cpp"), "\n") tools.replace_in_file(os.path.join(flann_cpp_dir, "CMakeLists.txt"), 'add_library(flann_cpp SHARED "")', 'add_library(flann_cpp SHARED empty.cpp)') tools.replace_in_file(os.path.join(flann_cpp_dir, "CMakeLists.txt"), 'add_library(flann SHARED "")', 'add_library(flann SHARED empty.cpp)') # remove embeded lz4 tools.rmdir( os.path.join(self._source_subfolder, "src", "cpp", "flann", "ext"))
def test_good_files(self): tools.save('conanfile.py', content=self.conan_file_info.format( 'os.path.join("lib", "cmake", "script.cmake")', ["lib/cmake"])) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output) tools.save('conanfile.py', content=self.conan_file_info.format( 'os.path.join("lib", "cmake", "script.cmake")', ["lib\\cmake"])) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertNotIn("ERROR: [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)]", output)
def test_path_with_spaces(self): conanfile = textwrap.dedent(r""" from conans import ConanFile class Recipe(ConanFile): def build(self): pass """) tools.save(os.path.join("path spaces", "conanfile.py"), content=conanfile) output = self.conan( ['export', 'path spaces/conanfile.py', 'name/version@']) recipe_path = os.path.join(os.getcwd(), "path spaces", "conanfile.py") self.assertIn("pre_export(): Lint recipe '{}'".format(recipe_path), output) self.assertIn("pre_export(): Linter detected '0' errors", output)
def test_conanfile_installer(self): tools.save('conanfile.py', content=self.conanfile_installer) output = self.conan(['create', '.', 'name/version@jgsogo/test']) self.assertIn("[RECIPE METADATA] OK", output) self.assertIn("[HEADER ONLY] OK", output) self.assertIn("[NO COPY SOURCE] OK", output) self.assertIn("[FPIC OPTION] OK", output) self.assertIn("[FPIC MANAGEMENT] 'fPIC' option not found", output) self.assertIn("[VERSION RANGES] OK", output) self.assertIn("[LIBCXX] OK", output) self.assertIn("ERROR: [MATCHING CONFIGURATION] Built artifacts does not match the settings", output) self.assertIn("[SHARED ARTIFACTS] OK", output) self.assertIn("ERROR: [PACKAGE LICENSE] No package licenses found", output) self.assertIn("[DEFAULT PACKAGE LAYOUT] OK", output) self.assertIn("[SHARED ARTIFACTS] OK", output)
def patch_project_jam(self): self.output.warn("Patching project-config.jam") contents = "\nusing zlib : %s : <include>%s <search>%s ;" % ( self.requires["zlib"].conan_reference.version, self.deps_cpp_info["zlib"].include_paths[0].replace('\\', '/'), self.deps_cpp_info["zlib"].lib_paths[0].replace('\\', '/')) if self.settings.os == "Linux" or self.settings.os == "Macos": contents += "\nusing bzip2 : %s : <include>%s <search>%s ;" % ( self.requires["bzip2"].conan_reference.version, self.deps_cpp_info["bzip2"].include_paths[0].replace( '\\', '/'), self.deps_cpp_info["bzip2"].lib_paths[0].replace('\\', '/')) filename = "%s/project-config.jam" % self.FOLDER_NAME tools.save(filename, tools.load(filename) + contents)
def test_bad_oss_licenses(self): """ Test when is not possible to retrieve the supported OSS license list from Bintray. The hook must stop when is not possible to request OSS licenses. """ responses.replace(responses.GET, "https://api.bintray.com/licenses/oss_licenses", status=500, json={"message": "You have reached a dark spot"}) tools.save('conanfile.py', content=self.conanfile_complete) self.conan(['export', '.', 'dummy/0.1.0@foobar/stable']) output = self.conan(['upload', '--remote=fake', 'dummy/0.1.0@foobar/stable']) self.assertIn("Uploading dummy/0.1.0@foobar/stable to remote 'fake'", output) self.assertIn("Uploaded conan recipe 'dummy/0.1.0@foobar/stable' to 'fake'", output) self.assertIn("post_upload_recipe(): Reading package info from Bintray.", output) self.assertIn("post_upload_recipe(): Inspecting recipe info.", output) self.assertIn('post_upload_recipe(): ERROR: Could not request OSS licenses. This hook ' \ 'requires access to OSS license list in Bintray (URL), you may deactivate ' \ 'the hook if the situation persists. Error (500): {"message": "You have ' \ 'reached a dark spot"}', output)
def test_find_and_find_files_and_config_files(self): conanfile = textwrap.dedent("""\ import os from conans import ConanFile, tools class AConan(ConanFile): def package(self): tools.save(os.path.join(self.package_folder, "FindXXX.cmake"), "foo") tools.save(os.path.join(self.package_folder, "XXXConfig.cmake"), "foo") """) tools.save('conanfile.py', content=conanfile) output = self.conan(['create', '.', 'name/version@user/channel']) self.assertIn( "ERROR: [CMAKE-MODULES-CONFIG-FILES (KB-H016)] Found files: ./FindXXX.cmake; ./XXXConfig.cmake", output)
def package(self): # Retrieve the details for the wrapped library from ue4cli from ue4lib import UE4Lib details = UE4Lib("${LIBNAME}") # Copy the header files (and any stray source files) into our package for includedir in details.includedirs(): # Filter out any instances where the module has specified the root of # the ThirdParty modules tree as an include directory (yes, seriously.) if os.path.basename(includedir) != 'ThirdParty': self.copy("*.h", "include", src=includedir) self.copy("*.hpp", "include", src=includedir) self.copy("*.inc", "include", src=includedir) self.copy("*.c", "include", src=includedir) self.copy("*.cc", "include", src=includedir) self.copy("*.cpp", "include", src=includedir) # Copy any static library files into our package, ignoring shared libraries # and gathering a list of any system libraries that need to be linked against systemLibs = details.systemlibs() for lib in details.libs(): # Determine if this is a system library if "." not in lib and "/" not in lib and "\\" not in lib: systemLibs.append(lib) # Determine if this is a static library elif lib.endswith(".dll") == False and lib.endswith(".so") == False: # Verify that the library file exists prior to attempting to copy it if os.path.exists(lib) == True and os.path.isfile(lib) == True: self.copy(os.path.basename(lib), "lib", src=os.path.dirname(lib)) # Serialise our defines and compiler flags so they can be retrieved later flags = { "defines": details.defines(), "cppflags": details.cxxflags(), "sharedlinkflags": details.ldflags(), "exelinkflags": details.ldflags(), "systemlibs": systemLibs } tools.save(self.flags_filename(), json.dumps(flags)) # Perform any package-specific post-build logic PackageDelegate.post_build(self)
def build(self): for patch in self.conan_data.get("patches", {}).get(self.version, []): tools.patch(**patch) if self.options.dat_package_file: dat_package_file = glob.glob(os.path.join(self.source_folder, self._source_subfolder, "source", "data", "in", "*.dat")) if dat_package_file: shutil.copy(str(self.options.dat_package_file), dat_package_file[0]) if self._is_msvc: run_configure_icu_file = os.path.join(self._source_subfolder, "source", "runConfigureICU") if self.settings.compiler == "Visual Studio": flags = "-{}".format(self.settings.compiler.runtime) if tools.Version(self.settings.compiler.version) >= "12": flags += " -FS" else: flags = "-{}{}".format( "MT" if self.settings.runtime == "static" else "MD", "d" if self.settings.runtime_type == "Debug" else "", ) flags += " -FS" tools.replace_in_file(run_configure_icu_file, "-MDd", flags) tools.replace_in_file(run_configure_icu_file, "-MD", flags) self._workaround_icu_20545() env_build = self._configure_autotools() build_dir = os.path.join(self.build_folder, self._source_subfolder, "build") os.mkdir(build_dir) with tools.vcvars(self.settings) if self._is_msvc else tools.no_op(): with tools.environment_append(env_build.vars): with tools.chdir(build_dir): # workaround for https://unicode-org.atlassian.net/browse/ICU-20531 os.makedirs(os.path.join("data", "out", "tmp")) # workaround for "No rule to make target 'out/tmp/dirs.timestamp'" tools.save(os.path.join("data", "out", "tmp", "dirs.timestamp"), "") self.run(self._build_config_cmd, win_bash=tools.os_info.is_windows) command = "{make} {silent} -j {cpu_count}".format(make=self._make_tool, silent=self._silent, cpu_count=tools.cpu_count()) self.run(command, win_bash=tools.os_info.is_windows) if self.options.with_unit_tests: command = "{make} {silent} check".format(make=self._make_tool, silent=self._silent) self.run(command, win_bash=tools.os_info.is_windows)
def test_path_with_spaces(self): conandatafile = textwrap.dedent(r""" sources: "version": url: "https://url.to/name/version.tar.xz" sha256: "3a530d1b243b5dec00bc54937455471aaa3e56849d2593edb8ded07228202240" patches: "version": - patch_file: "patches/abcdef.diff" base_path: "source" """) tools.save(os.path.join("path spaces", "conanfile.py"), content=self.conanfile) tools.save(os.path.join("path spaces", "conandata.py"), content=conandatafile) output = self.conan(['export', 'path spaces/conanfile.py', 'name/version@']) recipe_path = os.path.join(os.getcwd(), "path spaces", "conanfile.py") self.assertIn("pre_export(): Lint yaml '{}'".format(recipe_path), output) self.assertIn("pre_export(): YAML Linter detected '0' errors", output)