def no_prefix_test(self): conan_file = ConanFileMock() conan_file.settings = Settings() conan_file.package_folder = None meson = Meson(conan_file) meson.configure() self.assertNotIn('-Dprefix', conan_file.command) meson.build() self.assertIn("ninja -C", conan_file.command) with self.assertRaises(TypeError): meson.install()
def prefix_test(self): conan_file = ConanFileMock() conan_file.settings = Settings() conan_file.package_folder = os.getcwd() expected_prefix = '-Dprefix="%s"' % os.getcwd() meson = Meson(conan_file) meson.configure() self.assertIn(expected_prefix, conan_file.command) meson.build() self.assertIn("ninja -C", conan_file.command) meson.install() self.assertIn("ninja -C", conan_file.command)
def partial_build_test(self): conan_file = ConanFileMock() conan_file.settings = Settings() conan_file.should_configure = False conan_file.should_build = False conan_file.package_folder = os.path.join(self.tempdir, "my_cache_package_folder") meson = Meson(conan_file) meson.configure() self.assertIsNone(conan_file.command) meson.build() self.assertIsNone(conan_file.command) meson.test() self.assertIsNone(conan_file.command) meson.install() self.assertIsNone(conan_file.command)
def flags_applied_test(self, the_os, compiler, version, arch, runtime, flag): settings = Settings.loads(default_settings_yml) settings.os = the_os settings.compiler = compiler settings.compiler.version = version settings.arch = arch if runtime: settings.compiler.runtime = runtime settings.build_type = "Release" conan_file = ConanFileMock() conan_file.deps_cpp_info = MockDepsCppInfo() conan_file.settings = settings conan_file.package_folder = None meson = Meson(conan_file) meson.configure() meson.build() self.assertIn(flag, conan_file.captured_env["CFLAGS"]) self.assertIn(flag, conan_file.captured_env["CXXFLAGS"])
def folders_test(self): settings = Settings.loads(default_settings_yml) settings.os = "Linux" settings.compiler = "gcc" settings.compiler.version = "6.3" settings.arch = "x86" settings.build_type = "Release" package_folder = os.path.join(self.tempdir, "my_cache_package_folder") conan_file = ConanFileMock() conan_file.settings = settings conan_file.source_folder = os.path.join(self.tempdir, "my_cache_source_folder") conan_file.build_folder = os.path.join(self.tempdir, "my_cache_build_folder") conan_file.package_folder = package_folder meson = Meson(conan_file) defs = { 'default_library': 'shared', 'prefix': package_folder, 'libdir': 'lib', 'bindir': 'bin', 'sbindir': 'bin', 'libexecdir': 'bin', 'includedir': 'include', 'cpp_std': 'none' } meson.configure(source_dir=os.path.join(self.tempdir, "../subdir"), build_dir=os.path.join(self.tempdir, "build")) source_expected = os.path.join(self.tempdir, "../subdir") build_expected = os.path.join(self.tempdir, "build") cmd_expected = 'meson "%s" "%s" --backend=ninja %s --buildtype=release' \ % (source_expected, build_expected, defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) meson.configure(build_dir=os.path.join(self.tempdir, "build")) source_expected = os.path.join(self.tempdir, "my_cache_source_folder") build_expected = os.path.join(self.tempdir, "build") cmd_expected = 'meson "%s" "%s" --backend=ninja %s --buildtype=release' \ % (source_expected, build_expected, defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) meson.configure() source_expected = os.path.join(self.tempdir, "my_cache_source_folder") build_expected = os.path.join(self.tempdir, "my_cache_build_folder") cmd_expected = 'meson "%s" "%s" --backend=ninja %s --buildtype=release' \ % (source_expected, build_expected, defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) meson.configure(source_folder="source", build_folder="build") build_expected = os.path.join(self.tempdir, "my_cache_build_folder", "build") source_expected = os.path.join(self.tempdir, "my_cache_source_folder", "source") cmd_expected = 'meson "%s" "%s" --backend=ninja %s --buildtype=release' \ % (source_expected, build_expected, defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) conan_file.in_local_cache = True meson.configure(source_folder="source", build_folder="build", cache_build_folder="rel_only_cache") build_expected = os.path.join(self.tempdir, "my_cache_build_folder", "rel_only_cache") source_expected = os.path.join(self.tempdir, "my_cache_source_folder", "source") cmd_expected = 'meson "%s" "%s" --backend=ninja %s --buildtype=release' \ % (source_expected, build_expected, defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) conan_file.in_local_cache = False meson.configure(source_folder="source", build_folder="build", cache_build_folder="rel_only_cache") build_expected = os.path.join(self.tempdir, "my_cache_build_folder", "build") source_expected = os.path.join(self.tempdir, "my_cache_source_folder", "source") cmd_expected = 'meson "%s" "%s" --backend=ninja %s --buildtype=release' \ % (source_expected, build_expected, defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) conan_file.in_local_cache = True meson.configure(build_dir="build", cache_build_folder="rel_only_cache") build_expected = os.path.join(self.tempdir, "my_cache_build_folder", "rel_only_cache") source_expected = os.path.join(self.tempdir, "my_cache_source_folder") cmd_expected = 'meson "%s" "%s" --backend=ninja %s --buildtype=release' \ % (source_expected, build_expected, defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) args = ['--werror', '--warnlevel 3'] defs['default_library'] = 'static' meson.configure(source_folder="source", build_folder="build", args=args, defs={'default_library': 'static'}) build_expected = os.path.join(self.tempdir, "my_cache_build_folder", "build") source_expected = os.path.join(self.tempdir, "my_cache_source_folder", "source") cmd_expected = 'meson "%s" "%s" --backend=ninja %s %s --buildtype=release' \ % (source_expected, build_expected, args_to_string(args), defs_to_string(defs)) self._check_commands(cmd_expected, conan_file.command) # Raise mixing with self.assertRaisesRegexp(ConanException, "Use 'build_folder'/'source_folder'"): meson.configure(source_folder="source", build_dir="build") meson.test() self.assertEquals( "ninja -C \"%s\" %s" % (build_expected, args_to_string(["test"])), conan_file.command) meson.install() self.assertEquals( "ninja -C \"%s\" %s" % (build_expected, args_to_string(["install"])), conan_file.command)
def self_collect_libs_test(self): conanfile = ConanFileMock() # Without package_folder conanfile.package_folder = None result = conanfile.collect_libs() self.assertEqual([], result) self.assertIn("'self.collect_libs' is deprecated, use 'tools.collect_libs(self)' instead", conanfile.output) # Default behavior conanfile.package_folder = temp_folder() mylib_path = os.path.join(conanfile.package_folder, "lib", "mylib.lib") save(mylib_path, "") conanfile.cpp_info = CppInfo("") result = conanfile.collect_libs() self.assertEqual(["mylib"], result) # Custom folder customlib_path = os.path.join(conanfile.package_folder, "custom_folder", "customlib.lib") save(customlib_path, "") result = conanfile.collect_libs(folder="custom_folder") self.assertEqual(["customlib"], result) # Custom folder doesn't exist result = conanfile.collect_libs(folder="fake_folder") self.assertEqual([], result) self.assertIn("Lib folder doesn't exist, can't collect libraries:", conanfile.output) # Use cpp_info.libdirs conanfile.cpp_info.libdirs = ["lib", "custom_folder"] result = conanfile.collect_libs() self.assertEqual(["customlib", "mylib"], result) # Custom folder with multiple libdirs should only collect from custom folder self.assertEqual(["lib", "custom_folder"], conanfile.cpp_info.libdirs) result = conanfile.collect_libs(folder="custom_folder") self.assertEqual(["customlib"], result) # Warn same lib different folders conanfile = ConanFileMock() conanfile.package_folder = temp_folder() conanfile.cpp_info = CppInfo("") custom_mylib_path = os.path.join(conanfile.package_folder, "custom_folder", "mylib.lib") lib_mylib_path = os.path.join(conanfile.package_folder, "lib", "mylib.lib") save(custom_mylib_path, "") save(lib_mylib_path, "") conanfile.cpp_info.libdirs = ["lib", "custom_folder"] result = conanfile.collect_libs() self.assertEqual(["mylib"], result) self.assertIn("Library 'mylib' was either already found in a previous " "'conanfile.cpp_info.libdirs' folder or appears several times with a " "different file extension", conanfile.output) # Warn lib folder does not exist with correct result conanfile = ConanFileMock() conanfile.package_folder = temp_folder() conanfile.cpp_info = CppInfo("") lib_mylib_path = os.path.join(conanfile.package_folder, "lib", "mylib.lib") save(lib_mylib_path, "") no_folder_path = os.path.join(conanfile.package_folder, "no_folder") conanfile.cpp_info.libdirs = ["no_folder", "lib"] # 'no_folder' does NOT exist result = conanfile.collect_libs() self.assertEqual(["mylib"], result) self.assertIn("WARN: Lib folder doesn't exist, can't collect libraries: %s" % no_folder_path, conanfile.output)