Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export_sources for non-existent recipes in a local index #16776

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conans/client/rest_client_local_recipe_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ def call_method(self, method_name, *args, **kwargs):
return getattr(self, method_name)(*args, **kwargs)

def get_recipe(self, ref, dest_folder):
self.get_recipe_revision_reference(ref)
export_folder = self._app.cache.recipe_layout(ref).export()
return self._copy_files(export_folder, dest_folder)

def get_recipe_sources(self, ref, dest_folder):
self.get_recipe_revision_reference(ref)
export_sources = self._app.cache.recipe_layout(ref).export_sources()
return self._copy_files(export_sources, dest_folder)

Expand Down
70 changes: 70 additions & 0 deletions test/functional/test_local_recipes_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,73 @@ def package_info(self):
# Finally lets remove the remote, check that the clone is cleared
c.run('remote remove local')
assert "Removing temporary files for 'local' local-recipes-index remote" in c.out

def test_not_found(self):
"""testing that the correct exception is raised when a recipe is not found
"""
repo1_folder = temp_folder()
repo2_folder = temp_folder()
cmake = gen_cmakelists(libname="pkg", libsources=["pkg.cpp"], install=True,
public_header="pkg.h")
config_yml = textwrap.dedent("""\
versions:
"0.1":
folder: all
""")
conanfile = textwrap.dedent("""\
import os
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.files import copy

class PkgRecipe(ConanFile):
name = "pkg"
package_type = "library"

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

generators = "CMakeToolchain"

def export_sources(self):
src = os.path.dirname(os.path.dirname(os.path.dirname(self.recipe_folder)))
copy(self, "*", src=src, dst=self.export_sources_folder, excludes=["recipes*"])

def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = [self.name]
""")

save_files(repo2_folder, {"recipes/pkg/config.yml": config_yml,
"recipes/pkg/all/conanfile.py": conanfile,
"CMakeLists.txt": cmake,
"pkg.h": gen_function_h(name="pkg"),
"pkg.cpp": gen_function_cpp(name="pkg")})

c = TestClient()
c.run(f"remote add local1 '{repo1_folder}'")
c.run(f"remote add local2 '{repo2_folder}'")
c.run("new cmake_exe -d name=app -d version=0.1 -d requires=pkg/0.1")
c.run("create . --build=missing")
assert "pkg: Release!" in c.out