conan profile

管理 profiles

conan profile detect

$ conan profile detect -h
usage: conan profile detect [-h] [--out-file OUT_FILE] [-v [V]]
                            [-cc CORE_CONF] [--name NAME] [-f] [-e]

Generate a profile using auto-detected values.

options:
  -h, --help            show this help message and exit
  --out-file OUT_FILE   Write the output of the command to the specified file
                        instead of stdout.
  -v [V]                Level of detail of the output. Valid options from less
                        verbose to more verbose: -vquiet, -verror, -vwarning,
                        -vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
                        -vvv or -vtrace
  -cc CORE_CONF, --core-conf CORE_CONF
                        Define core configuration, overwriting global.conf
                        values. E.g.: -cc core:non_interactive=True
  --name NAME           Profile name, 'default' if not specified
  -f, --force           Overwrite if exists
  -e, --exist-ok        If the profile already exist, do not detect a new one

警告

conan profile detect 的输出是不稳定的。它可能会在未来的 Conan 版本中随时更改,以适应最新的工具、最新的版本或环境中的其他更改。有关更多信息,请参见 Conan 稳定性 部分。

您可以使用以下命令为您的配置创建一个新的自动检测的 profile

自动检测的 profile
$ conan profile detect
Found apple-clang 14.0
apple-clang>=13, using the major as version
Detected profile:
[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=14
os=Macos

WARN: This profile is a guess of your environment, please check it.
WARN: Defaulted to cppstd='gnu17' for apple-clang.
WARN: The output of this command is not guaranteed to be stable and can change in future Conan versions.
WARN: Use your own profile files for stability.
Saving detected profile to /Users/barbarians/.conan2/profiles/default

请注意,如果该 profile 已经存在,您必须使用 --force 覆盖它。否则将会失败

强制覆盖已存在的默认 profile
$ conan profile detect
ERROR: Profile '/Users/carlosz/.conan2/profiles/default' already exists
$ conan profile detect --force
Found apple-clang 14.0
...
Saving detected profile to /Users/carlosz/.conan2/profiles/default

注意

最佳实践 建议不要在生产中使用 conan profile detect。为了保证可重现性,建议定义您自己的 profiles,将它们存储在 git 仓库或服务器上的 zip 文件中,并使用 conan config install 将其分发给您的团队和 CI 机器,以及其他配置,如自定义设置、自定义 remotes 定义等。

conan profile list

$ conan profile list -h
usage: conan profile list [-h] [-f FORMAT] [--out-file OUT_FILE] [-v [V]]
                          [-cc CORE_CONF]

List all profiles in the cache.

options:
  -h, --help            show this help message and exit
  -f FORMAT, --format FORMAT
                        Select the output format: json
  --out-file OUT_FILE   Write the output of the command to the specified file
                        instead of stdout.
  -v [V]                Level of detail of the output. Valid options from less
                        verbose to more verbose: -vquiet, -verror, -vwarning,
                        -vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
                        -vvv or -vtrace
  -cc CORE_CONF, --core-conf CORE_CONF
                        Define core configuration, overwriting global.conf
                        values. E.g.: -cc core:non_interactive=True
强制覆盖已存在的默认 profile
$ conan profile list
Profiles found in the cache:
default
ios_base
ios_simulator
clang_15

conan profile path

$ conan profile path -h
usage: conan profile path [-h] [--out-file OUT_FILE] [-v [V]] [-cc CORE_CONF]
                          name

Show profile path location.

positional arguments:
  name                  Profile name

options:
  -h, --help            show this help message and exit
  --out-file OUT_FILE   Write the output of the command to the specified file
                        instead of stdout.
  -v [V]                Level of detail of the output. Valid options from less
                        verbose to more verbose: -vquiet, -verror, -vwarning,
                        -vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
                        -vvv or -vtrace
  -cc CORE_CONF, --core-conf CORE_CONF
                        Define core configuration, overwriting global.conf
                        values. E.g.: -cc core:non_interactive=True

用于获取 [CONAN_HOME] 文件夹中的 profile 位置

$ conan profile path default
/Users/barbarians/.conan2/profiles/default

conan profile show

$ conan profile show -h
usage: conan profile show [-h] [-f FORMAT] [--out-file OUT_FILE] [-v [V]]
                          [-cc CORE_CONF] [-pr PROFILE] [-pr:b PROFILE_BUILD]
                          [-pr:h PROFILE_HOST] [-pr:a PROFILE_ALL]
                          [-o OPTIONS] [-o:b OPTIONS_BUILD]
                          [-o:h OPTIONS_HOST] [-o:a OPTIONS_ALL] [-s SETTINGS]
                          [-s:b SETTINGS_BUILD] [-s:h SETTINGS_HOST]
                          [-s:a SETTINGS_ALL] [-c CONF] [-c:b CONF_BUILD]
                          [-c:h CONF_HOST] [-c:a CONF_ALL] [-cx {host,build}]

Show aggregated profiles from the passed arguments.

options:
  -h, --help            show this help message and exit
  -f FORMAT, --format FORMAT
                        Select the output format: json
  --out-file OUT_FILE   Write the output of the command to the specified file
                        instead of stdout.
  -v [V]                Level of detail of the output. Valid options from less
                        verbose to more verbose: -vquiet, -verror, -vwarning,
                        -vnotice, -vstatus, -v or -vverbose, -vv or -vdebug,
                        -vvv or -vtrace
  -cc CORE_CONF, --core-conf CORE_CONF
                        Define core configuration, overwriting global.conf
                        values. E.g.: -cc core:non_interactive=True
  -pr PROFILE, --profile PROFILE
                        Apply the specified profile. By default, or if
                        specifying -pr:h (--profile:host), it applies to the
                        host context. Use -pr:b (--profile:build) to specify
                        the build context, or -pr:a (--profile:all) to specify
                        both contexts at once
  -pr:b PROFILE_BUILD, --profile:build PROFILE_BUILD
  -pr:h PROFILE_HOST, --profile:host PROFILE_HOST
  -pr:a PROFILE_ALL, --profile:all PROFILE_ALL
  -o OPTIONS, --options OPTIONS
                        Apply the specified options. By default, or if
                        specifying -o:h (--options:host), it applies to the
                        host context. Use -o:b (--options:build) to specify
                        the build context, or -o:a (--options:all) to specify
                        both contexts at once. Example:
                        -o="pkg/*:with_qt=True"
  -o:b OPTIONS_BUILD, --options:build OPTIONS_BUILD
  -o:h OPTIONS_HOST, --options:host OPTIONS_HOST
  -o:a OPTIONS_ALL, --options:all OPTIONS_ALL
  -s SETTINGS, --settings SETTINGS
                        Apply the specified settings. By default, or if
                        specifying -s:h (--settings:host), it applies to the
                        host context. Use -s:b (--settings:build) to specify
                        the build context, or -s:a (--settings:all) to specify
                        both contexts at once. Example: -s="compiler=gcc"
  -s:b SETTINGS_BUILD, --settings:build SETTINGS_BUILD
  -s:h SETTINGS_HOST, --settings:host SETTINGS_HOST
  -s:a SETTINGS_ALL, --settings:all SETTINGS_ALL
  -c CONF, --conf CONF  Apply the specified conf. By default, or if specifying
                        -c:h (--conf:host), it applies to the host context.
                        Use -c:b (--conf:build) to specify the build context,
                        or -c:a (--conf:all) to specify both contexts at once.
                        Example:
                        -c="tools.cmake.cmaketoolchain:generator=Xcode"
  -c:b CONF_BUILD, --conf:build CONF_BUILD
  -c:h CONF_HOST, --conf:host CONF_HOST
  -c:a CONF_ALL, --conf:all CONF_ALL
  -cx {host,build}, --context {host,build}

使用 conan profile show 从命令行参数计算生成的 build 和 host profiles。例如,将不同的选项和设置与默认 profile 或使用 pr:bpr:h 参数的任何其他 profile 结合起来

$ conan profile show -s:h build_type=Debug -o:h shared=False
Host profile:
[settings]
arch=x86_64
build_type=Debug
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=14
os=Macos
[options]
shared=False
[conf]


Build profile:
[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=14
os=Macos
[conf]

它也很有用,可以展示 profiles 中的 jinja2 模板 的评估结果。例如,像这样的 profile

myprofile
[settings]
os = {{ {"Darwin": "Macos"}.get(platform.system(), platform.system()) }}

检查已评估的 profile

$ conan profile show -pr:h=myprofile
Host profile:
[settings]
os=Macos
[conf]
...

该命令还可以输出包含结果的 json

$ conan profile show --format=json

{
"host": {
    "settings": {
        "arch": "armv8",
        "build_type": "Release",
        "compiler": "apple-clang",
        "compiler.cppstd": "gnu17",
        "compiler.libcxx": "libc++",
        "compiler.version": "15",
        "os": "Macos"
    },
    "package_settings": {},
    "options": {},
    "tool_requires": {},
    "conf": {},
    "build_env": ""
},
"build": {
    "settings": {
        "arch": "armv8",
        "build_type": "Release",
        "compiler": "apple-clang",
        "compiler.cppstd": "gnu17",
        "compiler.libcxx": "libc++",
        "compiler.version": "15",
        "os": "Macos"
    },
    "package_settings": {},
    "options": {},
    "tool_requires": {},
    "conf": {},
    "build_env": ""
}
}

另请参阅