conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.14k stars 970 forks source link

[question] How to prevent `conan install` from polluting the source repository? #17026

Open PauloCarvalhoRJ opened 1 day ago

PauloCarvalhoRJ commented 1 day ago

Greetings,

So, I have a CI/CD script that builds packages with conan install commands (e.g. conan install ninja/1.12.1 -s build_type=Release --build=missing --build=outdated --build=ninja). The commands complete but they put the build artifacts in the source directory instead of in the b directory in Conan cache like the conan create does. How do I make conan install behave similarly to conan create?

thank you,

PC

Have you read the CONTRIBUTING guide?

memsharded commented 1 day ago

Hi @PauloCarvalhoRJ

Which Conan version? --build=outdated only existed in Conan 1, in Conan 2 it is useless. Furthermore the syntax conan install pkg/version is not correct neither in Conan 1 nor in Conan 2.

Could you please clarify the exact Conan version, the exact command that you are using, the output of the command, report what is inside the respective folders (which folders they are too) in the cache and compare that with the folders with conan create?

PauloCarvalhoRJ commented 1 day ago

Hello. Sorry , it's Conan 2.3.

memsharded commented 1 day ago

Hello. Sorry , it's Conan 2.3.

And what would be the correct command then? and the output, and the resulting folder contents?

PauloCarvalhoRJ commented 1 day ago

Ok.

The script forms the following command for Ninja: conan install ninja/1.12.1 -s build_type=Release --build=missing --build=outdated --build=ninja. The Ninja recipe is rather simple and only extracts the correct executable from a zip file to the package directory.

So, this command results in six shell scripts copied to the source diretcory: image

If I run conan create ninja/1.12.1, however, I get everything where they are supposed to be:

/home/conan2_packages/
|-- b
|   `-- ninja73b1cb0514cd0
|       |-- b
|       |   |-- conanbuildenv.sh
|       |   |-- conanbuild.sh
|       |   |-- conaninfo.txt
|       |   |-- conanrunenv.sh
|       |   |-- conanrun.sh
|       |   |-- deactivate_conanbuild.sh
|       |   |-- deactivate_conanrun.sh
|       |   |-- ninja
|       |   `-- ninja.exe
|       |-- d
|       |   `-- metadata
|       `-- p
|           |-- bin
|           |   `-- ninja
|           |-- conaninfo.txt
|           `-- conanmanifest.txt
|-- cache.sqlite3
|-- ninja20bbd65455361
|   |-- d
|   |   `-- metadata
|   |-- e
|   |   |-- conanfile.py
|   |   `-- conanmanifest.txt
|   |-- es
|   |   `-- ninja.zip
|   `-- s
|       `-- ninja.zip
`-- t
PauloCarvalhoRJ commented 1 day ago

Notice that the six scripts from the conan install ... are in cache.

memsharded commented 1 day ago

The commands conan install ninja/1.12.1 and conan create ninja/1.12.1 are incorrect in Conan 2.

PauloCarvalhoRJ commented 1 day ago

But conan create ninja/1.12.1 is working as expected.

memsharded commented 1 day ago
(conan2_310) λ conan create ninja/1.2.11
ERROR: Conanfile not found at C:\Users\memsharded\conanws\kk\ninja\1.2.11

this only works if you have a folder called ninja with a subfolder called 1.2.11, but that is not the case

PauloCarvalhoRJ commented 1 day ago

Ah... yes. My recipes are customized to have a fixed version. 1.2.11 in my case is the directory where the recipe is. Think conan create ninja/1.12.1 as conan create ninja or even conan create . when running from the same directory where the recipe is.

PauloCarvalhoRJ commented 1 day ago

Recall that I'm on Linux, so conan create ninja/1.12.1 should read conan create ninja\1.12.1 in Windows.

PauloCarvalhoRJ commented 1 day ago

Would you like to share my recipe/zip? They're quite small.

memsharded commented 1 day ago

Would you like to share my recipe/zip? They're quite small.

yes, please, if you are using a custom recipe, and not a known one from ConanCenter we need it to be able to reproduce.

PauloCarvalhoRJ commented 14 hours ago

Here:

ninja.zip

make_life_simple_please.zip

On a side note: why doesn't github accept certain file extensions? It only complicates life unnecessarily...

The recipe and the profile I'm using (for both host and build contexts) are inside the other zip.

Thank you!

valgur commented 13 hours ago

Your conanfile.py is probably missing a layout() section with either a cmake_layout(self), basic_layout(self) or similar as contents. Without one you need to pass -of to the install command to have the generated build files be placed in some subdir.

I have not checked in a while, but I think the Conan tutorial does not emphasize this detail all that well.

PauloCarvalhoRJ commented 6 hours ago

Hello, @valgur ,

That Ninja recipe is very simple and does not have a layout() callback. So far, I've never had the need for it. Anyway, I'm going to try it and report here the result.

thanks,

PC

PauloCarvalhoRJ commented 6 hours ago

So, @valgur , adding the following callback:

    def layout(self):
        basic_layout(self, src_folder="src")

improved the result of the conan install ... in a sense. The six forementioned Conan shell scripts are now in a build folder in the source repository and it is not "building". That is, it is not unzipping the Ninja executable to <Conan cache path>/b/ninja<hash>/p/bin/ninja. So, there is still a long way to go.

thanks,

PC