def _parse_conan_txt(self, contents, path, display_name, processed_profile): conanfile = ConanFile(self._output, self._runner, display_name) conanfile.initialize(Settings(), processed_profile._env_values) # 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 = processed_profile._settings.copy_values() try: parser = ConanFileTextLoader(contents) except Exception as e: raise ConanException("%s:\n%s" % (path, str(e))) for reference in parser.requirements: ConanFileReference.loads(reference) # Raise if invalid conanfile.requires.add(reference) for build_reference in parser.build_requirements: ConanFileReference.loads(build_reference) if not hasattr(conanfile, "build_requires"): conanfile.build_requires = [] conanfile.build_requires.append(build_reference) conanfile.generators = parser.generators options = OptionsValues.loads(parser.options) conanfile.options.values = options conanfile.options.initialize_upstream(processed_profile._user_options) # imports method conanfile.imports = parser.imports_method(conanfile) return conanfile
def _parse_conan_txt(self, contents, path, display_name, profile): conanfile = ConanFile(self._output, self._runner, display_name) tmp_settings = profile.processed_settings.copy() package_settings_values = profile.package_settings_values if "&" in package_settings_values: pkg_settings = package_settings_values.get("&") if pkg_settings: tmp_settings.update_values(pkg_settings) conanfile.initialize(Settings(), profile.env_values, profile.buildenv) conanfile.conf = profile.conf.get_conanfile_conf(None) # 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 = tmp_settings.copy_values() try: parser = ConanFileTextLoader(contents) except Exception as e: raise ConanException("%s:\n%s" % (path, str(e))) for reference in parser.requirements: ref = ConanFileReference.loads(reference) # Raise if invalid conanfile.requires.add_ref(ref) for build_reference in parser.build_requirements: ConanFileReference.loads(build_reference) if not hasattr(conanfile, "build_requires"): conanfile.build_requires = [] conanfile.build_requires.append(build_reference) if parser.layout: layout_method = { "cmake_layout": cmake_layout, "vs_layout": vs_layout, "bazel_layout": bazel_layout }.get(parser.layout) if not layout_method: raise ConanException( "Unknown predefined layout '{}' declared in " "conanfile.txt".format(parser.layout)) def layout(self): layout_method(self) conanfile.layout = types.MethodType(layout, conanfile) conanfile.generators = parser.generators try: options = OptionsValues.loads(parser.options) except Exception: raise ConanException( "Error while parsing [options] in conanfile\n" "Options should be specified as 'pkg:option=value'") conanfile.options.values = options conanfile.options.initialize_upstream(profile.user_options) # imports method conanfile.imports = parser.imports_method(conanfile) return conanfile