टैब

यह एक कॉन्टेक्स्ट ऑब्जेक्ट है, जिसे किसी नियम या आसपेक्ट के लिए लागू करने वाले फ़ंक्शन को पास किया जाता है. इससे मौजूदा टारगेट का विश्लेषण करने के लिए ज़रूरी जानकारी और तरीकों का ऐक्सेस मिलता है.

खास तौर पर, यह सुविधा लागू करने वाले फ़ंक्शन को मौजूदा टारगेट के लेबल, एट्रिब्यूट, कॉन्फ़िगरेशन, और उसकी डिपेंडेंसी के प्रोवाइडर को ऐक्सेस करने की अनुमति देती है. इसमें आउटपुट फ़ाइलों और उन्हें जनरेट करने वाले ऐक्शन के बारे में बताने के तरीके होते हैं.

कॉन्टेक्स्ट ऑब्जेक्ट, कॉल के दौरान लागू किए जाने वाले फ़ंक्शन के लिए ज़रूरी होते हैं. इन ऑब्जेक्ट को उनके फ़ंक्शन से बाहर ऐक्सेस करना काम का नहीं होता. ज़्यादा जानकारी के लिए, नियमों का पेज देखें.

सदस्य

कार्रवाइयां

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

मौजूदा टारगेट का बिल्ड कॉन्फ़िगरेशन. ज़्यादा जानकारी के लिए, Starlark कॉन्फ़िगरेशन टाइप और कॉन्फ़िगरेशन का दस्तावेज़ देखें.

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()

जिन नियमों के लिए _skylark_testable को 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)

अब काम नहीं करता. इसके बजाय, वैरिएबल ऐक्सेस करने के लिए ctx.var का इस्तेमाल करें.
"वैरिएबल बनाएं" के सभी रेफ़रंस को बड़ा करने के बाद, एक स्ट्रिंग दिखाता है. वैरिएबल इस फ़ॉर्मैट में होने चाहिए: $(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

The set of features that are explicitly enabled by the user for this rule. See example of use.

file

struct ctx.file

A 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]
In other words, use file to access the (singular) default output of a dependency. See example of use.

files

struct ctx.files

A 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]
In other words, use files to access the default outputs of a dependency. See example of use.

fragments

fragments ctx.fragments

Allows access to configuration fragments in target configuration.

genfiles_dir

root ctx.genfiles_dir

The root corresponding to genfiles directory.

info_file

File ctx.info_file

The file that is used to hold the non-volatile workspace status for the current build request. See documentation for --workspace_status_command for more information.

label

Label ctx.label

The label of the target currently being analyzed.

outputs

structure ctx.outputs

A pseudo-struct containing all the predeclared output files, represented by 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 outputs dict, then for every entry in the dict, there is a field whose name is the key and whose value is the corresponding File.
  • For every attribute of type attr.output that 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 corresponding File; otherwise the field value is None.
  • For every attribute of type attr.output_list that the rule declares, there is a field whose name is the attribute's name. The field value is a list of File objects 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 executable or test, 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 the executable arg of DefaultInfo.

package_relative_label

Label ctx.package_relative_label(input)

Converts the input string into a Label object, in the context of the package of the target currently being analyzed. If the input is already a 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={})

(एक्सपेरिमेंटल) यह हल किए गए इनपुट की सूची और हल किए गए कमांड के लिए argv सूची का टपल (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={})

यह फ़ंक्शन, runfiles ऑब्जेक्ट बनाता है.

पैरामीटर

पैरामीटर ब्यौरा
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 एट्रिब्यूट में मौजूद डिपेंडेंसी से डिफ़ॉल्ट रनफ़ाइलें इकट्ठा करनी हैं या नहीं.

dict; या SymlinkEntrys का depset; डिफ़ॉल्ट रूप से {}
होता है यह SymlinkEntry depset या रनफ़ाइल में जोड़े जाने वाले सिंबल लिंक का मैप होता है. सिमलिंक हमेशा मुख्य वर्कस्पेस की runfiles डायरेक्ट्री में जोड़े जाते हैं. जैसे, <runfiles_root>/_main/<symlink_path>, न कि मौजूदा टारगेट की रिपॉज़िटरी से जुड़ी डायरेक्ट्री. नियमों से जुड़ी गाइड में, रनफ़ाइल के सिमलिंक देखें.
dict; या SymlinkEntrys का depset; डिफ़ॉल्ट रूप से {}
होता है यह SymlinkEntry depset या रनफ़ाइल में जोड़े जाने वाले सिंबल लिंक का मैप होता है. नियमों से जुड़ी गाइड में, रनफ़ाइल के सिमलिंक देखें.

split_attr

struct ctx.split_attr

स्प्लिट कॉन्फ़िगरेशन वाले एट्रिब्यूट की वैल्यू ऐक्सेस करने के लिए स्ट्रक्चर. अगर एट्रिब्यूट, लेबल की सूची है, तो split_attr की वैल्यू, स्प्लिट की कुंजियों (स्ट्रिंग के तौर पर) का एक डिक्शनरी होती है. इसमें स्प्लिट की उस ब्रांच में कॉन्फ़िगर किए गए टारगेट की सूचियां होती हैं. अगर एट्रिब्यूट एक लेबल है, तो split_attr की वैल्यू, स्प्लिट की कुंजियों (स्ट्रिंग के तौर पर) से लेकर सिंगल ConfiguredTargets तक का डिक्शनरी होती है. स्प्लिट कॉन्फ़िगरेशन वाले एट्रिब्यूट, अब भी 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_status_command का दस्तावेज़ देखें.

workspace_name

string ctx.workspace_name

वर्कस्पेस का नाम. यह मुख्य रिपो के लिए, एक्ज़ीक्यूशन रूट का नाम और रनफ़ाइल प्रीफ़िक्स होता है. अगर --enable_bzlmod चालू है, तो यह तय की गई स्ट्रिंग _main है. अगर ऐसा नहीं है, तो यह WORKSPACE फ़ाइल में तय किया गया फ़ाइल फ़ोल्डर का नाम है.