本文档翻译自:https://docs.Conan.io/en/latest/reference/commands/creator/export-pkg.html
$ conan export-pkg [-h] [-bf BUILD_FOLDER] [-f] [-if INSTALL_FOLDER]
[-pf PACKAGE_FOLDER] [-sf SOURCE_FOLDER] [-j JSON]
[-l [LOCKFILE]] [--ignore-dirty] [-e ENV_HOST]
[-e:b ENV_BUILD] [-e:h ENV_HOST] [-o OPTIONS_HOST]
[-o:b OPTIONS_BUILD] [-o:h OPTIONS_HOST]
[-pr PROFILE_HOST] [-pr:b PROFILE_BUILD]
[-pr:h PROFILE_HOST] [-s SETTINGS_HOST]
[-s:b SETTINGS_BUILD] [-s:h SETTINGS_HOST]
path [reference]
导出配方,然后从本地源创建一个包并生成文件夹。
如果提供“ –package-folder”,它将从那里复制文件,否则,它将在“ –source-folder”和“ –build-folder”上执行package()方法以创建二进制软件包。
positional arguments:
path Path to a folder containing a conanfile.py or to a
recipe file e.g., my_folder/conanfile.py
reference user/channel or pkg/version@user/channel (if name and
version are not declared in the conanfile.py)
optional arguments:
-h, --help show this help message and exit
-bf BUILD_FOLDER, --build-folder BUILD_FOLDER
Directory for the build process. Defaulted to the
current directory. A relative path to the current
directory can also be specified
-f, --force Overwrite existing package if existing
-if INSTALL_FOLDER, --install-folder INSTALL_FOLDER
Directory containing the conaninfo.txt and
conanbuildinfo.txt files (from previous 'conan
install'). Defaulted to --build-folder If these files
are found in the specified folder and any of '-e',
'-o', '-pr' or '-s' arguments are used, it will raise
an error.
-pf PACKAGE_FOLDER, --package-folder PACKAGE_FOLDER
folder containing a locally created package. If a
value is given, it won't call the recipe 'package()'
method, and will run a copy of the provided folder.
-sf SOURCE_FOLDER, --source-folder SOURCE_FOLDER
Directory containing the sources. Defaulted to the
conanfile's directory. A relative path to the current
directory can also be specified
-j JSON, --json JSON Path to a json file where the install information will
be written
-l [LOCKFILE], --lockfile [LOCKFILE]
Path to a lockfile or folder containing 'conan.lock'
file. Lockfile will be updated with the exported
package
--ignore-dirty When using the "scm" feature with "auto" values,
capture the revision and url even if there are
uncommitted changes
-e ENV_HOST, --env ENV_HOST
Environment variables that will be set during the
package build (host machine). e.g.: -e
CXX=/usr/bin/clang++
-e:b ENV_BUILD, --env:build ENV_BUILD
Environment variables that will be set during the
package build (build machine). e.g.: -e:b
CXX=/usr/bin/clang++
-e:h ENV_HOST, --env:host ENV_HOST
Environment variables that will be set during the
package build (host machine). e.g.: -e:h
CXX=/usr/bin/clang++
-o OPTIONS_HOST, --options OPTIONS_HOST
Define options values (host machine), e.g.: -o
Pkg:with_qt=true
-o:b OPTIONS_BUILD, --options:build OPTIONS_BUILD
Define options values (build machine), e.g.: -o:b
Pkg:with_qt=true
-o:h OPTIONS_HOST, --options:host OPTIONS_HOST
Define options values (host machine), e.g.: -o:h
Pkg:with_qt=true
-pr PROFILE_HOST, --profile PROFILE_HOST
Apply the specified profile to the host machine
-pr:b PROFILE_BUILD, --profile:build PROFILE_BUILD
Apply the specified profile to the build machine
-pr:h PROFILE_HOST, --profile:host PROFILE_HOST
Apply the specified profile to the host machine
-s SETTINGS_HOST, --settings SETTINGS_HOST
Settings to build the package, overwriting the
defaults (host machine). e.g.: -s compiler=gcc
-s:b SETTINGS_BUILD, --settings:build SETTINGS_BUILD
Settings to build the package, overwriting the
defaults (build machine). e.g.: -s:b compiler=gcc
-s:h SETTINGS_HOST, --settings:host SETTINGS_HOST
Settings to build the package, overwriting the
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,以便将其与正确的设置相关联,并在使用时起作用。
如果工作文件夹中的文件是:
Release_x86/lib/libmycoollib.a
Release_x86/lib/other.a
Release_x86/include/mylib.h
Release_x86/include/other.h
然后,只需运行:
$ conan new hello/0.1 --bare # It creates a minimum recipe example
$ conan export-pkg . hello/0.1@user/stable -s os=Windows -s arch=x86 -s build_type=Release --package-folder=Release_x86
最后一条命令将从软件包文件夹复制所有内容,并创建与通过命令行提供的设置关联的软件包。
从源创建一个包并生成文件夹:
目的是从源文件夹(包括文件)和构建文件夹(库)收集将成为软件包一部分的文件,因此,如果这些是工作文件夹中的文件:
sources/include/mylib.h
sources/src/file.cpp
build/lib/mylib.lib
build/lib/mylib.tmp
build/file.obj
我们需要比上一个示例稍微复杂一些的Conanfile.py来选择要复制的文件,我们需要更改package()方法中的模式:
def package(self):
self.copy("*.h", dst="include", src="include")
self.copy("*.lib", dst="lib", keep_path=False)
现在,我们可以运行Conan创建包:
$ conan export-pkg . hello/0.1@user/stable -pr:host=myprofile --source-folder=sources --build-folder=build