Conan: [question] How to specify path relatives to the conanfile.py, instead of source-folder, in `source()` ?

Created on 8 Aug 2018  路  4Comments  路  Source: conan-io/conan

We are progressing with integrating our workflow with Conan packages,

Sometimes, we need to write a recipe for a 3rd party project that needs to be patched. For this purpose, we intend to rely on tools.patch helper, specifying a patch_file. This patch file is stored alongside our recipe, thus in a different repository than the 3rd party project.

The problem is that, when calling conan source . -sf ${other_folder}, the working directory in source() body is ${other_folder}, not the conanfile.py folder (which also contain the patch file).

Does conan provide a way to get the conanfile.py folder in the code?

Thank you for reading,


edit: As a workaround, currently using the scary os.path.dirname(os.path.realpath(__file__))

question

Most helpful comment

Hi @Adnn,

As you pointed that is exactly the purpose of exports_sources. Let me give you a basic conanfile as an example:

conanfile.py

from conans import ConanFile, tools

class TestConan(ConanFile):
    name = "test"
    version = "1.0"
    exports_sources = "custom_patch.patch"

    def source(self):
        tools.get("https://github.com/conan-io/conan/archive/1.6.1.zip")
        tools.patch(patch_file="custom_patch.patch")

This should work with both conan source . -sf source_folder and conan create . user/channel. exports_sources files will be copied to source folder as first step without the need to reference to the conanfile root directory.

All 4 comments

Actually, I realize that it may be a perfect use case for export_source: move the patch there, to be copied into the build folder before the source() step is called.

Hi @Adnn,

As you pointed that is exactly the purpose of exports_sources. Let me give you a basic conanfile as an example:

conanfile.py

from conans import ConanFile, tools

class TestConan(ConanFile):
    name = "test"
    version = "1.0"
    exports_sources = "custom_patch.patch"

    def source(self):
        tools.get("https://github.com/conan-io/conan/archive/1.6.1.zip")
        tools.patch(patch_file="custom_patch.patch")

This should work with both conan source . -sf source_folder and conan create . user/channel. exports_sources files will be copied to source folder as first step without the need to reference to the conanfile root directory.

Works perfectly fine, and with both conan source and conan create, thank you!

Great yo hear that! Thanks 馃槃

Was this page helpful?
0 / 5 - 0 ratings