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] conan tries to overwrite project's CMakePresets.json #15052

Closed
SSE4 opened this issue Nov 3, 2023 · 7 comments · Fixed by #15058
Closed

[bug] conan tries to overwrite project's CMakePresets.json #15052

SSE4 opened this issue Nov 3, 2023 · 7 comments · Fixed by #15058
Assignees
Milestone

Comments

@SSE4
Copy link
Contributor

SSE4 commented Nov 3, 2023

Environment details

  • Operating System+version: Linux debian12 6.5.7-x64v3-xanmod1 #0~20231010.gfdab4ec SMP PREEMPT_DYNAMIC Tue Oct 10 21:39:15 UTC x86_64 GNU/Linux
  • Compiler+version: gcc (Debian 12.2.0-14) 12.2.0
  • Conan version: Conan version 2.1.0-dev
  • Python version: Python 3.11.6

Steps to reproduce

  1. touch CMakePresets.json
  2. chmod aug-w CMakePresets.json
  3. conan install --requires zlib/1.2.11@ --build missing -g CMakeToolchain

Logs

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=12
os=Linux

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=12
os=Linux


======== Computing dependency graph ========
Graph root
    cli
Requirements
    zlib/1.2.11#dc0e384f0551386cd76dc29cc964c95e - Cache

======== Computing necessary packages ========
Requirements
    zlib/1.2.11#dc0e384f0551386cd76dc29cc964c95e:5bc851010eb7b707e5cb2e24cb8ccf0f27989fa9#b33bbab088cdd8cd2fc5510c1068e456 - Cache

======== Installing packages ========
zlib/1.2.11: Already installed! (1 of 1)
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'cpp_info.names' used in: zlib/1.2.11

======== Finalizing install (deploy, generators) ========
cli: Writing generators to /home/sse4/projects/tmp
cli: Generator 'CMakeToolchain' calling 'generate()'
cli: CMakeToolchain generated: conan_toolchain.cmake
cli: ERROR: Traceback (most recent call last):
  File "/home/sse4/projects/oss/conan/conans/client/generators/__init__.py", line 94, in write_generators
    generator.generate()
  File "/home/sse4/projects/oss/conan/conan/tools/cmake/toolchain/toolchain.py", line 214, in generate
    write_cmake_presets(self._conanfile, toolchain, self.generator, cache_variables,
  File "/home/sse4/projects/oss/conan/conan/tools/cmake/presets.py", line 16, in write_cmake_presets
    preset_path, preset_data = _CMakePresets.generate(conanfile, toolchain_file, generator,
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sse4/projects/oss/conan/conan/tools/cmake/presets.py", line 62, in generate
    save(preset_path, preset_content)
  File "/home/sse4/projects/oss/conan/conans/util/files.py", line 119, in save
    with open(path, "w", encoding=encoding, newline="") as handle:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/home/sse4/projects/tmp/CMakePresets.json'

ERROR: Error in generator 'CMakeToolchain': [Errno 13] Permission denied: '/home/sse4/projects/tmp/CMakePresets.json'
@SSE4
Copy link
Contributor Author

SSE4 commented Nov 3, 2023

this is a very inconvenient and causes a lot of frustration - many projects have their own CMakePresets.json. there is a high risk of losing all the local changes (there is no warning or confirmation - conan just erases the file if it already exists).
IMO conan shouldn't try to overwrite project files, all the files created has to be written either into conan cache, or into the temporary directories.

@memsharded
Copy link
Member

Lets try to add a check to avoid that.

In any case, the conan install --requires zlib/1.2.11@ --build missing -g CMakeToolchain is not a recommended case. The tutorial explicitly advice:

  • Use --output-folder to define the output files location
  • Use a conanfile with a layout defined

Note that we will raise an error saying that CMakePresets.json cannot be generated in the above case. Because that file can be necessary later, for example for conan build command, it would be the same case.

@memsharded memsharded self-assigned this Nov 3, 2023
@SSE4
Copy link
Contributor Author

SSE4 commented Nov 3, 2023

I've just checked new 2.0 tutorial, and indeed it does recommend --output-folder. however, many existing tutorials just suggest to do plain conan install, for instance:

  1. https://blog.conan.io/2023/07/20/introduction-to-game-dev-with-sdl2.html
  2. https://blog.conan.io/2019/06/26/An-introduction-to-the-Dear-ImGui-library.html

I think it's useful to re-check new tutorial from time to time to learn new practices, as many of my habits came straight from 1.X era xD.

anyway, there are several alternatives to consider:

  • show an error if CMakePresets.json already exists
  • show a confirmation dialogue prompt if user wishes to override this file
  • make a backup file (CMakePresets.json.bak) in case file already exists

to add some background to the issue - it's indeed a regression, as earlier conan version didn't overwrite this file (I don't remember which release - it might take some time for me to do git bisect to discover when conan first started to overwrite user's CMakePresets.json, but one year ago it definitely didn't). so it was breaking change at some point and has to be corrected.

@SSE4
Copy link
Contributor Author

SSE4 commented Nov 3, 2023

Note that we will raise an error saying that CMakePresets.json cannot be generated in the above case. Because that file can be necessary later, for example for conan build command, it would be the same case.

as I remember (correct me if I am wrong), it should be completely optional - CMakePresets.json is since CMake 3.19. but per conan tribe, conan's target is CMake 3.15. so conan build should be able to continue without this file.

@memsharded
Copy link
Member

No, Conan reads this file, even when running with CMake 3.15. The file must exist and must be created.

@SSE4
Copy link
Contributor Author

SSE4 commented Nov 3, 2023

No, Conan reads this file, even when running with CMake 3.15. The file must exist and must be created.

I wonder how does it ever work, if user's CMake doesn't support it?

@memsharded
Copy link
Member

Conan reads the values and pass them in command line.

@memsharded memsharded added this to the 2.0.14 milestone Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants