def _package(self, conanfile, pref, package_layout, conanfile_path): # FIXME: Is weak to assign here the recipe_hash manifest = package_layout.recipe_manifest() conanfile.info.recipe_hash = manifest.summary_hash # Creating ***info.txt files save(os.path.join(conanfile.folders.base_build, CONANINFO), conanfile.info.dumps()) self._output.info("Generated %s" % CONANINFO) save(os.path.join(conanfile.folders.base_build, BUILD_INFO), TXTGenerator(conanfile).content) self._output.info("Generated %s" % BUILD_INFO) package_id = pref.id # Do the actual copy, call the conanfile.package() method # While installing, the infos goes to build folder conanfile.folders.set_base_install(conanfile.folders.base_build) prev = run_package_method(conanfile, package_id, self._hook_manager, conanfile_path, pref.ref) update_package_metadata(prev, package_layout, package_id, pref.ref.revision) if get_env("CONAN_READ_ONLY_CACHE", False): make_read_only(conanfile.folders.base_package) # FIXME: Conan 2.0 Clear the registry entry (package ref) return prev
def export_pkg(app, recorder, full_ref, source_folder, build_folder, package_folder, install_folder, graph_info, force, remotes): ref = full_ref.copy_clear_rev() cache, output, hook_manager = app.cache, app.out, app.hook_manager graph_manager = app.graph_manager conan_file_path = cache.package_layout(ref).conanfile() if not os.path.exists(conan_file_path): raise ConanException("Package recipe '%s' does not exist" % str(ref)) # The graph has to be loaded with build_mode=[ref.name], so that node is not tried # to be downloaded from remotes # passing here the create_reference=ref argument is useful so the recipe is in "develop", # because the "package()" method is in develop=True already deps_graph = graph_manager.load_graph(ref, ref, graph_info=graph_info, build_mode=[ref.name], check_updates=False, update=False, remotes=remotes, recorder=recorder, apply_build_requires=False) # this is a bit tricky, but works. The root (virtual), has only 1 neighbor, # which is the exported pkg nodes = deps_graph.root.neighbors() pkg_node = nodes[0] conanfile = pkg_node.conanfile def _init_conanfile_infos(): node_order = [ n for n in pkg_node.public_closure if n.binary != BINARY_SKIP ] subtree_libnames = [node.ref.name for node in node_order] add_env_conaninfo(conanfile, subtree_libnames) _init_conanfile_infos() from conans.client.conan_api import existing_info_files if install_folder and existing_info_files(install_folder): load_deps_info(install_folder, conanfile, required=True) package_id = pkg_node.package_id output.info("Packaging to %s" % package_id) pref = PackageReference(ref, package_id) layout = cache.package_layout(ref, short_paths=conanfile.short_paths) if layout.package_id_exists(package_id) and not force: raise ConanException( "Package already exists. Please use --force, -f to overwrite it") layout.package_remove(pref) dest_package_folder = layout.package(pref) recipe_hash = layout.recipe_manifest().summary_hash conanfile.info.recipe_hash = recipe_hash conanfile.develop = True with layout.set_dirty_context_manager(pref): if package_folder: prev = packager.export_pkg(conanfile, package_id, package_folder, dest_package_folder, hook_manager, conan_file_path, ref) else: prev = run_package_method(conanfile, package_id, source_folder, build_folder, dest_package_folder, install_folder, hook_manager, conan_file_path, ref) packager.update_package_metadata(prev, layout, package_id, full_ref.revision) pref = PackageReference(pref.ref, pref.id, prev) if pkg_node.graph_lock_node: # after the package has been created we need to update the node PREV pkg_node.prev = pref.revision pkg_node.graph_lock_node.prev = pref.revision recorder.package_exported(pref)
def complete_test(self): """ basic installation of a new conans """ client = TestClient() files = cpp_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_profile()) run_package_method(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"))