def scopes_env_test(self): # Create a profile and use it create_profile( self.client.client_cache.profiles_path, "scopes_env", settings={}, scopes={ "Hello0:myscope": "1", "ALL:otherscope": "2", "undefined": "3", }, # undefined scope do not apply to my packages env=[("CXX", "/path/tomy/g++"), ("CC", "/path/tomy/gcc")], ) self.client.save({CONANFILE: conanfile_scope_env}) self.client.run("export lasote/stable") self.client.run("install Hello0/0.1@lasote/stable --build missing -pr scopes_env") self.assertIn("Scope myscope: 1", self.client.user_io.out) self.assertIn("Scope otherscope: 2", self.client.user_io.out) self.assertIn("Scope undefined: None", self.client.user_io.out) self._assert_env_variable_printed("CC", "/path/tomy/gcc") self._assert_env_variable_printed("CXX", "/path/tomy/g++") # The env variable shouldn't persist after install command self.assertFalse(os.environ.get("CC", None) == "/path/tomy/gcc") self.assertFalse(os.environ.get("CXX", None) == "/path/tomy/g++")
def test_list(self): client = TestClient() profiles = [ "default", "profile1", "profile2", "profile3", "nested" + os.path.sep + "profile4", "nested" + os.path.sep + "two" + os.path.sep + "profile5", "nested" + os.path.sep + "profile6" ] if platform.system() != "Windows": profiles.append("symlink_me" + os.path.sep + "profile7") for profile in profiles: create_profile(client.cache.profiles_path, profile) if platform.system() != "Windows": os.symlink(os.path.join(client.cache.profiles_path, 'symlink_me'), os.path.join(client.cache.profiles_path, 'link')) # profile7 will be shown twice because it is symlinked. profiles.append("link" + os.path.sep + "profile7") # Make sure local folder doesn't interact with profiles os.mkdir(os.path.join(client.current_folder, "profile3")) client.run("profile list") profiles.sort() self.assertEqual(profiles, list(str(client.out).splitlines())) # Test profile list json file client.run("profile list --json profile_list.json") json_path = os.path.join(client.current_folder, "profile_list.json") self.assertTrue(os.path.exists(json_path)) json_content = load(json_path) json_obj = json.loads(json_content) self.assertEqual(list, type(json_obj)) self.assertEqual(profiles, json_obj)
def install_profile_env_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] = conanfile_scope_env create_profile(self.client.client_cache.profiles_path, "envs", settings={}, env=[("A_VAR", "A_VALUE")], package_env={"Hello0": [("OTHER_VAR", "2")]}) self.client.save(files) self.client.run("export lasote/stable") self.client.run("install Hello0/0.1@lasote/stable --build missing -pr envs") self._assert_env_variable_printed("A_VAR", "A_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override with package var self.client.run("install Hello0/0.1@lasote/stable --build -pr envs -e Hello0:A_VAR=OTHER_VALUE") self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override package var with package var self.client.run("install Hello0/0.1@lasote/stable --build -pr envs " "-e Hello0:A_VAR=OTHER_VALUE -e Hello0:OTHER_VAR=3") self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "3") # Pass a variable with "=" symbol self.client.run("install Hello0/0.1@lasote/stable --build -pr envs " "-e Hello0:A_VAR=Valuewith=equal -e Hello0:OTHER_VAR=3") self._assert_env_variable_printed("A_VAR", "Valuewith=equal") self._assert_env_variable_printed("OTHER_VAR", "3")
def scopes_env_test(self): # Create a profile and use it create_profile( self.client.client_cache.profiles_path, "scopes_env", settings={}, scopes={ "Hello0:myscope": "1", "ALL:otherscope": "2", "undefined": "3" }, # undefined scope do not apply to my packages env=[("CXX", "/path/tomy/g++"), ("CC", "/path/tomy/gcc")]) self.client.save({CONANFILE: conanfile_scope_env}) self.client.run("export lasote/stable") self.client.run( "install Hello0/0.1@lasote/stable --build missing -pr scopes_env") self.assertIn("Scope myscope: 1", self.client.user_io.out) self.assertIn("Scope otherscope: 2", self.client.user_io.out) self.assertIn("Scope undefined: None", self.client.user_io.out) self._assert_env_variable_printed("CC", "/path/tomy/gcc") self._assert_env_variable_printed("CXX", "/path/tomy/g++") # The env variable shouldn't persist after install command self.assertFalse(os.environ.get("CC", None) == "/path/tomy/gcc") self.assertFalse(os.environ.get("CXX", None) == "/path/tomy/g++")
def install_profile_env_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] = conanfile_scope_env create_profile(self.client.client_cache.profiles_path, "envs", settings={}, env=[("A_VAR", "A_VALUE")], package_env={"Hello0": [("OTHER_VAR", 2)]}) self.client.save(files) self.client.run("export lasote/stable") self.client.run( "install Hello0/0.1@lasote/stable --build missing -pr envs") self._assert_env_variable_printed("A_VAR", "A_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override with package var self.client.run( "install Hello0/0.1@lasote/stable --build -pr envs -e Hello0:A_VAR=OTHER_VALUE" ) self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override package var with package var self.client.run( "install Hello0/0.1@lasote/stable --build -pr envs -e Hello0:A_VAR=OTHER_VALUE -e Hello0:OTHER_VAR=3" ) self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "3")
def info_with_profiles_test(self): self.client.run("remove '*' -f") # Create a simple recipe to require winreq_conanfile = ''' from conans.model.conan_file import ConanFile class WinRequireDefaultNameConan(ConanFile): name = "WinRequire" version = "0.1" settings = "os", "compiler", "arch", "build_type" ''' files = {"conanfile.py": winreq_conanfile} self.client.save(files) self.client.run("export lasote/stable") # Now require the first recipe depending on OS=windows conanfile = '''from conans.model.conan_file import ConanFile import os class DefaultNameConan(ConanFile): name = "Hello" version = "0.1" settings = "os", "compiler", "arch", "build_type" def config(self): if self.settings.os == "Windows": self.requires.add("WinRequire/0.1@lasote/stable") ''' files = {"conanfile.py": conanfile} self.client.save(files) self.client.run("export lasote/stable") # Create a profile that doesn't activate the require create_profile(self.client.client_cache.profiles_path, "scopes_env", settings={"os": "Linux"}, scopes={}) # Install with the previous profile self.client.run("info Hello/0.1@lasote/stable --profile scopes_env") self.assertNotIn( '''Requires: WinRequire/0.1@lasote/stable''', self.client.user_io.out) # Create a profile that activate the require create_profile(self.client.client_cache.profiles_path, "scopes_env", settings={"os": "Windows"}, scopes={}) # Install with the previous profile self.client.run("info Hello/0.1@lasote/stable --profile scopes_env") self.assertIn('''Requires: WinRequire/0.1@lasote/stable''', self.client.user_io.out)
def test_package_test(self): test_conanfile = '''from conans.model.conan_file import ConanFile from conans import CMake import os class DefaultNameConan(ConanFile): name = "DefaultName" version = "0.1" settings = "os", "compiler", "arch", "build_type" requires = "Hello0/0.1@lasote/stable" def build(self): # Print environment vars # self.run('cmake %s %s' % (self.conanfile_directory, cmake.command_line)) if self.settings.os == "Windows": self.run('echo "My var is %ONE_VAR%"') else: self.run('echo "My var is $ONE_VAR"') def test(self): pass ''' files = {"conanfile.py": conanfile_scope_env, "test_package/conanfile.py": test_conanfile} # Create a profile and use it create_profile(self.client.client_cache.profiles_path, "scopes_env", settings={}, scopes={}, env=[("ONE_VAR", "ONE_VALUE")]) self.client.save(files) self.client.run("test_package --profile scopes_env") self._assert_env_variable_printed("ONE_VAR", "ONE_VALUE") self.assertIn("My var is ONE_VALUE", str(self.client.user_io.out)) # Try now with package environment vars create_profile(self.client.client_cache.profiles_path, "scopes_env2", settings={}, scopes={}, package_env={"DefaultName": [("ONE_VAR", "IN_TEST_PACKAGE")], "Hello0": [("ONE_VAR", "PACKAGE VALUE")]}) self.client.run("test_package --profile scopes_env2") self._assert_env_variable_printed("ONE_VAR", "PACKAGE VALUE") self.assertIn("My var is IN_TEST_PACKAGE", str(self.client.user_io.out)) # Try now overriding some variables with command line self.client.run("test_package --profile scopes_env2 -e DefaultName:ONE_VAR=InTestPackageOverride " "-e Hello0:ONE_VAR=PackageValueOverride ") self._assert_env_variable_printed("ONE_VAR", "PackageValueOverride") self.assertIn("My var is InTestPackageOverride", str(self.client.user_io.out)) # A global setting in command line won't override a scoped package variable self.client.run("test_package --profile scopes_env2 -e ONE_VAR=AnotherValue") self._assert_env_variable_printed("ONE_VAR", "PACKAGE VALUE")
def install_profile_options_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) create_profile(self.client.client_cache.profiles_path, "vs_12_86", options=[("Hello0:language", 1), ("Hello0:static", False)]) self.client.save(files) self.client.run("install --build missing -pr vs_12_86") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("language=1", info) self.assertIn("static=False", info)
def info_with_profiles_test(self): self.client.run("remove '*' -f") # Create a simple recipe to require winreq_conanfile = ''' from conans.model.conan_file import ConanFile class WinRequireDefaultNameConan(ConanFile): name = "WinRequire" version = "0.1" settings = "os", "compiler", "arch", "build_type" ''' files = {"conanfile.py": winreq_conanfile} self.client.save(files) self.client.run("export lasote/stable") # Now require the first recipe depending on OS=windows conanfile = '''from conans.model.conan_file import ConanFile import os class DefaultNameConan(ConanFile): name = "Hello" version = "0.1" settings = "os", "compiler", "arch", "build_type" def config(self): if self.settings.os == "Windows": self.requires.add("WinRequire/0.1@lasote/stable") ''' files = {"conanfile.py": conanfile} self.client.save(files) self.client.run("export lasote/stable") # Create a profile that doesn't activate the require create_profile(self.client.client_cache.profiles_path, "scopes_env", settings={"os": "Linux"}, scopes={}) # Install with the previous profile self.client.run("info Hello/0.1@lasote/stable --profile scopes_env") self.assertNotIn('''Requires: WinRequire/0.1@lasote/stable''', self.client.user_io.out) # Create a profile that activate the require create_profile(self.client.client_cache.profiles_path, "scopes_env", settings={"os": "Windows"}, scopes={}) # Install with the previous profile self.client.run("info Hello/0.1@lasote/stable --profile scopes_env") self.assertIn('''Requires: WinRequire/0.1@lasote/stable''', self.client.user_io.out)
def show_test(self): client = TestClient() create_profile(client.client_cache.profiles_path, "profile1", settings={"os": "Windows"}, options=[("MyOption", "32")]) create_profile(client.client_cache.profiles_path, "profile3", env=[("package:VAR", "value"), ("CXX", "/path/tomy/g++_build"), ("CC", "/path/tomy/gcc_build")]) client.run("profile show profile1") self.assertIn("[settings]\nos=Windows", client.user_io.out) self.assertIn("MyOption=32", client.user_io.out) client.run("profile show profile3") self.assertIn("CC=/path/tomy/gcc_build", client.user_io.out) self.assertIn("CXX=/path/tomy/g++_build", client.user_io.out) self.assertIn("package:VAR=value", client.user_io.out)
def show_test(self): client = TestClient() create_profile(client.cache.profiles_path, "profile1", settings={"os": "Windows"}, options=[("MyOption", "32")]) create_profile(client.cache.profiles_path, "profile3", env=[("package:VAR", "value"), ("CXX", "/path/tomy/g++_build"), ("CC", "/path/tomy/gcc_build")]) client.run("profile show profile1") self.assertIn("[settings]\nos=Windows", client.user_io.out) self.assertIn("MyOption=32", client.user_io.out) client.run("profile show profile3") self.assertIn("CC=/path/tomy/gcc_build", client.user_io.out) self.assertIn("CXX=/path/tomy/g++_build", client.user_io.out) self.assertIn("package:VAR=value", client.user_io.out)
def test_show(self): client = TestClient() create_profile(client.cache.profiles_path, "profile1", settings={"os": "Windows"}, options=[("MyOption", "32")]) create_profile(client.cache.profiles_path, "profile3", env=[("package:VAR", "value"), ("CXX", "/path/tomy/g++_build"), ("CC", "/path/tomy/gcc_build")], conf=["tools.ninja:jobs=10", "tools.gnu.make:jobs=20"]) client.run("profile show profile1") self.assertIn("[settings]\nos=Windows", client.out) self.assertIn("MyOption=32", client.out) client.run("profile show profile3") self.assertIn("CC=/path/tomy/gcc_build", client.out) self.assertIn("CXX=/path/tomy/g++_build", client.out) self.assertIn("package:VAR=value", client.out) self.assertIn("tools.ninja:jobs=10", client.out) self.assertIn("tools.gnu.make:jobs=20", client.out)
def build_with_profile_test(self, path): if path == "": folder = self.client.client_cache.profiles_path elif path == "./local_profiles/": folder = os.path.join(self.client.current_folder, "local_profiles") else: folder = path create_profile( folder, "scopes_env", settings={}, scopes={}, # undefined scope do not apply to my packages env=[("CXX", "/path/tomy/g++_build"), ("CC", "/path/tomy/gcc_build")], ) self.client.save({CONANFILE: conanfile_scope_env}) self.client.run('build -pr "%sscopes_env"' % path) self._assert_env_variable_printed("CC", "/path/tomy/gcc_build") self._assert_env_variable_printed("CXX", "/path/tomy/g++_build")
def build_with_profile_test(self, path): if path == "": folder = self.client.client_cache.profiles_path elif path == "./local_profiles/": folder = os.path.join(self.client.current_folder, "local_profiles") else: folder = path create_profile( folder, "scopes_env", settings={}, scopes={}, # undefined scope do not apply to my packages env=[("CXX", "/path/tomy/g++_build"), ("CC", "/path/tomy/gcc_build")]) self.client.save({CONANFILE: conanfile_scope_env}) self.client.run('build -pr "%sscopes_env"' % path) self._assert_env_variable_printed("CC", "/path/tomy/gcc_build") self._assert_env_variable_printed("CXX", "/path/tomy/g++_build")
def list_test(self): client = TestClient() profiles = ["profile1", "profile2", "profile3", "nested" + os.path.sep + "profile4", "nested" + os.path.sep + "two" + os.path.sep + "profile5", "nested" + os.path.sep + "profile6"] if platform.system() != "Windows": profiles.append("symlink_me" + os.path.sep + "profile7") for profile in profiles: create_profile(client.cache.profiles_path, profile) if platform.system() != "Windows": os.symlink(os.path.join(client.cache.profiles_path, 'symlink_me'), os.path.join(client.cache.profiles_path, 'link')) # profile7 will be shown twice because it is symlinked. profiles.append("link" + os.path.sep + "profile7") # Make sure local folder doesn't interact with profiles os.mkdir(os.path.join(client.current_folder, "profile3")) client.run("profile list") profiles.sort() self.assertEqual(profiles, list(str(client.out).splitlines()))
def list_test(self): client = TestClient(default_profile=False) create_profile(client.client_cache.profiles_path, "profile3") create_profile(client.client_cache.profiles_path, "profile1") create_profile(client.client_cache.profiles_path, "profile2") client.run("profile list") self.assertEqual(list(["profile1", "profile2", "profile3"]), list(str(client.user_io.out).splitlines()))
def list_test(self): client = TestClient() create_profile(client.client_cache.profiles_path, "profile3") create_profile(client.client_cache.profiles_path, "profile1") create_profile(client.client_cache.profiles_path, "profile2") client.run("profile list") self.assertEqual(list(["profile1", "profile2", "profile3"]), list(str(client.user_io.out).splitlines()))
def list_test(self): client = TestClient() create_profile(client.client_cache.profiles_path, "profile3") create_profile(client.client_cache.profiles_path, "profile1") create_profile(client.client_cache.profiles_path, "profile2") # Make sure local folder doesn't interact with profiles os.mkdir(os.path.join(client.current_folder, "profile3")) client.run("profile list") self.assertEqual(list(["profile1", "profile2", "profile3"]), list(str(client.user_io.out).splitlines()))
def list_test(self): client = TestClient(default_profile=False) create_profile(client.client_cache.profiles_path, "profile3") create_profile(client.client_cache.profiles_path, "profile1") create_profile(client.client_cache.profiles_path, "profile2") # Make sure local folder doesn't interact with profiles os.mkdir(os.path.join(client.current_folder, "profile3")) client.run("profile list") self.assertEqual(list(["profile1", "profile2", "profile3"]), list(str(client.user_io.out).splitlines()))
def show_test(self): client = TestClient() create_profile(client.client_cache.profiles_path, "profile1", settings={"os": "Windows"}) create_profile(client.client_cache.profiles_path, "profile2", scopes={"test": True}) create_profile(client.client_cache.profiles_path, "profile3", env=[("CXX", "/path/tomy/g++_build"), ("CC", "/path/tomy/gcc_build")]) client.run("profile show profile1") self.assertIn(" os: Windows", client.user_io.out) client.run("profile show profile2") self.assertIn(" test=True", client.user_io.out) client.run("profile show profile3") self.assertIn(" CC: /path/tomy/gcc_build", client.user_io.out) self.assertIn(" CXX: /path/tomy/g++_build", client.user_io.out)
def show_test(self): client = TestClient() create_profile(client.client_cache.profiles_path, "profile1", settings={"os": "Windows"}) create_profile(client.client_cache.profiles_path, "profile2", scopes={"test": True}) create_profile(client.client_cache.profiles_path, "profile3", env=[("package:VAR", "value"), ("CXX", "/path/tomy/g++_build"), ("CC", "/path/tomy/gcc_build")]) client.run("profile show profile1") self.assertIn(" os: Windows", client.user_io.out) client.run("profile show profile2") self.assertIn(" test=True", client.user_io.out) client.run("profile show profile3") self.assertIn(" CC=/path/tomy/gcc_build", client.user_io.out) self.assertIn(" CXX=/path/tomy/g++_build", client.user_io.out) self.assertIn(" package:VAR=value", client.user_io.out)
def install_profile_settings_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) # Create a profile and use it profile_settings = OrderedDict([("compiler", "Visual Studio"), ("compiler.version", "12"), ("compiler.runtime", "MD"), ("arch", "x86")]) create_profile(self.client.client_cache.profiles_path, "vs_12_86", settings=profile_settings, package_settings={}) self.client.save(files) self.client.run("export lasote/stable") self.client.run("install --build missing -pr vs_12_86") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) for setting, value in profile_settings.items(): self.assertIn("%s=%s" % (setting, value), info) # Try to override some settings in install command self.client.run("install --build missing -pr vs_12_86 -s compiler.version=14") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) for setting, value in profile_settings.items(): if setting != "compiler.version": self.assertIn("%s=%s" % (setting, value), info) else: self.assertIn("compiler.version=14", info) # Use package settings in profile tmp_settings = OrderedDict() tmp_settings["compiler"] = "gcc" tmp_settings["compiler.libcxx"] = "libstdc++11" tmp_settings["compiler.version"] = "4.8" package_settings = {"Hello0": tmp_settings} create_profile(self.client.client_cache.profiles_path, "vs_12_86_Hello0_gcc", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run("install --build missing -pr vs_12_86_Hello0_gcc -s compiler.version=14") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=gcc", info) self.assertIn("compiler.libcxx=libstdc++11", info) # If other package is specified compiler is not modified package_settings = {"NoExistsRecipe": tmp_settings} create_profile(self.client.client_cache.profiles_path, "vs_12_86_Hello0_gcc", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run("install --build missing -pr vs_12_86_Hello0_gcc -s compiler.version=14") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=Visual Studio", info) self.assertNotIn("compiler.libcxx", info) # Mix command line package settings with profile package_settings = {"Hello0": tmp_settings} create_profile(self.client.client_cache.profiles_path, "vs_12_86_Hello0_gcc", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run("install --build missing -pr vs_12_86_Hello0_gcc" " -s compiler.version=14 -s Hello0:compiler.libcxx=libstdc++") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=gcc", info) self.assertNotIn("compiler.libcxx=libstdc++11", info) self.assertIn("compiler.libcxx=libstdc++", info)
def install_profile_settings_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) # Create a profile and use it profile_settings = OrderedDict([("compiler", "Visual Studio"), ("compiler.version", "12"), ("compiler.runtime", "MD"), ("arch", "x86")]) create_profile(self.client.client_cache.profiles_path, "vs_12_86", settings=profile_settings, package_settings={}) self.client.save(files) self.client.run("export lasote/stable") self.client.run("install --build missing -pr vs_12_86") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) for setting, value in profile_settings.items(): self.assertIn("%s=%s" % (setting, value), info) # Try to override some settings in install command self.client.run( "install --build missing -pr vs_12_86 -s compiler.version=14") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) for setting, value in profile_settings.items(): if setting != "compiler.version": self.assertIn("%s=%s" % (setting, value), info) else: self.assertIn("compiler.version=14", info) # Use package settings in profile tmp_settings = OrderedDict() tmp_settings["compiler"] = "gcc" tmp_settings["compiler.libcxx"] = "libstdc++11" tmp_settings["compiler.version"] = "4.8" package_settings = {"Hello0": tmp_settings} create_profile(self.client.client_cache.profiles_path, "vs_12_86_Hello0_gcc", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run( "install --build missing -pr vs_12_86_Hello0_gcc -s compiler.version=14" ) info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=gcc", info) self.assertIn("compiler.libcxx=libstdc++11", info) # If other package is specified compiler is not modified package_settings = {"NoExistsRecipe": tmp_settings} create_profile(self.client.client_cache.profiles_path, "vs_12_86_Hello0_gcc", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run( "install --build missing -pr vs_12_86_Hello0_gcc -s compiler.version=14" ) info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=Visual Studio", info) self.assertNotIn("compiler.libcxx", info) # Mix command line package settings with profile package_settings = {"Hello0": tmp_settings} create_profile(self.client.client_cache.profiles_path, "vs_12_86_Hello0_gcc", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run( "install --build missing -pr vs_12_86_Hello0_gcc" " -s compiler.version=14 -s Hello0:compiler.libcxx=libstdc++") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=gcc", info) self.assertNotIn("compiler.libcxx=libstdc++11", info) self.assertIn("compiler.libcxx=libstdc++", info)