def test_copy_command(self): client = TestClient() conanfile = """from conans import ConanFile class Pkg(ConanFile): settings = "os" """ client.save({"conanfile.py": conanfile}) client.run("export . Hello0/0.1@lasote/stable") client.run("install Hello0/0.1@lasote/stable -s os=Windows --build missing") client.run("install Hello0/0.1@lasote/stable -s os=Linux --build missing") client.run("install Hello0/0.1@lasote/stable -s os=Macos --build missing") # Copy all packages client.run("copy Hello0/0.1@lasote/stable pepe/testing --all") pkgdir = client.paths.packages(ConanFileReference.loads("Hello0/0.1@pepe/testing")) packages = os.listdir(pkgdir) self.assertEquals(len(packages), 3) # Copy just one client.run("copy Hello0/0.1@lasote/stable pepe/stable -p %s" % packages[0]) pkgdir = client.paths.packages(ConanFileReference.loads("Hello0/0.1@pepe/stable")) packages = os.listdir(pkgdir) self.assertEquals(len(packages), 1) # Force client.run("copy Hello0/0.1@lasote/stable pepe/stable -p %s --force" % packages[0]) packages = os.listdir(pkgdir) self.assertEquals(len(packages), 1) # Copy only recipe client.run("copy Hello0/0.1@lasote/stable pepe/alpha", ignore_error=True) pkgdir = client.paths.packages(ConanFileReference.loads("Hello0/0.1@pepe/alpha")) self.assertFalse(os.path.exists(pkgdir))
def case_insensitive_test(self): root_folder2 = "sdl/1.5/lasote/stable" conan_ref2 = ConanFileReference.loads("sdl/1.5@lasote/stable") os.makedirs("%s/%s" % (root_folder2, EXPORT_FOLDER)) root_folder3 = "assimp/0.14/phil/testing" conan_ref3 = ConanFileReference.loads("assimp/0.14@phil/testing") os.makedirs("%s/%s" % (root_folder3, EXPORT_FOLDER)) root_folder4 = "sdl/2.10/lasote/stable" conan_ref4 = ConanFileReference.loads("sdl/2.10@lasote/stable") os.makedirs("%s/%s" % (root_folder4, EXPORT_FOLDER)) root_folder5 = "SDL_fake/1.10/lasote/testing" conan_ref5 = ConanFileReference.loads("SDL_fake/1.10@lasote/testing") os.makedirs("%s/%s" % (root_folder5, EXPORT_FOLDER)) # Case insensitive searches search_adapter = DiskSearchAdapter() search_manager = DiskSearchManager(self.paths, search_adapter) reg_conans = sorted([str(_reg) for _reg in search_manager.search("*")]) self.assertEqual(reg_conans, [str(conan_ref5), str(conan_ref3), str(conan_ref2), str(conan_ref4)]) reg_conans = sorted([str(_reg) for _reg in search_manager.search(pattern="sdl*")]) self.assertEqual(reg_conans, [str(conan_ref5), str(conan_ref2), str(conan_ref4)]) # Case sensitive search self.assertEqual(str(search_manager.search(pattern="SDL*", ignorecase=False)[0]), str(conan_ref5))
def search_test(self): # Upload a conan1 conan_name1 = "HelloOnly/0.10@private_user/testing" conan_reference1 = ConanFileReference.loads(conan_name1) self._upload_recipe(conan_reference1) # Upload a package conan_info = """[settings] arch=x86_64 compiler=gcc os=Linux [options] 386=False [requires] Hello Bye/2.9 Say/2.1@user/testing Chat/2.1@user/testing:SHA_ABC """ package_reference = PackageReference(conan_reference1, "1F23223EFDA") self._upload_package(package_reference, {CONANINFO: conan_info}) # Upload a conan2 conan_name2 = "helloonlyToo/2.1@private_user/stable" conan_reference2 = ConanFileReference.loads(conan_name2) self._upload_recipe(conan_reference2) # Get the info about this ConanFileReference info = self.api.search_packages(conan_reference1, None) self.assertEqual(ConanInfo.loads(conan_info).serialize_min(), info["1F23223EFDA"]) # Search packages results = self.api.search("HelloOnly*", ignorecase=False) self.assertEqual(results, [conan_reference1])
def upper_option_txt_test(self): self._create("Hello0", "0.1", no_config=True) self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True) files = cpp_hello_conan_files("Hello2", "0.1", ["Hello1/0.1@lasote/stable"]) files.pop(CONANFILE) files[CONANFILE_TXT] = """[requires] Hello1/0.1@lasote/stable [options] Hello0:language=1 Hello1:language=0 """ self.client.save(files, clean_first=True) self.client.run("install %s --build missing" % self.settings) info_path = os.path.join(self.client.current_folder, CONANINFO) conan_info = ConanInfo.load_file(info_path) self.assertEqual("", conan_info.options.dumps()) conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable") hello0 = self.client.paths.package(PackageReference(conan_ref, "8b964e421a5b7e48b7bc19b94782672be126be8b")) hello0_info = os.path.join(hello0, CONANINFO) hello0_conan_info = ConanInfo.load_file(hello0_info) self.assertEqual(1, hello0_conan_info.options.language) package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"), "44671ecdd9c606eb7166f2197ab50be8d36a3c3b") hello1 = self.client.paths.package(package_ref1) hello1_info = os.path.join(hello1, CONANINFO) hello1_conan_info = ConanInfo.load_file(hello1_info) self.assertEqual(0, hello1_conan_info.options.language)
def _is_a_reference(ref): try: ConanFileReference.loads(ref) return "*" not in ref # If is a pattern, it is not a reference except ConanException: pass return False
def reuse_test(self): conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1", build=False) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) client.save(files) client.run("export lasote/stable") client.run("upload %s" % str(conan_reference)) gen_reference = ConanFileReference.loads("MyCustomGen/0.2@lasote/stable") files = {CONANFILE: generator} client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) client.save(files) client.run("export lasote/stable") client.run("upload %s" % str(gen_reference)) # Test local, no retrieval files = {CONANFILE_TXT: consumer} client.save(files, clean_first=True) client.run("install --build") generated = load(os.path.join(client.current_folder, "customfile.gen")) self.assertEqual(generated, "My custom generator content") # Test retrieval from remote client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files = {CONANFILE_TXT: consumer} client.save(files) client.run("install --build") generated = load(os.path.join(client.current_folder, "customfile.gen")) self.assertEqual(generated, "My custom generator content")
def load_conan_txt(self, conan_requirements_path, output): if not os.path.exists(conan_requirements_path): raise NotFoundException("Conanfile not found!") conanfile = ConanFile(output, self._runner, self._settings.copy(), os.path.dirname(conan_requirements_path)) try: parser = ConanFileTextLoader(load(conan_requirements_path)) except Exception as e: raise ConanException("%s:\n%s" % (conan_requirements_path, str(e))) for requirement_text in parser.requirements: ConanFileReference.loads(requirement_text) # Raise if invalid conanfile.requires.add(requirement_text) conanfile.generators = parser.generators options = OptionsValues.loads(parser.options) conanfile.options.values = options conanfile.options.initialize_upstream(self._options) # imports method conanfile.imports = ConanFileTextLoader.imports_method(conanfile, parser.import_parameters) conanfile.scope = self._scopes.package_scope() return conanfile
def _parse_conan_txt(self, contents, path, output): conanfile = ConanFile(output, self._runner, Settings()) # It is necessary to copy the settings, because the above is only a constraint of # conanfile settings, and a txt doesn't define settings. Necessary for generators, # as cmake_multi, that check build_type. conanfile.settings = self._settings.copy_values() try: parser = ConanFileTextLoader(contents) except Exception as e: raise ConanException("%s:\n%s" % (path, str(e))) for requirement_text in parser.requirements: ConanFileReference.loads(requirement_text) # Raise if invalid conanfile.requires.add(requirement_text) for build_requirement_text in parser.build_requirements: ConanFileReference.loads(build_requirement_text) if not hasattr(conanfile, "build_requires"): conanfile.build_requires = [] conanfile.build_requires.append(build_requirement_text) conanfile.generators = parser.generators options = OptionsValues.loads(parser.options) conanfile.options.values = options conanfile.options.initialize_upstream(self._user_options) # imports method conanfile.imports = parser.imports_method(conanfile) conanfile._env_values.update(self._env_values) return conanfile
def valid_xml_test(self): conanfile = ConanFile(None, None, Settings({}), None) ref = ConanFileReference.loads("MyPkg/0.1@user/testing") folder1 = temp_folder() folder1 = folder1.replace("\\", "/") os.makedirs(os.path.join(folder1, "include")) os.makedirs(os.path.join(folder1, "lib")) cpp_info = CppInfo(folder1) conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing") folder2 = temp_folder() folder2 = folder2.replace("\\", "/") os.makedirs(os.path.join(folder2, "include")) os.makedirs(os.path.join(folder2, "lib")) cpp_info = CppInfo(folder2) conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = VisualStudioLegacyGenerator(conanfile) content = generator.content xml.etree.ElementTree.fromstring(content) self.assertIn('AdditionalIncludeDirectories=""%s/include";"%s/include";"' % (folder1, folder2), content) self.assertIn('AdditionalLibraryDirectories=""%s/lib";"%s/lib";"' % (folder1, folder2), content)
def variables_setup_test(self): conanfile = ConanFile(None, None, Settings({}), None) ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder1") cpp_info.defines = ["MYDEFINE1"] cpp_info.cflags.append("-Flag1=23") cpp_info.version = "1.3" cpp_info.description = "My cool description" conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder2") cpp_info.defines = ["MYDEFINE2"] cpp_info.version = "2.3" cpp_info.exelinkflags = ["-exelinkflag"] cpp_info.sharedlinkflags = ["-sharedlinkflag"] cpp_info.cppflags = ["-cppflag"] cpp_info.public_deps = ["MyPkg"] conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = JsonGenerator(conanfile) json_out = generator.content parsed = json.loads(json_out) dependencies = parsed["dependencies"] self.assertEquals(len(dependencies), 2) my_pkg = dependencies[0] self.assertEquals(my_pkg["name"], "MyPkg") self.assertEquals(my_pkg["description"], "My cool description") self.assertEquals(my_pkg["defines"], ["MYDEFINE1"])
def test_override(self): files = cpp_hello_conan_files(name="VisualBuild", version="0.1", build=False, deps=["MinGWBuild/0.1@lasote/testing"]) self._patch_build_to_print_compiler(files) self.client.save(files) self.client.run("export . lasote/testing") self.client.run("install VisualBuild/0.1@lasote/testing --build missing -s compiler='Visual Studio' " "-s compiler.version=14 -s compiler.runtime=MD " "-s MinGWBuild:compiler='gcc' -s MinGWBuild:compiler.libcxx='libstdc++' " "-s MinGWBuild:compiler.version=4.8") self.assertIn("COMPILER=> MinGWBuild gcc", self.client.user_io.out) self.assertIn("COMPILER=> VisualBuild Visual Studio", self.client.user_io.out) # CHECK CONANINFO FILE packs_dir = self.client.paths.packages(ConanFileReference.loads("MinGWBuild/0.1@lasote/testing")) pack_dir = os.path.join(packs_dir, os.listdir(packs_dir)[0]) conaninfo = load(os.path.join(pack_dir, CONANINFO)) self.assertIn("compiler=gcc", conaninfo) # CHECK CONANINFO FILE packs_dir = self.client.paths.packages(ConanFileReference.loads("VisualBuild/0.1@lasote/testing")) pack_dir = os.path.join(packs_dir, os.listdir(packs_dir)[0]) conaninfo = load(os.path.join(pack_dir, CONANINFO)) self.assertIn("compiler=Visual Studio", conaninfo) self.assertIn("compiler.version=14", conaninfo)
def reuse_test(self): self._create("Hello0", "0.1") self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"]) self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False) for lang, id0, id1 in [(0, "2e38bbc2c3ef1425197c8e2ffa8532894c347d26", "44671ecdd9c606eb7166f2197ab50be8d36a3c3b"), (1, "8b964e421a5b7e48b7bc19b94782672be126be8b", "3eeab577a3134fa3afdcd82881751789ec48e08f")]: self.client.run("install -o language=%d %s --build missing" % (lang, self.settings)) info_path = os.path.join(self.client.current_folder, CONANINFO) conan_info = ConanInfo.load_file(info_path) self.assertEqual("arch=x86\n" "compiler=Visual Studio\n" "compiler.runtime=MD\n" "compiler.version=12\n" "os=Windows", conan_info.settings.dumps()) self.assertEqual("language=%s\nstatic=True" % lang, conan_info.options.dumps()) conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable") hello0 = self.client.paths.package(PackageReference(conan_ref, id0)) hello0_info = os.path.join(hello0, CONANINFO) hello0_conan_info = ConanInfo.load_file(hello0_info) self.assertEqual(lang, hello0_conan_info.options.language) package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"), id1) hello1 = self.client.paths.package(package_ref1) hello1_info = os.path.join(hello1, CONANINFO) hello1_conan_info = ConanInfo.load_file(hello1_info) self.assertEqual(lang, hello1_conan_info.options.language)
def inverse_upper_option_test(self): self._create("Hello0", "0.1", no_config=True) self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True) self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False, no_config=True) self.client.run("install -o language=0 -o Hello1:language=1 -o Hello0:language=0 %s " "--build missing" % self.settings) info_path = os.path.join(self.client.current_folder, CONANINFO) conan_info = ConanInfo.load_file(info_path) self.assertEqual("language=0\nstatic=True", conan_info.options.dumps()) conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable") hello0 = self.client.paths.package(PackageReference(conan_ref, "2e38bbc2c3ef1425197c8e2ffa8532894c347d26")) hello0_info = os.path.join(hello0, CONANINFO) hello0_conan_info = ConanInfo.load_file(hello0_info) self.assertEqual("language=0\nstatic=True", hello0_conan_info.options.dumps()) package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"), "3eeab577a3134fa3afdcd82881751789ec48e08f") hello1 = self.client.paths.package(package_ref1) hello1_info = os.path.join(hello1, CONANINFO) hello1_conan_info = ConanInfo.load_file(hello1_info) self.assertEqual("language=1\nstatic=True", hello1_conan_info.options.dumps())
def basic_test(self): boost_values = PackageOptionValues() boost_values.add_option("static", False) boost_values.add_option("thread", True) boost_values.add_option("thread.multi", "off") poco_values = PackageOptionValues() poco_values.add_option("deps_bundled", True) hello1_values = PackageOptionValues() hello1_values.add_option("static", False) hello1_values.add_option("optimized", 4) options = {"Boost": boost_values, "Poco": poco_values, "Hello1": hello1_values} down_ref = ConanFileReference.loads("Hello0/0.1@diego/testing") own_ref = ConanFileReference.loads("Hello1/0.1@diego/testing") output = TestBufferConanOutput() self.sut.propagate_upstream(options, down_ref, own_ref, output) self.assertEqual(self.sut.values.as_list(), [("optimized", "4"), ("path", "NOTDEF"), ("static", "False"), ("Boost:static", "False"), ("Boost:thread", "True"), ("Boost:thread.multi", "off"), ("Poco:deps_bundled", "True")]) boost_values = PackageOptionValues() boost_values.add_option("static", 2) boost_values.add_option("thread", "Any") boost_values.add_option("thread.multi", "on") poco_values = PackageOptionValues() poco_values.add_option("deps_bundled", "What") hello1_values = PackageOptionValues() hello1_values.add_option("static", True) hello1_values.add_option("optimized", "2") options2 = {"Boost": boost_values, "Poco": poco_values, "Hello1": hello1_values} down_ref = ConanFileReference.loads("Hello2/0.1@diego/testing") self.sut.propagate_upstream(options2, down_ref, own_ref, output) self.assertIn("""WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option optimized to 2 but it was already assigned to 4 by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option static to True but it was already assigned to False by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:static to 2 but it was already assigned to False by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread to Any but it was already assigned to True by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread.multi to on but it was already assigned to off by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Poco:deps_bundled to What but it was already assigned to True by Hello0/0.1@diego/testing""", str(output)) self.assertEqual(self.sut.values.dumps(), """optimized=4 path=NOTDEF static=False Boost:static=False Boost:thread=True Boost:thread.multi=off Poco:deps_bundled=True""")
def copy(self, *args): """ Copy packages to another user/channel """ parser = argparse.ArgumentParser(description=self.copy.__doc__, prog="conan copy") parser.add_argument("reference", default="", help='reference' 'e.g., OpenSSL/1.0.2e@lasote/stable') parser.add_argument("user_channel", default="", help='Destination user/channel' 'e.g., lasote/testing') parser.add_argument("--package", "-p", nargs=1, action=Extender, help='copy specified package ID') parser.add_argument("--all", action='store_true', default=False, help='Copy all packages from the specified reference') parser.add_argument("--force", action='store_true', default=False, help='Override destination packages and conanfile') args = parser.parse_args(*args) reference = ConanFileReference.loads(args.reference) new_ref = ConanFileReference.loads("%s/%s@%s" % (reference.name, reference.version, args.user_channel)) if args.all: args.package = [] self._manager.copy(reference, args.package, new_ref.user, new_ref.channel, args.force)
def copy(self, reference="", user_channel="", force=False, all=False, package=None): reference = ConanFileReference.loads(reference) new_ref = ConanFileReference.loads("%s/%s@%s" % (reference.name, reference.version, user_channel)) if all: package = [] self._manager.copy(reference, package, new_ref.user, new_ref.channel, force)
def setUp(self): self.ref1 = ConanFileReference.loads("lib1/1.0@conan/stable") self.ref2 = ConanFileReference.loads("lib2/1.0@conan/stable") self.ref3 = ConanFileReference.loads("lib3/1.0@conan/stable") self.ref_p1 = PackageReference(self.ref1, "1") self.ref_p2 = PackageReference(self.ref2, "2") self.ref_p3 = PackageReference(self.ref3, "3")
def reuse_test(self): self._export_upload("hello0/0.1@lasote/stable") self._export_upload("hello1/0.1@lasote/stable", 1, [0]) self._export_upload("hello2/0.1@lasote/stable", 2, [0]) self._export_upload("hello3/0.1@lasote/stable", 3, [1, 2]) client = TestClient(servers=self.servers, users=[("lasote", "mypass")]) # Mocked userio conan_reference = ConanFileReference.loads("hello4/0.2@lasote/stable") files3 = hello_conan_files(conan_reference=conan_reference, number=4, deps=[3], lang='go') client.save(files3) os.chdir(client.current_folder) client.run("install --build missing") client.run("build") command = "say_hello" if platform.system() == "Windows" else "./say_hello" with CustomEnvPath(paths_to_add=['$GOPATH/bin'], var_to_add=[('GOPATH', client.current_folder), ]): client.runner('go install hello4_main', os.path.join(client.current_folder, 'src')) if platform.system() == "Windows": command = "hello4_main" else: command = './hello4_main' client.runner(command, os.path.join(client.current_folder, 'bin')) self.assertEqual(['Hello 4', 'Hello 3', 'Hello 1', 'Hello 0', 'Hello 2', 'Hello 0'], str(client.user_io.out).splitlines()[-6:]) # Try to upload and reuse the binaries client.run("upload hello3/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) client.run("upload hello1/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) client.run("upload hello2/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) client.run("upload hello0/0.1@lasote/stable --all") self.assertEqual(str(client.user_io.out).count("Uploading package"), 1) # client2 = TestClient(servers=self.servers, users=[("lasote", "mypass")]) # Mocked userio conan_reference = ConanFileReference.loads("hello4/0.2@lasote/stable") files3 = hello_conan_files(conan_reference=conan_reference, number=4, deps=[3], lang='go') client2.save(files3) client2.run("install --build missing") command = "say_hello" if platform.system() == "Windows" else "./say_hello" with CustomEnvPath(paths_to_add=['$GOPATH/bin'], var_to_add=[('GOPATH', client2.current_folder), ]): client2.runner('go install hello4_main', os.path.join(client2.current_folder, 'src')) if platform.system() == "Windows": command = "hello4_main" else: command = './hello4_main' client2.runner(command, os.path.join(client2.current_folder, 'bin')) self.assertEqual(['Hello 4', 'Hello 3', 'Hello 1', 'Hello 0', 'Hello 2', 'Hello 0'], str(client2.user_io.out).splitlines()[-6:])
def check_wildcards_test(self): # Only pepe can read openssl versions read_perms = [("openssl/*@lasote/testing", "pepe"), ("*/*@*/*", "*")] # Only pepe (and lasote because its owner) can write it and no more users can write write_perms = [(str(self.openssl_ref), "pepe")] authorizer = BasicAuthorizer(read_perms, write_perms) # Pepe can read all openssl versions authorizer.check_read_conan("pepe", self.openssl_ref) authorizer.check_read_conan("pepe", self.openssl_ref2) # Other user can't self.assertRaises(ForbiddenException, authorizer.check_read_conan, "juan", self.openssl_ref) self.assertRaises(ForbiddenException, authorizer.check_read_conan, "juan", self.openssl_ref2) # Only pepe can read versions 2.0.1 of lasote/testing read_perms = [("*/2.0.2@lasote/testing", "pepe"), ("*/*@*/*", "*")] authorizer = BasicAuthorizer(read_perms, write_perms) # Pepe can read openssl 2.0.1 version and 2.0.2 (only matches 2.0.2, so other is allowed) authorizer.check_read_conan("pepe", self.openssl_ref2) authorizer.check_read_conan("pepe", self.openssl_ref2) # Other user can't read 2.0.2 authorizer.check_read_conan("juan", self.openssl_ref) self.assertRaises(ForbiddenException, authorizer.check_read_conan, "juan", self.openssl_ref2) # Only pepe can read openssl version 2.0.1 from any owner read_perms = [("openssl/2.0.1@*/testing", "pepe")] # Only pepe (and lasote because its owner) can write it and no more users can write write_perms = [(str(self.openssl_ref), "pepe")] authorizer = BasicAuthorizer(read_perms, write_perms) # Pepe can read any openssl/2.0.1 authorizer.check_read_conan("pepe", self.openssl_ref) tmp_ref = ConanFileReference.loads("openssl/2.0.1@alfred/testing") authorizer.check_read_conan("pepe", tmp_ref) self.assertRaises(ForbiddenException, authorizer.check_read_conan, "juan", self.openssl_ref) self.assertRaises(ForbiddenException, authorizer.check_read_conan, "juan", tmp_ref) # Only pepe can read openssl version 2.0.1 from lasote/any channel read_perms = [("openssl/2.0.1@lasote/*", "pepe")] # Only pepe (and lasote because its owner) can write it and no more users can write write_perms = [(str(self.openssl_ref), "pepe")] authorizer = BasicAuthorizer(read_perms, write_perms) # Pepe can read openssl/2.0.1 from any channel but only from lasote authorizer.check_read_conan("pepe", self.openssl_ref) tmp_ref = ConanFileReference.loads("openssl/2.0.1@alfred/testing") self.assertRaises(ForbiddenException, authorizer.check_read_conan, "pepe", tmp_ref) tmp_ref = ConanFileReference.loads("openssl/2.0.1@lasote/otherchannel") authorizer.check_read_conan("pepe", tmp_ref)
def variables_setup_test(self): conanfile = ConanFile(None, None, Settings({}), None) ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder1") cpp_info.defines = ["MYDEFINE1"] cpp_info.cflags.append("-Flag1=23") cpp_info.version = "1.3" cpp_info.description = "My cool description" cpp_info.libs = ["MyLib1"] conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder2") cpp_info.libs = ["MyLib2"] cpp_info.defines = ["MYDEFINE2"] cpp_info.version = "2.3" cpp_info.exelinkflags = ["-exelinkflag"] cpp_info.sharedlinkflags = ["-sharedlinkflag"] cpp_info.cppflags = ["-cppflag"] cpp_info.public_deps = ["MyPkg"] cpp_info.lib_paths.extend(["Path\\with\\slashes", "regular/path/to/dir"]) cpp_info.include_paths.extend(["other\\Path\\with\\slashes", "other/regular/path/to/dir"]) conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = BoostBuildGenerator(conanfile) self.assertEquals(generator.content, """lib MyLib1 : : # requirements <name>MyLib1 : # default-build : # usage-requirements <define>MYDEFINE1 <cflags>-Flag1=23 ; lib MyLib2 : : # requirements <name>MyLib2 <search>Path/with/slashes <search>regular/path/to/dir : # default-build : # usage-requirements <define>MYDEFINE2 <include>other/Path/with/slashes <include>other/regular/path/to/dir <cxxflags>-cppflag <ldflags>-sharedlinkflag ; alias conan-deps : MyLib1 MyLib2 ; """)
def basic_test(self): options = OptionsValues.loads("""other_option=True optimized_var=3 Poco:deps_bundled=True Boost:static=False Boost:thread=True Boost:thread.multi=off Hello1:static=False Hello1:optimized=4 """) down_ref = ConanFileReference.loads("Hello0/0.1@diego/testing") own_ref = ConanFileReference.loads("Hello1/0.1@diego/testing") output = TestBufferConanOutput() self.sut.propagate_upstream(options, down_ref, own_ref, output) self.assertEqual(self.sut.values.as_list(), [("optimized", "4"), ("path", "NOTDEF"), ("static", "False"), ("Boost:static", "False"), ("Boost:thread", "True"), ("Boost:thread.multi", "off"), ("Poco:deps_bundled", "True")]) options2 = OptionsValues.loads("""other_option=True optimized_var=3 Poco:deps_bundled=What Boost:static=2 Boost:thread=Any Boost:thread.multi=on Hello1:static=True Hello1:optimized=2 """) down_ref = ConanFileReference.loads("Hello2/0.1@diego/testing") self.sut.propagate_upstream(options2, down_ref, own_ref, output) self.assertIn("""WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option optimized to 2 but it was already assigned to 4 by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option static to True but it was already assigned to False by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:static to 2 but it was already assigned to False by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread to Any but it was already assigned to True by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread.multi to on but it was already assigned to off by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Poco:deps_bundled to What but it was already assigned to True by Hello0/0.1@diego/testing""", str(output)) self.assertEqual(self.sut.values.dumps(), """optimized=4 path=NOTDEF static=False Boost:static=False Boost:thread=True Boost:thread.multi=off Poco:deps_bundled=True""")
def pattern_unmatch_test(self): boost_values = PackageOptionValues() boost_values.add_option("fake_option", "FuzzBuzz") options = {"OpenSSL.*": boost_values} down_ref = ConanFileReference.loads("Boost.Assert/0.1@diego/testing") own_ref = ConanFileReference.loads("Boost.Assert/0.1@diego/testing") self.sut.propagate_upstream(options, down_ref, own_ref) self.assertEqual(self.sut.values.as_list(), [("optimized", "3"), ("path", "NOTDEF"), ("static", "True"), ("OpenSSL.*:fake_option", "FuzzBuzz"), ])
def basic_test(self): boost_values = PackageOptionValues() boost_values.add_option("static", False) boost_values.add_option("thread", True) boost_values.add_option("thread.multi", "off") poco_values = PackageOptionValues() poco_values.add_option("deps_bundled", True) hello1_values = PackageOptionValues() hello1_values.add_option("static", False) hello1_values.add_option("optimized", 4) options = {"Boost": boost_values, "Poco": poco_values, "Hello1": hello1_values} down_ref = ConanFileReference.loads("Hello0/0.1@diego/testing") own_ref = ConanFileReference.loads("Hello1/0.1@diego/testing") self.sut.propagate_upstream(options, down_ref, own_ref) self.assertEqual(self.sut.values.as_list(), [("optimized", "4"), ("path", "NOTDEF"), ("static", "False"), ("Boost:static", "False"), ("Boost:thread", "True"), ("Boost:thread.multi", "off"), ("Poco:deps_bundled", "True")]) boost_values = PackageOptionValues() boost_values.add_option("static", 2) boost_values.add_option("thread", "Any") boost_values.add_option("thread.multi", "on") poco_values = PackageOptionValues() poco_values.add_option("deps_bundled", "What") hello1_values = PackageOptionValues() hello1_values.add_option("static", True) hello1_values.add_option("optimized", "2") options2 = {"Boost": boost_values, "Poco": poco_values, "Hello1": hello1_values} down_ref = ConanFileReference.loads("Hello2/0.1@diego/testing") with self.assertRaisesRegexp(ConanException, "Hello2/0.1@diego/testing tried to change " "Hello1/0.1@diego/testing option optimized to 2"): self.sut.propagate_upstream(options2, down_ref, own_ref) self.assertEqual(self.sut.values.dumps(), """optimized=4 path=NOTDEF static=False Boost:static=False Boost:thread=True Boost:thread.multi=off Poco:deps_bundled=True""")
def test_node(self): """ nodes are different even if contain same values, so they can be repeated if necessary in the graph (common static libraries) """ conan_ref1 = ConanFileReference.loads("Hello/0.1@user/stable") conan_ref2 = ConanFileReference.loads("Hello/0.1@user/stable") conanfile1 = ConanFile(None, None, Settings({}), ".") conanfile2 = ConanFile(None, None, Settings({}), ".") n1 = Node(conan_ref1, conanfile1) n2 = Node(conan_ref2, conanfile2) self.assertNotEqual(n1, n2)
def reuse_test(self): conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1") client = TestClient() client.save(files) client.run("export lasote/stable") configs = [] # ("gcc", "4.8")] # Place to add different compilers if platform.system() == "Windows2": configs.append(("Visual Studio", "12")) for compiler, compiler_version in configs: client.default_settings(compiler, compiler_version) client.run("install %s --build missing" % str(conan_reference)) # Check compilation ok package_ids = client.paths.conan_packages(conan_reference) self.assertEquals(len(package_ids), len(configs)) for package_id in package_ids: package_ref = PackageReference(conan_reference, package_id) self._assert_library_exists(package_ref, client.paths) # Reuse them conan_reference = ConanFileReference.loads("Hello1/0.2@lasote/stable") files3 = cpp_hello_conan_files("Hello1", "0.1", ["Hello0/0.1@lasote/stable"]) client.current_folder = temp_folder() client.save(files3) for compiler, compiler_version in configs: client.default_settings(compiler, compiler_version) client.run('install') client.run('build') command = os.sep.join([".", "bin", "say_hello"]) client.runner(command, cwd=client.current_folder) self.assertIn("Hello Hello1", client.user_io.out) self.assertIn("Hello Hello0", client.user_io.out) new_conanfile = files3[CONANFILE].replace('"language": 0', '"language": 1') for compiler, compiler_version in configs: client.default_settings(compiler, compiler_version) client.save({CONANFILE: new_conanfile}) client.run('install') client.run('build') time.sleep(1) client.runner(command, cwd=client.current_folder) self.assertIn("Hola Hello1", client.user_io.out) self.assertIn("Hola Hello0", client.user_io.out)
def basic_test(self): ref = ConanFileReference.loads("opencv/2.4.10 @ lasote/testing") self.assertEqual(ref.name, "opencv") self.assertEqual(ref.version, "2.4.10") self.assertEqual(ref.user, "lasote") self.assertEqual(ref.channel, "testing") self.assertEqual(str(ref), "opencv/2.4.10@lasote/testing") ref = ConanFileReference.loads("opencv_lite/2.4.10@phil-lewis/testing") self.assertEqual(ref.name, "opencv_lite") self.assertEqual(ref.version, "2.4.10") self.assertEqual(ref.user, "phil-lewis") self.assertEqual(ref.channel, "testing") self.assertEqual(str(ref), "opencv_lite/2.4.10@phil-lewis/testing")
def check_digraph_line(line): self.assertTrue(dot_regex.match(line)) # root node (current project) is special case line = line.replace("@PROJECT", "@lasote/stable") node_matches = node_regex.findall(line) parent = ConanFileReference.loads(node_matches[0]) deps = [ConanFileReference.loads(ref) for ref in node_matches[1:]] check_conan_ref(parent) for dep in deps: check_conan_ref(dep) self.assertIn(dep.name, test_deps[parent.name])
def all_positive_test(self): boost_values = PackageOptionValues() boost_values.add_option("static", False) boost_values.add_option("path", "FuzzBuzz") options = {"*": boost_values} own_ref = ConanFileReference.loads("Boost.Assert/0.1@diego/testing") down_ref = ConanFileReference.loads("Consumer/0.1@diego/testing") self.sut.propagate_upstream(options, down_ref, own_ref) self.assertEqual(self.sut.values.as_list(), [("optimized", "3"), ("path", "FuzzBuzz"), ("static", "False"), ("*:path", "FuzzBuzz"), ("*:static", "False"), ])
def remove_specific_builds_test(self): client = TestClient() client.save({"conanfile.py": conanfile}) client.run("export user/channel") client.save({"conanfile.txt": consumer}, clean_first=True) client.run('install -s build_type=Debug') client.run('install -s build_type=Release') ref = ConanFileReference.loads("Pkg/0.1@user/channel") def _check_builds(): builds = client.client_cache.conan_builds(ref) self.assertEqual(1, len(builds)) packages = client.client_cache.conan_packages(ref) self.assertEqual(2, len(packages)) self.assertNotIn(builds[0], packages) return builds[0], packages build, packages = _check_builds() client.run("remove Pkg/0.1@user/channel -b %s -f" % packages[0]) _check_builds() client.run("remove Pkg/0.1@user/channel -b %s -f" % build) builds = client.client_cache.conan_builds(ref) self.assertEqual(0, len(builds)) packages = client.client_cache.conan_packages(ref) self.assertEqual(2, len(packages))
def get_package_info_test(self): # Upload a conans conan_reference = ConanFileReference.loads("conan3/1.0.0@private_user/testing") self._upload_recipe(conan_reference) # Upload an package package_reference = PackageReference(conan_reference, "1F23223EFDA") conan_info = """[settings] arch=x86_64 compiler=gcc os=Linux [options] 386=False [requires] Hello Bye/2.9 Say/2.1@user/testing Chat/2.1@user/testing:SHA_ABC """ self._upload_package(package_reference, {CONANINFO: conan_info}) # Get the package info info = self.api.get_package_info(package_reference) self.assertIsInstance(info, ConanInfo) self.assertEquals(info, ConanInfo.loads(conan_info))
def __init__(self, username=None, channel=None, runner=None, gcc_versions=None, visual_versions=None, visual_runtimes=None, visual_toolsets=None, apple_clang_versions=None, archs=None, options=None, use_docker=None, curpage=None, total_pages=None, docker_image=None, reference=None, password=None, remotes=None, upload=None, stable_branch_pattern=None, vs10_x86_64_enabled=False, mingw_configurations=None, stable_channel=None, platform_info=None, upload_retry=None, clang_versions=None, login_username=None, upload_only_when_stable=None, upload_only_when_tag=None, upload_only_recipe=None, upload_force=None, build_types=None, cppstds=None, skip_check_credentials=False, allow_gcc_minors=False, exclude_vcvars_precommand=False, docker_run_options=None, docker_image_skip_update=False, docker_image_skip_pull=False, docker_entry_script=None, docker_32_images=None, docker_conan_home=None, docker_shell=None, pip_install=None, build_policy=None, always_update_conan_in_docker=False, conan_api=None, client_cache=None, conanfile=None, ci_manager=None, out=None, test_folder=None, cwd=None, config_url=None, config_args=None, upload_dependencies=None, force_selinux=None, skip_recipe_export=False, update_dependencies=None, lockfile=None): conan_version = get_client_version() self.printer = Printer(out) self.printer.print_rule() self.printer.print_ascci_art() self.cwd = cwd or os.getcwd() if not conan_api: self.conan_api, _, _ = Conan.factory() self.conan_api.create_app() self.client_cache = self.conan_api.app.cache else: self.conan_api = conan_api self.client_cache = client_cache self.ci_manager = ci_manager or CIManager(self.printer) self.remotes_manager = RemotesManager(self.conan_api, self.printer, remotes, upload) self.username = username or os.getenv("CONAN_USERNAME", None) self.skip_check_credentials = skip_check_credentials or get_bool_from_env( "CONAN_SKIP_CHECK_CREDENTIALS") self.auth_manager = AuthManager( self.conan_api, self.printer, login_username, password, default_username=self.username, skip_check_credentials=self.skip_check_credentials) # Upload related variables self.upload_retry = upload_retry or os.getenv("CONAN_UPLOAD_RETRY", 3) if upload_only_when_stable is not None: self.upload_only_when_stable = upload_only_when_stable else: self.upload_only_when_stable = get_bool_from_env( "CONAN_UPLOAD_ONLY_WHEN_STABLE") if upload_only_when_tag is not None: self.upload_only_when_tag = upload_only_when_tag else: self.upload_only_when_tag = get_bool_from_env( "CONAN_UPLOAD_ONLY_WHEN_TAG") self.upload_only_recipe = upload_only_recipe or get_bool_from_env( "CONAN_UPLOAD_ONLY_RECIPE") self.upload_force = upload_force if upload_force is not None \ else get_custom_bool_from_env("CONAN_UPLOAD_FORCE", True) self.remotes_manager.add_remotes_to_conan() self.uploader = Uploader(self.conan_api, self.remotes_manager, self.auth_manager, self.printer, self.upload_retry, self.upload_force) self._builds = [] self._named_builds = {} self._packages_summary = [] self._update_conan_in_docker = always_update_conan_in_docker or get_bool_from_env( "CONAN_ALWAYS_UPDATE_CONAN_DOCKER") self._platform_info = platform_info or PlatformInfo() self.stable_branch_pattern = stable_branch_pattern or \ os.getenv("CONAN_STABLE_BRANCH_PATTERN", None) self.stable_channel = stable_channel or os.getenv( "CONAN_STABLE_CHANNEL", "stable") self.stable_channel = self.stable_channel.rstrip() self.partial_reference = reference or os.getenv( "CONAN_REFERENCE", None) self.channel = self._get_specified_channel(channel, reference) self.conanfile = conanfile or os.getenv("CONAN_CONANFILE", "conanfile.py") if self.partial_reference: if "@" in self.partial_reference: self.reference = ConanFileReference.loads( self.partial_reference) else: name, version = self.partial_reference.split("/") self.reference = ConanFileReference(name, version, self.username, self.channel) else: if not os.path.exists(os.path.join(self.cwd, self.conanfile)): raise Exception("Conanfile not found, specify a 'reference' " "parameter with name and version") conanfile = load_cf_class(os.path.join(self.cwd, self.conanfile), self.conan_api) name, version = conanfile.name, conanfile.version if name and version: self.reference = ConanFileReference(name, version, self.username, self.channel) else: self.reference = None self._docker_image = docker_image or os.getenv("CONAN_DOCKER_IMAGE", None) # If CONAN_DOCKER_IMAGE is specified, then use docker is True self.use_docker = (use_docker or os.getenv("CONAN_USE_DOCKER", False) or self._docker_image is not None) self.docker_conan_home = docker_conan_home or os.getenv( "CONAN_DOCKER_HOME", None) os_name = self._platform_info.system( ) if not self.use_docker else "Linux" self.build_generator = BuildGenerator( reference, os_name, gcc_versions, apple_clang_versions, clang_versions, visual_versions, visual_runtimes, visual_toolsets, vs10_x86_64_enabled, mingw_configurations, archs, allow_gcc_minors, build_types, options, cppstds) self.build_policy = (build_policy or self.ci_manager.get_commit_build_policy() or split_colon_env("CONAN_BUILD_POLICY")) if isinstance(self.build_policy, list): self.build_policy = ",".join(self.build_policy) self.sudo_docker_command = "" if "CONAN_DOCKER_USE_SUDO" in os.environ: self.sudo_docker_command = "sudo -E" if get_bool_from_env( "CONAN_DOCKER_USE_SUDO") else "" elif platform.system() != "Windows": self.sudo_docker_command = "sudo -E" self.sudo_pip_command = "" if "CONAN_PIP_USE_SUDO" in os.environ: self.sudo_pip_command = "sudo -E" if get_bool_from_env( "CONAN_PIP_USE_SUDO") else "" elif platform.system( ) != "Windows" and self._docker_image and 'conanio/' not in str( self._docker_image): self.sudo_pip_command = "sudo -E" self.pip_command = os.getenv("CONAN_PIP_COMMAND", "pip") pip_found = True if tools.os_info.is_windows else tools.which( self.pip_command) if not pip_found or not "pip" in self.pip_command: raise Exception( "CONAN_PIP_COMMAND: '{}' is not a valid pip command.".format( self.pip_command)) self.docker_pip_command = os.getenv("CONAN_DOCKER_PIP_COMMAND", "pip") self.docker_shell = docker_shell or os.getenv("CONAN_DOCKER_SHELL") if self.is_wcow: if self.docker_conan_home is None: self.docker_conan_home = "C:/Users/ContainerAdministrator" self.docker_shell = docker_shell or "cmd /C" else: if self.docker_conan_home is None: self.docker_conan_home = "/home/conan" self.docker_shell = docker_shell or "/bin/sh -c" self.docker_platform_param = "" self.lcow_user_workaround = "" if self.is_lcow: self.docker_platform_param = "--platform=linux" # With LCOW, Docker doesn't respect USER directive in dockerfile yet self.lcow_user_workaround = "sudo su conan && " self.exclude_vcvars_precommand = exclude_vcvars_precommand or \ get_bool_from_env("CONAN_EXCLUDE_VCVARS_PRECOMMAND") self._docker_image_skip_update = docker_image_skip_update or \ get_bool_from_env("CONAN_DOCKER_IMAGE_SKIP_UPDATE") self._docker_image_skip_pull = docker_image_skip_pull or \ get_bool_from_env("CONAN_DOCKER_IMAGE_SKIP_PULL") self.runner = runner or os.system self.output_runner = ConanOutputRunner() self.docker_run_options = docker_run_options or split_colon_env( "CONAN_DOCKER_RUN_OPTIONS") if isinstance(self.docker_run_options, list): self.docker_run_options = " ".join(self.docker_run_options) self.docker_entry_script = docker_entry_script or os.getenv( "CONAN_DOCKER_ENTRY_SCRIPT") self.pip_install = pip_install or split_colon_env("CONAN_PIP_INSTALL") self.upload_dependencies = upload_dependencies or split_colon_env( "CONAN_UPLOAD_DEPENDENCIES") or "" if isinstance(self.upload_dependencies, list): self.upload_dependencies = ",".join(self.upload_dependencies) if "all" in self.upload_dependencies and self.upload_dependencies != "all": raise Exception( "Upload dependencies only accepts or 'all' or package references. Do not mix both!" ) self.update_dependencies = update_dependencies or get_bool_from_env( "CONAN_UPDATE_DEPENDENCIES") if self.channel: os.environ["CONAN_CHANNEL"] = self.channel if docker_32_images is not None: self.docker_32_images = docker_32_images else: self.docker_32_images = os.getenv("CONAN_DOCKER_32_IMAGES", False) self.force_selinux = force_selinux or get_bool_from_env( "CONAN_FORCE_SELINUX") self.curpage = curpage or os.getenv("CONAN_CURRENT_PAGE", 1) self.total_pages = total_pages or os.getenv("CONAN_TOTAL_PAGES", 1) self.conan_pip_package = os.getenv("CONAN_PIP_PACKAGE", "conan==%s" % conan_version) if self.conan_pip_package in ("0", "False"): self.conan_pip_package = "" self.vs10_x86_64_enabled = vs10_x86_64_enabled self.builds_in_current_page = [] self.test_folder = test_folder or os.getenv("CPT_TEST_FOLDER") self.config_url = config_url or os.getenv("CONAN_CONFIG_URL") self.skip_recipe_export = skip_recipe_export or \ get_bool_from_env("CONAN_SKIP_RECIPE_EXPORT") self.config_args = config_args or os.getenv("CONAN_CONFIG_ARGS") self.lockfile = lockfile or os.getenv("CONAN_LOCKFILE") def valid_pair(var, value): return (isinstance(value, six.string_types) or isinstance(value, bool) or isinstance(value, list) ) and not var.startswith("_") and "password" not in var with self.printer.foldable_output("local_vars"): self.printer.print_dict({ var: value for var, value in self.__dict__.items() if valid_pair(var, value) })
def test_autotools_fix_shared_libs(): """ From comments in: https://github.com/conan-io/conan/pull/11365 Case 1: libopencv_core.3.4.17.dylib libopencv_core.3.4.dylib (symlink) -> libopencv_core.3.4.17.dylib libopencv_core.dylib (symlink) -> libopencv_core.3.4.dylib Install name in libopencv_core.3.4.17.dylib is libopencv_core.3.4.dylib NOT the dylib name So we have to add the rpath to that. Case 2: libopencv_core.dylib libopencv_imgproc.dylib libopencv_imgproc.dylib depends on libopencv_core.dylib and declares that dependency not using the @rpath, we have to make sure that we patch the dependencies in the dylibs using install_name_tool -change Let's create a Conan package with two libraries: bye and hello (bye depends on hello) and recreate this whole situation to check that we are correctly fixing the dylibs """ client = TestClient(path_with_spaces=False) client.run("new hello/0.1 --template=autotools_lib") conanfile = textwrap.dedent(""" import os from conan import ConanFile from conan.tools.gnu import AutotoolsToolchain, Autotools from conan.tools.layout import basic_layout from conan.tools.apple import fix_apple_shared_install_name class HelloConan(ConanFile): name = "hello" version = "0.1" settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} exports_sources = "configure.ac", "Makefile.am", "src/*" def layout(self): basic_layout(self) def generate(self): at_toolchain = AutotoolsToolchain(self) at_toolchain.generate() def build(self): autotools = Autotools(self) autotools.autoreconf() autotools.configure() autotools.make() def package(self): autotools = Autotools(self) autotools.install() # before fixing the names we try to reproduce the two cases explained # in the test that dylib name and install name are not the same self.run("install_name_tool {} -id /lib/libbye.dylib".format(os.path.join(self.package_folder, "lib", "libbye.0.dylib"))) # also change that in the libbye dependencies self.run("install_name_tool {} -change /lib/libhello.0.dylib /lib/libhello.dylib".format(os.path.join(self.package_folder, "lib", "libbye.0.dylib"))) self.run("install_name_tool {} -id /lib/libhello.dylib".format(os.path.join(self.package_folder, "lib","libhello.0.dylib"))) fix_apple_shared_install_name(self) def package_info(self): self.cpp_info.libs = ["hello", "bye"] """) bye_cpp = textwrap.dedent(""" #include <iostream> #include "hello.h" #include "bye.h" void bye(){ hello(); std::cout << "Bye, bye!" << std::endl; } """) bye_h = textwrap.dedent(""" #pragma once void bye(); """) makefile_am = textwrap.dedent(""" lib_LTLIBRARIES = libhello.la libbye.la libhello_la_SOURCES = hello.cpp hello.h libhello_la_HEADERS = hello.h libhello_ladir = $(includedir) libbye_la_SOURCES = bye.cpp bye.h libbye_la_HEADERS = bye.h libbye_ladir = $(includedir) libbye_la_LIBADD = libhello.la """) test_src = textwrap.dedent(""" #include "bye.h" int main() { bye(); } """) client.save({ "src/makefile.am": makefile_am, "src/bye.cpp": bye_cpp, "src/bye.h": bye_h, "test_package/main.cpp": test_src, "conanfile.py": conanfile, }) client.run("create . -o hello:shared=True -tf=None") package_id = re.search(r"Package (\S+)", str(client.out)).group(1) package_id = package_id.replace("'", "") pref = PackageReference(ConanFileReference.loads("hello/0.1"), package_id) package_folder = client.cache.package_layout(pref.ref).package(pref) # install name fixed client.run_command("otool -D {}".format( os.path.join(package_folder, "lib", "libhello.0.dylib"))) assert "@rpath/libhello.dylib" in client.out client.run_command("otool -D {}".format( os.path.join(package_folder, "lib", "libbye.0.dylib"))) assert "@rpath/libbye.dylib" in client.out # dependencies fixed client.run_command("otool -L {}".format( os.path.join(package_folder, "lib", "libbye.0.dylib"))) assert "/lib/libhello.dylib (compatibility version 1.0.0, current version 1.0.0)" not in client.out assert "/lib/libbye.dylib (compatibility version 1.0.0, current version 1.0.0)" not in client.out assert "@rpath/libhello.dylib (compatibility version 1.0.0, current version 1.0.0)" in client.out assert "@rpath/libbye.dylib (compatibility version 1.0.0, current version 1.0.0)" in client.out client.run("test test_package hello/0.1@ -o hello:shared=True") assert "Bye, bye!" in client.out
def test_submodule(self): subsubmodule, _ = create_local_git_repo({"subsubmodule": "contents"}) submodule, _ = create_local_git_repo({"submodule": "contents"}, submodules=[subsubmodule]) path, commit = create_local_git_repo({"myfile": "contents"}, branch="my_release", submodules=[submodule]) def _relative_paths(folder): submodule_path = os.path.join( folder, os.path.basename(os.path.normpath(submodule))) subsubmodule_path = os.path.join( submodule_path, os.path.basename(os.path.normpath(subsubmodule))) return submodule_path, subsubmodule_path # Check old (default) behaviour tmp = ''' from conans import ConanFile, tools class ConanLib(ConanFile): name = "lib" version = "0.1" scm = {{ "type": "git", "url": "{url}", "revision": "{revision}" }} ''' conanfile = tmp.format(url=path, revision=commit) self.client.save({"conanfile.py": conanfile}) self.client.run("create . user/channel") ref = ConanFileReference.loads("lib/0.1@user/channel") folder = self.client.cache.package_layout(ref).source() submodule_path, _ = _relative_paths(folder) self.assertTrue(os.path.exists(os.path.join(folder, "myfile"))) self.assertFalse( os.path.exists(os.path.join(submodule_path, "submodule"))) # Check invalid value tmp = ''' from conans import ConanFile, tools class ConanLib(ConanFile): name = "lib" version = "0.1" scm = {{ "type": "git", "url": "{url}", "revision": "{revision}", "submodule": "{submodule}" }} ''' conanfile = tmp.format(url=path, revision=commit, submodule="invalid") self.client.save({"conanfile.py": conanfile}) self.client.run("create . user/channel", assert_error=True) self.assertIn("Invalid 'submodule' attribute value in the 'scm'.", self.client.out) # Check shallow conanfile = tmp.format(url=path, revision=commit, submodule="shallow") self.client.save({"conanfile.py": conanfile}) self.client.run("create . user/channel") ref = ConanFileReference.loads("lib/0.1@user/channel") folder = self.client.cache.package_layout(ref).source() submodule_path, subsubmodule_path = _relative_paths(folder) self.assertTrue(os.path.exists(os.path.join(folder, "myfile"))) self.assertTrue( os.path.exists(os.path.join(submodule_path, "submodule"))) self.assertFalse( os.path.exists(os.path.join(subsubmodule_path, "subsubmodule"))) # Check recursive conanfile = tmp.format(url=path, revision=commit, submodule="recursive") self.client.save({"conanfile.py": conanfile}) self.client.run("create . user/channel") ref = ConanFileReference.loads("lib/0.1@user/channel") folder = self.client.cache.package_layout(ref).source() submodule_path, subsubmodule_path = _relative_paths(folder) self.assertTrue(os.path.exists(os.path.join(folder, "myfile"))) self.assertTrue( os.path.exists(os.path.join(submodule_path, "submodule"))) self.assertTrue( os.path.exists(os.path.join(subsubmodule_path, "subsubmodule")))
def complete_test(self): """ basic installation of a new conans """ servers = {} # All can write (for avoid authentication until we mock user_io) test_server = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")]) servers["default"] = test_server conan_digest = FileTreeManifest(123123123, {}) client = TestClient(servers=servers) client.init_dynamic_vars() conan_ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable") reg_folder = client.paths.export(conan_ref) files = hello_source_files() client.save(files, path=reg_folder) client.save( { CONANFILE: myconan1, CONAN_MANIFEST: str(conan_digest), "include/math/lib1.h": "//copy", "my_lib/debug/libd.a": "//copy", "my_data/readme.txt": "//copy" }, path=reg_folder) package_ref = PackageReference(conan_ref, "fakeid") package_folder = client.paths.package(package_ref) save(os.path.join(package_folder, CONANINFO), "info") save(os.path.join(package_folder, CONAN_MANIFEST), "manifest") save(os.path.join(package_folder, "include", "lib1.h"), "//header") save(os.path.join(package_folder, "lib", "my_lib", "libd.a"), "//lib") save(os.path.join(package_folder, "res", "shares", "readme.txt"), "//res") digest_path = client.client_cache.digestfile_package(package_ref) expected_manifest = FileTreeManifest.create( os.path.dirname(digest_path)) save(os.path.join(package_folder, CONAN_MANIFEST), str(expected_manifest)) client.run("upload %s" % str(conan_ref)) client.run("upload %s -p %s" % (str(conan_ref), package_ref.package_id)) client2 = TestClient(servers=servers) client2.init_dynamic_vars() installer = ConanProxy(client2.paths, client2.user_io, client2.remote_manager, "default") installer.get_recipe(conan_ref) installer.get_package(package_ref, force_build=False, short_paths=False, check_outdated=False) # Check that the output is done in order lines = [ line.strip() for line in str(client2.user_io.out).splitlines() if line.startswith("Downloading") ] self.assertEqual(lines, [ "Downloading conanmanifest.txt", "Downloading conanfile.py", "Downloading conan_export.tgz", "Downloading conanmanifest.txt", "Downloading conaninfo.txt", "Downloading conan_package.tgz" ]) reg_path = client2.paths.export( ConanFileReference.loads("Hello/1.2.1/frodo/stable")) pack_folder = client2.paths.package(package_ref) # Test the file in the downloaded conans files = [ 'CMakeLists.txt', 'my_lib/debug/libd.a', 'hello.cpp', 'hello0.h', CONANFILE, CONAN_MANIFEST, 'main.cpp', 'include/math/lib1.h', 'my_data/readme.txt' ] for _file in files: self.assertTrue(os.path.exists(os.path.join(reg_path, _file))) self.assertTrue(os.path.exists(pack_folder)) # Test the file in the downloaded package self.assertTrue(os.path.exists(pack_folder)) self.assertTrue( os.path.exists(os.path.join(pack_folder, "include", "lib1.h"))) self.assertTrue( os.path.exists(os.path.join(pack_folder, "lib", "my_lib/libd.a"))) self.assertTrue( os.path.exists( os.path.join(pack_folder, "res", "shares/readme.txt")))
def install(self, *args): """ install in the local store the given requirements. Requirements can be defined in the command line or in a conanfile. EX: conan install opencv/2.4.10@lasote/testing """ parser = argparse.ArgumentParser(description=self.install.__doc__, prog="conan install", formatter_class=RawTextHelpFormatter) parser.add_argument( "reference", nargs='?', default="", help='package recipe reference' 'e.g., MyPackage/1.2@user/channel or ./my_project/') parser.add_argument( "--package", "-p", nargs=1, action=Extender, help='Force install specified package ID (ignore settings/options)' ) parser.add_argument( "--all", action='store_true', default=False, help='Install all packages from the specified package recipe') parser.add_argument( "--integrity", "-i", action='store_true', default=False, help='Check that the stored recipe or package manifests are correct' ) parser.add_argument("--file", "-f", help="specify conanfile filename") parser.add_argument("--update", "-u", action='store_true', default=False, help="update with new upstream packages") parser.add_argument("--scope", "-sc", nargs=1, action=Extender, help='Define scopes for packages') parser.add_argument("--generator", "-g", nargs=1, action=Extender, help='Generators to use') self._parse_args(parser) args = parser.parse_args(*args) current_path = os.getcwd() try: reference = ConanFileReference.loads(args.reference) except: reference = os.path.normpath( os.path.join(current_path, args.reference)) if args.all or args.package: # Install packages without settings (fixed ids or all) if args.all: args.package = [] if not args.reference or not isinstance(reference, ConanFileReference): raise ConanException("Invalid package recipe reference. " "e.g., MyPackage/1.2@user/channel") self._manager.download(reference, args.package, remote=args.remote) else: # Classic install, package chosen with settings and options # Get False or a list of patterns to check args.build = self._get_build_sources_parameter(args.build) options = self._get_tuples_list_from_extender_arg(args.options) settings = self._get_tuples_list_from_extender_arg(args.settings) scopes = Scopes.from_list(args.scope) if args.scope else None self._manager.install(reference=reference, current_path=current_path, remote=args.remote, options=options, settings=settings, build_mode=args.build, filename=args.file, update=args.update, integrity=args.integrity, scopes=scopes, generators=args.generator)
def add_common_builds(self, shared_option_name=None, pure_c=True, dll_with_static_runtime=False, reference=None, header_only=True, build_all_options_values=None): if reference: if "@" in reference: reference = ConanFileReference.loads(reference) else: name, version = reference.split("/") reference = ConanFileReference(name, version, self.username, self.channel) else: reference = self.reference if not reference: raise Exception( "Specify a CONAN_REFERENCE or name and version fields in the recipe" ) if shared_option_name is None: env_shared_option_name = os.getenv("CONAN_SHARED_OPTION_NAME", None) shared_option_name = env_shared_option_name if str( env_shared_option_name).lower() != "false" else False build_all_options_values = build_all_options_values or split_colon_env( "CONAN_BUILD_ALL_OPTIONS_VALUES") or [] if not isinstance(build_all_options_values, list): raise Exception( "'build_all_options_values' must be a list. e.g. ['foo:opt', 'foo:bar']" ) conanfile = None if os.path.exists(os.path.join(self.cwd, self.conanfile)): conanfile = load_cf_class(os.path.join(self.cwd, self.conanfile), self.conan_api) header_only_option = None if conanfile: if hasattr( conanfile, "options" ) and conanfile.options and "header_only" in conanfile.options: header_only_option = "%s:header_only" % reference.name if shared_option_name is None: if conanfile: if hasattr( conanfile, "options" ) and conanfile.options and "shared" in conanfile.options: shared_option_name = "%s:shared" % reference.name # filter only valid options raw_options_for_building = [ opt[opt.find(":") + 1:] for opt in build_all_options_values ] for raw_option in reversed(raw_options_for_building): if hasattr(conanfile, "options") and conanfile.options and \ not isinstance(conanfile.options.get(raw_option), list): raw_options_for_building.remove(raw_option) if raw_options_for_building and conanfile: # get option and its values cloned_options = copy.copy(conanfile.options) for key, value in conanfile.options.items(): if key == "shared" and shared_option_name: continue elif key not in raw_options_for_building: del cloned_options[key] cloned_options2 = {} for key, value in cloned_options.items(): # add package reference to the option name if not key.startswith("{}:".format(reference.name)): cloned_options2["{}:{}".format(reference.name, key)] = value # combine all options x values (cartesian product) build_all_options_values = [ dict(zip(cloned_options2, v)) for v in product(*cloned_options2.values()) ] builds = self.build_generator.get_builds(pure_c, shared_option_name, dll_with_static_runtime, reference, build_all_options_values) if header_only_option and header_only: if conanfile.default_options.get("header_only"): cloned_builds = copy.deepcopy(builds) for settings, options, env_vars, build_requires, reference in cloned_builds: options.update({header_only_option: False}) builds.extend(cloned_builds) else: settings, options, env_vars, build_requires, reference = builds[ 0] cloned_options = copy.copy(options) cloned_options.update({header_only_option: True}) builds.append( BuildConf(copy.copy(settings), cloned_options, copy.copy(env_vars), copy.copy(build_requires), reference)) self._builds.extend(builds)
def duplicated_error_test(self): content = """ from conans import ConanFile class Log3cppConan(ConanFile): name = "log4cpp" version = "1.1.1" """ log4cpp_ref = ConanFileReference.loads( "log4cpp/1.1.1@memsharded/testing") self.retriever.conan(log4cpp_ref, content) content = """ from conans import ConanFile class LoggerInterfaceConan(ConanFile): name = "LoggerInterface" version = "0.1.1" def requirements(self): self.requires("log4cpp/[~1.1]@memsharded/testing") """ logiface_ref = ConanFileReference.loads( "LoggerInterface/0.1.1@memsharded/testing") self.retriever.conan(logiface_ref, content) content = """ from conans import ConanFile class OtherConan(ConanFile): name = "other" version = "2.0.11549" requires = "LoggerInterface/[~0.1]@memsharded/testing" """ other_ref = ConanFileReference.loads( "other/2.0.11549@memsharded/testing") self.retriever.conan(other_ref, content) content = """ from conans import ConanFile class Project(ConanFile): requires = "LoggerInterface/[~0.1]@memsharded/testing", "other/[~2.0]@memsharded/testing" """ deps_graph = self.root(content) log4cpp = _get_nodes(deps_graph, "log4cpp")[0] logger_interface = _get_nodes(deps_graph, "LoggerInterface")[0] other = _get_nodes(deps_graph, "other")[0] self.assertEqual(4, len(deps_graph.nodes)) self.assertEqual(log4cpp.conan_ref, log4cpp_ref) conanfile = log4cpp.conanfile self.assertEqual(conanfile.version, "1.1.1") self.assertEqual(conanfile.name, "log4cpp") self.assertEqual(logger_interface.conan_ref, logiface_ref) conanfile = logger_interface.conanfile self.assertEqual(conanfile.version, "0.1.1") self.assertEqual(conanfile.name, "LoggerInterface") self.assertEqual(other.conan_ref, other_ref) conanfile = other.conanfile self.assertEqual(conanfile.version, "2.0.11549") self.assertEqual(conanfile.name, "other")
def reuse_test(self): client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1") files[CONANFILE] = files[CONANFILE].replace("build", "build2") client.save(files) client.run("export lasote/stable") client.run("install %s --build missing" % str(conan_reference)) self.assertTrue(os.path.exists(client.paths.builds(conan_reference))) self.assertTrue(os.path.exists(client.paths.packages(conan_reference))) # Upload client.run("upload %s --all" % str(conan_reference)) # Now from other "computer" install the uploaded conans with same options (nothing) other_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) other_conan.run("install %s --build missing" % str(conan_reference)) self.assertFalse( os.path.exists(other_conan.paths.builds(conan_reference))) self.assertTrue( os.path.exists(other_conan.paths.packages(conan_reference))) # Now from other "computer" install the uploaded conans with same options (nothing) other_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) other_conan.run("install %s --build" % str(conan_reference)) self.assertTrue( os.path.exists(other_conan.paths.builds(conan_reference))) self.assertTrue( os.path.exists(other_conan.paths.packages(conan_reference))) # Use an invalid pattern and check that its not builded from source other_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) other_conan.run("install %s --build HelloInvalid" % str(conan_reference)) self.assertIn("No package matching 'HelloInvalid' pattern", other_conan.user_io.out) self.assertFalse( os.path.exists(other_conan.paths.builds(conan_reference))) # self.assertFalse(os.path.exists(other_conan.paths.packages(conan_reference))) # Use another valid pattern and check that its not builded from source other_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) other_conan.run("install %s --build HelloInvalid -b Hello" % str(conan_reference)) self.assertIn("No package matching 'HelloInvalid' pattern", other_conan.user_io.out) # self.assertFalse(os.path.exists(other_conan.paths.builds(conan_reference))) # self.assertFalse(os.path.exists(other_conan.paths.packages(conan_reference))) # Now even if the package is in local store, check that's rebuilded other_conan.run("install %s -b Hello*" % str(conan_reference)) self.assertIn("Copying sources to build folder", other_conan.user_io.out) other_conan.run("install %s" % str(conan_reference)) self.assertNotIn("Copying sources to build folder", other_conan.user_io.out)
def test_simple_fields(self): # Result of a create files = cpp_hello_conan_files("CC", "1.0", build=False) self.client.save(files, clean_first=True) self.client.run("create . private_user/channel --json=myfile.json") my_json = json.loads( load(os.path.join(self.client.current_folder, "myfile.json"))) self.assertFalse(my_json["error"]) tmp = ConanFileReference.loads(my_json["installed"][0]["recipe"]["id"]) self.assertEqual(str(tmp), "CC/1.0@private_user/channel") if self.client.cache.config.revisions_enabled: self.assertIsNotNone(tmp.revision) self.assertFalse(my_json["installed"][0]["recipe"]["dependency"]) self.assertTrue(my_json["installed"][0]["recipe"]["exported"]) self.assertFalse(my_json["installed"][0]["recipe"]["downloaded"]) self.assertIsNone(my_json["installed"][0]["recipe"]["remote"]) self.assertTrue(my_json["installed"][0]["packages"][0]["built"]) self.assertTrue(my_json["installed"][0]["packages"][0]["cpp_info"]) # Result of an install retrieving only the recipe self.client.run("upload CC/1.0@private_user/channel -c") self.client.run("remove '*' -f") self.client.run( "install CC/1.0@private_user/channel --json=myfile.json --build missing " ) my_json = json.loads( load(os.path.join(self.client.current_folder, "myfile.json"))) the_time_str = my_json["installed"][0]["recipe"]["time"] self.assertIn("T", the_time_str) # Weak validation of the ISO 8601 self.assertFalse(my_json["error"]) self.assertEqual(my_json["installed"][0]["recipe"]["id"], "CC/1.0@private_user/channel") self.assertTrue(my_json["installed"][0]["recipe"]["dependency"]) self.assertTrue(my_json["installed"][0]["recipe"]["downloaded"]) self.assertIsNotNone(my_json["installed"][0]["recipe"]["remote"]) self.assertTrue(my_json["installed"][0]["packages"][0]["built"]) self.assertTrue(my_json["installed"][0]["packages"][0]["cpp_info"]) # Upload the binary too self.client.run("upload CC/1.0@private_user/channel --all -c") self.client.run("remove '*' -f") self.client.run( "install CC/1.0@private_user/channel --json=myfile.json") my_json = json.loads( load(os.path.join(self.client.current_folder, "myfile.json"))) self.assertFalse(my_json["error"]) self.assertEqual(my_json["installed"][0]["recipe"]["id"], "CC/1.0@private_user/channel") self.assertTrue(my_json["installed"][0]["recipe"]["downloaded"]) self.assertIsNotNone(my_json["installed"][0]["recipe"]["remote"]) self.assertFalse(my_json["installed"][0]["packages"][0]["built"]) self.assertTrue(my_json["installed"][0]["packages"][0]["downloaded"]) self.assertTrue(my_json["installed"][0]["packages"][0]["cpp_info"]) # Force build self.client.run("remove '*' -f") self.client.run( "install CC/1.0@private_user/channel --json=myfile.json --build") my_json = json.loads( load(os.path.join(self.client.current_folder, "myfile.json"))) self.assertFalse(my_json["error"]) self.assertEqual(my_json["installed"][0]["recipe"]["id"], "CC/1.0@private_user/channel") self.assertTrue(my_json["installed"][0]["recipe"]["downloaded"]) self.assertIsNotNone(my_json["installed"][0]["recipe"]["remote"]) self.assertTrue(my_json["installed"][0]["packages"][0]["built"]) self.assertFalse(my_json["installed"][0]["packages"][0]["downloaded"]) self.assertTrue(my_json["installed"][0]["packages"][0]["cpp_info"])
def test_profiles_includes(self): tmp = temp_folder() def save_profile(txt, name): abs_profile_path = os.path.join(tmp, name) save(abs_profile_path, txt) os.mkdir(os.path.join(tmp, "subdir")) profile0 = """ ROOTVAR=0 [build_requires] one/1.$ROOTVAR@lasote/stable two/1.2@lasote/stable """ save_profile(profile0, "subdir/profile0.txt") profile1 = """ # Include in subdir, curdir MYVAR=1 include(./profile0.txt) [settings] os=Windows [options] zlib:aoption=1 zlib:otheroption=1 [env] package1:ENVY=$MYVAR """ save_profile(profile1, "subdir/profile1.txt") profile2 = """ # Include in subdir include(./subdir/profile1.txt) [settings] os=$MYVAR """ save_profile(profile2, "profile2.txt") profile3 = """ OTHERVAR=34 [build_requires] one/1.5@lasote/stable """ save_profile(profile3, "profile3.txt") profile4 = """ include(./profile2.txt) include(./profile3.txt) [env] MYVAR=FromProfile3And$OTHERVAR [options] zlib:otheroption=12 """ save_profile(profile4, "profile4.txt") profile, variables = read_profile("./profile4.txt", tmp, None) self.assertEqual( variables, { "MYVAR": "1", "OTHERVAR": "34", "PROFILE_DIR": tmp.replace('\\', '/'), "ROOTVAR": "0" }) self.assertEqual("FromProfile3And34", profile.env_values.data[None]["MYVAR"]) self.assertEqual("1", profile.env_values.data["package1"]["ENVY"]) self.assertEqual(profile.settings, {"os": "1"}) self.assertEqual(profile.options.as_list(), [('zlib:aoption', '1'), ('zlib:otheroption', '12')]) self.assertEqual( profile.build_requires, { "*": [ ConanFileReference.loads("one/1.0@lasote/stable"), ConanFileReference.loads("two/1.2@lasote/stable"), ConanFileReference.loads("one/1.5@lasote/stable") ] })
def reuse_test(self): ref = ConanFileReference.loads("stringutil/0.1@lasote/stable") files = { 'conanfile.py': stringutil_conanfile, 'reverse.go': reverse, 'reverse_test.go': reverse_test, 'reverse.txt': reverse, 'hello/helloreverse.txt': reverse } files_without_conanfile = set(files.keys()) - set(["conanfile.py"]) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("install %s --build missing" % str(ref)) # Check compilation ok package_ids = self.client.cache.conan_packages(ref) self.assertEquals(len(package_ids), 1) pref = PackageReference(ref, package_ids[0]) self._assert_package_exists(pref, self.client.cache, files_without_conanfile) # Upload conans self.client.run("upload %s" % str(ref)) # Check that conans exists on server server_paths = self.servers["default"].server_store rev = server_paths.get_last_revision(ref).revision conan_path = server_paths.export(ref.copy_with_rev(rev)) self.assertTrue(os.path.exists(conan_path)) # Upload package self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) # Check library on server self._assert_package_exists_in_server(pref, server_paths, files_without_conanfile) # Now from other "computer" install the uploaded conans with same options (nothing) other_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) other_conan.run("install %s --build missing" % str(ref)) # Build should be empty build_path = other_conan.cache.build(pref) self.assertFalse(os.path.exists(build_path)) # Lib should exist self._assert_package_exists(pref, other_conan.cache, files_without_conanfile) reuse_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files = {'conanfile.py': reuse_conanfile, 'src/hello/main.go': main} reuse_conan.save(files) reuse_conan.run("install . --build missing") with environment_append({ "PATH": ['$GOPATH/bin'], 'GOPATH': reuse_conan.current_folder }): if platform.system() == "Windows": command = "hello" else: command = './hello' reuse_conan.runner('go install hello', cwd=reuse_conan.current_folder) reuse_conan.runner(command, cwd=os.path.join(reuse_conan.current_folder, 'bin')) self.assertIn("Hello, Go!", reuse_conan.user_io.out)
def setUp(self): self.ref = ConanFileReference.loads("lib/0.1@user/channel") self.client = TestClient()
def test_update_not_date(): client = TestClient(default_server_user=True) # Regression for https://github.com/conan-io/conan/issues/949 client.save({"conanfile.py": GenConanfile("Hello0", "1.0")}) client.run("export . lasote/stable") client.save( { "conanfile.py": GenConanfile("Hello1", "1.0").with_requirement("Hello0/1.0@lasote/stable") }, clean_first=True) client.run("install . --build") client.run("upload Hello0/1.0@lasote/stable --all") client.run("remote list_ref") assert "Hello0/1.0@lasote/stable" in client.out client.run("remote list_pref Hello0/1.0@lasote/stable") package_reference = "Hello0/1.0@lasote/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9" assert package_reference in client.out ref = ConanFileReference.loads("Hello0/1.0@lasote/stable") pref = PackageReference(ref, "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") export_folder = client.cache.package_layout(ref).export() recipe_manifest = os.path.join(export_folder, CONAN_MANIFEST) package_folder = client.cache.package_layout(pref.ref).package(pref) package_manifest = os.path.join(package_folder, CONAN_MANIFEST) def timestamps(): recipe_timestamp = load(recipe_manifest).splitlines()[0] package_timestamp = load(package_manifest).splitlines()[0] return recipe_timestamp, package_timestamp initial_timestamps = timestamps() time.sleep(1) # Change and rebuild package client.save( {"conanfile.py": GenConanfile("Hello0", "1.0").with_test("pass")}, clean_first=True) client.run("export . lasote/stable") client.run("install Hello0/1.0@lasote/stable --build") client.run("remote list_ref") assert "Hello0/1.0@lasote/stable" in client.out client.run("remote list_pref Hello0/1.0@lasote/stable") assert "Hello0/1.0@lasote/stable:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9" in client.out rebuild_timestamps = timestamps() assert rebuild_timestamps != initial_timestamps # back to the consumer, try to update client.save( { "conanfile.py": GenConanfile("Hello1", "1.0").with_requirement("Hello0/1.0@lasote/stable") }, clean_first=True) # First assign the preference to a remote, it has been cleared when exported locally client.run("install . --update") # *1 With revisions here is removing the package because it doesn't belong to the recipe assert "Hello0/1.0@lasote/stable from 'default' - Newer" in client.out failed_update_timestamps = timestamps() assert rebuild_timestamps == failed_update_timestamps # hack manifests, put old time for manifest_file in (recipe_manifest, package_manifest): manifest = load(manifest_file) lines = manifest.splitlines() lines[0] = "123" save(manifest_file, "\n".join(lines)) client.run("install . --update") update_timestamps = timestamps() assert update_timestamps == initial_timestamps
def generators_test(self): ref = ConanFileReference.loads("Hello/0.1@lasote/stable") client = TestClient() client.save({ "conanfile.py": """from conans import ConanFile import os class Pkg(ConanFile): def package(self): os.makedirs(os.path.join(self.package_folder, "lib")) os.makedirs(os.path.join(self.package_folder, "include")) def package_info(self): self.cpp_info.libs = ["hello"] self.cpp_info.cxxflags = ["-some_cxx_compiler_flag"] self.cpp_info.cflags = ["-some_c_compiler_flag"] """ }) client.run("export . Hello/0.1@lasote/stable") conanfile_txt = '''[requires] Hello/0.1@lasote/stable # My req comment [generators] gcc # I need this generator for.. cmake visual_studio xcode ''' client.save({"conanfile.txt": conanfile_txt}, clean_first=True) # Install requirements client.run('install . --build missing') self.assertEqual( sorted([ CONANFILE_TXT, BUILD_INFO_GCC, BUILD_INFO_CMAKE, BUILD_INFO_VISUAL_STUDIO, BUILD_INFO, BUILD_INFO_XCODE, CONANINFO, GRAPH_INFO_FILE, LOCKFILE ]), sorted(os.listdir(client.current_folder))) cmake = load(os.path.join(client.current_folder, BUILD_INFO_CMAKE)) gcc = load(os.path.join(client.current_folder, BUILD_INFO_GCC)) self.assertIn("CONAN_INCLUDE_DIRS", cmake) self.assertIn("CONAN_LIB_DIRS", cmake) self.assertIn("CONAN_LIBS", cmake) self.assertIn("CONAN_INCLUDE_DIRS", cmake) self.assertIn("CONAN_LIB_DIRS", cmake) self.assertIn("/data/Hello/0.1/lasote/stable/package", cmake) self.assertIn("-L", gcc) self.assertIn("-l", gcc) self.assertIn("-I", gcc) self.assertIn("/data/Hello/0.1/lasote/stable/package", gcc) # CHECK VISUAL STUDIO GENERATOR from xml.dom import minidom xmldoc = minidom.parse( os.path.join(client.current_folder, BUILD_INFO_VISUAL_STUDIO)) definition_group = xmldoc.getElementsByTagName( 'ItemDefinitionGroup')[0] compiler = definition_group.getElementsByTagName("ClCompile")[0] linker = definition_group.getElementsByTagName("Link")[0] def element_content(node): return node.firstChild.data if node.firstChild else "" include_dirs = element_content( xmldoc.getElementsByTagName("ConanIncludeDirectories")[0]) definitions = element_content( xmldoc.getElementsByTagName("ConanPreprocessorDefinitions")[0]) lib_dirs = element_content( xmldoc.getElementsByTagName("ConanLibraryDirectories")[0]) libs = element_content( linker.getElementsByTagName("AdditionalDependencies")[0]) package_id = os.listdir(client.cache.package_layout(ref).packages())[0] pref = PackageReference(ref, package_id) package_path = client.cache.package_layout(pref.ref).package(pref) replaced_path = re.sub(os.getenv("USERPROFILE", "not user profile").replace( "\\", "\\\\"), "$(USERPROFILE)", package_path, flags=re.I) expected_lib_dirs = os.path.join(replaced_path, "lib") expected_include_dirs = os.path.join(replaced_path, "include") self.assertIn(expected_lib_dirs, lib_dirs) self.assertEqual("$(ConanLibraries)%(AdditionalDependencies)", libs) self.assertEqual("", definitions) self.assertIn(expected_include_dirs, include_dirs) # CHECK XCODE GENERATOR xcode = load(os.path.join(client.current_folder, BUILD_INFO_XCODE)) expected_c_flags = '-some_c_compiler_flag' expected_cpp_flags = '-some_cxx_compiler_flag' expected_lib_dirs = os.path.join(package_path, "lib").replace("\\", "/") expected_include_dirs = os.path.join(package_path, "include").replace("\\", "/") self.assertIn( 'LIBRARY_SEARCH_PATHS = $(inherited) "%s"' % expected_lib_dirs, xcode) self.assertIn( 'HEADER_SEARCH_PATHS = $(inherited) "%s"' % expected_include_dirs, xcode) self.assertIn("GCC_PREPROCESSOR_DEFINITIONS = $(inherited)", xcode) self.assertIn('OTHER_CFLAGS = $(inherited) %s' % expected_c_flags, xcode) self.assertIn( 'OTHER_CPLUSPLUSFLAGS = $(inherited) %s' % expected_cpp_flags, xcode) self.assertIn( 'FRAMEWORK_SEARCH_PATHS = $(inherited) "%s"' % package_path.replace("\\", "/"), xcode)
def pkg_cmake(name, version, requires=None, exe=False): refs = [ConanFileReference.loads(r) for r in requires or []] pkg_name = name name = name.replace(".", "_") conanfile = textwrap.dedent("""\ import os from conans import ConanFile from conan.tools.cmake import CMake, cmake_layout class Pkg(ConanFile): name = "{pkg_name}" version = "{version}" exports_sources = "CMakeLists.txt", "src/*", "include/*" {deps} settings = "os", "compiler", "arch", "build_type" options = {{"shared": [True, False]}} default_options = {{"shared": False}} generators = "CMakeToolchain", "CMakeDeps" def layout(self): cmake_layout(self) def build(self): cmake = CMake(self) cmake.configure() cmake.build() def package(self): self.copy("*.h", dst="include", src="include") self.copy("*.lib", dst="lib", keep_path=False) self.copy("*.dll", dst="bin", keep_path=False) self.copy("*.dylib*", dst="lib", keep_path=False) self.copy("*.so", dst="lib", keep_path=False) self.copy("*.a", dst="lib", keep_path=False) self.copy("*app.exe", dst="bin", keep_path=False) self.copy("*app", dst="bin", keep_path=False) def package_info(self): self.cpp_info.libs = ["{name}"] """) deps = "requires = " + ", ".join('"{}"'.format(r) for r in requires) if requires else "" conanfile = conanfile.format(pkg_name=pkg_name, name=name, version=version, deps=deps) hdr = gen_function_h(name=name) deps = [r.name.replace(".", "_") for r in refs] src = gen_function_cpp(name=name, includes=deps, calls=deps) deps = [r.name for r in refs] files = { "include/{}.h".format(name): hdr, "src/{}.cpp".format(name): src, "conanfile.py": conanfile } if exe: src_app = gen_function_cpp(name="main", includes=[name], calls=[name]) files["src/{}_app.cpp".format(name)] = src_app cmake = gen_cmakelists(appname="{}_app".format(name), appsources=["src/{}_app.cpp".format(name)], libname=name, libsources=["src/{}.cpp".format(name)], find_package=deps) else: cmake = gen_cmakelists(libname=name, libsources=["src/{}.cpp".format(name)], find_package=deps) files["CMakeLists.txt"] = cmake return files
def setUp(self): unittest.TestCase.setUp(self) self.openssl_ref = ConanFileReference.loads("openssl/2.0.1@lasote/testing") self.package_reference = PackageReference(self.openssl_ref, "123123123") self.openssl_ref2 = ConanFileReference.loads("openssl/2.0.2@lasote/testing") self.package_reference2 = PackageReference(self.openssl_ref2, "123123123")
def info(self, *args): """ Prints information about the requirements. Requirements can be defined in the command line or in a conanfile. EX: conan info opencv/2.4.10@lasote/testing """ parser = argparse.ArgumentParser(description=self.info.__doc__, prog="conan info", formatter_class=RawTextHelpFormatter) parser.add_argument( "reference", nargs='?', default="", help='reference name or path to conanfile file, ' 'e.g., MyPackage/1.2@user/channel or ./my_project/') parser.add_argument("--file", "-f", help="specify conanfile filename") parser.add_argument("-r", "--remote", help='look for in the remote storage') parser.add_argument( "--options", "-o", help='load options to build the package, e.g., -o with_qt=true', nargs=1, action=Extender) parser.add_argument( "--settings", "-s", help='load settings to build the package, -s compiler:gcc', nargs=1, action=Extender) parser.add_argument("--only", "-n", help='show fields only') parser.add_argument( "--integrity", "-i", action='store_true', default=False, help='Check that the stored recipe or package manifests are correct' ) parser.add_argument("--update", "-u", action='store_true', default=False, help="check updates exist from upstream remotes") parser.add_argument( "--build_order", "-bo", help= 'given a modified reference, return ordered list to build (CI)', nargs=1, action=Extender) parser.add_argument("--scope", "-sc", nargs=1, action=Extender, help='Define scopes for packages') args = parser.parse_args(*args) options = self._get_tuples_list_from_extender_arg(args.options) settings = self._get_tuples_list_from_extender_arg(args.settings) current_path = os.getcwd() try: reference = ConanFileReference.loads(args.reference) except: reference = os.path.normpath( os.path.join(current_path, args.reference)) scopes = Scopes.from_list(args.scope) if args.scope else None self._manager.info(reference=reference, current_path=current_path, remote=args.remote, options=options, settings=settings, info=args.only or True, check_updates=args.update, integrity=args.integrity, filename=args.file, build_order=args.build_order, scopes=scopes)
def test_trace_actions(self): client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) trace_file = os.path.join(temp_folder(), "conan_trace.log") with tools.environment_append({"CONAN_TRACE_FILE": trace_file}): # UPLOAD A PACKAGE conan_reference = ConanFileReference.loads( "Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1", need_patch=True, build=False) client.save(files) client.run("user lasote -p mypass -r default") client.run("export . lasote/stable") client.run("install %s --build missing" % str(conan_reference)) client.run("upload %s --all" % str(conan_reference)) traces = load(trace_file) self.assertNotIn("mypass", traces) self.assertIn('"password": "******"', traces) self.assertIn('"Authorization": "**********"', traces) self.assertIn('"X-Client-Anonymous-Id": "**********"', traces) actions = traces.splitlines() without_rest_api = [it for it in actions if "REST_API_CALL" not in it] self.assertTrue(len(without_rest_api) == 11) for trace in actions: doc = json.loads(trace) self.assertIn("_action", doc) # Valid jsons self.assertEquals( json.loads(without_rest_api[0])["_action"], "COMMAND") self.assertEquals( json.loads(without_rest_api[0])["name"], "authenticate") self.assertEquals( json.loads(without_rest_api[2])["_action"], "COMMAND") self.assertEquals(json.loads(without_rest_api[2])["name"], "export") self.assertEquals( json.loads(without_rest_api[3])["_action"], "COMMAND") self.assertEquals( json.loads(without_rest_api[3])["name"], "install_reference") self.assertEquals( json.loads(without_rest_api[4])["_action"], "GOT_RECIPE_FROM_LOCAL_CACHE") self.assertEquals( json.loads(without_rest_api[4])["_id"], "Hello0/0.1@lasote/stable") self.assertEquals( json.loads(without_rest_api[5])["_action"], "PACKAGE_BUILT_FROM_SOURCES") self.assertEquals( json.loads(without_rest_api[6])["_action"], "COMMAND") self.assertEquals(json.loads(without_rest_api[6])["name"], "upload") self.assertEquals(json.loads(without_rest_api[7])["_action"], "ZIP") self.assertEquals( json.loads(without_rest_api[8])["_action"], "UPLOADED_RECIPE") self.assertEquals(json.loads(without_rest_api[9])["_action"], "ZIP") self.assertEquals( json.loads(without_rest_api[10])["_action"], "UPLOADED_PACKAGE") num_put = len( [it for it in actions if "REST_API_CALL" in it and "PUT" in it]) self.assertEquals(num_put, 6) # 3 files the recipe 3 files the package num_post = len( [it for it in actions if "REST_API_CALL" in it and "POST" in it]) if "/v2/" in traces: self.assertEquals(num_post, 0) else: self.assertEquals(num_post, 2) # 2 get urls num_get = len( [it for it in actions if "REST_API_CALL" in it and "GET" in it]) self.assertEquals(num_get, 10) # Check masked signature for action in actions: doc = json.loads(action) if doc.get("url") and "signature" in doc.get("url"): self.assertIn("signature=*****", doc.get("url"))
def new(self, *args): """ create a new package template conanfile.py and other optional files """ parser = argparse.ArgumentParser(description=self.new.__doc__, prog="conan new", formatter_class=RawTextHelpFormatter) parser.add_argument("name", help='Package name, e.g.: Poco/1.7.3@user/testing') parser.add_argument( "-t", "--test", action='store_true', default=False, help='Create test_package skeleton to test package') parser.add_argument("-i", "--header", action='store_true', default=False, help='Create a headers only package') parser.add_argument( "-c", "--pure_c", action='store_true', default=False, help='Create a C language package only package (non-headers)') args = parser.parse_args(*args) root_folder = os.getcwd() try: name, version, user, channel = ConanFileReference.loads(args.name) pattern = re.compile('[\W_]+') package_name = pattern.sub('', name).capitalize() except: raise ConanException("Bad parameter, please use full package name," "e.g: MyLib/1.2.3@user/testing") from conans.client.new import (conanfile, conanfile_header, test_conanfile, test_cmake, test_main) if args.header: files = { "conanfile.py": conanfile_header.format(name=name, version=version, package_name=package_name) } else: files = { "conanfile.py": conanfile.format(name=name, version=version, package_name=package_name) } if args.pure_c: config = "\n def config(self):\n del self.settings.compiler.libcxx" files["conanfile.py"] = files["conanfile.py"] + config if args.test: files["test_package/conanfile.py"] = test_conanfile.format( name=name, version=version, user=user, channel=channel, package_name=package_name) files["test_package/CMakeLists.txt"] = test_cmake files["test_package/example.cpp"] = test_main save_files(root_folder, files) for f in sorted(files): self._user_io.out.success("File saved: %s" % f)
def add(self, reference, private=False, override=False): """ to define requirements by the user in text, prior to any propagation """ assert isinstance(reference, six.string_types) ref = ConanFileReference.loads(reference) self.add_ref(ref, private, override)
def test_export_read_only(self): client = TestClient() conanfile = """ from conans import ConanFile class TestConan(ConanFile): name = "Hello" version = "1.2" exports = "file1.txt" exports_sources = "file2.txt" """ ref = ConanFileReference.loads("Hello/1.2@lasote/stable") export_path = client.client_cache.export(ref) export_src_path = client.client_cache.export_sources(ref) files = {CONANFILE: conanfile, "file1.txt": "", "file2.txt": ""} client.save(files) mode1 = os.stat(os.path.join(client.current_folder, "file1.txt")).st_mode mode2 = os.stat(os.path.join(client.current_folder, "file2.txt")).st_mode os.chmod(os.path.join(client.current_folder, "file1.txt"), mode1 & ~stat.S_IWRITE) os.chmod(os.path.join(client.current_folder, "file2.txt"), mode2 & ~stat.S_IWRITE) client.run("export lasote/stable") self.assertEqual(load(os.path.join(export_path, "file1.txt")), "") self.assertEqual(load(os.path.join(export_src_path, "file2.txt")), "") with self.assertRaises(IOError): save(os.path.join(export_path, "file1.txt"), "") with self.assertRaises(IOError): save(os.path.join(export_src_path, "file2.txt"), "") self.assertIn("WARN: Conanfile doesn't have 'license'", client.user_io.out) files = { CONANFILE: conanfile, "file1.txt": "file1", "file2.txt": "file2" } os.chmod(os.path.join(client.current_folder, "file1.txt"), mode1 | stat.S_IWRITE) os.chmod(os.path.join(client.current_folder, "file2.txt"), mode2 | stat.S_IWRITE) client.save(files) client.run("export lasote/stable") self.assertEqual(load(os.path.join(export_path, "file1.txt")), "file1") self.assertEqual(load(os.path.join(export_src_path, "file2.txt")), "file2") client.run("install Hello/1.2@lasote/stable --build=missing") self.assertIn("Hello/1.2@lasote/stable: Generating the package", client.out) files = {CONANFILE: conanfile, "file1.txt": "", "file2.txt": ""} client.save(files) os.chmod(os.path.join(client.current_folder, "file1.txt"), mode1 & ~stat.S_IWRITE) os.chmod(os.path.join(client.current_folder, "file2.txt"), mode2 & ~stat.S_IWRITE) client.run("export lasote/stable") self.assertEqual(load(os.path.join(export_path, "file1.txt")), "") self.assertEqual(load(os.path.join(export_src_path, "file2.txt")), "") client.run("install Hello/1.2@lasote/stable --build=Hello") self.assertIn("Hello/1.2@lasote/stable: Generating the package", client.out)
def setUp(self): tmp_dir = temp_folder() stream = StringIO() output = ConanOutput(stream) self.cache = ClientCache(tmp_dir, tmp_dir, output) self.ref = ConanFileReference.loads("lib/1.0@conan/stable")
def load_conaninfo(lib): # Read the LIB_A conaninfo packages_path = client.client_cache.packages(ConanFileReference.loads("LIB_%s/1.0@lasote/stable" % lib)) package_path = os.path.join(packages_path, os.listdir(packages_path)[0]) info = ConanInfo.loads(load(os.path.join(package_path, CONANINFO))) return info
def test_docker(self): client_version = get_client_version() ci_manager = MockCIManager() unique_ref = "zlib/%s" % str(time.time()) conanfile = """from conans import ConanFile import os class Pkg(ConanFile): settings = "os", "compiler", "build_type", "arch" """ self.save_conanfile(conanfile) with tools.environment_append({ "CONAN_DOCKER_RUN_OPTIONS": "--network=host -v{}:/tmp/cpt".format( self.root_project_folder), "CONAN_DOCKER_ENTRY_SCRIPT": "pip install -U /tmp/cpt", "CONAN_USE_DOCKER": "1", "CONAN_DOCKER_IMAGE_SKIP_UPDATE": "TRUE", "CONAN_LOGIN_USERNAME": "******", "CONAN_USERNAME": "******", "CONAN_UPLOAD": DockerTest.CONAN_SERVER_ADDRESS, "CONAN_PASSWORD": "******" }): self.packager = ConanMultiPackager(channel="mychannel", gcc_versions=["6"], archs=["x86", "x86_64"], build_types=["Release"], reference=unique_ref, ci_manager=ci_manager) self.packager.add_common_builds() self.packager.run() search_pattern = "%s*" % unique_ref ref = ConanFileReference.loads("%s@demo/mychannel" % unique_ref) # Remove from remote if Version(client_version) < Version("1.7"): results = self.api.search_recipes( search_pattern, remote="upload_repo")["results"][0]["items"] self.assertEquals(len(results), 1) packages = self.api.search_packages( ref, remote="upload_repo")["results"][0]["items"][0]["packages"] self.assertEquals(len(packages), 2) self.api.authenticate(name=CONAN_LOGIN_UPLOAD, password=CONAN_UPLOAD_PASSWORD, remote="upload_repo") self.api.remove(search_pattern, remote="upload_repo", force=True) self.assertEquals( self.api.search_recipes(search_pattern)["results"], []) else: results = self.api.search_recipes( search_pattern, remote_name="upload_repo")["results"][0]["items"] self.assertEquals(len(results), 1) if Version(client_version) >= Version("1.12.0"): ref = repr(ref) packages = self.api.search_packages( ref, remote_name="upload_repo" )["results"][0]["items"][0]["packages"] self.assertEquals(len(packages), 2) self.api.authenticate(name="demo", password="******", remote_name="upload_repo") self.api.remove(search_pattern, remote_name="upload_repo", force=True) self.assertEquals( self.api.search_recipes(search_pattern)["results"], []) # Try upload only when stable, shouldn't upload anything with tools.environment_append({ "CONAN_DOCKER_RUN_OPTIONS": "--network=host -v{}:/tmp/cpt".format( self.root_project_folder), "CONAN_DOCKER_ENTRY_SCRIPT": "pip install -U /tmp/cpt", "CONAN_USE_DOCKER": "1", "CONAN_LOGIN_USERNAME": "******", "CONAN_USERNAME": "******", "CONAN_PASSWORD": "******", "CONAN_DOCKER_IMAGE_SKIP_UPDATE": "TRUE", "CONAN_UPLOAD_ONLY_WHEN_STABLE": "1" }): self.packager = ConanMultiPackager( channel="mychannel", gcc_versions=["6"], archs=["x86", "x86_64"], build_types=["Release"], reference=unique_ref, upload=DockerTest.CONAN_SERVER_ADDRESS, ci_manager=ci_manager) self.packager.add_common_builds() self.packager.run() if Version(client_version) < Version("1.7"): results = self.api.search_recipes(search_pattern, remote="upload_repo")["results"] self.assertEquals(len(results), 0) self.api.remove(search_pattern, remote="upload_repo", force=True) else: results = self.api.search_recipes( search_pattern, remote_name="upload_repo")["results"] self.assertEquals(len(results), 0) self.api.remove(search_pattern, remote_name="upload_repo", force=True)
def basic_test(self): boost_values = PackageOptionValues() boost_values.add_option("static", False) boost_values.add_option("thread", True) boost_values.add_option("thread.multi", "off") poco_values = PackageOptionValues() poco_values.add_option("deps_bundled", True) hello1_values = PackageOptionValues() hello1_values.add_option("static", False) hello1_values.add_option("optimized", 4) options = { "Boost": boost_values, "Poco": poco_values, "Hello1": hello1_values } down_ref = ConanFileReference.loads("Hello0/0.1@diego/testing") own_ref = ConanFileReference.loads("Hello1/0.1@diego/testing") output = TestBufferConanOutput() self.sut.propagate_upstream(options, down_ref, own_ref, output) self.assertEqual(self.sut.values.as_list(), [("optimized", "4"), ("path", "NOTDEF"), ("static", "False"), ("Boost:static", "False"), ("Boost:thread", "True"), ("Boost:thread.multi", "off"), ("Poco:deps_bundled", "True")]) boost_values = PackageOptionValues() boost_values.add_option("static", 2) boost_values.add_option("thread", "Any") boost_values.add_option("thread.multi", "on") poco_values = PackageOptionValues() poco_values.add_option("deps_bundled", "What") hello1_values = PackageOptionValues() hello1_values.add_option("static", True) hello1_values.add_option("optimized", "2") options2 = { "Boost": boost_values, "Poco": poco_values, "Hello1": hello1_values } down_ref = ConanFileReference.loads("Hello2/0.1@diego/testing") self.sut.propagate_upstream(options2, down_ref, own_ref, output) self.assertIn( """WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option optimized to 2 but it was already assigned to 4 by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option static to True but it was already assigned to False by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:static to 2 but it was already assigned to False by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread to Any but it was already assigned to True by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread.multi to on but it was already assigned to off by Hello0/0.1@diego/testing WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Poco:deps_bundled to What but it was already assigned to True by Hello0/0.1@diego/testing""", str(output)) self.assertEqual( self.sut.values.dumps(), """optimized=4 path=NOTDEF static=False Boost:static=False Boost:thread=True Boost:thread.multi=off Poco:deps_bundled=True""")
def _get_metadata(self, ref): reference = ConanFileReference.loads(self._get_reference(ref)) package_layout = self._conan_cache.package_layout(reference) metadata = package_layout.load_metadata() return metadata
def test_build_settings(self): def install_and_get_info(package_id_text): self.client.run("remove * -f") self._export("Hello", "1.2.0", package_id_text=package_id_text, channel="user/testing", settings=["os", "os_build", "arch", "arch_build"]) self.client.run('install Hello/1.2.0@user/testing ' ' -s os="Windows" ' ' -s os_build="Linux"' ' -s arch="x86_64"' ' -s arch_build="x86"' ' --build missing') ref = ConanFileReference.loads("Hello/1.2.0@user/testing") pkg = os.listdir(self.client.cache.package_layout(ref).packages()) pref = PackageReference(ref, pkg[0]) pkg_folder = self.client.cache.package_layout( pref.ref).package(pref) return ConanInfo.loads(load(os.path.join(pkg_folder, CONANINFO))) info = install_and_get_info(None) # Default self.assertEqual(str(info.settings.os_build), "None") self.assertEqual(str(info.settings.arch_build), "None") # Package has to be present with only os and arch settings self.client.run('install Hello/1.2.0@user/testing ' ' -s os="Windows" ' ' -s arch="x86_64"') # Even with wrong build settings self.client.run('install Hello/1.2.0@user/testing ' ' -s os="Windows" ' ' -s arch="x86_64"' ' -s os_build="Macos"' ' -s arch_build="x86_64"') # take into account build info = install_and_get_info("self.info.include_build_settings()") self.assertEqual(str(info.settings.os_build), "Linux") self.assertEqual(str(info.settings.arch_build), "x86") # Now the build settings matter err = self.client.run( 'install Hello/1.2.0@user/testing ' ' -s os="Windows" ' ' -s arch="x86_64"' ' -s os_build="Macos"' ' -s arch_build="x86_64"', assert_error=True) self.assertTrue(err) self.assertIn("Can't find", self.client.out) self.client.run('install Hello/1.2.0@user/testing ' ' -s os="Windows" ' ' -s arch="x86_64"' ' -s os_build="Linux"' ' -s arch_build="x86"') # Now only settings for build self.client.run("remove * -f") self._export("Hello", "1.2.0", channel="user/testing", settings=["os_build", "arch_build"]) self.client.run('install Hello/1.2.0@user/testing ' ' -s os_build="Linux"' ' -s arch_build="x86"' ' --build missing') ref = ConanFileReference.loads("Hello/1.2.0@user/testing") pkg = os.listdir(self.client.cache.package_layout(ref).packages()) pref = PackageReference(ref, pkg[0]) pkg_folder = self.client.cache.package_layout(pref.ref).package(pref) info = ConanInfo.loads(load(os.path.join(pkg_folder, CONANINFO))) self.assertEqual(str(info.settings.os_build), "Linux") self.assertEqual(str(info.settings.arch_build), "x86")
def complete_test(self): """ basic installation of a new conans """ client = TestClient() files = hello_source_files() ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable") reg_folder = client.cache.package_layout(ref).export() client.save(files, path=reg_folder) client.save( { CONANFILE: myconan1, "infos/%s" % CONANINFO: "//empty", "include/no_copy/lib0.h": "NO copy", "include/math/lib1.h": "copy", "include/math/lib2.h": "copy", "include/physics/lib.hpp": "copy", "my_lib/debug/libd.a": "copy", "my_data/readme.txt": "copy", "my_data/readme.md": "NO copy", "contrib/math/math.h": "copy", "contrib/physics/gravity.h": "copy", "contrib/contrib.h": "copy", "include/opencv/opencv.hpp": "copy", "include/opencv2/opencv2.hpp": "copy", "modules/simu/src/simu.cpp": "NO copy", "modules/simu/include/opencv2/simu/simu.hpp": "copy", "modules/3D/doc/readme.md": "NO copy", "modules/3D/include/opencv2/3D/3D.hpp": "copy", "modules/dev/src/dev.cpp": "NO copy", "modules/dev/include/opencv2/dev/dev.hpp": "copy", "modules/opencv_mod.hpp": "copy" }, path=reg_folder) conanfile_path = os.path.join(reg_folder, CONANFILE) pref = PackageReference(ref, "myfakeid") build_folder = client.cache.package_layout(pref.ref).build(pref) package_folder = client.cache.package_layout(pref.ref).package(pref) install_folder = os.path.join(build_folder, "infos") shutil.copytree(reg_folder, build_folder) loader = ConanFileLoader(None, TestBufferConanOutput(), ConanPythonRequire(None, None)) conanfile = loader.load_consumer(conanfile_path, test_processed_profile()) create_package(conanfile, None, build_folder, build_folder, package_folder, install_folder, Mock(), conanfile_path, ref, copy_info=True) # test build folder self.assertTrue(os.path.exists(build_folder)) self.assertTrue(os.path.exists(os.path.join(package_folder, CONANINFO))) # test pack folder self.assertTrue(os.path.exists(package_folder)) def exist(rel_path): return os.path.exists(os.path.join(package_folder, rel_path)) # Expected files self.assertTrue(exist("include/lib1.h")) self.assertTrue(exist("include/lib2.h")) self.assertTrue(exist("include/physics/lib.hpp")) self.assertTrue(exist("include/contrib/math/math.h")) self.assertTrue(exist("include/contrib/physics/gravity.h")) self.assertTrue(exist("include/contrib/contrib.h")) self.assertTrue(exist("include/opencv/opencv.hpp")) self.assertTrue(exist("include/opencv2/opencv2.hpp")) self.assertTrue(exist("include/opencv2/simu/simu.hpp")) self.assertTrue(exist("include/opencv2/3D/3D.hpp")) self.assertTrue(exist("include/opencv2/dev/dev.hpp")) self.assertTrue(exist("lib/my_lib/libd.a")) self.assertTrue(exist("res/shares/readme.txt")) # Not expected files self.assertFalse(exist("include/opencv2/opencv_mod.hpp")) self.assertFalse(exist("include/opencv2/simu.hpp")) self.assertFalse(exist("include/opencv2/3D.hpp")) self.assertFalse(exist("include/opencv2/dev.hpp")) self.assertFalse(exist("include/modules/simu/src/simu.cpp")) self.assertFalse(exist("include/modules/3D/doc/readme.md")) self.assertFalse(exist("include/modules/dev/src/dev.cpp")) self.assertFalse(exist("include/opencv2/opencv_mod.hpp")) self.assertFalse(exist("include/include/no_copy/lib0.h")) self.assertFalse(exist("res/my_data/readme.md"))
def test_copy(self): output = TestBufferConanOutput() userio = MockedBooleanUserIO(True, out=output) paths = SimplePaths(temp_folder()) # Create some packages to copy reference = ConanFileReference.loads("Hello/0.1@lasote/testing") self._create_conanfile(reference, paths) self._create_package(reference, "0101001", paths) self._create_package(reference, "2222222", paths) # Copy all to destination package_copy(reference, "lasote/stable", ["0101001", "2222222"], paths, user_io=userio, force=False) new_reference = ConanFileReference.loads("Hello/0.1@lasote/stable") self._assert_conanfile_exists(new_reference, paths) self._assert_package_exists(new_reference, "0101001", paths) self._assert_package_exists(new_reference, "2222222", paths) self.assertIn( "Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable", output) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Copy again, without force and answering yes output._stream.truncate(0) # Reset output package_copy(reference, "lasote/stable", ["0101001", "2222222"], paths, user_io=userio, force=False) self.assertIn( "Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable", output) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) self.assertIn("'Hello/0.1@lasote/stable' already exist. Override?", output) self.assertIn("Package '2222222' already exist. Override?", output) self.assertIn("Package '0101001' already exist. Override?", output) # Now alter the origin and copy again to same destination and confirm the copy self._create_conanfile(reference, paths, "new content") self._create_package(reference, "0101001", paths, "new lib content") self._create_package(reference, "2222222", paths, "new lib content") output._stream.truncate(0) # Reset output package_copy(reference, "lasote/stable", ["0101001", "2222222"], paths, user_io=userio, force=False) conanfile_content = load( os.path.join(paths.export(new_reference), "conanfile.py")) self.assertEquals(conanfile_content, "new content") package_content = load( os.path.join( paths.package(PackageReference(new_reference, "0101001")), "package.lib")) self.assertEquals(package_content, "new lib content") # Now we are going to answer always NO to override output._stream.truncate(0) # Reset output userio = MockedBooleanUserIO(False, out=output) self._create_conanfile(reference, paths, "content22") self._create_package(reference, "0101001", paths, "newlib22") self._create_package(reference, "2222222", paths, "newlib22") package_copy(reference, "lasote/stable", ["0101001", "2222222"], paths, user_io=userio, force=False) conanfile_content = load( os.path.join(paths.export(new_reference), "conanfile.py")) self.assertEquals(conanfile_content, "new content") # Not content22 p_ref = PackageReference(new_reference, "0101001") package_content = load( os.path.join(paths.package(p_ref), "package.lib")) self.assertEquals(package_content, "new lib content") # Not newlib22 # If conanfile is not override it exist self.assertNotIn("Package '2222222' already exist. Override?", output) self.assertNotIn("Package '0101001' already exist. Override?", output) self.assertNotIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertNotIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Now override output._stream.truncate(0) # Reset output package_copy(reference, "lasote/stable", ["0101001", "2222222"], paths, user_io=userio, force=True) self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output) self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output) # Now copy just one package to another user/channel output._stream.truncate(0) # Reset output package_copy(reference, "pepe/mychannel", ["0101001"], paths, user_io=userio, force=True) self.assertIn("Copied 0101001 to Hello/0.1@pepe/mychannel", output) self.assertNotIn("Copied 2222222 to Hello/0.1@pepe/mychannel", output) new_reference = ConanFileReference.loads("Hello/0.1@pepe/mychannel") self._assert_package_exists(new_reference, "0101001", paths) self._assert_package_doesnt_exists(new_reference, "2222222", paths)
def _get_recipe_snapshot(self, ref): url = self.conans_router.recipe_snapshot(ref) ref_str = ref.full_repr() snap, reference, rev_time = self._get_snapshot(url, ref_str) ref = ConanFileReference.loads(reference) return snap, ref, rev_time