How can I specify a specific default installation directory with Conan?

Question:

I am seeking to deploy (on Linux) a Conan package on a system and there is no deploy() method specified in the conanfile.py. So (I believe) this means the package will be installed in the current directory.

Instead I’d like to specify a default directory. I have tried using conan install -if /some/directory but get:

conan install: error: unrecognized arguments: -if  /some/directory 

(It seems I need to couple -g with -if ? But I’m not trying to build the package just deploy it.)

Is there a way to do this? Have I understood the default behaviour correctly?

Update: Writing the question helped clarify my thoughts so I tried with conan install -g deploy -if /some/directory PACKAGE and while I no longer get the -if related error message, it still doesn’t work: merely leaving a conanbuildinfo.txt file in the specified directory.

Asked By: adrianmcmenamin

||

Answers:

Short answer appears to be I can’t.

Answered By: adrianmcmenamin

As per conan documentation: conan install installs the requirements specified in a recipe (conanfile.py or conanfile.txt). It can also be used to install a concrete package specifying a reference.
It normally installs packages on the cache

Depending on the conanfile.py and the installation documentation provided, if it doesn’t implement deploy() method, this possibly means that the artifacts are copied to the package. You can figure that out from package() in conanfile.py.

One workaround to copy the artifacts to your custom directory is to copy it manually from the installed package in the cache. You can normally find the package on the path ~/.conan/data/<Package_Reference>/package/<Binary_Package_ID> shown in the terminal while running conan install.

If the package has source code that can be built to generate the binary artifacts, then you can use the following commands to generate the binary artifacts on a local folder:

 $ conan source . --source-folder src
 $ conan install . --install-folder build
 $ conan build . --build-folder build --source-folder src

You will find the generated artifacts on build folder.

Answered By: Bassem Ramzy

Searching online pops support answers to the same issue in the project’s repository,

https://github.com/conan-io/conan/issues/2250

I see references to environment variables CONAN_USER_HOME, CONAN_USER_HOME_SHORT and to a command conan config set storage.path=<your new path here>.

I should not forget that separating the installation across multiple conan sessions on the same machine should consider 3 areas of racing,

  • Filesystem-wide root.
  • User-specific root.
  • Session-specific root.

The "short Windows path" workaround to an older OS limit of path lengths (which extends into the new OSes until opting-in and relying on Unicode API) avoids collision between users. Because the workaround appends only the user’s hash to the filesystem root, it will be vulnerable to collisions in sessions running by the same user, even with different checkouts of code consuming the libraries (as in the case of a build server).

Conan’s own instruction on non-conflicting installs into different CONAN_USER_HOMEs will need CONAN_USER_HOME_SHORT=None and tools using Unicode filesystem API on Windows.

Answered By: eel ghEEz
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.