खास तौर पर, यह सुविधा लागू करने वाले फ़ंक्शन को मौजूदा टारगेट के लेबल, एट्रिब्यूट, कॉन्फ़िगरेशन, और उसकी डिपेंडेंसी के प्रोवाइडर को ऐक्सेस करने की अनुमति देती है. इसमें आउटपुट फ़ाइलों और उन्हें जनरेट करने वाले ऐक्शन के बारे में बताने के तरीके होते हैं.
कॉन्टेक्स्ट ऑब्जेक्ट, कॉल के दौरान लागू किए जाने वाले फ़ंक्शन के लिए ज़रूरी होते हैं. इन ऑब्जेक्ट को उनके फ़ंक्शन से बाहर ऐक्सेस करना काम का नहीं होता. ज़्यादा जानकारी के लिए, नियमों का पेज देखें.
सदस्य
- कार्रवाइयां
- aspect_ids
- attr
- bin_dir
- build_file_path
- build_setting_value
- कॉन्फ़िगरेशन
- coverage_instrumented
- created_actions
- disabled_features
- exec_groups
- executable
- expand_location
- expand_make_variables
- सुविधाएं
- फ़ाइल
- फ़ाइलें
- फ़्रैगमेंट
- genfiles_dir
- info_file
- लेबल
- आउटपुट
- package_relative_label
- resolve_command
- resolve_tools
- rule
- 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 दिया गया है, तो यह फ़ंक्शन उस टारगेट के लिए कोड कवरेज इंस्ट्रुमेंटेशन जनरेट करने के बारे में बताता है. (अगर कोई नॉन-रूल या स्टार्लार्क नियम वाला टारगेट दिया जाता है, तो यह False दिखाता है.) यह जांच करता है कि मौजूदा नियम (अगर कोई टारगेट नहीं दिया गया है) के सोर्स या टारगेट के सोर्स को --instrumentation_filter और --instrument_test_targets कॉन्फ़िगरेशन सेटिंग के आधार पर इंस्ट्रुमेंट किया जाना चाहिए या नहीं. यह कॉन्फ़िगरेशन में मौजूद coverage_enabled से अलग है. इससे यह पता चलता है कि पूरे रन के लिए कवरेज डेटा कलेक्शन की सुविधा चालू है या नहीं. हालांकि, इससे यह पता नहीं चलता कि किसी खास टारगेट को इंस्ट्रुमेंट किया जाना चाहिए या नहीं.
पैरामीटर
| पैरामीटर | ब्यौरा |
|---|---|
target
|
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
struct में, लेबल टाइप एट्रिब्यूट में तय की गई एक्ज़ीक्यूटेबल फ़ाइलें शामिल हैं. इन्हें executable=True के तौर पर मार्क किया गया है. स्ट्रक्ट फ़ील्ड, एट्रिब्यूट के नामों से मेल खाते हैं. स्ट्रक्ट में मौजूद हर वैल्यू, File या None होती है. अगर नियम में विकल्प के तौर पर दिए गए एट्रिब्यूट की वैल्यू नहीं दी जाती है, तो उससे जुड़ी स्ट्रक्चर वैल्यू None होती है. अगर किसी लेबल टाइप को executable=True के तौर पर मार्क नहीं किया गया है, तो उससे जुड़ा कोई स्ट्रक्चर फ़ील्ड जनरेट नहीं होता है. इस्तेमाल का उदाहरण देखें.
expand_location
string ctx.expand_location(input, targets=[])
$(location ...) टेंप्लेट को बड़ा करता है. इसके लिए, यह $(location //x) को टारगेट //x की आउटपुट फ़ाइल के पाथ से बदलता है. एक्सपेंशन की सुविधा सिर्फ़ उन लेबल के लिए काम करती है जो इस नियम की सीधी डिपेंडेंसी की ओर इशारा करते हैं या जिन्हें targets वाले वैकल्पिक तर्क में साफ़ तौर पर शामिल किया गया है. $(location ...) से गड़बड़ी होगी, अगर रेफ़र किए गए टारगेट के कई आउटपुट हैं. इस मामले में, कृपया $(locations ...) का इस्तेमाल करें, क्योंकि यह आउटपुट पाथ की स्पेस से अलग की गई सूची बनाता है. इसका इस्तेमाल, एक आउटपुट फ़ाइल के लिए भी सुरक्षित तरीके से किया जा सकता है.यह फ़ंक्शन, उपयोगकर्ता को BUILD फ़ाइल में कोई कमांड (जैसे कि
genrule के लिए) तय करने की अनुमति देने के लिए काम का है. अन्य मामलों में, सीधे तौर पर लेबल में बदलाव करना ज़्यादा बेहतर होता है.
पैरामीटर
| पैरामीटर | ब्यौरा |
|---|---|
input
|
string;
ज़रूरी है बड़ी की जाने वाली स्ट्रिंग. |
targets
|
Targets का 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;
डिफ़ॉल्ट तौर पर ''होता है हल करने के लिए कमांड. |
attribute
|
string या None;
डिफ़ॉल्ट रूप से Noneहोता है उस एट्रिब्यूट का नाम जिसके लिए गड़बड़ी की सूचना देनी है या कोई नहीं. |
expand_locations
|
bool;
डिफ़ॉल्ट रूप से Falseहोता है क्या हमें $(location) वैरिएबल को बड़ा करना चाहिए? ज़्यादा जानकारी के लिए, ctx.expand_location() देखें. |
make_variables
|
dict; या None;
डिफ़ॉल्ट रूप से Noneहोता है बढ़ाने के लिए वैरिएबल बनाएं या कोई नहीं. |
tools
|
Targets का sequence;
डिफ़ॉल्ट रूप से []होता है टूल की सूची (टारगेट की सूची). |
label_dict
|
dict;
डिफ़ॉल्ट रूप से {}होता है हल किए गए लेबल और उनसे जुड़ी फ़ाइलों की सूची वाली डिक्शनरी. यह Label : list of Files की डिक्शनरी होती है. |
execution_requirements
|
dict;
डिफ़ॉल्ट रूप से {}होता है इस निर्देश को हल करने के लिए कार्रवाई को शेड्यूल करने की जानकारी. काम की कुंजियों के लिए, टैग देखें. |
resolve_tools
tuple ctx.resolve_tools(*, tools=[])
(inputs, empty list) दिखाता है. इसे ctx.actions.run और ctx.actions.run_shell तरीकों के एक ही नाम वाले तर्क के तौर पर पास किया जा सकता है. ctx.resolve_command के उलट, इस तरीके में मशीन पर Bash इंस्टॉल करना ज़रूरी नहीं है. इसलिए, यह Windows पर बनाए गए नियमों के लिए सही है. पुराने सिस्टम के साथ काम करने की सुविधा के लिए, खाली सूची को टपल के हिस्से के तौर पर दिखाया जाता है.
पैरामीटर
| पैरामीटर | ब्यौरा |
|---|---|
tools
|
Targets का sequence;
डिफ़ॉल्ट रूप से []होता है टूल की सूची (टारगेट की सूची). |
नियम
rule_attributes ctx.rule
runfiles
runfiles ctx.runfiles(files=[], transitive_files=None, collect_data=False, collect_default=False, symlinks={}, root_symlinks={})
पैरामीटर
| पैरामीटर | ब्यौरा |
|---|---|
files
|
sequence of Files;
डिफ़ॉल्ट रूप से []होता है रनफ़ाइल में जोड़ी जाने वाली फ़ाइलों की सूची. |
transitive_files
|
Files का depset; या None;
डिफ़ॉल्ट रूप से Noneहोता है रनफ़ाइलों में जोड़े जाने वाले फ़ाइलों का (ट्रांज़िटिव) सेट. डिपसेट को default क्रम का इस्तेमाल करना चाहिए. नाम से पता चलता है कि यह डिफ़ॉल्ट क्रम है.
|
collect_data
|
bool;
डिफ़ॉल्ट रूप से Falseहोता है इस पैरामीटर का इस्तेमाल करने का सुझाव नहीं दिया जाता. runfiles गाइड देखें. यह तय करता है कि srcs, data, और deps एट्रिब्यूट में मौजूद डिपेंडेंसी से डेटा रनफ़ाइलें इकट्ठा करनी हैं या नहीं. |
collect_default
|
bool;
डिफ़ॉल्ट रूप से Falseहोता है इस पैरामीटर का इस्तेमाल करने का सुझाव नहीं दिया जाता. runfiles गाइड देखें. srcs, data, और deps एट्रिब्यूट में मौजूद डिपेंडेंसी से डिफ़ॉल्ट रनफ़ाइलें इकट्ठा करनी हैं या नहीं. |
symlinks
|
dict; या SymlinkEntrys का depset;
डिफ़ॉल्ट रूप से {}होता है यह SymlinkEntry depset या रनफ़ाइल में जोड़े जाने वाले सिंबल लिंक का मैप होता है. सिमलिंक हमेशा मुख्य वर्कस्पेस की runfiles डायरेक्ट्री में जोड़े जाते हैं. जैसे, <runfiles_root>/_main/<symlink_path>, न कि मौजूदा टारगेट की रिपॉज़िटरी से जुड़ी डायरेक्ट्री. नियमों से जुड़ी गाइड में, रनफ़ाइल के सिमलिंक देखें.
|
root_symlinks
|
dict; या SymlinkEntrys का depset;
डिफ़ॉल्ट रूप से {}होता है यह SymlinkEntry depset या रनफ़ाइल में जोड़े जाने वाले सिंबल लिंक का मैप होता है. नियमों से जुड़ी गाइड में, रनफ़ाइल के सिमलिंक देखें. |
split_attr
struct ctx.split_attr
बढ़िया
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 फ़ाइल में तय किया गया फ़ाइल फ़ोल्डर का नाम है.