创建conan包-不同/相同repo中的配方和来源

创建conan包-不同/相同repo中的配方和来源

  • 1 Recipe and Sources in a Different Repo
    • 1.1 source()的方法
    • 1.2 使用scm 属性
  • 2 Recipe and Sources in the Same Repo
    • 2.1 Exporting the Sources with the Recipe: exports_sources
    • 2.2 Capturing the Remote and Commit: scm

本文是基于对conan官方文档Recipe and Sources in a Different Repo - Recipe and Sources in the Same Repo翻译而来, 更详细的信息可以去查阅conan官方文档。

1 Recipe and Sources in a Different Repo

In the previous section, we fetched the sources of our library from an external repository. It is a typical workflow for packaging third party libraries.
在上一节中,我们从外部资源库获取了库的源代码。这是打包第三方库的典型工作流程。

There are two different ways to fetch the sources from an external repository:
从外部资源库获取源文件有两种不同的方法:

1.1 source()的方法

Using the source() method as we displayed in the previous section:
使用我们在上一节中展示的 source() 方法:

from conans import ConanFile, CMake, toolsclass HelloConan(ConanFile):...def source(self):self.run("git clone https://github.com/conan-io/hello.git")...

You can also use the tools.Git class:
您还可以使用 tools.Git 类:

from conans import ConanFile, CMake, toolsclass HelloConan(ConanFile):...def source(self):git = tools.Git(folder="hello")git.clone("https://github.com/conan-io/hello.git", "master")...

1.2 使用scm 属性

Using the scm attribute of the ConanFile:
使用 ConanFile 的 scm 属性:

Warning
This is a deprecated feature. Please refer to the Migration Guidelines to find the feature that replaces this one.
这是一项已废弃的功能。请参阅 "迁移指南 "查找替代此功能的功能。

from conans import ConanFile, CMake, toolsclass HelloConan(ConanFile):scm = {"type": "git","subfolder": "hello","url": "https://github.com/conan-io/hello.git","revision": "master"}...

Conan will clone the scm url and will checkout the scm revision. Head to creating package documentation to know more details about SCM feature.
conan将克隆 scm 网址并签出 scm 修订版。前往创建软件包文档,了解有关 SCM 功能的更多详情。

The source() method will be called after the checkout process, so you can still use it to patch something or retrieve more sources, but it is not necessary in most cases.
source() 方法将在checkout过程后调用,因此您仍可使用它来修补或检索更多来源,但在大多数情况下并无必要。

2 Recipe and Sources in the Same Repo

Caution
We are actively working to finalize the Conan 2.0 Release. Some of the information on this page references deprecated features which will not be carried forward with the new release. It’s important to check the Migration Guidelines to ensure you are using the most up to date features.
我们正在积极努力完成conan 2.0 版本的最终定稿。本页面中的部分信息引用了过时的功能,这些功能将不会在新版本中继续使用。请务必查看 “迁移指南”,以确保您使用的是最新功能。

Sometimes it is more convenient to have the recipe and source code together in the same repository. This is true especially if you are developing and packaging your own library, and not one from a third-party.
有时,将配方和源代码放在同一个资源库中会更方便。尤其是在开发和打包自己的库,而不是第三方库时更是如此。

There are two different approaches:
有两种不同的方法:

  • Using the exports sources attribute of the conanfile to export the source code together with the recipe. This way the recipe is self-contained and will not need to fetch the code from external origins when building from sources. It can be considered a “snapshot” of the source code.
  • 使用 conanfileexports sources 属性将源代码与配方一起导出。这样,配方就自成一体,在从源代码构建时无需从外部获取代码。它可以被视为源代码的 “snapshot”。
  • Using the scm attribute of the conanfile to capture the remote and commit of your repository automatically.
  • 使用 conanfilescm 属性自动捕获版本库的remote和commit。

2.1 Exporting the Sources with the Recipe: exports_sources

This could be an appropriate approach if we want the package recipe to live in the same repository as the source code it is packaging.
如果我们希望软件包配方与打包的源代码位于同一版本库中,这可能是一种合适的方法。

First, let’s get the initial source code and create the basic package recipe:
首先,让我们获取初始源代码并创建基本软件包配方:

$ conan new hello/0.1 -t -s

A src folder will be created with the same “hello” source code as in the previous example. You can have a look at it and see that the code is straightforward.
将创建一个 src 文件夹,其中包含与上一个示例中相同的 "hello "源代码。你可以看一看,代码非常简单。

Now let’s have a look at conanfile.py:
现在,让我们来看看 conanfile.py:

from conans import ConanFile, CMakeclass HelloConan(ConanFile):name = "hello"version = "0.1"license = "<Put the package license here>"url = "<Package recipe repository url here, for issues about the package>"description = "<Description of hello here>"settings = "os", "compiler", "build_type", "arch"options = {"shared": [True, False]}default_options = {"shared": False}generators = "cmake"exports_sources = "src/*"def build(self):cmake = CMake(self)cmake.configure(source_folder="src")cmake.build()# Explicit way:# self.run('cmake "%s/src" %s' % (self.source_folder, cmake.command_line))# self.run("cmake --build . %s" % cmake.build_config)def package(self):self.copy("*.h", dst="include", src="src")self.copy("*.lib", dst="lib", keep_path=False)self.copy("*.dll", dst="bin", keep_path=False)self.copy("*.dylib*", dst="lib", keep_path=False)self.copy("*.so", dst="lib", keep_path=False)self.copy("*.a", dst="lib", keep_path=False)def package_info(self):self.cpp_info.libs = ["hello"]

There are two important changes:
有两个重要的变化:

  • Added the exports_sources field, indicating to Conan to copy all the files from the local src folder into the package recipe.
  • 添加 exports_sources 字段,指示conan将本地 src 文件夹中的所有文件复制到软件包配方中。
  • Removed the source() method, since it is no longer necessary to retrieve external sources.
  • 删除了 source() 方法,因为不再需要检索外部来源。

Also, you can notice the two CMake lines:

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

They are not added in the package recipe, as they can be directly added to the src/CMakeLists.txt file.
它们不会添加到软件包配方中,因为它们可以直接添加到 src/CMakeLists.txt 文件中。

And simply create the package for user and channel demo/testing as described previously:
只需按照前面所述,为user和channel演示/测试创建软件包即可:

$ conan create . demo/testing
...
hello/0.1@demo/testing test package: Running test()
Hello world Release!

2.2 Capturing the Remote and Commit: scm

Warning
This is a deprecated feature. Please refer to the Migration Guidelines to find the feature that replaces this one.
这是一项已废弃的功能。请参阅 "迁移指南 "查找替代此功能的功能。

You can use the scm attribute with the url and revision field set to auto. When you export the recipe (or when conan create is called) the exported recipe will capture the remote and commit of the local repository:
你可以使用 scm 属性,并将 urlrevision字段设置为自动。导出配方时(或调用 conan create 时),导出的配方将捕获本地版本库的remote和commit:

import osfrom conans import ConanFile, CMake, toolsclass HelloConan(ConanFile):scm = {"type": "git",  # Use "type": "svn", if local repo is managed using SVN"subfolder": "hello","url": "auto","revision": "auto","password": os.environ.get("SECRET", None)}...

You can commit and push the conanfile.py to your origin repository, which will always preserve the auto values. When the file is exported to the Conan local cache (except you have uncommitted changes, read below), these data will be stored in the conanfile.py itself (Conan will modify the file) or in a special file conandata.yml that will be stored together with the recipe, depending on the value of the configuration parameter scm_to_conandata.
您可以提交 conanfile.py 并将其推送到您的源版本库,这样将始终保留自动值。当文件导出到 Conan 本地缓存时(除非您有未提交的修改,请阅读下文),这些数据将存储在 conanfile.py 本身(Conan 将修改该文件)或一个特殊文件 conandata.yml,该文件将与配方一起存储,具体取决于配置参数 scm_to_conandata 的值。

  • If the scm_to_conandata is not activated (default behavior in Conan v1.x) Conan will store a modified version of the conanfile.py with the values of the fields in plain text:
  • 如果未激活 scm_to_conandata(Conan v1.x 中的默认行为),Conan 将以纯文本形式存储字段值的 conanfile.py 修改版:
    import osfrom conans import ConanFile, CMake, toolsclass HelloConan(ConanFile):scm = {"type": "git","subfolder": "hello","url": "https://github.com/conan-io/hello.git","revision": "437676e15da7090a1368255097f51b1a470905a0","password": "MY_SECRET"}...

So when you upload the recipe to a Conan remote, the recipe will contain the “resolved” URL and commit.
因此,当您将配方上传到conan远程服务器时,配方将包含 "已解析 "的 URL 和提交。

  • If scm_to_conandata is activated, the value of these fields (except username and password) will be stored in the conandata.yml file that will be automatically exported with the recipe.
  • 如果激活了 scm_to_conandata,这些字段的值(用户名和密码除外)将保存在 conandata.yml 文件中,该文件将随配方自动导出。

Whichever option you choose, the data resolved will be assigned by Conan to the corresponding field when the recipe file is loaded, and they will be available for all the methods defined in the recipe. Also, if building the package from sources, Conan will fetch the code in the captured url/commit before running the method source() in the recipe (if defined).
无论您选择哪个选项,在加载配方文件时,conan都会将已解析的数据分配到相应的字段,这些数据将用于配方中定义的所有方法。此外,如果从源代码构建软件包,在运行配方中的 source() 方法(如果已定义)之前,conan将在捕获的 url/commit 中获取代码。

As SCM attributes are evaluated in the local directory context (see scm attribute), you can write more complex functions to retrieve the proper values, this source conanfile.py will be valid too:
由于 SCM 属性是在本地目录上下文中评估的(参见 scm 属性),你可以编写更复杂的函数来获取适当的值,这样 conanfile.py 源文件也会有效:

 import osfrom conans import ConanFile, CMake, toolsdef get_remote_url():""" Get remote url regardless of the cloned directory """here = os.path.dirname(__file__)svn = tools.SVN(here)return svn.get_remote_url()class HelloConan(ConanFile):scm = {"type": "svn","subfolder": "hello","url": get_remote_url(),"revision": "auto"}...

Tip
When doing a conan create or conan export, Conan will capture the sources of the local scm project folder in the local cache.
在创建或导出 Conan 时,Conan 会在本地缓存中捕获本地 scm 项目文件夹的源代码。

This allows building packages making changes to the source code without the need of committing them and pushing them to the remote repository. This convenient to speed up the development of your packages when cloning from a local repository.
这允许在构建软件包时修改源代码,而无需提交并推送到远程版本库。当从本地版本库克隆软件包时,这可以加快软件包的开发速度。

So, if you are using the scm feature, with some auto field for url and/or revision and you have uncommitted changes in your repository a warning message will be printed:
因此,如果您使用 scm 功能,并自动输入网址和/或修订版本,而版本库中有未提交的更改,则会打印一条警告信息:

$ conan export . hello/0.1@demo/testinghello/0.1@demo/testing: WARN: There are uncommitted changes, skipping the replacement of 'scm.url'and 'scm.revision' auto fields. Use --ignore-dirty to force it.The 'conan upload' command will prevent uploading recipes with 'auto' values in these fields.

As the warning message explains, the auto fields won’t be replaced unless you specify --ignore-dirty, and by default, the conan upload will block the upload of the recipe. This prevents recipes to be uploaded with incorrect scm values exported. You can use conan upload --force to force uploading the recipe with the auto values un-replaced.
正如警告信息所述,除非指定--ignore-dirty,否则自动字段不会被替换。这可以防止在上传配方时导出错误的 scm 值。你可以使用 conan upload --force 来强制上传未替换自动值的配方。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/183130.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第二十章 多线程总结

继承Thread 类 Thread 类时 java.lang 包中的一个类&#xff0c;从类中实例化的对象代表线程&#xff0c;程序员启动一个新线程需要建立 Thread 实例。 Thread 对象需要一个任务来执行&#xff0c;任务是指线程在启动时执行的工作&#xff0c;start() 方法启动线程&…

五、初识FreeRTOS之FreeRTOS的任务创建和删除

本节主要学习以下内容&#xff1a; 1&#xff0c;任务创建和删除的API函数&#xff08;熟悉&#xff09; 2&#xff0c;任务创建和删除&#xff08;动态方法&#xff09;&#xff08;掌握&#xff09; 3&#xff0c;任务创建和删除&#xff08;静态方法&#xff09;&#xf…

Spark_日期参数解析参数-spark.sql.legacy.timeParserPolicy

在Apache Spark中&#xff0c;spark.sql.legacy.timeParserPolicy是一个配置选项&#xff0c;它控制着时间和日期解析策略。此选项主要影响如何解析日期和时间字符串。 在Spark 3.0之前的版本中&#xff0c;日期和时间解析使用java.text.SimpleDateFormat&#xff0c;它在解析…

【11】Python函数专题(中)

文章目录 1. 函数的返回值1.1 一个返回值1.2 多个返回值1.3 无返回值2. 文档字符串2.2 `help()`函数3. 函数的作用域3.1 局部作用域3.2 全局作用域3.3 嵌套作用域3.4 内置作用域3.5 global关键字4. 命名空间5. 递归函数1. 函数的返回值 在Python中,定义一个函数时,可以使用r…

mongodb基本操作命令

mongodb快速搭建及使用 1.mongodb安装1.1 docker安装启动mongodb 2.mongo shell常用命令2.1 插入文档2.1.1 插入单个文档2.1.2 插入多个文档2.1.3 用脚本批量插入 2.2 查询文档 前言&#xff1a;本篇默认你是对nongodb的基础概念有了了解&#xff0c;操作是非常基础的。但是与关…

微信小程序——给按钮添加点击音效

今天来讲解一下如何给微信小程序的按钮添加点击音效 注意&#xff1a;这里的按钮不一定只是 <button>&#xff0c;也可以是一张图片&#xff0c;其实只是添加一个监听点击事件的函数而已 首先来看下按钮的定义 <button bind:tap"onInput" >点我有音效&…

C++面向对象复习笔记暨备忘录

C指针 指针作为形参 交换两个实际参数的值 #include <iostream> #include<cassert> using namespace std;int swap(int *x, int* y) {int a;a *x;*x *y;*y a;return 0; } int main() {int a 1;int b 2;swap(&a, &b);cout << a << &quo…

Metasploit框架(3), meterpreter 常用命令, sniffer流量监听, portfwd端口转发, kiwi, Mimikatz密码破解

Metasploit框架(3), meterpreter 常用命令与扩展工具 进入到 meterpreter > 提示符环境下才能执行命令 一, 常用命令 sysinfo # 系统信息 getuid # 当前用户 getprivs # 当前权限 load priv # 加载priv getsystem # 提权到系统权限 clearev # 清除系…

【开源视频联动物联网平台】为什么需要物联网网关?

在一些物联网项目中&#xff0c;物联网网关这一产品经常被涉及。那么&#xff0c;物联网网关究竟有何作用&#xff1f;具备哪些功能&#xff1f;同时&#xff0c;我们也发现有些物联网设备并不需要网关。那么&#xff0c;究竟在何时需要物联网网关呢&#xff1f; 物联网的架构…

LaTeX插入裁剪后的pdf图像

画图 VSCode Draw.io Integration插件 有数学公式的打开下面的选项&#xff1a; 导出 File -> Export -> .svg导出成svg格式的文件。然后用浏览器打开svg文件后CtrlP选择另存为PDF&#xff0c;将图片存成pdf格式。 裁剪 只要安装了TeXLive&#xff0c;就只需要在图…

LVS-NAT实验

实验前准备&#xff1a; LVS负载调度器&#xff1a;ens33&#xff1a;192.168.20.11 ens34&#xff1a;192.168.188.3 Web1节点服务器1&#xff1a;192.168.20.12 Web2节点服务器2&#xff1a;192.168.20.13 NFS服务器&#xff1a;192.168.20.14 客户端&#xff08;win11…

java线程池管理工具类

1&#xff0c;这是线程池管理工具类&#xff0c;在系统关闭时确保任务执行完毕&#xff0c;自定义线程名字&#xff0c;自定义抛弃策略默认使用了CallerRunsPolicy拒绝策略 import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue;imp…

网络数据通信—ProtoBuf实现序列化和反序列化

目录 前言 1.环境搭建 2. centos下编写的注意事项 3.约定双端交互接口 4.约定双端交互req/resp 5. 客户端代码实现 6.服务端代码实现 前言 Protobuf还常用于通讯协议、服务端数据交换场景。那么在这个示例中&#xff0c;我们将实现一个网络版本的通讯录&#xff0c;模拟…

ESD静电试验方法及标准

文章目录 概述静电放电抗扰标准静电放电实验室的型式试验静电放电试验配置静电放电试验方法 静电放电等级 参考静电放电发生器&#xff08;ESD&#xff09;试验方法及标准 概述 在低湿度环境下通过摩擦使人体充电的人体在与设备接触时可能会放电&#xff0c;静电放电的后果是&…

Spring Boot 在进行依赖注入时,使用了反射机制,类加载器-启动类拓展类-应用类加载器

类加载器作用 将class文件字节码内容加载到内存中&#xff0c;并将这些静态数据转换成方法区的运行时数据结构&#xff0c;然后在堆中生成一个代表这个类的java.lang.Class对象&#xff0c;作为方法区中类数据的访问入口。能不能用通俗的语言翻译一下类加载器的作用 类加载通…

uniapp 打包的 IOS打开白屏 uniapp打包页面空白

uniapp的路由跟vue一样,有hash模式和history模式, 使用 URL 的 hash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载。 如果不想要很丑的 hash,我们可以用路由的 history 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面。…

PHP项目用docker一键部署

公司新项目依赖较多&#xff0c;扩展版本参差不一&#xff0c;搭建环境复杂缓慢&#xff0c;所以搭建了一键部署的功能。 docker-compose build 构建docker docker-compose up 更新docker docker-compose up -d 后台运行docker docker exec -it docker-php-1 /bin/bas…

00Hadoop数据仓库平台

在这里是学习大数据的第一站 什么是数据仓库常见大数据平台组件及介绍 什么是数据仓库 在计算领域&#xff0c;数据仓库&#xff08;DW 或 DWH&#xff09;也称为企业数据仓库&#xff08;EDW&#xff09;&#xff0c;是一种用于报告和数据分析的系统&#xff0c;被认为是商业智…

Vite 了解

1、vite 与 create-vite 的区别 2、vite 解决的部分问题 3、vite配置文件的细节 3.1、vite语法提示配置 3.2、环境的处理 3.3、环境变量 上图补充 使用 3.4、vite 识别&#xff0c;vue文件的原理 简单概括就是&#xff0c;我们在运行 npm润dev 的时候&#xff0c;vite 会搭起…

hugging face下载dataset时候出现You must be authenticated to access it.问题解决

Cannot access gated repo for url https://huggingface.co/tiiuae/falcon-180B/resolve/main/tokenizer_config.json. Repo model tiiuae/falcon-180B is gated. You must be authenticated to access it. 参考https://huggingface.co/docs/huggingface_hub/guides/download …