規則
sh_binary
查看規則來源sh_binary(name, deps, srcs, data, args, compatible_with, deprecation, distribs, env, exec_compatible_with, exec_properties, features, licenses, output_licenses, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
sh_binary
規則是用來宣告可執行的殼層指令碼。(sh_binary
容易造成錯誤:其輸出結果不一定是二進位檔)。這項規則可確保所有依附元件都已建構,並在執行時顯示在 runfiles
區域中。建議您將指令碼命名為 sh_binary()
,並以指令碼名稱減去副檔名 (例如 .sh
);規則名稱和檔案名稱不得重複。sh_binary
會遵循檔案櫃,因此您也可以使用任何可用的解譯器 (例如,#!/bin/zsh
)
範例
針對沒有依附元件和部分資料檔案的簡易殼層指令碼:
sh_binary( name = "foo", srcs = ["foo.sh"], data = glob(["datafiles/*.txt"]), )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
deps
|
deps 的一般評論。
此屬性應用於列出其他 |
srcs
|
這個屬性必須是單例清單,其元素是殼層指令碼。這個指令碼必須是執行檔,而且可能是來源檔案或產生的檔案。執行階段所需的所有其他檔案 (指令碼或資料) 都屬於 |
sh_library
查看規則來源sh_library(name, deps, srcs, data, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, licenses, restricted_to, tags, target_compatible_with, testonly, visibility)
這項規則的主要用途是彙整一個邏輯「資料庫」,其中包含相關指令碼,也就是需要編譯或連結且可編譯或連結連結的程式,例如 Bourne shell,以及這些程式在執行階段所需的所有資料。接著,您可以透過一或多個 sh_binary
規則的 data
屬性使用這類「程式庫」。
您可以使用 filegroup
規則來匯總資料檔案。
在解譯的程式設計語言中,「程式碼」和「資料」之間並沒有明顯的差別:畢竟,程式與解譯器的觀點只是「資料」,因此,這項規則有三個屬性,基本上都是相同的:srcs
、deps
和 data
。目前的實作不會區分這些清單中的元素。這三項屬性都接受規則、來源檔案和產生的檔案。但我們建議將屬性用於一般用途 (就像其他規則一樣)。
範例
sh_library( name = "foo", data = [ ":foo_service_script", # an sh_binary with srcs ":deploy_foo", # another sh_binary with srcs ], )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
deps
|
deps 的一般評論。
此屬性應用於列出其他 |
srcs
|
這項屬性應用來列出屬於這個程式庫的殼層指令碼來源檔案。指令碼可透過殼層的 |
sh_test
查看規則來源sh_test(name, deps, srcs, data, args, compatible_with, deprecation, distribs, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, licenses, local, restricted_to, shard_count, size, tags, target_compatible_with, testonly, timeout, toolchains, visibility)
sh_test()
規則會建立以 Bourne 殼層指令碼編寫的測試。
範例
sh_test( name = "foo_integration_test", size = "small", srcs = ["foo_integration_test.sh"], deps = [":foo_sh_lib"], data = glob(["testdata/*.txt"]), )
引數
屬性 | |
---|---|
name |
此目標的專屬名稱。 |
deps
|
deps 的一般評論。
此屬性應用於列出其他 |
srcs
|
這個屬性必須是單例清單,其元素是殼層指令碼。這個指令碼必須是執行檔,而且可能是來源檔案或產生的檔案。執行階段所需的所有其他檔案 (指令碼或資料) 都屬於 |