Search code examples
c++conan

Conan package manager - how to remove folders during conan install?


I have a local conanfile.py to consume a package, the package is already located on the local cache (~/.conan/).

In the conanfile.py there is the imports() function in which I copy some files from the package into my build folder. I have two files with the same name in different directories and I copy them to the same directory and rename one of them.

After I do that, I am left with an empty directory I want to remove, but can't find a way to do so from conanfile.py, every attempt seems to remove the folder before the files gets run. My imports looks as follows:

class SomeConanPkg(ConanFile):
    name = "SomeName"
    description = "SomeDesc"
    requires = (
        "SomePkg/1.0.0.0@SomeRepo/stable")        

    def imports(self):
        # copy of 1st file
        self.copy("somefile.dll", src=os.path.join("src"), dst=os.path.join(build_dest))
        # copy of 2nd file to nested directory
        self.copy("somefile.dll", src=os.path.join("src", "folder"), dst=os.path.join(build_dst, "folder"))
        # move and rename the file to parent directory
        shutil.copy2(os.path.join(build_dst, "folder", "somefile.dll"), os.path.join(build_dst, "renamed_file.dll"))
        # now build_dst/folder is an empty directory

I have tried to use conan tools.rmmdir() or just calling shutil.rmmtree() but all of them seems to run before the files gets copied. I also tried to add a package() or deploy() member functions and execute the remove inside but these methods don't seem to run at all (verified with a debug print).

Any ideas?


Solution

  • I ended us solving it in the package creation side. Renamed the files as I wanted and then just consumed them