Profile 插件

profile.py 扩展插件是一个 Python 脚本,它接收一个 profile 并允许检查和修改它。

此插件位于缓存目录 extensions/plugins/profile.py 中。

profile.py 包含一个默认实现,其功能如下:

  • 如果 msvcclang 编译器(在 Windows 上)的 compiler.runtime_type 未定义,则会尝试定义它,并将其定义为与 settings.build_type 匹配。这允许用户在 profiles 中不定义它,而只通过命令行 -s build_type=Debug 方便地切换它。

  • 如果定义了 compiler.cppstd 值,将检查其是否与当前编译器版本兼容。例如,如果开发者尝试使用 -s compiler=gcc -s compiler.version=5 -s compiler.cppstd=20,将会引发错误。

  • 尽管 profile.py 插件有一些处理 compiler.cstd 检查的准备,但它们尚未实现,因此插件对定义错误将是宽容的,请确保您的编译器版本实际支持 compiler.cstd

用户可以自定义此 profile.py 并通过 conan config install 进行分发,在这种情况下,应删除前几行:

# This file was generated by Conan. Remove this comment if you edit this file or Conan
# will destroy your changes.

并且 profile.py 应包含一个具有如下签名的函数:

def profile_plugin(profile):
    settings = profile.settings
    print(settings)

计算 profile 时,会显示类似以下内容:

OrderedDict([('arch', 'x86_64'), ('build_type', 'Release'), ('compiler', 'msvc'), ('compiler.cppstd', '14'), ('compiler.runtime', 'dynamic'), ('compiler.runtime_type', 'Release'), ('compiler.version', '192'), ('os', 'Windows')])

另请参阅