Conan Package Manager Documentation

repository·develop2·Indexed 27 days ago

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

Conan is a decentralized, open-source C and C++ package manager that manages binaries across multiple platforms and integrates with build systems like CMake and Meson. This documentation covers installation from source, development environment setup, testing with pytest and Artifactory, and detailed CLI usage including build policies, lockfiles, remotes, and custom command extensions. It also details the 'conan audit' suite for scanning recipes and dependency graphs for vulnerabilities using security providers.

Tokens
14.5K
Snippets
5
Records
135
Agent score
94%

What's inside Conan

  1. Install Conan from source

    develop2

    To run Conan from source on Windows, MacOS, or Linux, follow these steps:

    1. Ensure pip is installed.
    2. Clone the repository into a directory named conan-io (to avoid naming conflicts with the conan command itself).
    3. Install the package in editable mode.

    Note for Linux users: If your distribution prevents installing Python packages in editable mode in the root Python installation, you must create a Python virtual environment (venv) first.

  2. Run Conan tests

    develop2

    Conan uses pytest for its test suite. You can run the full suite, specific tests, or tests filtered by markers (like Artifactory readiness).

    Prerequisites:

    • Specific tool versions are required (e.g., cmake>=3.15).
    • The test suite configures tools like CMake and Ninja via conftest.py.
  3. Set up the Conan development environment for testing

    develop2

    Before running the Conan test suite, you must install the necessary Python requirements and configure your PYTHONPATH environment variable.

    Requirements Installation: Install the following requirement files using pip (use sudo on Linux if not using a virtual environment):

    • conans/requirements.txt
    • conans/requirements_server.txt
    • conans/requirements_dev.txt

    Environment Configuration: Set the PYTHONPATH to include the current working directory so the tests can locate the Conan modules.

    # Install requirements
    $ python -m pip install -r conans/requirements.txt
    $ python -m pip install -r conans/requirements_server.txt
    $ python -m pip install -r conans/requirements_dev.txt
    
    # Set PYTHONPATH (Linux/MacOS)
    $ export PYTHONPATH=$PYTHONPATH:$(pwd)
    
    # Set PYTHONPATH (Windows)
    $ set PYTHONPATH=.
  4. Remove packages using a query or list file

    develop2

    You can perform batch removals using either a package query or a pre-defined package list file.

    Using a Package Query: When using -p or --package-query, you can filter which binaries are removed based on settings or options. Note that if you use a query, the pattern must match packages.

    Using a List File: Provide a file via -l or --list containing the packages to be removed.

    Constraints:

    • You cannot define both a pattern and a --list file in the same command.
    • You cannot define both --package-query and a --list file in the same command.
    • --lru cannot be used with a --list file or when targeting a remote.
  5. Format Conan audit vulnerability output

    develop2

    When running Conan audit commands, you can specify different output formats for the vulnerability report. The available formats are:

    • Text (Default): A human-readable, colorized terminal output showing package references, vulnerability counts, severity levels (Critical, High, Medium, Low), descriptions, CVSS scores, and fix versions.
    • JSON: A machine-readable JSON representation of the full audit result.
    • HTML: A detailed, styled HTML report suitable for browser viewing, featuring a searchable DataTables interface, severity badges, and JFrog Research advisories.
  6. Extend Conan with custom commands

    develop2

    Conan allows you to add custom commands by placing Python modules in specific directories. Custom commands must have a filename starting with cmd_ (e.g., cmd_mycommand.py).

    Command Locations

    1. Default Extension Path: ${CONAN_HOME}/extensions/commands (where ${CONAN_HOME} is your Conan cache folder).
    2. Developer Path: You can override the default location for testing/debugging by setting the environment variable _CONAN_INTERNAL_CUSTOM_COMMANDS_PATH to a directory of your choice.

    Command Structure

    • Naming: A module cmd_foo.py will be registered as the command foo.
    • Subcommands: To implement subcommands, define methods in your command module that follow the pattern {main_command_name}_{subcommand_name} and are instances of ConanSubCommand.
    • Layered Commands: Conan supports layered commands. If a folder inside your custom commands directory contains modules starting with cmd_, they are registered as folder_name:command_name.
  7. Configure Artifactory testing environment variables

    develop2

    To run tests against an Artifactory instance, define the following environment variables. If running a local instance with default credentials, use these values:

    • CONAN_TEST_WITH_ARTIFACTORY: Set to 1 to enable Artifactory tests.
    • ARTIFACTORY_DEFAULT_URL: The base URL for the Artifactory repository (e.g., http://localhost:8081/artifactory).
    • ARTIFACTORY_DEFAULT_USER: The Artifactory username.
    • ARTIFACTORY_DEFAULT_PASSWORD: The Artifactory password.

    Warning: Running tests with a real Artifactory instance will create repositories on the fly; use a dedicated testing server.

    $ export CONAN_TEST_WITH_ARTIFACTORY=1
    $ export ARTIFACTORY_DEFAULT_URL=http://localhost:8081/artifactory
    $ export ARTIFACTORY_DEFAULT_USER=admin
    $ export ARTIFACTORY_DEFAULT_PASSWORD=password
  8. Print package status and binary information

    develop2

    The print_graph_packages(graph) function provides a detailed view of the packages within a dependency graph, focusing on their binary status and remote origins. It categorizes packages into:

    • Requirements
    • Test requirements
    • Build requirements

    For each package, it reports the status, such as:

    • Skip: Binary is skipped.
    • Missing or Invalid: Binary status issues (shown in red).
    • Build: Package needs to be built (shown in yellow).
    • Other statuses (e.g., specific binary IDs) are shown in cyan.

    If the output level allows LEVEL_DEBUG, it also prints a compact summary of the package information. If the output level is not LEVEL_VERBOSE, it provides a summary list of Skipped binaries.

  9. Format dependency graphs as HTML

    develop2
    Conan can render dependency graphs as HTML files. By default, it uses an internal template, but you can provide a custom template by placing a file named graph.html in your Conan cache's templates folder. The template has access to the serialized dependency graph (deps_graph), the base_template_path, and the Conan version.