def user_profile_test(self): conanfile = ConanFile(None, None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@user/testing") tmp_folder = temp_folder() pkg1 = os.path.join(tmp_folder, "pkg1") cpp_info = CppInfo(pkg1) cpp_info.includedirs = ["include"] save(os.path.join(pkg1, "include/file.h"), "") conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing") pkg2 = os.path.join(tmp_folder, "pkg2") cpp_info = CppInfo(pkg2) cpp_info.includedirs = ["include"] save(os.path.join(pkg2, "include/file.h"), "") conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = VisualStudioGenerator(conanfile) with tools.environment_append({"USERPROFILE": tmp_folder}): content = generator.content xml.etree.ElementTree.fromstring(content) self.assertIn("<AdditionalIncludeDirectories>$(USERPROFILE)/pkg1/include;" "$(USERPROFILE)/pkg2/include;", content) with tools.environment_append({"USERPROFILE": tmp_folder.upper()}): content = generator.content xml.etree.ElementTree.fromstring(content) self.assertIn("<AdditionalIncludeDirectories>$(USERPROFILE)/pkg1/include;" "$(USERPROFILE)/pkg2/include;", content)
def user_profile_test(self): conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@user/testing") tmp_folder = temp_folder() pkg1 = os.path.join(tmp_folder, "pkg1") cpp_info = CppInfo(pkg1) cpp_info.includedirs = ["include"] save(os.path.join(pkg1, "include", "file.h"), "") conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing") pkg2 = os.path.join(tmp_folder, "pkg2") cpp_info = CppInfo(pkg2) cpp_info.includedirs = ["include"] save(os.path.join(pkg2, "include", "file.h"), "") conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = VisualStudioGenerator(conanfile) path1 = os.path.join("$(USERPROFILE)", "pkg1", "include") path2 = os.path.join("$(USERPROFILE)", "pkg2", "include") expected1 = "<ConanIncludeDirectories>%s;%s;" % (path1, path2) expected2 = "<AdditionalIncludeDirectories>$(ConanIncludeDirectories)%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>" with tools.environment_append({"USERPROFILE": tmp_folder}): content = generator.content xml.etree.ElementTree.fromstring(content) self.assertIn(expected1, content) self.assertIn(expected2, content) with tools.environment_append({"USERPROFILE": tmp_folder.upper()}): content = generator.content xml.etree.ElementTree.fromstring(content) self.assertIn(expected1, content) self.assertIn(expected2, content)
def extend(cpp_info, config): """ adds the specific config configuration to the common one """ config_info = cpp_info.configs.get(config) if config_info: def add_lists(seq1, seq2): return seq1 + [s for s in seq2 if s not in seq1] result = CppInfo(str(config_info), config_info.rootpath) result.filter_empty = cpp_info.filter_empty result.includedirs = add_lists(cpp_info.includedirs, config_info.includedirs) result.libdirs = add_lists(cpp_info.libdirs, config_info.libdirs) result.bindirs = add_lists(cpp_info.bindirs, config_info.bindirs) result.resdirs = add_lists(cpp_info.resdirs, config_info.resdirs) result.builddirs = add_lists(cpp_info.builddirs, config_info.builddirs) result.libs = cpp_info.libs + config_info.libs result.defines = cpp_info.defines + config_info.defines result.cflags = cpp_info.cflags + config_info.cflags result.cxxflags = cpp_info.cxxflags + config_info.cxxflags result.sharedlinkflags = cpp_info.sharedlinkflags + config_info.sharedlinkflags result.exelinkflags = cpp_info.exelinkflags + config_info.exelinkflags result.system_libs = add_lists(cpp_info.system_libs, config_info.system_libs) result.build_modules = merge_dicts(cpp_info.build_modules, config_info.build_modules) return result return cpp_info
def test_read_write(self): conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder1") cpp_info.names["txt"] = "mypkg1-txt" cpp_info.version = ref.version cpp_info.defines = ["MYDEFINE1"] cpp_info.cxxflags = ["-cxxflag_parent"] cpp_info.includedirs = ["mypkg1/include"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder2") cpp_info.defines = ["MYDEFINE2"] cpp_info.cxxflags = ["-cxxflag_dep"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) master_content = TXTGenerator(conanfile).content after_parse, _, _ = TXTGenerator.loads(master_content, filter_empty=False) conanfile.deps_cpp_info = after_parse after_content = TXTGenerator(conanfile).content self.assertListEqual(master_content.splitlines(), after_content.splitlines())
def get_cpp_info(name): cppinfo = CppInfo("{}/1.0".format(name), "/tmp/root") cppinfo.includedirs = [] cppinfo.includedirs.append("path/includes/{}".format(name)) cppinfo.includedirs.append("other\\include\\path\\{}".format(name)) # To test some path in win, to be used with MinGW make or MSYS etc cppinfo.libdirs = [] cppinfo.libdirs.append("one\\lib\\path\\{}".format(name)) cppinfo.libs = [] cppinfo.libs.append("{}_onelib".format(name)) cppinfo.libs.append("{}_twolib".format(name)) cppinfo.defines = [] cppinfo.defines.append("{}_onedefinition".format(name)) cppinfo.defines.append("{}_twodefinition".format(name)) cppinfo.cflags = ["{}_a_c_flag".format(name)] cppinfo.cxxflags = ["{}_a_cxx_flag".format(name)] cppinfo.sharedlinkflags = ["{}_shared_link_flag".format(name)] cppinfo.exelinkflags = ["{}_exe_link_flag".format(name)] cppinfo.sysroot = "/path/to/folder/{}".format(name) cppinfo.frameworks = [] cppinfo.frameworks.append("{}_oneframework".format(name)) cppinfo.frameworks.append("{}_twoframework".format(name)) cppinfo.system_libs = [] cppinfo.system_libs.append("{}_onesystemlib".format(name)) cppinfo.system_libs.append("{}_twosystemlib".format(name)) cppinfo.frameworkdirs = [] cppinfo.frameworkdirs.append("one/framework/path/{}".format(name)) return cppinfo
def setUp(self): self.tmp_folder1 = temp_folder() self.tmp_folder2 = temp_folder() save(os.path.join(self.tmp_folder1, "include1", "file.h"), "") save(os.path.join(self.tmp_folder2, "include2", "file.h"), "") save(os.path.join(self.tmp_folder1, "lib1", "file.a"), "") save(os.path.join(self.tmp_folder2, "lib2", "file.a"), "") save(os.path.join(self.tmp_folder1, "bin1", "file.bin"), "") save(os.path.join(self.tmp_folder2, "bin2", "file.bin"), "") self.conanfile = ConanFile(TestBufferConanOutput(), None) self.conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg1/0.1@lasote/stables") cpp_info = CppInfo(self.tmp_folder1) cpp_info.defines = ["MYDEFINE1"] cpp_info.includedirs = ['include1'] cpp_info.libdirs = ['lib1'] cpp_info.libs = ['libfoo'] cpp_info.system_libs = ['syslib1'] cpp_info.bindirs = ['bin1'] cpp_info.version = "0.1" cpp_info.cflags = ['-fPIC'] cpp_info.cxxflags = ['-fPIE'] cpp_info.sharedlinkflags = ['-framework Cocoa'] cpp_info.exelinkflags = ['-framework QuartzCore'] self.conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("MyPkg2/3.2.3@lasote/stables") cpp_info = CppInfo(self.tmp_folder2) cpp_info.defines = ["MYDEFINE2"] cpp_info.includedirs = ['include2'] cpp_info.libdirs = ['lib2'] cpp_info.libs = ['libbar'] cpp_info.system_libs = ['syslib2'] cpp_info.bindirs = ['bin2'] cpp_info.version = "3.2.3" cpp_info.cflags = ['-mtune=native'] cpp_info.cxxflags = ['-march=native'] cpp_info.sharedlinkflags = [ '-framework AudioFoundation', '-framework "Some Spaced Framework"' ] cpp_info.exelinkflags = [ '-framework VideoToolbox', '-framework "Other Spaced Framework"' ] self.conanfile.deps_cpp_info.update(cpp_info, ref.name)
def test_absolute_directory(self): conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("pkg/0.1") cpp_info = CppInfo(ref.name, "C:/my/root/path") cpp_info.includedirs = ["D:/my/path/to/something"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) master_content = TXTGenerator(conanfile).content after_cpp_info, _, _, _ = TXTGenerator.loads(master_content, filter_empty=False) self.assertListEqual(after_cpp_info[ref.name].includedirs, ["D:/my/path/to/something"]) self.assertListEqual(after_cpp_info[ref.name].include_paths, ["D:/my/path/to/something"])
def test_abs_path_unix(self): conanfile = ConanFile(Mock(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("pkg/0.1") cpp_info = CppInfo(ref.name, "/rootdir") cpp_info.includedirs = ["/an/absolute/dir"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) master_content = TXTGenerator(conanfile).content after_cpp_info, _, _, _ = TXTGenerator.loads(master_content, filter_empty=False) self.assertListEqual(after_cpp_info[ref.name].includedirs, ["../an/absolute/dir"]) self.assertListEqual(after_cpp_info[ref.name].include_paths, ["/rootdir/../an/absolute/dir"])
def test_types(self): deps_cpp_info = DepsCppInfo() cpp_info = CppInfo("pkg", "rootpath") cpp_info.version = "version" cpp_info.libs = ["lib1", "lib2"] cpp_info.includedirs = ["include1"] deps_cpp_info.add("pkg", DepCppInfo(cpp_info)) info_for_package = deps_cpp_info["pkg"] # Documented as list for 'self.cpp_info' object self.assertIsInstance(info_for_package.includedirs, list) self.assertIsInstance(info_for_package.libdirs, list) self.assertIsInstance(info_for_package.resdirs, list) self.assertIsInstance(info_for_package.bindirs, list) self.assertIsInstance(info_for_package.builddirs, list) self.assertIsInstance(info_for_package.libs, list) self.assertIsInstance(info_for_package.defines, list) self.assertIsInstance(info_for_package.cflags, list) self.assertIsInstance(info_for_package.cppflags, list) self.assertIsInstance(info_for_package.cxxflags, list) self.assertIsInstance(info_for_package.sharedlinkflags, list) self.assertIsInstance(info_for_package.exelinkflags, list) self.assertIsInstance(info_for_package.frameworks, list) self.assertIsInstance(info_for_package.frameworkdirs, list) self.assertIsInstance(info_for_package.rootpath, six.string_types) self.assertIsInstance(info_for_package.name, six.string_types) self.assertIsInstance(info_for_package.system_libs, list) self.assertIsInstance(info_for_package.build_modules, list) self.assertIsInstance(info_for_package.components, dict) # Documented as list for `deps_cpp_info["pkg"]` self.assertIsInstance(info_for_package.include_paths, list) self.assertIsInstance(info_for_package.lib_paths, list) self.assertIsInstance(info_for_package.bin_paths, list) self.assertIsInstance(info_for_package.build_paths, list) self.assertIsInstance(info_for_package.res_paths, list) self.assertIsInstance(info_for_package.framework_paths, list) self.assertIsInstance(info_for_package.build_modules_paths, list) self.assertIsInstance(info_for_package.get_name("generator"), six.string_types) self.assertIsInstance(info_for_package.version, six.string_types) self.assertIsInstance(info_for_package.components, dict)
def extend(cpp_info, config): """ adds the specific config configuration to the common one """ config_info = cpp_info.configs.get(config) if config_info: result = CppInfo(config_info.rootpath) result.includedirs = cpp_info.includedirs + config_info.includedirs result.libdirs = cpp_info.libdirs + config_info.libdirs result.bindirs = cpp_info.bindirs + config_info.bindirs result.resdirs = cpp_info.resdirs + config_info.resdirs result.builddirs = cpp_info.builddirs + config_info.builddirs result.libs = cpp_info.libs + config_info.libs result.defines = cpp_info.defines + config_info.defines result.cflags = cpp_info.cflags + config_info.cflags result.cppflags = cpp_info.cppflags + config_info.cppflags result.sharedlinkflags = cpp_info.sharedlinkflags + config_info.sharedlinkflags result.exelinkflags = cpp_info.exelinkflags + config_info.exelinkflags return result return cpp_info
def variables_setup_test(self): tmp_folder1 = temp_folder() tmp_folder2 = temp_folder() save(os.path.join(tmp_folder1, "include1", "file.h"), "") save(os.path.join(tmp_folder2, "include2", "file.h"), "") save(os.path.join(tmp_folder1, "lib1", "file.a"), "") save(os.path.join(tmp_folder2, "lib2", "file.a"), "") save(os.path.join(tmp_folder1, "bin1", "file.bin"), "") save(os.path.join(tmp_folder2, "bin2", "file.bin"), "") save(os.path.join(tmp_folder1, "SystemFrameworks", "file.bin"), "") conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg1/0.1@lasote/stables") cpp_info = CppInfo(ref.name, tmp_folder1) cpp_info.defines = ["MYDEFINE1"] cpp_info.includedirs = ['include1'] cpp_info.libdirs = ['lib1'] cpp_info.libs = ['libfoo'] cpp_info.bindirs = ['bin1'] cpp_info.version = "0.1" cpp_info.cflags = ['-fgimple'] cpp_info.cxxflags = ['-fdollars-in-identifiers'] cpp_info.sharedlinkflags = ['-framework Cocoa'] cpp_info.exelinkflags = ['-framework QuartzCore'] cpp_info.frameworks = ['AudioUnit'] cpp_info.frameworkdirs = ['SystemFrameworks'] cpp_info.system_libs = ["system_lib1"] conanfile.deps_cpp_info.add(ref.name, cpp_info) ref = ConanFileReference.loads("MyPkg2/3.2.3@lasote/stables") cpp_info = CppInfo(ref.name, tmp_folder2) cpp_info.defines = ["MYDEFINE2"] cpp_info.includedirs = ['include2'] cpp_info.libdirs = ['lib2'] cpp_info.libs = ['libbar'] cpp_info.bindirs = ['bin2'] cpp_info.version = "3.2.3" cpp_info.cflags = ['-fno-asm'] cpp_info.cxxflags = ['-pthread'] cpp_info.sharedlinkflags = ['-framework AudioFoundation'] cpp_info.exelinkflags = ['-framework VideoToolbox'] cpp_info.system_libs = ["system_lib2"] conanfile.deps_cpp_info.add(ref.name, cpp_info) generator = MakeGenerator(conanfile) content = generator.content content_template = """ CONAN_ROOT_MYPKG1 ?= \\ {conan_root_mypkg1} CONAN_SYSROOT_MYPKG1 ?= \\ CONAN_INCLUDE_DIRS_MYPKG1 += \\ {conan_include_dirs_mypkg1} CONAN_LIB_DIRS_MYPKG1 += \\ {conan_lib_dirs_mypkg1} CONAN_BIN_DIRS_MYPKG1 += \\ {conan_bin_dirs_mypkg1} CONAN_BUILD_DIRS_MYPKG1 += \\ {conan_build_dirs_mypkg1} CONAN_RES_DIRS_MYPKG1 += \\ CONAN_LIBS_MYPKG1 += \\ libfoo CONAN_SYSTEM_LIBS_MYPKG1 += \\ system_lib1 CONAN_DEFINES_MYPKG1 += \\ MYDEFINE1 CONAN_CFLAGS_MYPKG1 += \\ -fgimple CONAN_CXXFLAGS_MYPKG1 += \\ -fdollars-in-identifiers CONAN_SHAREDLINKFLAGS_MYPKG1 += \\ -framework Cocoa CONAN_EXELINKFLAGS_MYPKG1 += \\ -framework QuartzCore CONAN_FRAMEWORKS_MYPKG1 += \\ AudioUnit CONAN_FRAMEWORK_PATHS_MYPKG1 += \\ {conan_framework_dirs_mypkg1} CONAN_ROOT_MYPKG2 ?= \\ {conan_root_mypkg2} CONAN_SYSROOT_MYPKG2 ?= \\ CONAN_INCLUDE_DIRS_MYPKG2 += \\ {conan_include_dirs_mypkg2} CONAN_LIB_DIRS_MYPKG2 += \\ {conan_lib_dirs_mypkg2} CONAN_BIN_DIRS_MYPKG2 += \\ {conan_bin_dirs_mypkg2} CONAN_BUILD_DIRS_MYPKG2 += \\ {conan_build_dirs_mypkg2} CONAN_RES_DIRS_MYPKG2 += \\ CONAN_LIBS_MYPKG2 += \\ libbar CONAN_SYSTEM_LIBS_MYPKG2 += \\ system_lib2 CONAN_DEFINES_MYPKG2 += \\ MYDEFINE2 CONAN_CFLAGS_MYPKG2 += \\ -fno-asm CONAN_CXXFLAGS_MYPKG2 += \\ -pthread CONAN_SHAREDLINKFLAGS_MYPKG2 += \\ -framework AudioFoundation CONAN_EXELINKFLAGS_MYPKG2 += \\ -framework VideoToolbox CONAN_FRAMEWORKS_MYPKG2 += \\ CONAN_FRAMEWORK_PATHS_MYPKG2 += \\ CONAN_ROOTPATH += \\ $(CONAN_ROOTPATH_MYPKG1) \\ $(CONAN_ROOTPATH_MYPKG2) CONAN_SYSROOT += \\ $(CONAN_SYSROOT_MYPKG1) \\ $(CONAN_SYSROOT_MYPKG2) CONAN_INCLUDE_DIRS += \\ $(CONAN_INCLUDE_DIRS_MYPKG1) \\ $(CONAN_INCLUDE_DIRS_MYPKG2) CONAN_LIB_DIRS += \\ $(CONAN_LIB_DIRS_MYPKG1) \\ $(CONAN_LIB_DIRS_MYPKG2) CONAN_BIN_DIRS += \\ $(CONAN_BIN_DIRS_MYPKG1) \\ $(CONAN_BIN_DIRS_MYPKG2) CONAN_BUILD_DIRS += \\ $(CONAN_BUILD_DIRS_MYPKG1) \\ $(CONAN_BUILD_DIRS_MYPKG2) CONAN_RES_DIRS += \\ $(CONAN_RES_DIRS_MYPKG1) \\ $(CONAN_RES_DIRS_MYPKG2) CONAN_LIBS += \\ $(CONAN_LIBS_MYPKG1) \\ $(CONAN_LIBS_MYPKG2) CONAN_DEFINES += \\ $(CONAN_DEFINES_MYPKG1) \\ $(CONAN_DEFINES_MYPKG2) CONAN_CFLAGS += \\ $(CONAN_CFLAGS_MYPKG1) \\ $(CONAN_CFLAGS_MYPKG2) CONAN_CXXFLAGS += \\ $(CONAN_CXXFLAGS_MYPKG1) \\ $(CONAN_CXXFLAGS_MYPKG2) CONAN_SHAREDLINKFLAGS += \\ $(CONAN_SHAREDLINKFLAGS_MYPKG1) \\ $(CONAN_SHAREDLINKFLAGS_MYPKG2) CONAN_EXELINKFLAGS += \\ $(CONAN_EXELINKFLAGS_MYPKG1) \\ $(CONAN_EXELINKFLAGS_MYPKG2) CONAN_FRAMEWORKS += \\ $(CONAN_FRAMEWORKS_MYPKG1) \\ $(CONAN_FRAMEWORKS_MYPKG2) CONAN_FRAMEWORK_PATHS += \\ $(CONAN_FRAMEWORK_PATHS_MYPKG1) \\ $(CONAN_FRAMEWORK_PATHS_MYPKG2) """ root1 = tmp_folder1.replace('\\', '/') root2 = tmp_folder2.replace('\\', '/') inc1 = os.path.join(tmp_folder1, 'include1').replace('\\', '/') inc2 = os.path.join(tmp_folder2, 'include2').replace('\\', '/') lib1 = os.path.join(tmp_folder1, 'lib1').replace('\\', '/') lib2 = os.path.join(tmp_folder2, 'lib2').replace('\\', '/') bin1 = os.path.join(tmp_folder1, 'bin1').replace('\\', '/') bin2 = os.path.join(tmp_folder2, 'bin2').replace('\\', '/') expected_content = content_template.format( conan_root_mypkg1=root1, conan_include_dirs_mypkg1=inc1, conan_lib_dirs_mypkg1=lib1, conan_bin_dirs_mypkg1=bin1, conan_build_dirs_mypkg1=root1 + "/", conan_root_mypkg2=root2, conan_include_dirs_mypkg2=inc2, conan_lib_dirs_mypkg2=lib2, conan_bin_dirs_mypkg2=bin2, conan_build_dirs_mypkg2=root2 + "/", conan_framework_dirs_mypkg1=root1 + "/SystemFrameworks") self.maxDiff = None self.assertIn(expected_content, content)
def variables_setup_test(self): tmp_folder1 = temp_folder() tmp_folder2 = temp_folder() save(os.path.join(tmp_folder1, "include1", "file.h"), "") save(os.path.join(tmp_folder2, "include2", "file.h"), "") save(os.path.join(tmp_folder1, "lib1", "file.a"), "") save(os.path.join(tmp_folder2, "lib2", "file.a"), "") save(os.path.join(tmp_folder1, "bin1", "file.bin"), "") save(os.path.join(tmp_folder2, "bin2", "file.bin"), "") conanfile = ConanFile(None, None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg1/0.1@lasote/stables") cpp_info = CppInfo(tmp_folder1) cpp_info.defines = ["MYDEFINE1"] cpp_info.includedirs = ['include1'] cpp_info.libdirs = ['lib1'] cpp_info.libs = ['libfoo'] cpp_info.bindirs = ['bin1'] cpp_info.version = "0.1" cpp_info.cflags = ['-fPIC'] cpp_info.cppflags = ['-fPIE'] cpp_info.sharedlinkflags = ['-framework Cocoa'] cpp_info.exelinkflags = ['-framework QuartzCore'] conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("MyPkg2/3.2.3@lasote/stables") cpp_info = CppInfo(tmp_folder2) cpp_info.defines = ["MYDEFINE2"] cpp_info.includedirs = ['include2'] cpp_info.libdirs = ['lib2'] cpp_info.libs = ['libbar'] cpp_info.bindirs = ['bin2'] cpp_info.version = "3.2.3" cpp_info.cflags = ['-mtune=native'] cpp_info.cppflags = ['-march=native'] cpp_info.sharedlinkflags = ['-framework AudioFoundation'] cpp_info.exelinkflags = ['-framework VideoToolbox'] conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = PremakeGenerator(conanfile) content = generator.content self.assertIn('conan_cppdefines = {"MYDEFINE2", "MYDEFINE1"}', content) self.assertIn('conan_cppdefines_MyPkg1 = {"MYDEFINE1"}', content) self.assertIn('conan_cppdefines_MyPkg2 = {"MYDEFINE2"}', content) inc1 = os.path.join(tmp_folder1, 'include1').replace('\\', '/') inc2 = os.path.join(tmp_folder2, 'include2').replace('\\', '/') self.assertIn('conan_includedirs = {"%s",\n"%s"}' % (inc1, inc2), content) self.assertIn('conan_includedirs_MyPkg1 = {"%s"}' % inc1, content) self.assertIn('conan_includedirs_MyPkg2 = {"%s"}' % inc2, content) lib1 = os.path.join(tmp_folder1, 'lib1').replace('\\', '/') lib2 = os.path.join(tmp_folder2, 'lib2').replace('\\', '/') self.assertIn('conan_libdirs = {"%s",\n"%s"}' % (lib1, lib2), content) self.assertIn('conan_libdirs_MyPkg1 = {"%s"}' % lib1, content) self.assertIn('conan_libdirs_MyPkg2 = {"%s"}' % lib2, content) bin1 = os.path.join(tmp_folder1, 'bin1').replace('\\', '/') bin2 = os.path.join(tmp_folder2, 'bin2').replace('\\', '/') self.assertIn('conan_bindirs = {"%s",\n"%s"}' % (bin1, bin2), content) self.assertIn('conan_bindirs_MyPkg1 = {"%s"}' % bin1, content) self.assertIn('conan_bindirs_MyPkg2 = {"%s"}' % bin2, content) self.assertIn('conan_libs = {"libfoo", "libbar"}', content) self.assertIn('conan_libs_MyPkg1 = {"libfoo"}', content) self.assertIn('conan_libs_MyPkg2 = {"libbar"}', content) self.assertIn('conan_cflags = {"-mtune=native", "-fPIC"}', content) self.assertIn('conan_cflags_MyPkg1 = {"-fPIC"}', content) self.assertIn('conan_cflags_MyPkg2 = {"-mtune=native"}', content) self.assertIn('conan_cppflags = {"-march=native", "-fPIE"}', content) self.assertIn('conan_cppflags_MyPkg1 = {"-fPIE"}', content) self.assertIn('conan_cppflags_MyPkg2 = {"-march=native"}', content) self.assertIn( 'conan_sharedlinkflags = {"-framework AudioFoundation", "-framework Cocoa"}', content) self.assertIn('conan_sharedlinkflags_MyPkg1 = {"-framework Cocoa"}', content) self.assertIn( 'conan_sharedlinkflags_MyPkg2 = {"-framework AudioFoundation"}', content) self.assertIn( 'conan_exelinkflags = {"-framework VideoToolbox", "-framework QuartzCore"}', content) self.assertIn('conan_exelinkflags_MyPkg1 = {"-framework QuartzCore"}', content) self.assertIn( 'conan_exelinkflags_MyPkg2 = {"-framework VideoToolbox"}', content)
def test_idempotent(self): conanfile = ConanFile(Mock(), None) conanfile.initialize(Settings({}), EnvValues()) # Add some cpp_info ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder1") cpp_info.names["txt"] = "mypkg1-txt" cpp_info.version = ref.version cpp_info.defines = ["MYDEFINE1"] cpp_info.cxxflags = ["-cxxflag_parent"] cpp_info.includedirs = ["mypkg1/include"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder2") cpp_info.defines = ["MYDEFINE2"] cpp_info.cxxflags = ["-cxxflag_dep"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) # Add env_info env_info = EnvInfo() env_info.VAR1 = "value1" env_info.PATH.append("path-extended") conanfile.deps_env_info.update(env_info, "my_pkg") env_info = EnvInfo() env_info.VAR1 = "other-value1" env_info.PATH.append("other-path-extended") conanfile.deps_env_info.update(env_info, "other-pkg") # Add user_info for HOST user_info = UserInfo() user_info.VAR1 = "value1" conanfile.deps_user_info["my_pkg"] = user_info user_info = UserInfo() user_info.VAR1 = "other-value1" conanfile.deps_user_info["other-pkg"] = user_info # Add user_info for BUILD conanfile.user_info_build = DepsUserInfo() user_info = UserInfo() user_info.VAR1 = "value1" conanfile.user_info_build["build_pkg"] = user_info user_info = UserInfo() user_info.VAR1 = "other-value1" conanfile.user_info_build["other-build-pkg"] = user_info master_content = TXTGenerator(conanfile).content after_cpp_info, after_user_info, after_env_info, after_user_info_build = \ TXTGenerator.loads(master_content, filter_empty=False) # Assign them to a different conanfile other_conanfile = ConanFile(Mock(), None) other_conanfile.initialize(Settings({}), EnvValues()) other_conanfile.deps_cpp_info = after_cpp_info other_conanfile.deps_env_info = after_env_info other_conanfile.deps_user_info = after_user_info other_conanfile.user_info_build = after_user_info_build after_content = TXTGenerator(other_conanfile).content self.assertListEqual(master_content.splitlines(), after_content.splitlines())