def _loader(self, current_path=None, user_settings_values=None, user_options_values=None, scopes=None): # The disk settings definition, already including the default disk values settings = self._paths.settings options = OptionsValues() conaninfo_scopes = Scopes() if current_path: conan_info_path = os.path.join(current_path, CONANINFO) if os.path.exists(conan_info_path): existing_info = ConanInfo.load_file(conan_info_path) settings.values = existing_info.full_settings options = existing_info.full_options # Take existing options from conaninfo.txt conaninfo_scopes = existing_info.scope if user_settings_values: aux_values = Values.from_list(user_settings_values) settings.values = aux_values if user_options_values is not None: # Install will pass an empty list [] # Install OVERWRITES options, existing options in CONANINFO are not taken # into account, just those from CONANFILE + user command line options = OptionsValues.from_list(user_options_values) if scopes: conaninfo_scopes.update_scope(scopes) self._current_scopes = conaninfo_scopes return ConanFileLoader(self._runner, settings, options=options, scopes=conaninfo_scopes)
def test_replace_in_file(self): file_content = ''' from conans import ConanFile from conans.tools import download, unzip, replace_in_file import os class ConanFileToolsTest(ConanFile): name = "test" version = "1.9.10" settings = [] def source(self): pass def build(self): replace_in_file("otherfile.txt", "ONE TWO THREE", "FOUR FIVE SIX") ''' tmp_dir = temp_folder() file_path = os.path.join(tmp_dir, "conanfile.py") other_file = os.path.join(tmp_dir, "otherfile.txt") save(file_path, file_content) save(other_file, "ONE TWO THREE") loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), Scopes(), None, None) ret = loader.load_conan(file_path, None) curdir = os.path.abspath(os.curdir) os.chdir(tmp_dir) try: ret.build() finally: os.chdir(curdir) content = load(other_file) self.assertEquals(content, "FOUR FIVE SIX")
def __init__(self): # Sections self.settings = OrderedDict() self.package_settings = defaultdict(OrderedDict) self.env_values = EnvValues() self.scopes = Scopes() self.options = OptionsValues()
def __init__(self): # Sections self._settings = OrderedDict() self._package_settings = defaultdict(OrderedDict) self._env = OrderedDict() self._package_env = defaultdict(OrderedDict) self.scopes = Scopes()
def _loader(self, current_path=None, user_settings_values=None, package_settings=None, user_options_values=None, scopes=None, env_values=None, use_conaninfo=True): # The disk settings definition, already including the default disk values settings = self._client_cache.settings conaninfo_scopes = Scopes() user_options = OptionsValues(user_options_values) mixed_env_values = EnvValues() mixed_env_values.update(env_values) if current_path: conan_info_path = os.path.join(current_path, CONANINFO) if use_conaninfo and os.path.exists(conan_info_path): existing_info = ConanInfo.load_file(conan_info_path) settings.values = existing_info.full_settings options = existing_info.full_options # Take existing options from conaninfo.txt options.update(user_options) user_options = options conaninfo_scopes = existing_info.scope # Update with info (prioritize user input) mixed_env_values.update(existing_info.env_values) if user_settings_values: aux_values = Values.from_list(user_settings_values) settings.values = aux_values if scopes: conaninfo_scopes.update_scope(scopes) self._current_scopes = conaninfo_scopes return ConanFileLoader(self._runner, settings, package_settings=package_settings, options=user_options, scopes=conaninfo_scopes, env_values=mixed_env_values)
def __init__(self): # Sections self.settings = OrderedDict() self.package_settings = defaultdict(OrderedDict) self.env_values = EnvValues() self.scopes = Scopes() self.options = OptionsValues() self.build_requires = OrderedDict() # conan_ref Pattern: list of conan_ref
def _profile_parse_args(settings, options, envs, scopes): """ return a Profile object result of parsing raw data """ def _get_tuples_list_from_extender_arg(items): if not items: return [] # Validate the pairs for item in items: chunks = item.split("=", 1) if len(chunks) != 2: raise ConanException("Invalid input '%s', use 'name=value'" % item) return [(item[0], item[1]) for item in [item.split("=", 1) for item in items]] def _get_simple_and_package_tuples(items): """Parse items like "thing:item=value or item2=value2 and returns a tuple list for the simple items (name, value) and a dict for the package items {package: [(item, value)...)], ...} """ simple_items = [] package_items = defaultdict(list) tuples = _get_tuples_list_from_extender_arg(items) for name, value in tuples: if ":" in name: # Scoped items tmp = name.split(":", 1) ref_name = tmp[0] name = tmp[1] package_items[ref_name].append((name, value)) else: simple_items.append((name, value)) return simple_items, package_items def _get_env_values(env, package_env): env_values = EnvValues() for name, value in env: env_values.add(name, EnvValues.load_value(value)) for package, data in package_env.items(): for name, value in data: env_values.add(name, EnvValues.load_value(value), package) return env_values result = Profile() options = _get_tuples_list_from_extender_arg(options) result.options = OptionsValues(options) env, package_env = _get_simple_and_package_tuples(envs) env_values = _get_env_values(env, package_env) result.env_values = env_values settings, package_settings = _get_simple_and_package_tuples(settings) result.settings = OrderedDict(settings) for pkg, values in package_settings.items(): result.package_settings[pkg] = OrderedDict(values) result.scopes = Scopes.from_list(scopes) if scopes else Scopes() return result
def test_package_settings(self): # CREATE A CONANFILE TO LOAD tmp_dir = temp_folder() conanfile_path = os.path.join(tmp_dir, "conanfile.py") conanfile = """from conans import ConanFile class MyTest(ConanFile): requires = {} name = "MyPackage" version = "1.0" settings = "os" """ save(conanfile_path, conanfile) # Apply windows for MyPackage package_settings = {"MyPackage": [("os", "Windows")]} loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), package_settings, OptionsValues.loads(""), Scopes(), None, None) recipe = loader.load_conan(conanfile_path, None) self.assertEquals(recipe.settings.os, "Windows") # Apply Linux for MyPackage package_settings = {"MyPackage": [("os", "Linux")]} loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), package_settings, OptionsValues.loads(""), Scopes(), None, None) recipe = loader.load_conan(conanfile_path, None) self.assertEquals(recipe.settings.os, "Linux") # If the package name is different from the conanfile one, it wont apply package_settings = {"OtherPACKAGE": [("os", "Linux")]} loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}), package_settings, OptionsValues.loads(""), Scopes(), None, None) recipe = loader.load_conan(conanfile_path, None) self.assertIsNone(recipe.settings.os.value)
def _build_and_check(self, tmp_dir, file_path, text_file, msg): loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), Scopes(), None) ret = loader.load_conan(file_path, None) curdir = os.path.abspath(os.curdir) os.chdir(tmp_dir) try: ret.build() finally: os.chdir(curdir) content = load(text_file) self.assertEquals(content, msg)
def requires_init_test(self): loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), Scopes(), None, None) tmp_dir = temp_folder() conanfile_path = os.path.join(tmp_dir, "conanfile.py") conanfile = """from conans import ConanFile class MyTest(ConanFile): requires = {} def requirements(self): self.requires("MyPkg/0.1@user/channel") """ for requires in ("''", "[]", "()", "None"): save(conanfile_path, conanfile.format(requires)) result = loader.load_conan(conanfile_path, output=None, consumer=True) result.requirements() self.assertEqual("MyPkg/0.1@user/channel", str(result.requires))
def test_patch_from_file(self): file_content = ''' from conans import ConanFile from conans.tools import patch import os class ConanFileToolsTest(ConanFile): name = "test" version = "1.9.10" settings = [] def source(self): pass def build(self): patch(patch_file="file.patch") ''' patch_content = '''--- text.txt\t2016-01-25 17:57:11.452848309 +0100 +++ text_new.txt\t2016-01-25 17:57:28.839869950 +0100 @@ -1 +1 @@ -ONE TWO THREE +ONE TWO FOUR''' tmp_dir = temp_folder() file_path = os.path.join(tmp_dir, "conanfile.py") text_file = os.path.join(tmp_dir, "text.txt") patch_file = os.path.join(tmp_dir, "file.patch") save(file_path, file_content) save(text_file, "ONE TWO THREE") save(patch_file, patch_content) loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), Scopes(), None, None) ret = loader.load_conan(file_path, None) curdir = os.path.abspath(os.curdir) os.chdir(tmp_dir) try: ret.build() finally: os.chdir(curdir) content = load(text_file) self.assertEquals(content, "ONE TWO FOUR")
def setUp(self): self.output = TestBufferConanOutput() self.loader = ConanFileLoader(None, Settings.loads(""), None, OptionsValues.loads(""), Scopes(), None, None) self.retriever = Retriever(self.loader, self.output) self.remote_search = MockSearchRemote() self.resolver = RequireResolver(self.output, self.retriever, self.remote_search) self.builder = DepsBuilder(self.retriever, self.output, self.loader, self.resolver) for v in ["0.1", "0.2", "0.3", "1.1", "1.1.2", "1.2.1", "2.1", "2.2.1"]: say_content = """ from conans import ConanFile class SayConan(ConanFile): name = "Say" version = "%s" """ % v say_ref = ConanFileReference.loads("Say/%s@memsharded/testing" % v) self.retriever.conan(say_ref, say_content)
def load_conan_txt_test(self): file_content = '''[requires] OpenCV/2.4.10@phil/stable OpenCV2/2.4.10@phil/stable [generators] one two [imports] OpenCV/bin, * -> ./bin # I need this binaries OpenCV/lib, * -> ./lib [options] OpenCV:use_python=True OpenCV:other_option=False OpenCV2:use_python2=1 OpenCV2:other_option=Cosa ''' tmp_dir = temp_folder() file_path = os.path.join(tmp_dir, "file.txt") save(file_path, file_content) loader = ConanFileLoader(None, Settings(), OptionsValues.loads(""), Scopes()) ret = loader.load_conan_txt(file_path, None) options1 = OptionsValues.loads("""OpenCV:use_python=True OpenCV:other_option=False OpenCV2:use_python2=1 OpenCV2:other_option=Cosa""") requirements = Requirements() requirements.add("OpenCV/2.4.10@phil/stable") requirements.add("OpenCV2/2.4.10@phil/stable") self.assertEquals(ret.requires, requirements) self.assertEquals(ret.generators, ["one", "two"]) self.assertEquals(ret.options.values.dumps(), options1.dumps()) ret.copy = Mock() ret.imports() self.assertTrue(ret.copy.call_args_list, [('*', './bin', 'OpenCV/bin'), ('*', './lib', 'OpenCV/lib')]) # Now something that fails file_content = '''[requires] OpenCV/2.4.104phil/stable <- use_python:True, other_option:False ''' tmp_dir = temp_folder() file_path = os.path.join(tmp_dir, "file.txt") save(file_path, file_content) loader = ConanFileLoader(None, Settings(), OptionsValues.loads(""), Scopes()) with self.assertRaisesRegexp(ConanException, "Wrong package recipe reference(.*)"): loader.load_conan_txt(file_path, None) file_content = '''[requires] OpenCV/2.4.10@phil/stable <- use_python:True, other_option:False [imports] OpenCV/bin/* - ./bin ''' tmp_dir = temp_folder() file_path = os.path.join(tmp_dir, "file.txt") save(file_path, file_content) loader = ConanFileLoader(None, Settings(), OptionsValues.loads(""), Scopes()) with self.assertRaisesRegexp(ConanException, "is too long. Valid names must contain"): loader.load_conan_txt(file_path, None)
def complete_test(self): """ basic installation of a new conans """ client = TestClient() client.init_dynamic_vars() files = hello_source_files() conan_ref = ConanFileReference.loads("Hello/1.2.1/frodo/stable") reg_folder = client.paths.export(conan_ref) client.save(files, path=reg_folder) client.save({CONANFILE: myconan1, 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) package_ref = PackageReference(conan_ref, "myfakeid") build_folder = client.paths.build(package_ref) package_folder = client.paths.package(package_ref) shutil.copytree(reg_folder, build_folder) loader = ConanFileLoader(None, Settings(), None, OptionsValues.loads(""), Scopes(), None) conanfile = loader.load_conan(conanfile_path, None) output = ScopedOutput("", TestBufferConanOutput()) create_package(conanfile, build_folder, package_folder, output) # 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 setUp(self): self.output = TestBufferConanOutput() self.loader = ConanFileLoader(None, Settings.loads(""), OptionsValues.loads(""), Scopes()) self.retriever = Retriever(self.loader, self.output) self.builder = DepsBuilder(self.retriever, self.output, self.loader)
def __init__(self): # Sections self.settings = OrderedDict() self.env = OrderedDict() self.scopes = Scopes()