在 Bitbake 配置中使用 PREMIRRORS [英] Using PREMIRRORS in Bitbake configuration

查看:28
本文介绍了在 Bitbake 配置中使用 PREMIRRORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Bitbake 本地配置或配方中使用 PREMIRRORS?

How do I use PREMIRRORS in Bitbake local configurations or recipes?

我想为一些缓慢或无法访问的第三方 URL 提供我自己的下载位置,但 官方PREMIRRORS 文档 含糊不清,缺少示例.

I want to provide my own download locations for some slow or inaccessible third-party URLs, but the official PREMIRRORS documentation is vague and lacks examples.

推荐答案

注意:这些结果基于 Yocto 2.3 的实验,但可能也适用于 2.5.

Note: These results are based on experimentation with Yocto 2.3, but probably apply to 2.5 as well.

假设您的配方文件包含此目标网址:

Suppose that your recipe file contains this target URL:

SRC_URI = "http://download.example.com:8080/foo/bar/baz-1.0.tar.gz"

然后在您的 local.conf 中,您可以将自定义下载位置定义为:

Then in your local.conf, you can define your custom download location as:

PREMIRRORS_prepend = "http://download\.example\.com:8080/.* http://my-mirror.example.com/copies/\n"

在这种默认情况下(没有特殊占位符)Bitbake 包含额外的 /foo/bar 路径元素,而是尝试仅从 <代码>http://my-mirror.example.com/copies/baz-1.0.tar.gz

In this default case (with no special placeholders) Bitbake does not include the additional /foo/bar path elements, and instead tries to download just the filename from http://my-mirror.example.com/copies/baz-1.0.tar.gz

这些示例使用特殊的预定义占位符,下一节将详细介绍.

These samples use special predefined placeholders, which are detailed in the next section.

  • 食谱:SRC_URI = "https://example.com:1234/foo/bar.zip"
  • 设置:PREMIRRORS_prepend = "http(s)?://example\.com(:\d+)?/.* http://mirror.local/PATH\n"
  • 尝试:http://mirror.local/foo/bar.zip
  • 食谱:SRC_URI = "https://example.com:1234/foo/bar.zip"
  • 设置:PREMIRRORS_prepend = "http(s)?://example\.com(:\d+)?/.* http://mirror.local/MIRRORNAME\n"
  • 尝试:http://mirror.local/example.com.1234.foo.bar.zip
  • 配方:SRC_URI = "ftp://example.com:1234/foo/bar.zip"
  • 设置:PREMIRRORS_prepend = "(\w+)://example\.com(:\d+)?/.* TYPE://mirror.local/PATH\n"
  • 尝试:ftp://mirrors.local/foo/bar.zip

PREMIRRORS 解析所有匹配的 URI 并在目标 URI 中提供五个特殊的占位符值.假设匹配的URI是http://host.example.com:1234/foo/bar/baz.txt:

PREMIRRORS parses all matched URIs and provides five special placeholder values in the target URI. Supposing the matched URI is http://host.example.com:1234/foo/bar/baz.txt:

TYPE          https
HOST          host.example.com%3A1234
PATH          foo/bar/baz.txt
BASENAME      baz.txt
MIRRORNAME    host.example.com.1234.foo.bar.baz.txt

改变PREMIRRORS变量

PREMIRRORS 变量由一系列行(由 \n 分隔)组成,每行都有一个匹配 URI 的正则表达式,然后是一个替换字符串,包含两个部分用空格隔开.

Altering the PREMIRRORS variable

The PREMIRRORS variable consists of series of lines (separated by \n) each with a regular expression to match a URI, and then a replacement string, with both portions separated by a space.

Bitbake 按出现的顺序尝试它们,并且您通常希望您的私人镜像优先,所以在 PREMIRRORS 前加上,例如:

Bitbake tries them in order of appearance, and you generally want your private mirrors to take priority, so prepend onto PREMIRRORS, ex:

PREMIRRORS_prepend = "http://original/location/.* http://alternate/location/\n"

我应该编辑什么文件?

您可以在 bitbake 食谱中向 PREMIRRORS 添加条目,但不建议这样做,因为 PREMIRRORS 的主要用途是让人们在其他情况下重用您的食谱或位置.

What file should I edit?

You can add entries to PREMIRRORS inside your bitbake recipes, but it is not recommended, since a major use of PREMIRRORS is for people reusing your recipe in some other context or location.

相反,您可以将其放入您的 local.conf 文件位于现有构建目录中.或者,编辑 Poky 脚本在新构建目录中创建新 local.conf 时使用的源模板.

Instead, you can put it inside your local.conf file in an existing build directory. Alternately, edit the source template which Poky script use when creating a new local.conf in a fresh build-directory.

SOURCE_MIRROR_URL 是为所有支持的协议添加一系列 PREMIRROR 条目的快速方法.例如,这个设置:

The SOURCE_MIRROR_URL is a quick way to add a series of PREMIRROR entries for all supported protocols. For example, this setting:

INHERIT += "own-mirrors"    
SOURCE_MIRROR_URL = "TYPE://mirror.local/PATH"

与写作相同:

PREMIRRORS_prepend = "\
cvs://.*/.*     TYPE://mirror.local/PATH \
svn://.*/.*     TYPE://mirror.local/PATH \
git://.*/.*     TYPE://mirror.local/PATH \
gitsm://.*/.*   TYPE://mirror.local/PATH \
hg://.*/.*      TYPE://mirror.local/PATH \ 
bzr://.*/.*     TYPE://mirror.local/PATH \
p4://.*/.*      TYPE://mirror.local/PATH \
osc://.*/.*     TYPE://mirror.local/PATH \ 
https?$://.*/.* TYPE://mirror.local/PATH \
ftp://.*/.*     TYPE://mirror.local/PATH \
npm://.*/?.*    TYPE://mirror.local/PATH \
"

如果在您的 local.conf 中使用 INHERIT+SOURCE_MIRROR_URL 指令似乎仍然有效(而不是特定配方.)但是,Bitbake 会发出警告,因此它可能不是预期的用例.例如:

It seems the INHERIT+SOURCE_MIRROR_URL directives will still work if used in your local.conf (as opposed to a particular recipe.) However, Bitbake will emit warnings, so it may not be the intended use-case. Ex:

WARNING: Invalid protocol in PREMIRRORS: ('cvs://.*/.*', 'TYPE://mirror.local/PATH')

如何检查和调试我的设置?

-D 调试标志将导致 bitbake 发出有关它尝试从哪些 URL 下载的信息.您还可以使用 -C do_fetch,这将强制它尝试获取步骤并重新下载给定配方所需的任何内容.

How can I check and debug my settings?

The -D debug flag will cause bitbake to emit information about what URLs it attempts to download from. You can also use -C do_fetch, which will force it to try the fetch step and re-download anything needed for the given recipe.

bitbake -D -C do_fetch software-recipe-name-here

以下是一些调试输出示例,显示了它尝试访问的 PREMIRROR URL:

Here's some example debug output, showing the PREMIRROR URL it attempts to access:

DEBUG: some-software-1.0 do_fetch: Trying PREMIRRORS
DEBUG: some-software-1.0 do_fetch: Fetcher accessed the network with the command /usr/bin/env wget -t 2 -T 30 -nv --passive-ftp --no-check-certificate -P /home/user/build_foo/DL_DIR 'http://mirror.local/path/to/the/filename.ext

如果您需要多次试验和运行 bitbake,将新的 PREMIRRORS_prepend 指令临时放入特定的测试配方中会更快,而不是修改local.conf.这是因为无论何时更改 Bitbake 都不需要重新解析所有其他配方.

If you need to experiment and run bitbake many times, it will be faster to temporarily put your new PREMIRRORS_prepend directive into a particular test-recipe, as opposed to modifying the local.conf. This is because Bitbake won't need to re-parse all the other recipes whenever you change it.

显然没有简单的方法可以自行获得 123.虽然 PREMIRRORS 允许您使用正则表达式匹配,但它似乎不支持在替换 URI 中使用匹配项中的捕获文本.

Apparently there's no easy way to get the 123 on its own. While PREMIRRORS allows you to match with regular expressions, it does not seem to support using captured text from the match inside the replacement URI.

端口号存在于 HOSTMIRRORNAME 中,但没有标准机制将这些值分开.

The port number is present inside HOST and MIRRORNAME, but there's no standard mechanism to split those values apart.

这篇关于在 Bitbake 配置中使用 PREMIRRORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆