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

[bug][2.0] patches cannot be applied when using cmake_layout #10374

Closed
theodelrieu opened this issue Jan 19, 2022 · 10 comments · Fixed by #10408 or #10875
Closed

[bug][2.0] patches cannot be applied when using cmake_layout #10374

theodelrieu opened this issue Jan 19, 2022 · 10 comments · Fixed by #10408 or #10875
Assignees
Milestone

Comments

@theodelrieu
Copy link
Contributor

theodelrieu commented Jan 19, 2022

Hello,

It seems that files.patch and cmake_layout do not get along very well. The former does not find the patch files, even when specifying base_path=self.build_folder, although they are inside the build folder.

I've joined a 2.0 version of docopt.cpp that shows the issue.

Environment Details (include every applicable attribute)

  • Conan version: 2.0.0a2

Steps to reproduce (Include if Applicable)

  • create the package
  • uncomment the layout method
  • it should go to the test_package step (which breaks because cmake_layout is commented)

Logs (Executed commands with output) (Include/Attach if Applicable)

ERROR: docopt.cpp/0.6.2-r1: Error in build() method, line 35
	files.patch(self, **patch, base_path=self.build_folder)
	FileNotFoundError: [Errno 2] No such file or directory: 'patches/include-stdexcept.patch'

docopt.cpp.zip

EDIT:

The test_package fails because I forgot to add cmake_layout there.

@memsharded
Copy link
Member

This might be missing a small detail:

with files.chdir(self, self.source_folder):
      for patch in self.conan_data["patches"][str(self._upstream_version)]:
            files.patch(self, **patch)

Note:

  • You are running in the build() method, not the source() method
  • By default, the build() method runs in the self.build_folder directory
  • The patches are located in the source self.source_folder and must be applied to the source folder.

@theodelrieu
Copy link
Contributor Author

I thought I was supposed to apply patches in build, not source 🤔

Isn't the whole source folder copied to the build folder? I do see the patches in it.

@memsharded
Copy link
Member

memsharded commented Jan 19, 2022

You are applying patches in the source copy contained in the build directory, not on the original sources. But the layout inside the cache is still the same, and there will be a "source" subfolder and a "build" subfolder, to replicate and mimic the user layour (while in dev in their user folder), inside the "build" folder of the cache for the current package_id.

What you should not do is the no_copy_sources = True, because that could break the common sources.

@theodelrieu
Copy link
Contributor Author

and there will be a "source" subfolder and a "build" subfolder

I see, I just got confused big time 🤯

Thanks for the info!

@theodelrieu
Copy link
Contributor Author

I still have to explicitly write the full path to the patch file though, or change the cwd myself, as there is no way to set the cwd for files.patch.

@memsharded
Copy link
Member

Not sure what you mean, the code above I tested it, seems to be working fine:

def build(self):
    with files.chdir(self, self.source_folder):
        for patch in self.conan_data["patches"][str(self._upstream_version)]:
            files.patch(self, **patch)

@theodelrieu
Copy link
Contributor Author

theodelrieu commented Jan 20, 2022

Yeah it works on my side fine I just mean that it seems a bit weird to change directory inside the conan recipe itself, rather than with a kwarg cwd=self.source_folder.

@memsharded
Copy link
Member

Oh, that is a good point. Actually, it might be possible to try to use the self.source_folder by default as the location of the patches, it seems it would be a reasonable default. Lets check if makes sense.

@lasote
Copy link
Contributor

lasote commented Feb 23, 2022

Hi, I reopen this issue because I think that the default folder to contain the patch files shouldn't default to self.source_folder. @memsharded is working on the management of the source for 2.0 and we talked about introducing a self.export_sources_folder that would be a better default. The last changes introduced by @memsharded are in the direction of not copying the export_sources to the "self.source_folder" but to the conanfile.folders.base_source, so I keep this open to take a look.

@lasote lasote reopened this Feb 23, 2022
@lasote
Copy link
Contributor

lasote commented Feb 23, 2022

Related: #10643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment