특히 구현 함수가 현재 타겟의 라벨, 속성, 구성, 종속 항목의 제공자에 액세스할 수 있습니다. 출력 파일과 이를 생성하는 작업을 선언하는 메서드가 있습니다.
컨텍스트 객체는 기본적으로 구현 함수 호출 기간 동안 유지됩니다. 연결된 함수 외부에서 이러한 객체에 액세스하는 것은 유용하지 않습니다. 자세한 내용은 규칙 페이지를 참고하세요.
회원
- actions
- aspect_ids
- attr
- bin_dir
- build_file_path
- build_setting_value
- 구성
- coverage_instrumented
- created_actions
- disabled_features
- exec_groups
- 실행 가능
- expand_location
- expand_make_variables
- 기능
- 파일
- 파일
- fragments
- genfiles_dir
- info_file
- label
- outputs
- package_relative_label
- resolve_command
- resolve_tools
- 규칙
- runfiles
- split_attr
- super
- target_platform_has_constraint
- 도구 모음
- var
- version_file
- workspace_name
작업
actions ctx.actions
aspect_ids
list ctx.aspect_ids
attr
struct ctx.attr
rule 함수에 제공된 attrs dict의 키와 값에 해당합니다. 사용 예시 보기
bin_dir
root ctx.bin_dir
build_file_path
string ctx.build_file_path
ctx.label.package + '/BUILD'를 사용하세요. 소스 루트를 기준으로 하는 이 규칙의 BUILD 파일 경로입니다.
build_setting_value
unknown ctx.build_setting_value
build_setting 속성을 설정하는 규칙 인스턴스의 컨텍스트가 아닌 경우 이를 읽으면 오류가 발생합니다.
구성
configuration ctx.configuration
coverage_instrumented
bool ctx.coverage_instrumented(target=None)
target가 제공된 경우 해당 타겟으로 지정된 규칙의 컴파일 작업을 실행할 때 코드 커버리지 계측을 생성해야 하는지 여부를 반환합니다. (규칙이 아닌 타겟이나 Starlark 규칙 타겟이 제공되면 False가 반환됩니다.) --instrumentation_filter 및 --instrument_test_targets 구성 설정에 따라 현재 규칙의 소스 (타겟이 제공되지 않은 경우) 또는 타겟의 소스를 계측해야 하는지 확인합니다. 이는 구성의 coverage_enabled와는 다릅니다. coverage_enabled는 전체 실행에 대해 커버리지 데이터 수집이 사용 설정되었는지 여부를 나타내지만 특정 타겟이 계측되어야 하는지 여부는 나타내지 않습니다.
매개변수
| 매개변수 | 설명 |
|---|---|
target
|
타겟 또는 None. 기본값은 None입니다. 규칙을 지정하는 타겟입니다. 제공되지 않으면 기본값은 현재 규칙입니다. |
created_actions
StarlarkValue ctx.created_actions()
True로 설정된 규칙의 경우 현재 규칙에 대해 지금까지 생성된 모든 작업을 나타내는 Actions 제공자를 반환합니다. 다른 모든 규칙의 경우 None을 반환합니다. 후속 작업을 생성할 때는 제공자가 업데이트되지 않으므로 검사하려면 이 함수를 다시 호출해야 합니다. 이는
ctx 객체를 가져와 객체에 작업을 생성할 수 있는 규칙 구현 도우미 함수의 테스트를 작성하는 데 도움이 됩니다.
disabled_features
list ctx.disabled_features
exec_groups
ExecGroupCollection ctx.exec_groups
ctx.exec_groups[name_of_group]로 액세스
실행 파일
struct ctx.executable
executable=True로 표시된 라벨 유형 속성에 정의된 실행 파일이 포함된 struct 구조체 필드는 속성 이름에 해당합니다. 구조체의 각 값은 File 또는 None입니다. 선택적 속성이 규칙에 지정되지 않으면 해당 구조체 값은 None입니다. 라벨 유형이 executable=True로 표시되지 않으면 해당 구조체 필드가 생성되지 않습니다. 사용 예시 보기
expand_location
string ctx.expand_location(input, targets=[])
$(location //x)을 타겟 //x의 출력 파일 경로로 대체하여 지정된 문자열의 모든 $(location ...) 템플릿을 확장합니다. 확장은 이 규칙의 직접 종속 항목을 가리키거나 선택적 인수 targets에 명시적으로 나열된 라벨에만 작동합니다. 참조된 타겟에 출력이 여러 개 있으면 $(location ...)로 인해 오류가 발생합니다. 이 경우 출력 경로의 공백으로 구분된 목록을 생성하는 $(locations ...)를 사용하세요. 단일 출력 파일에도 안전하게 사용할 수 있습니다.이 함수는 사용자가 BUILD 파일에서 명령어를 지정하도록 하는 데 유용합니다 (예:
genrule). 다른 경우에는 라벨을 직접 조작하는 것이 더 나은 경우가 많습니다.
매개변수
| 매개변수 | 설명 |
|---|---|
input
|
string;
required 확장할 문자열입니다. |
targets
|
Target의 sequence입니다. 기본값은 []입니다. 추가 조회 정보를 위한 타겟 목록입니다. 이는 다음과 같이 확장됩니다. DefaultInfo.files에 단일 파일이 있는 타겟은 해당 파일로 확장됩니다. 다른 타겟은 설정되어 있고 --incompatible_locations_prefers_executable이 사용 설정된 경우 DefaultInfo.executable 파일로 확장되고, 그렇지 않으면 DefaultInfo.files로 확장됩니다.
|
None을 반환할 수 있습니다.
expand_make_variables
string ctx.expand_make_variables(attribute_name, command, additional_substitutions)
'변수 만들기'에 대한 모든 참조를 확장한 후 문자열을 반환합니다. 변수는
$(VAR_NAME) 형식이어야 합니다. 또한 $$VAR_NAME expands to $VAR_NAME. Examples:
ctx.expand_make_variables("cmd", "$(MY_VAR)", {"MY_VAR": "Hi"}) # == "Hi"
ctx.expand_make_variables("cmd", "$$PWD", {}) # == "$PWD"
Additional variables may come from other places, such as configurations. Note that this function is experimental.
Parameters
| Parameter | Description |
|---|---|
attribute_name
|
string;
required The attribute name. Used for error reporting. |
command
|
string;
required The expression to expand. It can contain references to "Make variables". |
additional_substitutions
|
dict;
required Additional substitutions to make beyond the default make variables. |
features
list ctx.features
file
struct ctx.file
struct containing files defined in label type attributes marked as allow_single_file. The struct fields correspond to the attribute names. The struct value is always a File or None. If an optional attribute is not specified in the rule then the corresponding struct value is None. If a label type is not marked as allow_single_file, no corresponding struct field is generated. It is a shortcut for:list(ctx.attr.<ATTR>.files)[0]
file to access the (singular) default output of a dependency. See example of use.
files
struct ctx.files
struct containing files defined in label or label list type attributes. The struct fields correspond to the attribute names. The struct values are list of Files. It is a shortcut for:[f for t in ctx.attr.<ATTR> for f in t.files]
files to access the default outputs of a dependency. See example of use.
fragments
fragments ctx.fragments
genfiles_dir
root ctx.genfiles_dir
info_file
File ctx.info_file
label
Label ctx.label
outputs
structure ctx.outputs
File objects. See the Rules page for more information and examples.This field does not exist on aspect contexts, since aspects do not have predeclared outputs.
The fields of this object are defined as follows. It is an error if two outputs produce the same field name or have the same label.
- If the rule declares an
outputsdict, then for every entry in the dict, there is a field whose name is the key and whose value is the correspondingFile. - For every attribute of type
attr.outputthat the rule declares, there is a field whose name is the attribute's name. If the target specified a label for that attribute, then the field value is the correspondingFile; otherwise the field value isNone. - For every attribute of type
attr.output_listthat the rule declares, there is a field whose name is the attribute's name. The field value is a list ofFileobjects corresponding to the labels given for that attribute in the target, or an empty list if the attribute was not specified in the target. - (Deprecated) If the rule is marked
executableortest, there is a field named"executable", which is the default executable. It is recommended that instead of using this, you pass another file (either predeclared or not) to theexecutablearg ofDefaultInfo.
package_relative_label
Label ctx.package_relative_label(input)
Label, it is returned unchanged.The result of this function is the same 는 Label value as would be produced by passing the given string to a label-valued attribute of the rule and accessing the corresponding Label()Label()가 현재 분석 중인 타겟의 패키지가 아닌 이를 호출한 .bzl 파일의 패키지 컨텍스트를 사용한다는 것입니다. 이 함수는 규칙이나 측면 구현 함수에서 사용할 수 없는
native.package_relative_label()와 동일한 동작을 합니다.
매개변수
| 매개변수 | 설명 |
|---|---|
input
|
string 또는 Label;
required 입력 라벨 문자열 또는 Label 객체입니다. Label 객체가 전달되면 그대로 반환됩니다. |
resolve_command
tuple ctx.resolve_command(*, command='', attribute=None, expand_locations=False, make_variables=None, tools=[], label_dict={}, execution_requirements={})
(inputs, command, empty list)을 반환합니다. 둘 다 ctx.action 메서드의 이름이 같은 인수로 전달하는 데 적합합니다.Windows 사용자 참고사항: 이 메서드에는 Bash (MSYS2)가 필요합니다. 필요한 경우
resolve_tools()을 대신 사용하는 것이 좋습니다. 빈 목록은 하위 호환성을 위해 튜플의 세 번째 멤버로 반환됩니다.
매개변수
| 매개변수 | 설명 |
|---|---|
command
|
string;
default is ''Command to resolve. |
attribute
|
string 또는 None. 기본값은 None입니다. 오류를 발생시킬 연결된 속성의 이름 또는 None입니다. |
expand_locations
|
bool;
default is False$(location) 변수를 확장해야 하나요? 자세한 내용은 ctx.expand_location()을 참고하세요. |
make_variables
|
dict 또는 None. 기본값은 None입니다. 확장할 변수 또는 None입니다. |
tools
|
Target의 sequence. 기본값은 []입니다. 도구 목록 (타겟 목록)입니다. |
label_dict
|
dict;
default is {}해결된 라벨과 해당 파일 목록의 사전입니다 (라벨 : 파일 목록의 사전). |
execution_requirements
|
dict;
default is {}이 명령어를 해결하기 위한 작업을 예약하는 데 필요한 정보입니다. 유용한 키는 태그를 참고하세요. |
resolve_tools
tuple ctx.resolve_tools(*, tools=[])
ctx.actions.run 및 ctx.actions.run_shell 메서드의 동일한 이름의 인수로 전달하는 데 적합합니다.(inputs, empty list) ctx.resolve_command과 달리 이 메서드는 머신에 Bash가 설치되어 있지 않아도 되므로 Windows에서 빌드된 규칙에 적합합니다. 빈 목록은 하위 호환성을 위해 튜플의 일부로 반환됩니다.
매개변수
| 매개변수 | 설명 |
|---|---|
tools
|
Target의 sequence. 기본값은 []입니다. 도구 목록 (타겟 목록)입니다. |
규칙
rule_attributes ctx.rule
runfiles
runfiles ctx.runfiles(files=[], transitive_files=None, collect_data=False, collect_default=False, symlinks={}, root_symlinks={})
매개변수
| 매개변수 | 설명 |
|---|---|
files
|
File의 sequence;
default is []runfiles에 추가할 파일 목록입니다. |
transitive_files
|
File의 depset 또는 None입니다. 기본값은 None입니다. 런파일에 추가할 파일의 (전이적) 집합입니다. deps는 default 순서 (이름에서 알 수 있듯이 기본값)를 사용해야 합니다.
|
collect_data
|
bool;
default is False이 매개변수는 사용하지 않는 것이 좋습니다. runfiles 가이드를 참고하세요. srcs, data, deps 속성의 종속 항목에서 데이터 실행 파일을 수집할지 여부입니다. |
collect_default
|
bool;
default is False이 매개변수는 사용하지 않는 것이 좋습니다. runfiles 가이드를 참고하세요. srcs, data, deps 속성의 종속 항목에서 기본 실행 파일을 수집할지 여부입니다. |
symlinks
|
dict 또는 SymlinkEntry의 depset입니다. 기본값은 {}입니다. SymlinkEntry depset 또는 실행 파일에 추가할 심볼릭 링크의 맵입니다. 심볼릭 링크는 항상 기본 워크스페이스의 runfiles 디렉터리 (예: 현재 타겟의 저장소에 해당하는 디렉터리가 아님) 아래에 추가됩니다. <runfiles_root>/_main/<symlink_path> 규칙 가이드의 Runfiles 심볼릭 링크를 참고하세요.
|
root_symlinks
|
dict 또는 SymlinkEntry의 depset. 기본값은 {}입니다. 런파일에 추가할 심볼릭 링크의 SymlinkEntry depset 또는 맵입니다. 규칙 가이드의 Runfiles 심볼릭 링크를 참고하세요. |
split_attr
struct ctx.split_attr
super
unknown ctx.super()
target_platform_has_constraint
bool ctx.target_platform_has_constraint(constraintValue)
매개변수
| 매개변수 | 설명 |
|---|---|
constraintValue
|
ConstraintValueInfo;
required 타겟 플랫폼을 확인할 제약조건 값입니다. |
도구 모음으로의 통합
ToolchainContext ctx.toolchains
var
dict ctx.var
version_file
File ctx.version_file
workspace_name
string ctx.workspace_name
--enable_bzlmod가 사용 설정된 경우 고정된 문자열 _main입니다. 그렇지 않으면 WORKSPACE 파일에 정의된 작업공간 이름입니다.