utils 存放區規則

回報問題 查看來源 Nightly · 8.3 · 8.2 · 8.1 · 8.0 · 7.6

您可以從 @bazel_tools//tools/build_defs/repo:utils.bzl 載入下列函式。

用於操控外部存放區的公用程式 (擷取後)。

設定

這些公用程式適用於其他存放區規則。載入方式如下。

load(
    "@bazel_tools//tools/build_defs/repo:utils.bzl",
    "workspace_and_buildfile",
    "patch",
    "update_attrs",
)

download_remote_files

load("@bazel//tools/build_defs/repo:utils.bzl", "download_remote_files")

download_remote_files(ctx, auth)

用於下載遠端檔案的公用函式。

這項規則適用於存放區規則的實作函式。並假設 ctx.attr 中存在 remote_file_urlsremote_file_integrity 參數。

參數

ctx 必要。

呼叫這個公用程式函式的存放區規則存放區內容。

auth 選用。 預設值為 None

選用字典,指定部分網址的驗證資訊。

get_auth

load("@bazel//tools/build_defs/repo:utils.bzl", "get_auth")

get_auth(ctx, urls)

公用程式函式,可從 .netrc 檔案取得網址清單的正確授權字典。

支援選填的 netrc 和 auth_patterns 屬性 (如有)。

參數

ctx 必要。

呼叫這個公用程式函式的存放區規則存放區內容。

urls 必要。

要讀取的網址清單

傳回

可傳遞至 repository_ctx.download 的驗證字典

也許

load("@bazel//tools/build_defs/repo:utils.bzl", "maybe")

maybe(repo_rule, name, **kwargs)

公用函式,僅在存放區尚未存在時新增存放區。

這是為了實作 https://bazel.build/rules/deploying#dependencies 中記錄的安全 repositories.bzl 巨集。

參數

repo_rule 必要。

存放區規則函式。

name 必要。

要建立的存放區名稱。

kwargs 選用。

傳遞至 repo_rule 函式的其餘引數。

傳回

無,視需要定義存放區做為附帶影響。

parse_netrc

load("@bazel//tools/build_defs/repo:utils.bzl", "parse_netrc")

parse_netrc(contents, filename)

用來剖析至少基本 .netrc 檔案的公用程式函式。

參數

contents 必要。

剖析器的輸入內容。

filename 選用。 預設值為 "a .netrc file"

錯誤訊息中使用的檔案名稱 (如有)。

傳回

字典,將機器名稱對應至包含相關資訊的字典

patch

load("@bazel//tools/build_defs/repo:utils.bzl", "patch")

patch(ctx, patches, patch_cmds, patch_cmds_win, patch_tool, patch_args, auth)

實作修補已擷取的存放區。

這項規則適用於存放區規則的實作函式。如果未指定 patchespatch_toolpatch_argspatch_cmdspatch_cmds_win 參數,系統會從 ctx.attr 取得這些參數。

參數

ctx 必要。

呼叫這個公用程式函式的存放區規則存放區內容。

patches 選用。 預設值為 None

要套用的修補程式檔案。字串、標籤或路徑清單。

patch_cmds 選用。 預設值為 None

要執行的修補 Bash 指令,一次傳遞一個指令給 bash -c。字串清單

patch_cmds_win 選用。 預設值為 None

要執行的修補程式 Powershell 指令,一次傳遞一個指令至 powershell /c。字串清單。如果這個參數的布林值為 false,系統會使用 patch_cmds,並忽略這個參數。

patch_tool 選用。 預設值為 None

要執行的修補工具路徑,用於套用修補程式。字串。

patch_args 選用。 預設值為 None

要傳遞至修補程式工具的引數。字串清單。

auth 選用。 預設值為 None

選用字典,指定部分網址的驗證資訊。

read_netrc

load("@bazel//tools/build_defs/repo:utils.bzl", "read_netrc")

read_netrc(ctx, filename)

用來剖析至少基本 .netrc 檔案的公用程式函式。

參數

ctx 必要。

呼叫這個公用程式函式的存放區規則存放區內容。

filename 必要。

要讀取的 .netrc 檔案名稱

傳回

字典,將機器名稱對應至包含相關資訊的字典

read_user_netrc

load("@bazel//tools/build_defs/repo:utils.bzl", "read_user_netrc")

read_user_netrc(ctx)

讀取使用者的預設 .netrc 檔案。

參數

ctx 必要。

呼叫這個公用程式函式的存放區規則的存放區環境。

傳回

字典,將機器名稱對應至包含機器相關資訊的字典。

update_attrs

load("@bazel//tools/build_defs/repo:utils.bzl", "update_attrs")

update_attrs(orig, keys, override)

公用函式,用於變更特定存放區規則調用中的指定屬性,以及新增這些屬性。

這項功能可用於重現規則。

參數

orig 必要。

實際設定的屬性字典 (明確或隱含),由特定規則呼叫

keys 必要。

這項規則定義的完整屬性集

override 必要。

要覆寫或新增至原始值的屬性字典

傳回

屬性字典,其中包含插入/更新的覆寫鍵

use_netrc

load("@bazel//tools/build_defs/repo:utils.bzl", "use_netrc")

use_netrc(netrc, urls, patterns)

從已剖析的 netrc 檔案和網址清單計算授權字典。

參數

netrc 必要。

已剖析為 dict 的 netrc 檔案,例如從 read_netrc 取得的檔案

urls 必要。

網址清單。

patterns 必要。

網址至授權模式的選用字典

傳回

適合做為 ctx.download 的驗證引數的 dict;更精確地說,dict 會將 netrc 檔案提供登入和密碼的所有網址,對應至包含相應登入、密碼和選用授權模式的 dict,以及「type」對應至「basic」或「pattern」的對應。

workspace_and_buildfile

load("@bazel//tools/build_defs/repo:utils.bzl", "workspace_and_buildfile")

workspace_and_buildfile(ctx)

用於寫入 BUILD 檔案的公用程式函式。

這項規則適用於存放區規則的實作函式。並假設 ctx.attr 中存在 namebuild_filebuild_file_content 參數,後兩者可能沒有值。

參數

ctx 必要。

呼叫這個公用程式函式的存放區規則存放區內容。