conanfile.py-Methods-source()/build()/package()

本文是基于对conan官方文档source()build()package()翻译而来, 更详细的信息可以去查阅conan官方文档。

1 source()

Method used to retrieve the source code from any other external origin like github using $ git clone or just a regular download.
用于从其他外部来源获取源代码的方法,例如使用 $ git clone 从 github 获取源代码,或直接下载。

For example, “exporting” the source code files, together with the conanfile.py file, can be handy if the source code is not under version control. But if the source code is available in a repository, you can directly get it from there:
例如,如果源代码不在版本控制之下,"exporting "源代码文件和 conanfile.py 文件会很方便。但如果源代码在版本控制库中,则可以直接从版本控制库中获取:

from conans import ConanFile

class HelloConan(ConanFile):
    name = "hello"
    version = "0.1"
    settings = "os", "compiler", "build_type", "arch"

    def source(self):
        self.run("git clone https://github.com/conan-io/hello.git")
        # You can also change branch, commit or whatever
        # self.run("cd hello && git checkout 2fe5...")
        #
        # Or using the Git class:
        # git = tools.Git(folder="hello")
        # git.clone("https://github.com/conan-io/hello.git")

The current working directory where the source() method runs is the self.source_folder. Note, however, that this folder can be different if the recipe defines the layout() method and specifies a self.folders.source = "src". In that case, the self.source_folder and the current working directory will be the composition of the base folder (typically where the recipe is) and the user specified "src" subfolder.
运行 source() 方法的当前工作目录是 self.source_folder 文件夹。但请注意,如果配方定义了 layout() 方法并指定了 self.folders.source = "src",则该文件夹可以不同。在这种情况下,self.source_folder 和当前工作目录将由基本文件夹(通常是配方所在的文件夹)和用户指定的"src" 子文件夹组成。

This will work, as long as git is in your current path (so in Win you probably want to run things in msysgit, cmder, etc). You can also use another VCS or direct download/unzip. For that purpose, we have provided some helpers, but you can use your own code or origin as well. This is a snippet of the conanfile of the Poco library:
只要 git 在您的当前路径中(因此在 Win 中,您可能希望在 msysgit、cmder 等中运行),这样就可以了。您也可以使用其他 VCS 或直接下载/解压。为此,我们提供了一些辅助工具,但你也可以使用自己的代码或源代码。这是 Poco 库的 conanfile 片段:

from conans import ConanFile
from conans.tools import download, unzip, check_md5, check_sha1, check_sha256
import os
import shutil

class PocoConan(ConanFile):
    name = "poco"
    version = "1.6.0"

    def source(self):
        zip_name = "poco-1.6.0-release.zip"
        download("https://github.com/pocoproject/poco/archive/poco-1.6.0-release.zip", zip_name)
        # check_md5(zip_name, "51e11f2c02a36689d6ed655b6fff9ec9")
        # check_sha1(zip_name, "8d87812ce591ced8ce3a022beec1df1c8b2fac87")
        # check_sha256(zip_name, "653f983c30974d292de58444626884bee84a2731989ff5a336b93a0fef168d79")
        unzip(zip_name)
        shutil.move("poco-poco-1.6.0-release", "poco")
        os.unlink(zip_name)

The download, unzip utilities can be imported from conan, but you can also use your own code here to retrieve source code from any origin. You can even create packages for pre-compiled libraries you already have, even if you don’t have the source code. You can download the binaries, skip the build() method and define your package() and package_info() accordingly.
下载和解压缩工具可以从 Conan 中导入,但也可以使用自己的代码从任何来源获取源代码。即使没有源代码,你也可以为已有的预编译库创建软件包。你可以下载二进制文件,跳过build()方法,并相应地定义你的package()package_info()

You can also use check_md5(), check_sha1() and check_sha256() from the tools module to verify that a package is downloaded correctly.
您还可以使用工具模块中的 check_md5()check_sha1()check_sha256(),验证软件包是否已正确下载。

It is very important to recall that the source() method will be executed just once, and the source code will be shared for all the package builds. So it is not a good idea to conditionally use settings or options to make changes or patches on the source code. Maybe the only setting that makes sense is the OS self.settings.os, if not doing cross-building, for example to retrieve different sources:
请记住,source() 方法只执行一次,源代码将在所有软件包的构建过程中共享,这一点非常重要。因此,有条件地使用设置或选项对源代码进行修改或打补丁并不是一个好主意。如果不进行交叉编译,例如检索不同的源代码,也许唯一有意义的设置就是操作系统的 self.settings.os

def source(self):
    if platform.system() == "Windows":
        # download some Win source zip
    else:
        # download sources from Nix systems in a tgz

If you need to patch the source code or build scripts differently for different variants of your packages, you can do it in the build() method, which uses a different folder and source code copy for each variant.
如果需要为软件包的不同变体打上不同的源代码补丁或构建脚本,可以在 build() 方法中进行,该方法会为每个变体使用不同的文件夹和源代码副本。

def build(self):
    tools.patch(patch_file="0001-fix.patch")

2 build()

This method is used to build the source code of the recipe using the desired commands. You can use your command line tools to invoke your build system or any of the build helpers provided with Conan.
此方法用于使用所需的命令构建配方的源代码。您可以使用命令行工具调用您的构建系统或 Conan 提供的任何构建助手。

def build(self):
    cmake = CMake(self)
    self.run("cmake . %s" % (cmake.command_line))
    self.run("cmake --build . %s" % cmake.build_config)

2.1 Build helpers

You can use these classes to prepare your build system’s command invocation:
您可以使用这些类来准备构建系统的命令调用:

  • CMake: Prepares the invocation of cmake command with your settings.
  • CMake: 根据您的设置准备调用 cmake 命令。
  • AutoToolsBuildEnvironment: If you are using configure/Makefile to build your project you can use this helper. Read more: Building with Autotools.
  • 自动工具构建环境: 如果使用 configure/Makefile 来构建项目,则可以使用此辅助工具。了解更多: 使用 Autotools 构建
  • MSBuild: If you are using Visual Studio compiler directly to build your project you can use this helper MSBuild(). For lower level control, the VisualStudioBuildEnvironment can also be used: VisualStudioBuildEnvironment.
  • MSBuild: 如果直接使用 Visual Studio 编译器来构建项目,则可以使用 MSBuild() 这个辅助工具。对于较低级别的控制,也可以使用 VisualStudioBuildEnvironment: VisualStudioBuildEnvironment.

2.2 (Unit) Testing your library

We have seen how to run package tests with conan, but what if we want to run full unit tests on our library before packaging, so that they are run for every build configuration? Nothing special is required here. We can just launch the tests from the last command in our build() method:
我们已经了解了如何使用 conan 运行打包测试,但如果我们想在打包之前对库运行完整的单元测试,以便在每次构建配置时都运行这些测试,该怎么办呢?这里不需要什么特别的东西。我们只需在 build() 方法的最后一条命令中启动测试即可:

def build(self):
    cmake = CMake(self)
    cmake.configure()
    cmake.build()
    # here you can run CTest, launch your binaries, etc
    cmake.test()

3 package()

The actual creation of the package, once that it is built, is done in the package() method. Using the self.copy() method, artifacts are copied from the build folder to the package folder.
软件包构建完成后,软件包的实际创建将在 package() 方法中完成。使用 self.copy() 方法,工件会从构建文件夹复制到package文件夹。

The syntax of self.copy inside package() is as follows:
package() 中的 self.copy 语法如下:

self.copy(pattern, dst="", src="", keep_path=True, symlinks=None, excludes=None, ignore_case=True)

Returns: A list with absolute paths of the files copied in the destination folder.
返回值 包含目标文件夹中已复制文件绝对路径的列表。

Parameters:

  • pattern (Required): A pattern following fnmatch syntax of the files you want to copy, from the build to the package folders. Typically something like *.lib or *.h.
  • pattern(必须项): 要从构建文件夹复制到软件包文件夹的文件的 fnmatch 语法模式。通常为 *.lib*.h
  • src (Optional, Defaulted to ""): The folder where you want to search the files in the build folder. If you know that your libraries when you build your package will be in build/lib, you will typically use build/lib in this parameter. Leaving it empty means the root build folder in local cache.
  • src(可选项,默认为""): 您要在联编文件夹中搜索文件的文件夹。如果你知道在构建软件包时你的库将在 build/lib 中,通常会在此参数中使用 build/lib。留空表示使用本地缓存中的根编译文件夹。
  • dst (Optional, Defaulted to ""): Destination folder in the package. They will typically be include for headers, lib for libraries and so on, though you can use any convention you like. Leaving it empty means the root package folder in local cache.
  • dst(可选项,默认为""): 软件包中的目标文件夹。通常情况下,头文件文件夹为 include,库文件夹为 lib,等等,但也可以使用任何你喜欢的约定。留空表示本地缓存中的软件包根文件夹。
  • keep_path (Optional, Defaulted to True): Means if you want to keep the relative path when you copy the files from the src folder to the dst one. Typically headers are packaged with relative path.
  • keep_path(可选项,默认为 “True”): 表示在将文件从源文件夹复制到dst文件夹时,是否要保留相对路径。通常情况下,头文件会与相对路径一起打包。
  • symlinks (Optional, Defaulted to None): Set it to True to activate symlink copying, like typical lib.so->lib.so.9.
  • symlinks(可选项,默认为None): 设为 True 可激活符号软连接复制,如典型的 lib.so->lib.so.9
  • excludes (Optional, Defaulted to None): Single pattern or a tuple of patterns to be excluded from the copy. If a file matches both the include and the exclude pattern, it will be excluded.
  • excludes(可选项,默认为“None”):要从副本中排除的单个模式或模式元组。如果一个文件同时匹配包含和排除模式,它将被排除。
  • ignore_case (Optional, Defaulted to True): If enabled, it will do a case-insensitive pattern matching.
  • ignore_case(可选项,默认为 True): 如果启用,将进行不区分大小写的模式匹配。

For example:
例如:

self.copy("*.h", "include", "build/include") #keep_path default is True

The final path in the package will be: include/mylib/path/header.h, and as the include is usually added to the path, the includes will be in the form: #include "mylib/path/header.h" which is something desired.
软件包的最终路径将是 include/mylib/path/header.h,而由于 include 通常会添加到路径中,因此 includes 的形式将是 "#include “mylib/path/header.h”: 由于 include 通常会添加到路径中,因此包含的形式将是:#include "mylib/path/header.h",这也是我们所希望的。

keep_path=False is something typically desired for libraries, both static and dynamic. Some compilers as MSVC, put them in paths as Debug/x64/MyLib/Mylib.lib. Using this option, we could write:
keep_path=False 通常是静态和动态库所需要的。有些编译器(如 MSVC)会将它们放在 Debug/x64/MyLib/Mylib.lib 这样的路径下。使用该选项,我们可以编写。

self.copy("*.lib", "lib", "", keep_path=False)

And it will copy the lib to the package folder lib/Mylib.lib, which can be linked easily.
它将把库复制到软件包文件夹 lib/Mylib.lib,这样就可以轻松链接。

If you are using CMake and you have an install target defined in your CMakeLists.txt, you might be able to reuse it for this package() method. Please check How to reuse cmake install for package() method.
如果您使用的是 CMake,并且在 CMakeLists.txt 中定义了安装目标,您或许可以将其用于此 package() 方法。请查看 如何为 package() 方法重用 cmake install

This method copies files from build/source folder to the package folder depending on two situations:
这种方法会根据两种情况将文件从 build/source 文件夹复制到 package 文件夹:

  • Build folder and source folder are the same: Normally during conan create source folder content is copied to the build folder. In this situation src parameter of self.copy() will be relative to the build folder in the local cache.

  • 构建文件夹和源代码文件夹是相同的: 通常在conan create 时,源文件夹的内容会被复制到联编文件夹。在这种情况下,self.copy()src参数将相对于本地缓存中的联编文件夹。

  • Build folder is different from source folder: When developing a package recipe and source and build folder are different (conan package . --source-folder=source --build-folder=build) or when no_copy_source is defined, every self.copy() is internally called twice: One will copy from the source folder (src parameter of self.copy() will point to the source folder), and the other will copy from the build folder (src parameter of self.copy() will point to the build folder).

  • 编译文件夹与源代码文件夹不同: 当 developing a package recipe 源文件夹和构建文件夹不同(conan package . --source-folder=source --build-folder=build )或定义了 no_copy_source 时,每个 self.copy() 都会被内部调用两次:一次是从源文件夹复制(self.copy()src 参数将指向源文件夹),另一次是从构建文件夹复制(`self.copy() 的 src 参数将指向构建文件夹)。

  • 22
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 33
    评论
在现有省、市港口信息化系统进行有效整合基础上,借鉴新 一代的感知-传输-应用技术体系,实现对码头、船舶、货物、重 大危险源、危险货物装卸过程、航管航运等管理要素的全面感知、 有效传输和按需定制服务,为行政管理人员和相关单位及人员提 供高效的管理辅助,并为公众提供便捷、实时的水运信息服务。 建立信息整合、交换和共享机制,建立健全信息化管理支撑 体系,以及相关标准规范和安全保障体系;按照“绿色循环低碳” 交通的要求,搭建高效、弹性、高可扩展性的基于虚拟技术的信 息基础设施,支撑信息平台低成本运行,实现电子政务建设和服务模式的转变。 实现以感知港口、感知船舶、感知货物为手段,以港航智能 分析、科学决策、高效服务为目的和核心理念,构建“智慧港口”的发展体系。 结合“智慧港口”相关业务工作特点及信息化现状的实际情况,本项目具体建设目标为: 一张图(即GIS 地理信息服务平台) 在建设岸线、港口、港区、码头、泊位等港口主要基础资源图层上,建设GIS 地理信息服务平台,在此基础上依次接入和叠加规划建设、经营、安全、航管等相关业务应用专题数据,并叠 加动态数据,如 AIS/GPS/移动平台数据,逐步建成航运管理处 "一张图"。系统支持扩展框架,方便未来更多应用资源的逐步整合。 现场执法监管系统 基于港口(航管)执法基地建设规划,依托统一的执法区域 管理和数字化监控平台,通过加强对辖区内的监控,结合移动平 台,形成完整的多维路径和信息追踪,真正做到问题能发现、事态能控制、突发问题能解决。 运行监测和辅助决策系统 对区域港口与航运业务日常所需填报及监测的数据经过科 学归纳及分析,采用统一平台,消除重复的填报数据,进行企业 输入和自动录入,并进行系统智能判断,避免填入错误的数据, 输入的数据经过智能组合,自动生成各业务部门所需的数据报 表,包括字段、格式,都可以根据需要进行定制,同时满足扩展 性需要,当有新的业务监测数据表需要产生时,系统将分析新的 需求,将所需字段融合进入日常监测和决策辅助平台的统一平台中,并生成新的所需业务数据监测及决策表。 综合指挥调度系统 建设以港航应急指挥中心为枢纽,以各级管理部门和经营港 口企业为节点,快速调度、信息共享的通信网络,满足应急处置中所需要的信息采集、指挥调度和过程监控等通信保障任务。 设计思路 根据项目的建设目标和“智慧港口”信息化平台的总体框架、 设计思路、建设内容及保障措施,围绕业务协同、信息共享,充 分考虑各航运(港政)管理处内部管理的需求,平台采用“全面 整合、重点补充、突出共享、逐步完善”策略,加强重点区域或 运输通道交通基础设施、运载装备、运行环境的监测监控,完善 运行协调、应急处置通信手段,促进跨区域、跨部门信息共享和业务协同。 以“统筹协调、综合监管”为目标,以提供综合、动态、实 时、准确、实用的安全畅通和应急数据共享为核心,围绕“保畅通、抓安全、促应急"等实际需求来建设智慧港口信息化平台。 系统充分整合和利用航运管理处现有相关信息资源,以地理 信息技术、网络视频技术、互联网技术、移动通信技术、云计算 技术为支撑,结合航运管理处专网与行业数据交换平台,构建航 运管理处与各部门之间智慧、畅通、安全、高效、绿色低碳的智 慧港口信息化平台。 系统充分考虑航运管理处安全法规及安全职责今后的变化 与发展趋势,应用目前主流的、成熟的应用技术,内联外引,优势互补,使系统建设具备良好的开放性、扩展性、可维护性。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值