規則
sh_binary
查看規則來源sh_binary(name, deps, srcs, data, args, aspect_hints, compatible_with, deprecation, env, env_inherit, exec_compatible_with, exec_group_compatible_with, exec_properties, features, output_licenses, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, use_bash_launcher, visibility)
  sh_binary 規則用於宣告可執行的殼層指令碼。
  (sh_binary 是誤稱,因為輸出內容不一定是二進位檔)。這項規則可確保所有依附元件都已建構,並在執行階段顯示在 runfiles 區域中。建議您以指令碼名稱 (不含副檔名) 為 sh_binary() 規則命名 (例如 .sh),規則名稱和檔案名稱不得相同。sh_binary 會遵守 Shebang,因此可以使用任何可用的直譯器 (例如 #!/bin/zsh)
範例
如要建立簡單的 Shell 指令碼 (沒有任何依附元件) 和一些資料檔案,請執行下列操作:
sh_binary(
    name = "foo",
    srcs = ["foo.sh"],
    data = glob(["datafiles/*.txt"]),
)
引數
| 屬性 | |
|---|---|
name | 
        
           名稱:必填 這個目標的專屬名稱。  | 
      
          deps
         | 
        
                     標籤清單;預設值為  deps
有關大多數建構規則定義的典型屬性的一般註解。
  這個屬性應列出其他   | 
      
          srcs
         | 
        
                     標籤清單;預設值為  
  這項屬性必須是單例清單,其元素為殼層指令碼。
  這個指令碼必須可執行,且可以是來源檔案或產生的檔案。
  執行階段所需的所有其他檔案 (無論是指令碼或資料) 都屬於   | 
      
          env_inherit
         | 
        
                     字串清單;預設值為   | 
      
          use_bash_launcher
         | 
        
                     布林值;預設值為   | 
      
sh_library
查看規則來源sh_library(name, deps, srcs, data, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, 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
         | 
        
                     標籤清單;預設值為  
  這項屬性用於列出屬於這個程式庫的 Shell 指令碼來源檔案。指令碼可以使用殼層的   | 
      
sh_test
查看規則來源sh_test(name, deps, srcs, data, args, aspect_hints, compatible_with, deprecation, env, env_inherit, exec_compatible_with, exec_group_compatible_with, exec_properties, features, flaky, local, package_metadata, restricted_to, shard_count, size, tags, target_compatible_with, testonly, timeout, toolchains, use_bash_launcher, 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
         | 
        
                     標籤清單;預設值為  
  這項屬性必須是單例清單,其元素為殼層指令碼。
  這個指令碼必須可執行,且可以是來源檔案或產生的檔案。
  執行階段所需的所有其他檔案 (無論是指令碼或資料) 都屬於   | 
      
          use_bash_launcher
         | 
        
                     布林值;預設值為   |