本文档翻译自:https://docs.Conan.io/en/latest/reference/commands/creator/export-pkg.html

    1. $ conan export-pkg [-h] [-bf BUILD_FOLDER] [-f] [-if INSTALL_FOLDER]
    2. [-pf PACKAGE_FOLDER] [-sf SOURCE_FOLDER] [-j JSON]
    3. [-l [LOCKFILE]] [--ignore-dirty] [-e ENV_HOST]
    4. [-e:b ENV_BUILD] [-e:h ENV_HOST] [-o OPTIONS_HOST]
    5. [-o:b OPTIONS_BUILD] [-o:h OPTIONS_HOST]
    6. [-pr PROFILE_HOST] [-pr:b PROFILE_BUILD]
    7. [-pr:h PROFILE_HOST] [-s SETTINGS_HOST]
    8. [-s:b SETTINGS_BUILD] [-s:h SETTINGS_HOST]
    9. path [reference]

    导出配方,然后从本地源创建一个包并生成文件夹。
    如果提供“ –package-folder”,它将从那里复制文件,否则,它将在“ –source-folder”和“ –build-folder”上执行package()方法以创建二进制软件包。

    1. positional arguments:
    2. path Path to a folder containing a conanfile.py or to a
    3. recipe file e.g., my_folder/conanfile.py
    4. reference user/channel or pkg/version@user/channel (if name and
    5. version are not declared in the conanfile.py)
    6. optional arguments:
    7. -h, --help show this help message and exit
    8. -bf BUILD_FOLDER, --build-folder BUILD_FOLDER
    9. Directory for the build process. Defaulted to the
    10. current directory. A relative path to the current
    11. directory can also be specified
    12. -f, --force Overwrite existing package if existing
    13. -if INSTALL_FOLDER, --install-folder INSTALL_FOLDER
    14. Directory containing the conaninfo.txt and
    15. conanbuildinfo.txt files (from previous 'conan
    16. install'). Defaulted to --build-folder If these files
    17. are found in the specified folder and any of '-e',
    18. '-o', '-pr' or '-s' arguments are used, it will raise
    19. an error.
    20. -pf PACKAGE_FOLDER, --package-folder PACKAGE_FOLDER
    21. folder containing a locally created package. If a
    22. value is given, it won't call the recipe 'package()'
    23. method, and will run a copy of the provided folder.
    24. -sf SOURCE_FOLDER, --source-folder SOURCE_FOLDER
    25. Directory containing the sources. Defaulted to the
    26. conanfile's directory. A relative path to the current
    27. directory can also be specified
    28. -j JSON, --json JSON Path to a json file where the install information will
    29. be written
    30. -l [LOCKFILE], --lockfile [LOCKFILE]
    31. Path to a lockfile or folder containing 'conan.lock'
    32. file. Lockfile will be updated with the exported
    33. package
    34. --ignore-dirty When using the "scm" feature with "auto" values,
    35. capture the revision and url even if there are
    36. uncommitted changes
    37. -e ENV_HOST, --env ENV_HOST
    38. Environment variables that will be set during the
    39. package build (host machine). e.g.: -e
    40. CXX=/usr/bin/clang++
    41. -e:b ENV_BUILD, --env:build ENV_BUILD
    42. Environment variables that will be set during the
    43. package build (build machine). e.g.: -e:b
    44. CXX=/usr/bin/clang++
    45. -e:h ENV_HOST, --env:host ENV_HOST
    46. Environment variables that will be set during the
    47. package build (host machine). e.g.: -e:h
    48. CXX=/usr/bin/clang++
    49. -o OPTIONS_HOST, --options OPTIONS_HOST
    50. Define options values (host machine), e.g.: -o
    51. Pkg:with_qt=true
    52. -o:b OPTIONS_BUILD, --options:build OPTIONS_BUILD
    53. Define options values (build machine), e.g.: -o:b
    54. Pkg:with_qt=true
    55. -o:h OPTIONS_HOST, --options:host OPTIONS_HOST
    56. Define options values (host machine), e.g.: -o:h
    57. Pkg:with_qt=true
    58. -pr PROFILE_HOST, --profile PROFILE_HOST
    59. Apply the specified profile to the host machine
    60. -pr:b PROFILE_BUILD, --profile:build PROFILE_BUILD
    61. Apply the specified profile to the build machine
    62. -pr:h PROFILE_HOST, --profile:host PROFILE_HOST
    63. Apply the specified profile to the host machine
    64. -s SETTINGS_HOST, --settings SETTINGS_HOST
    65. Settings to build the package, overwriting the
    66. defaults (host machine). e.g.: -s compiler=gcc
    67. -s:b SETTINGS_BUILD, --settings:build SETTINGS_BUILD
    68. Settings to build the package, overwriting the
    69. defaults (build machine). e.g.: -s:b compiler=gcc
    70. -s:h SETTINGS_HOST, --settings:host SETTINGS_HOST
    71. Settings to build the package, overwriting the
    72. defaults (host machine). e.g.: -s:h compiler=gcc

    export-pkg命令使您可以从工作文件夹中已经存在的文件中创建一个软件包,如果您使用的是Conan外部的构建过程并且不想为其提供配方,则该命令很有用。 不过,您应该考虑到它将生成一个程序包,而Conan将无法保证其可重复性或再次对其进行重新生成。 这不是创建Conan软件包的正常或建议的流程。
    执行此命令将导致多个文件复制到由packageid标识的缓存中的package文件夹中(Conan将执行所有必需的操作来计算此_id:构建图形,评估要求和选项并调用任何必需的方法) ,但文件可能有两个不同的来源:

    • 如果提供了—package-folder参数,Conan只会将该文件夹的所有内容复制到缓存中的一个软件包中。
    • 如果没有给出—package-folder,Conan将执行一次方法package(),而self.copy(…)函数会将匹配的文件从source_folder和build_folder复制到Conan缓存中的相应路径(工作目录) 对应于build_folder)。
    • 如果声明了—package-folder,`—build-folder或—source-folder参数,但是路径不正确,则export-pkg将引发异常。

    在不同的情况下,此命令看起来很有用:

    • 您正在本地处理软件包,并且希望将其上传到缓存以能够从其他配方中使用。 在这种情况下,您可以使用export-pkg命令将软件包复制到缓存中,但是也可以将软件包置于可编辑模式,并避免执行此额外步骤。
    • 您只有可用的预编译二进制文件,然后可以使用export-pkg创建Conan软件包,或者可以构建有效的配方来下载和打包它们。 在文档部分如何打包现有二进制文件中描述了这些方案。

    :::info Note
    请注意,如果未向export-pkg提供—profile,设置或选项,则将从先前的Conan安装后存储的信息中提取配置。 在某些情况下,该信息可能不完整,因此我们强烈建议使用—profile或—settings,-options等。 :::

    Examples
    从包含Windows / x86 / Release二进制文件的目录中创建一个软件包:
    我们需要从本地文件系统中收集所有文件,并告诉Conan计算正确的package_id,以便将其与正确的设置相关联,并在使用时起作用。
    如果工作文件夹中的文件是:

    1. Release_x86/lib/libmycoollib.a
    2. Release_x86/lib/other.a
    3. Release_x86/include/mylib.h
    4. Release_x86/include/other.h

    然后,只需运行:

    1. $ conan new hello/0.1 --bare # It creates a minimum recipe example
    2. $ conan export-pkg . hello/0.1@user/stable -s os=Windows -s arch=x86 -s build_type=Release --package-folder=Release_x86

    最后一条命令将从软件包文件夹复制所有内容,并创建与通过命令行提供的设置关联的软件包。

    从源创建一个包并生成文件夹:
    目的是从源文件夹(包括文件)和构建文件夹(库)收集将成为软件包一部分的文件,因此,如果这些是工作文件夹中的文件:

    1. sources/include/mylib.h
    2. sources/src/file.cpp
    3. build/lib/mylib.lib
    4. build/lib/mylib.tmp
    5. build/file.obj

    我们需要比上一个示例稍微复杂一些的Conanfile.py来选择要复制的文件,我们需要更改package()方法中的模式:

    1. def package(self):
    2. self.copy("*.h", dst="include", src="include")
    3. self.copy("*.lib", dst="lib", keep_path=False)

    现在,我们可以运行Conan创建包:

    1. $ conan export-pkg . hello/0.1@user/stable -pr:host=myprofile --source-folder=sources --build-folder=build