Powershell rules

Rules

Providers

pwsh_binary

load("@rules_powershell//powershell:defs.bzl", "pwsh_binary")

pwsh_binary(name, deps, srcs, data, env)

The pwsh_binary rule is used to declare executable powershell scripts. (pwsh_binary is a misnomer: its outputs aren't necessarily binaries.) This rule ensures that all dependencies are built, and appear in the runfiles area at execution time. We recommend that you name your pwsh_binary() rules after the name of the script minus the extension (e.g. .ps1); the rule name and the file name must be distinct.

For a simple Powershell script with no dependencies and some data files:

pwsh_binary(
    name = "foo",
    srcs = ["foo.ps1"],
    data = glob(["datafiles/*.txt"]),
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules.

This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target.
List of labelsoptional[]
srcsThe list of source (.ps1) files that are processed to create the target.List of labelsoptional[]
dataFiles needed by this rule at runtime. May list file or rule targets. Generally allows any target.List of labelsoptional[]
envDictionary of strings; values are subject to $(location) and "Make variable" substitution.Dictionary: String -> Stringoptional{}

pwsh_library

load("@rules_powershell//powershell:defs.bzl", "pwsh_library")

pwsh_library(name, deps, srcs, data)

The main use for this rule is to aggregate together a logical "library" consisting of related scripts and modules.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules.

This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target.
List of labelsoptional[]
srcsThe list of source files that are processed to create the target.List of labelsoptional[]
dataFiles needed by this rule at runtime. May list file or rule targets. Generally allows any target.List of labelsoptional[]

pwsh_test

load("@rules_powershell//powershell:defs.bzl", "pwsh_test")

pwsh_test(name, deps, srcs, data, env, env_inherit)

A pwsh_test rule creates a test written as a Powershell script.

pwsh_test(
    name = "foo_integration_test",
    size = "small",
    srcs = ["foo_integration_test.ps1"],
    deps = [":foo_sh_lib"],
    data = glob(["testdata/*.txt"]),
)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsThe list of "library" targets to be aggregated into this target. See general comments about deps at Typical attributes defined by most build rules.

This attribute should be used to list other sh_library rules that provide interpreted program source code depended on by the code in srcs. The files provided by these rules will be present among the runfiles of this target.
List of labelsoptional[]
srcsThe list of source (.ps1) files that are processed to create the target.List of labelsoptional[]
dataFiles needed by this rule at runtime. May list file or rule targets. Generally allows any target.List of labelsoptional[]
envDictionary of strings; values are subject to $(location) and "Make variable" substitution.Dictionary: String -> Stringoptional{}
env_inheritSpecifies additional environment variables to inherit from the external environment when the test is executed by bazel test.List of stringsoptional[]

PwshInfo

load("@rules_powershell//powershell:defs.bzl", "PwshInfo")

PwshInfo(imports, srcs)

A provider for Powershell rules.

FIELDS

NameDescription
importsDepset[str]: The list of rlocation paths to module files (.psm1, .psd1) for PSModulePath setup.
srcsDepset[File]: The list of source files associated with the powershell target.