pythonc++package-managersconan

Access files in the directory running the conan create command


Trying to create a conan (v2.11) package from a zip archive to store in a gitlab conan registry. However in my conanfile.py I can't seem to copy or access files from the directory where I'm running conan as it appears to have set the current directory to within the .conan2/p/ cache directory structure.

These diagnostics:

def generate(self):
    print(f"Recipe path: {self.recipe_folder}")
    print(f"Source path: {self.source_folder}")
    print(f"Build path: {self.build_folder}")
    print(f"Dest/Package path: {self.package_folder}")
    current_directory = os.getcwd()
    print(f"Current_directory: {current_directory}")

have this output:

mypack/1.7.0@jim/test: Calling generate()
mypack/1.7.0@jim/test: Generators folder: C:\Users\jim\.conan2\p\b\mypack4aacdfed668f5\b
Recipe path: C:\Users\jim\.conan2\p\badl5fe3d4cc2e7b1\e
Source path: C:\Users\jim\.conan2\p\b\badl4aacdfed668f5\b
Build path: C:\Users\jim\.conan2\p\b\badl4aacdfed668f5\b
Dest/Package path: C:\Users\jim\.conan2\p\b\badl4aacdfed668f5\p
Current_directory: C:\Users\jim\.conan2\p\b\badl4aacdfed668f5\b

Here is my conanfile.py:

from conan import ConanFile
from conan.tools.files import copy

class MyPackConan(ConanFile):
    name = "mypack"
    version = "1.7.0"
    exports_sources = "."

    ...

    def build(self):
        self.run("ant package", cwd=self.recipe_folder)

    def package(self):
        copy(self, pattern="dist/*.zip", src=".", dst=self.package_folder, keep_path=False)

    def package_id(self):
        self.info.requires.full_recipe_mode()

I was hoping the export_sources = "." would give me access to the files of interest by copying them to the recipe or source or build directories but that did not happen. Any help greatly appreciated.


Solution

  • . will only match a file with the name . you need a wildcard like * to match all files https://docs.conan.io/2/reference/conanfile/attributes.html#exports-sources