def configs_test(self): deps_cpp_info = DepsCppInfo() deps_cpp_info.includedirs.append("C:/whatever") deps_cpp_info.debug.includedirs.append("C:/whenever") deps_cpp_info.libs.extend(["math"]) deps_cpp_info.debug.libs.extend(["debug_Lib"]) child = DepsCppInfo() child.includedirs.append("F:/ChildrenPath") child.debug.includedirs.append("F:/ChildrenDebugPath") child.cppflags.append("cxxmyflag") child.debug.cppflags.append("cxxmydebugflag") deps_cpp_info._dependencies["Boost"] = child deps_env_info = DepsEnvInfo() env_info_lib1 = EnvInfo() env_info_lib1.var = "32" env_info_lib1.othervar.append("somevalue") deps_env_info.update(env_info_lib1, "LIB1") deps_user_info = DepsUserInfo() deps_user_info["LIB2"].myuservar = "23" fakeconan = namedtuple("Conanfile", "deps_cpp_info cpp_info deps_env_info env_info user_info deps_user_info") output = TXTGenerator(fakeconan(deps_cpp_info, None, deps_env_info, deps_user_info, {}, defaultdict(dict))).content deps_cpp_info2, _, deps_env_info2 = TXTGenerator.loads(output) self.assertEqual(deps_cpp_info.includedirs, deps_cpp_info2.includedirs) self.assertEqual(deps_cpp_info.libdirs, deps_cpp_info2.libdirs) self.assertEqual(deps_cpp_info.bindirs, deps_cpp_info2.bindirs) self.assertEqual(deps_cpp_info.libs, deps_cpp_info2.libs) self.assertEqual(len(deps_cpp_info._dependencies), len(deps_cpp_info2._dependencies)) self.assertEqual(deps_cpp_info["Boost"].includedirs, deps_cpp_info2["Boost"].includedirs) self.assertEqual(deps_cpp_info["Boost"].cppflags, deps_cpp_info2["Boost"].cppflags) self.assertEqual(deps_cpp_info["Boost"].cppflags, ["cxxmyflag"]) self.assertEqual(deps_cpp_info.debug.includedirs, deps_cpp_info2.debug.includedirs) self.assertEqual(deps_cpp_info.debug.includedirs, ["C:/whenever"]) self.assertEqual(deps_cpp_info.debug.libs, deps_cpp_info2.debug.libs) self.assertEqual(deps_cpp_info.debug.libs, ["debug_Lib"]) self.assertEqual(deps_cpp_info["Boost"].debug.includedirs, deps_cpp_info2["Boost"].debug.includedirs) self.assertEqual(deps_cpp_info["Boost"].debug.includedirs, ["F:/ChildrenDebugPath"]) self.assertEqual(deps_cpp_info["Boost"].debug.cppflags, deps_cpp_info2["Boost"].debug.cppflags) self.assertEqual(deps_cpp_info["Boost"].debug.cppflags, ["cxxmydebugflag"]) self.assertEqual(deps_env_info["LIB1"].var, "32") self.assertEqual(deps_env_info["LIB1"].othervar, ["somevalue"]) self.assertEqual(deps_user_info["LIB2"].myuservar, "23")
def assign_test(self): env = DepsEnvInfo() env.foo = ["var"] env.foo.append("var2") env.foo2 = "var3" env.foo2 = "var4" env.foo63 = "other" self.assertEquals(env.vars, {"foo": ["var", "var2"], "foo2": "var4", "foo63": "other"})
def assign_test(self): env = DepsEnvInfo() env.foo = ["var"] env.foo.append("var2") env.foo2 = "var3" env.foo2 = "var4" env.foo63 = "other" self.assertEqual(env.vars, {"foo": ["var", "var2"], "foo2": "var4", "foo63": "other"})
def configs_test(self): deps_cpp_info = DepsCppInfo() deps_cpp_info.filter_empty = False child = CppInfo("Boost", "F:/") child.filter_empty = False child.version = "<version>" child.includedirs.append("ChildrenPath") child.debug.includedirs.append("ChildrenDebugPath") child.cxxflags.append("cxxmyflag") child.debug.cxxflags.append("cxxmydebugflag") child.libs.extend(["math"]) child.debug.libs.extend(["debug_Lib"]) deps_cpp_info.add("Boost", DepCppInfo(child)) deps_env_info = DepsEnvInfo() env_info_lib1 = EnvInfo() env_info_lib1.var = "32" env_info_lib1.othervar.append("somevalue") deps_env_info.update(env_info_lib1, "LIB1") deps_user_info = DepsUserInfo() deps_user_info["LIB2"].myuservar = "23" fakeconan = namedtuple("Conanfile", "deps_cpp_info cpp_info deps_env_info env_info user_info deps_user_info") output = TXTGenerator(fakeconan(deps_cpp_info, None, deps_env_info, deps_user_info, {}, defaultdict(dict))).content deps_cpp_info2, _, deps_env_info2, _ = TXTGenerator.loads(output, filter_empty=False) self.assertEqual(deps_cpp_info.includedirs, deps_cpp_info2.includedirs) self.assertEqual(deps_cpp_info.libdirs, deps_cpp_info2.libdirs) self.assertEqual(deps_cpp_info.bindirs, deps_cpp_info2.bindirs) self.assertEqual(deps_cpp_info.libs, deps_cpp_info2.libs) self.assertEqual(len(deps_cpp_info._dependencies), len(deps_cpp_info2._dependencies)) self.assertEqual(deps_cpp_info["Boost"].includedirs, deps_cpp_info2["Boost"].includedirs) self.assertEqual(deps_cpp_info["Boost"].cxxflags, deps_cpp_info2["Boost"].cxxflags) self.assertEqual(deps_cpp_info["Boost"].cxxflags, ["cxxmyflag"]) self.assertEqual(deps_cpp_info.debug.includedirs, deps_cpp_info2.debug.includedirs) self.assertEqual(deps_cpp_info.debug.includedirs, ['F:/include', 'F:/ChildrenDebugPath']) self.assertEqual(deps_cpp_info.debug.libs, deps_cpp_info2.debug.libs) self.assertEqual(deps_cpp_info.debug.libs, ["debug_Lib"]) self.assertEqual(deps_cpp_info["Boost"].debug.includedirs, deps_cpp_info2["Boost"].debug.includedirs) self.assertEqual(deps_cpp_info["Boost"].debug.includedirs, ['include', 'ChildrenDebugPath']) self.assertEqual(deps_cpp_info["Boost"].debug.cxxflags, deps_cpp_info2["Boost"].debug.cxxflags) self.assertEqual(deps_cpp_info["Boost"].debug.cxxflags, ["cxxmydebugflag"]) self.assertEqual(deps_env_info["LIB1"].var, "32") self.assertEqual(deps_env_info["LIB1"].othervar, ["somevalue"]) self.assertEqual(deps_user_info["LIB2"].myuservar, "23")
def loads(text, filter_empty=False): user_info_host_idx = text.find("[{}_".format(TXTGenerator._USER_INFO_HOST_PREFIX)) deps_env_info_idx = text.find("[ENV_") user_info_build_idx = text.find("[{}_".format(TXTGenerator._USER_INFO_BUILD_PREFIX)) user_info_host_txt = deps_env_info_txt = "" # Get chunk with deps_cpp_info: from the beginning to the first one of the others last_idx = next((x for x in [user_info_host_idx, deps_env_info_idx, user_info_build_idx] if x != -1), None) deps_cpp_info_txt = text[:last_idx] if user_info_host_idx != -1: last_idx = next((x for x in [deps_env_info_idx, user_info_build_idx] if x != -1), None) user_info_host_txt = text[user_info_host_idx:last_idx] if deps_env_info_idx != -1: last_idx = next((x for x in [user_info_build_idx] if x != -1), None) deps_env_info_txt = text[deps_env_info_idx:last_idx] user_info_build = None if user_info_build_idx != -1: user_info_build_txt = text[user_info_build_idx:] user_info_build = TXTGenerator._loads_user_info(user_info_build_txt, TXTGenerator._USER_INFO_BUILD_PREFIX) deps_cpp_info = TXTGenerator._loads_cpp_info(deps_cpp_info_txt, filter_empty=filter_empty) deps_user_info = TXTGenerator._loads_user_info(user_info_host_txt, TXTGenerator._USER_INFO_HOST_PREFIX) deps_env_info = DepsEnvInfo.loads(deps_env_info_txt) return deps_cpp_info, deps_user_info, deps_env_info, user_info_build
def initialize(self, settings, env, local=None): if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings, local) try: if self.settings.os_build and self.settings.os: self.output.writeln("*"*60, front=Color.BRIGHT_RED) self.output.writeln(" This package defines both 'os' and 'os_build' ", front=Color.BRIGHT_RED) self.output.writeln(" Please use 'os' for libraries and 'os_build'", front=Color.BRIGHT_RED) self.output.writeln(" only for build-requires used for cross-building", front=Color.BRIGHT_RED) self.output.writeln("*"*60, front=Color.BRIGHT_RED) except ConanException: pass # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() # user declared variables self.user_info = None # Keys are the package names, and the values a dict with the vars self.deps_user_info = DepsUserInfo() # user specified env variables self._conan_env_values = env.copy() # user specified -e
def loads(text): user_defines_index = text.find("[USER_") env_defines_index = text.find("[ENV_") if user_defines_index != -1: deps_cpp_info_txt = text[:user_defines_index] if env_defines_index != -1: user_info_txt = text[user_defines_index:env_defines_index] deps_env_info_txt = text[env_defines_index:] else: user_info_txt = text[user_defines_index:] deps_env_info_txt = "" else: if env_defines_index != -1: deps_cpp_info_txt = text[:env_defines_index] deps_env_info_txt = text[env_defines_index:] else: deps_cpp_info_txt = text deps_env_info_txt = "" user_info_txt = "" deps_cpp_info = TXTGenerator._loads_cpp_info(deps_cpp_info_txt) deps_user_info = TXTGenerator._loads_deps_user_info(user_info_txt) deps_env_info = DepsEnvInfo.loads(deps_env_info_txt) return deps_cpp_info, deps_user_info, deps_env_info
def initialize(self, settings, env, buildenv=None): self._conan_buildenv = buildenv if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings) conan_v2_error("Setting 'cppstd' is deprecated in favor of 'compiler.cppstd'," " please update your recipe.", 'cppstd' in self.settings.fields) # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self._conan_dep_cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() # user declared variables self.user_info = None # Keys are the package names (only 'host' if different contexts) self.deps_user_info = DepsUserInfo() # user specified env variables self._conan_env_values = env.copy() # user specified -e if self.description is not None and not isinstance(self.description, six.string_types): raise ConanException("Recipe 'description' must be a string.") if not hasattr(self, "virtualenv"): # Allow the user to override it with True or False self.virtualenv = True
def __init__(self, shared=None, options=None, options_values=None): options = options or "" self.command = None self.path = None self.source_folder = self.build_folder = "." self.settings = None self.options = Options(PackageOptions.loads(options)) if options_values: for var, value in options_values.items(): self.options._data[var] = value self.deps_cpp_info = MockDepsCppInfo( ) # ("deps_cpp_info", "sysroot")("/path/to/sysroot") self.deps_cpp_info.sysroot = "/path/to/sysroot" self.output = TestBufferConanOutput() self.in_local_cache = False self.install_folder = "myinstallfolder" if shared is not None: self.options = namedtuple("options", "shared")(shared) self.should_configure = True self.should_build = True self.should_install = True self.should_test = True self.generators = [] self.captured_env = {} self.deps_env_info = DepsEnvInfo() self.env_info = EnvInfo() self.deps_user_info = DepsUserInfo() self._conan_env_values = EnvValues()
def initialize(self, settings, env): if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings) if 'cppstd' in self.settings.fields: conan_v2_behavior("Setting 'cppstd' is deprecated in favor of 'compiler.cppstd'," " please update your recipe.", v1_behavior=self.output.warn) # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self._conan_dep_cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() # user declared variables self.user_info = None # Keys are the package names (only 'host' if different contexts) self.deps_user_info = DepsUserInfo() # user specified env variables self._conan_env_values = env.copy() # user specified -e if self.description is not None and not isinstance(self.description, six.string_types): raise ConanException("Recipe 'description' must be a string.")
def _get_conanfile(settings, frameworks=False, system_libs=False): conan_file = ConanFileMock() conan_file.settings = settings conan_file.source_folder = "my_cache_source_folder" conan_file.build_folder = "my_cache_build_folder" conan_file.deps_env_info = DepsEnvInfo() conan_file.deps_user_info = DepsUserInfo() conan_file.deps_cpp_info = DepsCppInfo() cpp_info = CppInfo("/root") cpp_info.include_paths.append("path/to/include1") cpp_info.lib_paths.append("path/to/lib1") cpp_info.libs.append("mylib") cpp_info.bindirs = "path/to/bin1" cpp_info.cflags.append("c_flag1") cpp_info.cxxflags.append("cxx_flag1") cpp_info.defines.append("mydefine1") if system_libs: cpp_info.system_libs.append("system_lib1") if frameworks: cpp_info.frameworks = ["AVFoundation", "VideoToolbox"] cpp_info.framework_paths.extend(['path/to/Frameworks1', 'path/to/Frameworks2']) conan_file.deps_cpp_info.update(cpp_info, "zlib") conan_file.env_info = EnvInfo() return conan_file
def initialize(self, settings, env): if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings) if 'cppstd' in self.settings.fields: self.output.warn( "Setting 'cppstd' is deprecated in favor of 'compiler.cppstd'," " please update your recipe.") # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() # user declared variables self.user_info = None # Keys are the package names, and the values a dict with the vars self.deps_user_info = DepsUserInfo() # user specified env variables self._conan_env_values = env.copy() # user specified -e
def __init__(self, output, runner, settings, conanfile_directory): ''' param settings: Settings ''' # User defined generators self.generators = self.generators if hasattr(self, "generators") else ["txt"] if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings) self.exports = create_exports(self) # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() self.copy = None # initialized at runtime # an output stream (writeln, info, warn error) self.output = output # something that can run commands, as os.sytem self._runner = runner self._conanfile_directory = conanfile_directory self.package_folder = None # Assigned at runtime self._scope = None
def help_test(self): deps_env_info = DepsEnvInfo() deps_cpp_info = DepsCppInfo() child = CppInfo("Boost", "F:") child.filter_empty = False child.includedirs.append("ChildrenPath") child.cxxflags.append("cxxmyflag") deps_cpp_info.add("Boost", DepCppInfo(child)) fakeconan = namedtuple( "Conanfile", "deps_cpp_info cpp_info deps_env_info env_info user_info deps_user_info" ) output = TXTGenerator( fakeconan(deps_cpp_info, None, deps_env_info, None, {}, defaultdict(dict))).content deps_cpp_info2, _, _, _ = TXTGenerator.loads(output) self.assertEqual(deps_cpp_info.configs, deps_cpp_info2.configs) self.assertEqual(deps_cpp_info.includedirs, deps_cpp_info2.includedirs) self.assertEqual(deps_cpp_info.libdirs, deps_cpp_info2.libdirs) self.assertEqual(deps_cpp_info.bindirs, deps_cpp_info2.bindirs) self.assertEqual(deps_cpp_info.libs, deps_cpp_info2.libs) self.assertEqual(len(deps_cpp_info._dependencies), len(deps_cpp_info2._dependencies)) self.assertEqual(deps_cpp_info["Boost"].includedirs, deps_cpp_info2["Boost"].includedirs) self.assertEqual(deps_cpp_info["Boost"].cxxflags, deps_cpp_info2["Boost"].cxxflags) self.assertEqual(deps_cpp_info["Boost"].cxxflags, ["cxxmyflag"])
def help_test(self): deps_env_info = DepsEnvInfo() deps_cpp_info = DepsCppInfo() deps_cpp_info.includedirs.append("C:/whatever") deps_cpp_info.includedirs.append("C:/whenever") deps_cpp_info.libdirs.append("C:/other") deps_cpp_info.libs.extend(["math", "winsock", "boost"]) child = DepsCppInfo() child.includedirs.append("F:/ChildrenPath") child.cppflags.append("cxxmyflag") deps_cpp_info._dependencies["Boost"] = child fakeconan = namedtuple( "Conanfile", "deps_cpp_info cpp_info deps_env_info env_info user_info deps_user_info" ) output = TXTGenerator( fakeconan(deps_cpp_info, None, deps_env_info, None, {}, defaultdict(dict))).content deps_cpp_info2, _ = TXTGenerator.loads(output) self.assertEqual(deps_cpp_info.configs, deps_cpp_info2.configs) self.assertEqual(deps_cpp_info.includedirs, deps_cpp_info2.includedirs) self.assertEqual(deps_cpp_info.libdirs, deps_cpp_info2.libdirs) self.assertEqual(deps_cpp_info.bindirs, deps_cpp_info2.bindirs) self.assertEqual(deps_cpp_info.libs, deps_cpp_info2.libs) self.assertEqual(len(deps_cpp_info._dependencies), len(deps_cpp_info2._dependencies)) self.assertEqual(deps_cpp_info["Boost"].includedirs, deps_cpp_info2["Boost"].includedirs) self.assertEqual(deps_cpp_info["Boost"].cppflags, deps_cpp_info2["Boost"].cppflags) self.assertEqual(deps_cpp_info["Boost"].cppflags, ["cxxmyflag"])
def __init__(self, output, runner, settings, user=None, channel=None, local=None): # User defined generators self.generators = self.generators if hasattr(self, "generators") else ["txt"] if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings, local) try: if self.settings.os_build and self.settings.os: output.writeln("*"*60, front=Color.BRIGHT_RED) output.writeln(" This package defines both 'os' and 'os_build' ", front=Color.BRIGHT_RED) output.writeln(" Please use 'os' for libraries and 'os_build'", front=Color.BRIGHT_RED) output.writeln(" only for build-requires used for cross-building", front=Color.BRIGHT_RED) output.writeln("*"*60, front=Color.BRIGHT_RED) except ConanException: pass self.exports = create_exports(self) self.exports_sources = create_exports_sources(self) # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() # user declared variables self.user_info = None # Keys are the package names, and the values a dict with the vars self.deps_user_info = DepsUserInfo() self.copy = None # initialized at runtime self.copy_deps = None # initialized at runtime # an output stream (writeln, info, warn error) self.output = output # something that can run commands, as os.sytem self._runner = runner self.develop = False # user specified env variables self._env_values = EnvValues() # Updated at runtime, user specified -e self._user = user self._channel = channel self.in_local_cache = False self.description = None # Vars to control the build steps (build(), package()) self.should_configure = True self.should_build = True self.should_install = True
def test_loads(self): # string text = "[ENV_libname]\nvar1=value1" ret = DepsEnvInfo.loads(text) self.assertDictEqual(ret.vars, {'var1': 'value1'}) # string with spaces text = "[ENV_libname]\nvar1=value 1" ret = DepsEnvInfo.loads(text) self.assertDictEqual(ret.vars, {'var1': 'value 1'}) # quoted string text = "[ENV_libname]\nvar1=\"value 1\"" ret = DepsEnvInfo.loads(text) self.assertDictEqual(ret.vars, {'var1': '\"value 1\"'}) # quoted string text = "[ENV_libname]\nvar1='value 1'" ret = DepsEnvInfo.loads(text) self.assertDictEqual(ret.vars, {'var1': '\'value 1\''}) # number text = "[ENV_libname]\nvar1=123" ret = DepsEnvInfo.loads(text) self.assertDictEqual(ret.vars, {'var1': '123'}) # empty text = "[ENV_libname]\nvar1=" ret = DepsEnvInfo.loads(text) self.assertDictEqual(ret.vars, {'var1': ''}) # mixed text = "[ENV_libname]\nvar1=value1\nvar2=\nvar3=\"value3\"" ret = DepsEnvInfo.loads(text) self.assertDictEqual(ret.vars, {'var1': 'value1', 'var2': '', 'var3': '\"value3\"'})
def update_test(self): env = DepsEnvInfo() env.foo = ["var"] env.foo.append("var2") env.foo2 = "var3" env.foo2 = "var4" env.foo63 = "other" env2 = DepsEnvInfo() env2.foo = "new_value" env2.foo2.append("not") env2.foo3.append("var3") env.update(env2, ConanFileReference.loads("pack/1.0@lasote/testing")) self.assertEqual(env.vars, {"foo": ["var", "var2", "new_value"], "foo2": "var4", "foo3": ["var3"], "foo63": "other"})
def build(self, conanfile_path, current_path, test=False, filename=None, profile_name=None): """ Call to build() method saved on the conanfile.py param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Building in %s" % current_path) logger.debug("Conanfile in %s" % conanfile_path) if filename and filename.endswith(".txt"): raise ConanException("A conanfile.py is needed to call 'conan build'") conanfile_file = os.path.join(conanfile_path, filename or CONANFILE) try: output = ScopedOutput("Project", self._user_io.out) conan_file = self._loader(current_path).load_conan(conanfile_file, output, consumer=True) except NotFoundException: # TODO: Auto generate conanfile from requirements file raise ConanException("'%s' file is needed for build.\n" "Create a '%s' and move manually the " "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) try: build_info_file = os.path.join(current_path, BUILD_INFO) if os.path.exists(build_info_file): try: deps_cpp_info = DepsCppInfo.loads(load(build_info_file)) conan_file.deps_cpp_info = deps_cpp_info except: pass env_file = os.path.join(current_path, "conanenv.txt") if os.path.exists(env_file): try: deps_env_info = DepsEnvInfo.loads(load(env_file)) conan_file.deps_env_info = deps_env_info except: pass os.chdir(current_path) conan_file._conanfile_directory = conanfile_path # Append env_vars to execution environment and clear when block code ends profile = self._read_profile(profile_name) env_vars = self._read_profile_env_vars(profile) with environment_append(env_vars): conan_file.build() if test: conan_file.test() except ConanException: raise # Raise but not let to reach the Exception except (not print traceback) except Exception: import traceback trace = traceback.format_exc().split('\n') raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
def __init__(self, output, runner, settings, conanfile_directory, user=None, channel=None): # User defined generators self.generators = self.generators if hasattr( self, "generators") else ["txt"] if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings) self.exports = create_exports(self) self.exports_sources = create_exports_sources(self) # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() # user declared variables self.user_info = None # Keys are the package names, and the values a dict with the vars self.deps_user_info = DepsUserInfo() self.copy = None # initialized at runtime # an output stream (writeln, info, warn error) self.output = output # something that can run commands, as os.sytem self._runner = runner self.conanfile_directory = conanfile_directory self._scope = None self.develop = False # user specified env variables self._env_values = EnvValues() # Updated at runtime, user specified -e self._user = user self._channel = channel # Are we in local cache? Suggest a better name self.in_local_cache = False # Init a description self.description = None
def pythonpath_test(self): """ Check PYTHONPATH env variable """ conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues.loads("PYTHONPATH=[1,2,three]")) conanfile.deps_env_info = DepsEnvInfo.loads( '[ENV_A]\nPYTHONPATH=["DepAPath"]\n[ENV_B]\nPYTHONPATH=["DepBPath"]' ) gen = VirtualEnvPythonGenerator(conanfile) gen.output_path = "not-used" content = gen.content self.assertIn('PYTHONPATH="1":"2":"three":"DepAPath":"DepBPath"${PYTHONPATH+:$PYTHONPATH}', content["environment_run_python.sh.env"])
def update_test(self): env = DepsEnvInfo() env.foo = ["var"] env.foo.append("var2") env.foo2 = "var3" env.foo2 = "var4" env.foo63 = "other" env2 = DepsEnvInfo() env2.foo = "new_value" env2.foo2.append("not") env2.foo3.append("var3") env.update(env2, ConanFileReference.loads("pack/1.0@lasote/testing")) self.assertEquals(env.vars, {"foo": ["var", "var2", "new_value"], "foo2": "var4", "foo3": ["var3"], "foo63": "other"})
def test_update_concat(self): env_info = EnvInfo() env_info.path.append("SOME/PATH") deps_info = DepsEnvInfo() deps_info.update(env_info, "lib") deps_info2 = DepsEnvInfo() deps_info2.update(env_info, "lib2") env = EnvValues() env.add("PATH", ["MYPATH"]) env.update(deps_info) self.assertEqual(env.env_dicts(None), ({}, {'PATH': ['MYPATH', 'SOME/PATH']})) env.update(deps_info2) self.assertEqual(env.env_dicts(None), ({}, {'PATH': ['MYPATH', 'SOME/PATH', 'SOME/PATH']}))
def help_test(self): deps_env_info = DepsEnvInfo() deps_cpp_info = DepsCppInfo() deps_cpp_info.includedirs.append("C:/whatever") deps_cpp_info.includedirs.append("C:/whenever") deps_cpp_info.libdirs.append("C:/other") deps_cpp_info.libs.extend(["math", "winsock", "boost"]) child = DepsCppInfo() child.includedirs.append("F:/ChildrenPath") child.cppflags.append("cxxmyflag") deps_cpp_info._dependencies["Boost"] = child fakeconan = namedtuple( "Conanfile", "deps_cpp_info cpp_info deps_env_info env_info") output = TXTGenerator( fakeconan(deps_cpp_info, None, deps_env_info, None)).content deps_cpp_info2 = DepsCppInfo.loads(output) self._equal(deps_cpp_info, deps_cpp_info2)
def __init__(self, *args): if len(args) == 2: deps_cpp_info = args[0] deps_env_info = DepsEnvInfo() settings = args[1] self.output = ConanOutput(sys.stdout) elif len(args) == 1: # conanfile (new interface) self.conanfile = args[0] self.output = self.conanfile.output deps_cpp_info = self.conanfile.deps_cpp_info deps_env_info = self.conanfile.deps_env_info settings = self.conanfile.settings assert isinstance(settings, Settings) self._settings = settings self._deps_cpp_info = deps_cpp_info self._deps_env_info = deps_env_info try: self.compiler = str(self._settings.compiler) except: self.compiler = None try: self.arch = str(self._settings.arch) except: self.arch = None try: self.os = str(self._settings.os) except: self.os = None try: self.build_type = str(self._settings.build_type) except: self.build_type = None try: self.libcxx = str(self.compiler.libcxx) except: self.libcxx = None
def _get_conanfile(self, settings): conan_file = ConanFileMock() conan_file.settings = settings conan_file.source_folder = "my_cache_source_folder" conan_file.build_folder = "my_cache_build_folder" conan_file.deps_env_info = DepsEnvInfo() conan_file.deps_user_info = DepsUserInfo() conan_file.deps_cpp_info = DepsCppInfo() cpp_info = CppInfo("/root") cpp_info.include_paths.append("path/to/include1") cpp_info.lib_paths.append("path/to/lib1") cpp_info.libs.append("mylib") cpp_info.bindirs = "path/to/bin1" cpp_info.cflags.append("c_flag1") cpp_info.cppflags.append("cxx_flag1") cpp_info.defines.append("mydefine1") conan_file.deps_cpp_info.update(cpp_info, "zlib") conan_file.env_info = EnvInfo() return conan_file
def visual_studio_extensions_test(self): settings = Settings.loads(get_default_settings_yml()) settings.os = "Windows" settings.compiler = "Visual Studio" settings.compiler.version = "15" settings.arch = "x86" settings.build_type = "Release" conan_file = ConanFileMock() conan_file.settings = settings conan_file.deps_env_info = DepsEnvInfo() conan_file.deps_user_info = DepsUserInfo() conan_file.deps_cpp_info = DepsCppInfo() cpp_info = CppInfo("/root") cpp_info.libs.append("mylib") cpp_info.libs.append("other.lib") conan_file.deps_cpp_info.update(cpp_info, "zlib") conan_file.env_info = EnvInfo() gen = CompilerArgsGenerator(conan_file) self.assertEqual('-O2 -Ob2 -DNDEBUG -link mylib.lib other.lib', gen.content)
def test_update_concat(self): env_info = EnvInfo() env_info.path.append("SOME/PATH") deps_info = DepsEnvInfo() deps_info.update(env_info, ConanFileReference.loads("lib/1.0@lasote/stable")) deps_info2 = DepsEnvInfo() deps_info2.update(env_info, ConanFileReference.loads("lib2/1.0@lasote/stable")) env = EnvValues() env.add("PATH", ["MYPATH"]) env.update(deps_info) self.assertEquals(env.env_dicts(None), ({}, { 'PATH': ['MYPATH', 'SOME/PATH'] })) env.update(deps_info2) self.assertEquals(env.env_dicts(None), ({}, { 'PATH': ['MYPATH', 'SOME/PATH', 'SOME/PATH'] }))
def __init__(self, shared=None, options=None, options_values=None): options = options or "" self.command = None self.path = None self.settings = None self.options = Options(PackageOptions.loads(options)) if options_values: for var, value in options_values.items(): self.options._data[var] = value self.deps_cpp_info = MockDepsCppInfo( ) # ("deps_cpp_info", "sysroot")("/path/to/sysroot") self.deps_cpp_info.sysroot = "/path/to/sysroot" self.output = TestBufferConanOutput() self.in_local_cache = False if shared is not None: self.options = namedtuple("options", "shared")(shared) self.should_configure = True self.should_build = True self.should_install = True self.should_test = True self.generators = [] self.captured_env = {} self.deps_env_info = DepsEnvInfo() self.env_info = EnvInfo() self.deps_user_info = DepsUserInfo() self._conan_env_values = EnvValues() self.folders = Folders() self.folders.set_base_source(".") self.folders.set_base_export_sources(".") self.folders.set_base_build(".") self.folders.set_base_install("myinstallfolder") self.folders.set_base_generators(".") self._conan_user = None self._conan_channel = None self.env_scripts = {} self.win_bash = None self.conf = ConfDefinition().get_conanfile_conf(None) self.cpp = Infos()
def test_update_concat(self): env_info = EnvInfo() env_info.path.append("SOME/PATH") deps_info = DepsEnvInfo() deps_info.update(env_info, "lib") deps_info2 = DepsEnvInfo() deps_info2.update(env_info, "lib2") env = EnvValues() env.add("PATH", ["MYPATH"]) env.update(deps_info) self.assertEquals(env.env_dicts(None), ({}, {'PATH': ['MYPATH', 'SOME/PATH']})) env.update(deps_info2) self.assertEquals(env.env_dicts(None), ({}, {'PATH': ['MYPATH', 'SOME/PATH', 'SOME/PATH']}))
def _load_deps_info(self, current_path, conanfile, output): build_info_file = os.path.join(current_path, BUILD_INFO) if os.path.exists(build_info_file): try: deps_cpp_info = DepsCppInfo.loads(load(build_info_file)) conanfile.deps_cpp_info = deps_cpp_info except: output.error("Parse error in '%s' file in %s" % (BUILD_INFO, current_path)) else: output.warn("%s file not found in %s\nIt is recommended for source, build and package " "commands\nYou can generate it using 'conan install -g env -g txt'" % (BUILD_INFO, current_path)) env_file = os.path.join(current_path, CONANENV) if os.path.exists(env_file): try: deps_env_info = DepsEnvInfo.loads(load(env_file)) conanfile.deps_env_info = deps_env_info except: output.error("Parse error in '%s' file in %s" % (CONANENV, current_path)) else: output.warn("%s file not found in %s\nIt is recommended for source, build and package " "commands\nYou can generate it using 'conan install -g env -g txt'" % (CONANENV, current_path))
def __init__(self, *args): if len(args) == 2: deps_cpp_info = args[0] deps_env_info = DepsEnvInfo() settings = args[1] self.output = ConanOutput(sys.stdout) elif len(args) == 1: # conanfile (new interface) self.conanfile = args[0] self.output = self.conanfile.output deps_cpp_info = self.conanfile.deps_cpp_info deps_env_info = self.conanfile.deps_env_info settings = self.conanfile.settings assert isinstance(settings, Settings) self.output.warn(""" *********************************************************************** WARNING!!! ConfigureEnvironment class is deprecated and will be removed soon. With ConfigureEnvironment, env variables from profiles and/or command line are not applied. Replace it with the right one according your needs: - AutoToolsBuildEnvironment - VisualStudioBuildEnvironment Check docs.conan.io *********************************************************************** """) self._settings = settings self._deps_cpp_info = deps_cpp_info self._deps_env_info = deps_env_info try: self.compiler = str(self._settings.compiler) except: self.compiler = None try: self.arch = str(self._settings.arch) except: self.arch = None try: self.os = str(self._settings.os) except: self.os = None try: self.build_type = str(self._settings.build_type) except: self.build_type = None try: self.libcxx = str(self._settings.compiler.libcxx) except: self.libcxx = None
def deps_env_info(self): return DepsEnvInfo()