当前位置: 首页 > news >正文

【Bazel入门与精通】 rules之属性

https://bazel.build/extending/rules?hl=zh-cn#attributes
在这里插入图片描述

Attributes

An attribute is a rule argument. Attributes can provide specific values to a target’s implementation, or they can refer to other targets, creating a graph of dependencies.

  • Rule-specific attributes, such as srcs or deps, are defined by passing a map from attribute names to schemas (created using the attr module) to the attrs parameter of rule.
  • Common attributes, such as name and visibility, are implicitly added to all rules.
  • Additional attributes are implicitly added to executable and test rules specifically. Attributes which are implicitly added to a rule can’t be included in the dictionary passed to attrs.

属性是规则参数。属性可以为目标的 implementation 提供特定值,也可以引用其他目标,从而创建依赖关系图。

  • 特定于规则的属性(例如 srcs 或 deps)是通过将属性名称到架构的映射(使用 attr 模块创建)传递给 rule 的 attrs 参数来定义的。
  • name 和 visibility 等常用属性会隐式添加到所有规则中。
  • 其他属性会具体地隐式添加到可执行和测试规则中。隐式添加到规则的属性无法包含在传递给 attrs 的字典中。

Dependency attributes

Rules that process source code usually define the following attributes to handle various types of dependencies:

  • srcs specifies source files processed by a target’s actions. Often, the attribute schema specifies which file extensions are expected for the sort of source file the rule processes. Rules for languages with header files generally specify a separate hdrs attribute for headers processed by a target and its consumers.
  • deps specifies code dependencies for a target. The attribute schema should specify which providers those dependencies must provide. (For example, cc_library provides CcInfo.)
  • data specifies files to be made available at runtime to any executable which depends on a target. That should allow arbitrary files to be specified.

依赖项属性

处理源代码的规则通常会定义以下属性来处理各种类型的依赖项:

  • srcs 用于指定目标的操作处理的源文件。通常,属性架构会指定规则处理的源文件类型所需的文件扩展名。针对具有头文件的语言的规则通常会为目标及其使用方处理的标头指定单独的 hdrs 属性。
  • deps 用于指定目标的代码依赖项。属性架构应指定这些依赖项必须提供的 provider。(例如,cc_library 提供 CcInfo。)
  • data 指定在运行时可供依赖于目标的任何可执行文件使用的文件。这应允许指定任意文件。
example_library = rule(implementation = _example_library_impl,attrs = {"srcs": attr.label_list(allow_files = [".example"]),"hdrs": attr.label_list(allow_files = [".header"]),"deps": attr.label_list(providers = [ExampleInfo]),"data": attr.label_list(allow_files = True),...},
)

These are examples of dependency attributes. Any attribute that specifies an input label (those defined with attr.label_list, attr.label, or attr.label_keyed_string_dict) specifies dependencies of a certain type between a target and the targets whose labels (or the corresponding Label objects) are listed in that attribute when the target is defined. The repository, and possibly the path, for these labels is resolved relative to the defined target.

这些是依赖项属性的示例。任何指定输入标签的属性(使用 attr.label_list、attr.label 或 attr.label_keyed_string_dict 定义的属性)都指定了目标与在其标签(或相应的 Label 对象)中列出目标(或相应 Label 对象)之间的特定类型的依赖关系。这些标签的代码库(也可能是路径)将相对于定义的目标进行解析。


example_library(name = "my_target",deps = [":other_target"],
)example_library(name = "other_target",...
)

In this example, other_target is a dependency of my_target, and therefore other_target is analyzed first. It is an error if there is a cycle in the dependency graph of targets.
在此示例中,other_target 是 my_target 的依赖项,因此首先分析 other_target。如果目标的依赖关系图中存在循环,则会出错。

Private attributes and implicit dependencies

A dependency attribute with a default value creates an implicit dependency. It is implicit because it’s a part of the target graph that the user doesn’t specify it in a BUILD file. Implicit dependencies are useful for hard-coding a relationship between a rule and a tool (a build-time dependency, such as a compiler), since most of the time a user is not interested in specifying what tool the rule uses. Inside the rule’s implementation function, this is treated the same as other dependencies.

If you want to provide an implicit dependency without allowing the user to override that value, you can make the attribute private by giving it a name that begins with an underscore (_). Private attributes must have default values. It generally only makes sense to use private attributes for implicit dependencies.

私有属性和隐式依赖项
具有默认值的依赖项属性会创建隐式依赖项。由于它是目标图的一部分,因此用户并未在 BUILD 文件中指定它,因此它是隐式的。隐式依赖项适用于对规则与工具(构建时依赖项,例如编译器)之间的关系进行硬编码,因为大多数情况下,用户都不关心指定规则使用的工具。在规则的实现函数内,系统会将其视为与其他依赖项相同。

如果您想提供隐式依赖项,而又不允许用户替换该值,则可以为属性指定一个以下划线 (_) 开头的名称,使其具有私有属性。私有属性必须具有默认值。通常,只有将私有属性用于隐式依赖项才有意义。

example_library = rule(implementation = _example_library_impl,attrs = {..."_compiler": attr.label(default = Label("//tools:example_compiler"),allow_single_file = True,executable = True,cfg = "exec",),},
)

在此示例中,example_library 类型的每个目标都具有对编译器 //tools:example_compiler 的隐式依赖项。这样,example_library 的实现函数就可以生成调用编译器的操作,即使用户没有将其标签作为输入传递也是如此。由于 _compiler 是私有属性,因此在此规则类型的所有目标中,ctx.attr._compiler 将始终指向 //tools:example_compiler。或者,您也可以将该属性命名为 compiler(不带下划线),并保留默认值。这样一来,用户可以在必要时替换其他编译器,但不知道编译器的标签。

隐式依赖项通常用于与规则实现位于同一代码库中的工具。如果该工具来自执行平台或其他代码库,则该规则应从工具链中获取该工具。

相关文章:

【Bazel入门与精通】 rules之属性

https://bazel.build/extending/rules?hlzh-cn#attributes Attributes An attribute is a rule argument. Attributes can provide specific values to a target’s implementation, or they can refer to other targets, creating a graph of dependencies. Rule-specifi…...

Elementor无需第三方插件实现高级下拉菜单/巨型菜单

使用新的嵌套功能创建美观的菜单和大型菜单。巨型菜单是具有复杂导航结构和独特设计的网站的理想选择。 Elementor-设置-特性-Menu启用 之后再去前端编辑器设计即可,就会有一个新的menu菜单模块了。 这个菜单的下拉则是通过Elementor直接来设计,也就以为…...

【数学】什么是傅里叶变换?什么是离散傅里叶变换?什么是拉普拉斯变换?

文章目录 什么是傅里叶变换?什么是离散傅里叶变换?什么是拉普拉斯变换?背景公式示例题目详细讲解Python代码求解实际生活中的例子 什么是线性时不变系统线性性(Linearity)时不变性(Time-Invariance&#xf…...

opencv安装笔记 各种平台

目录 python安装opencv-python c 麒麟arm系统安装和用法 python安装opencv-python pypi上搜索 Search results PyPI 现在安装是一个版本,大于3.6都可以安装 c 麒麟arm系统安装和用法 参考: ffmpeg rknn麒麟系统 安装 opencv_ffmpeg4 解码示例-CSDN…...

前端开发中的热更新原理

一、什么是热更新 热更新(Hot Module Replacement,HMR)是一种在前端开发中极为重要的技术。它允许开发者在不重新加载整个页面的情况下,实时更新应用程序中的某些模块。简单来说,热更新能让你在开发过程中即时看到代码…...

unix环境高级编程第2版:深入探索UNIX编程的奥秘

unix环境高级编程第2版:深入探索UNIX编程的奥秘 在数字世界的浩瀚海洋中,UNIX环境以其稳定、高效和灵活的特性,一直备受程序员们的青睐。而《unix环境高级编程第2版》这本书,无疑是探索UNIX编程奥秘的绝佳指南。接下来&#xff0…...

力扣42 接雨水

听说字节每人都会接雨水,我也要会哈哈哈 数据结构:数组 算法:核心是计算这一列接到多少雨水,它取决于它左边的最大值和右边的最大值,如下图第三根柱子能接到的雨水应该是第一根柱子高度和第五根柱子高度的最小值减去第…...

【代码随想录】【算法训练营】【第35天】[134]加油站 [135]分发糖果 [860]柠檬水找零 [406]根据身高重建队列

前言 思路及算法思维,指路 代码随想录。 题目来自 LeetCode。 day 35,连休两天~ 题目详情 [134] 加油站 题目描述 134 加油站 解题思路 前提:数组 思路:全局贪心算法:最小累加剩余汽油为负数,说明…...

Talk|新加坡国立大学贾鑫宇:适用于高自由度机器人的运动控制器

本期为TechBeat人工智能社区第600期线上Talk。 北京时间6月13日(周四)20:00,新加坡国立大学博士生—贾鑫宇的Talk已经准时在TechBeat人工智能社区开播! 他与大家分享的主题是: “适用于高自由度机器人的运动控制器”,向大家系统地介绍了如何通…...

【npm】console工具(含胶囊,表格,gif图片)

这是一款控制台花样输出工具 相对丰富的输出方式 文本输出属性值输出胶囊样式输出表格输出图片输出(含动图) 安装 npm install v_aot引用 import v_aot from "v_aot";字段说明 字段类型属性字符串值字符串类型default 、 primary 、 suc…...

OpenCV读取图片

import cv2 as cv # 读取图像 image cv.imread(F:\\mytupian\\xihuduanqiao.jpg) # 创建窗口 cv.namedWindow(image, cv.WINDOW_NORMAL) #显示图像后,允许用户随意调整窗口大小 # 显示图像 cv.imshow(image, image) cv.waitKey(0)import cv2 as cv srccv.imread(…...

HBase中的CRUD

Table接口:负责表数据的基本操作。 Admin类:负责管理建表、删表、该表等元数据操作的接口。 1、Put方法 1.1、了解put方法之前,必须知道的相关知识。 在HBase中有一个理念:所有的数据皆为bytes。因此在HBase中所有的数据最终都…...

C/C++学习笔记 C语言中的\0以及查找字符串中字符出现的频率

在此示例中&#xff0c;计算了字符串对象中字符的频率。 为此&#xff0c;使用size()函数查找字符串对象的长度。然后for 循环迭代直到字符串末尾。 在每次迭代中&#xff0c;检查字符是否出现&#xff0c;如果发现&#xff0c;则计数增加 1。 示例 1 #include <iostream&g…...

在C#中,有多种方式可以实现每天在指定的时间清空数据库数据。下面列出几种常用的方法,并提供简要的实现思路:

在C#中&#xff0c;实现每天在指定时间清空数据库数据的需求&#xff0c;可以通过多种方式来完成。下面列举了几种常用的方法&#xff1a; 方式一&#xff1a;使用 Task 和 Timer 这种方法利用 System.Threading.Timer 类来定时执行清空数据库的操作。 using System; using …...

深入理解java设计模式之单例模式

目录 概述单例模式是什么单例模式的使用场景单例模式的优缺点单例模式的几种实现方式饿汉式懒汉式双重检查锁定机制静态内部类枚举使用容器几种可能破坏单例类的方法多线程环境下的竞争条件使用反射机制使用序列化多个类加载器概述 单例模式是什么 定义:单例模式确保一个类在…...

程序员自由创业周记#36:Gap Year

程序员自由创业周记#36&#xff1a;Gap Year 一整年 刚过去的一周&#xff0c;度过了我31周岁的生日&#xff0c;距离结束上一份工作&#xff0c;刚好一年。一年过得好快&#xff0c;犹记得刚失业那会的迷茫&#xff0c;第一个月的纠结&#xff0c;是继续打工还是自己当“老板…...

Java 类与对象 -- Java 语言的类与对象、构造器、static、final、包和 JAR

大家好&#xff0c;我是栗筝i&#xff0c;这篇文章是我的 “栗筝i 的 Java 技术栈” 专栏的第 006 篇文章&#xff0c;在 “栗筝i 的 Java 技术栈” 这个专栏中我会持续为大家更新 Java 技术相关全套技术栈内容。专栏的主要目标是已经有一定 Java 开发经验&#xff0c;并希望进…...

MTK平台纯色背景抑制

MTK中有两个机制可以抑制纯色背景的亮度&#xff0c;分别是Main target、Histogram。 Main target的纯色背景亮度机制原理大概如下&#xff1a; 将图像分成64*48块&#xff0c;分别统计每一块的亮度Y。 但对于纯色背景时&#xff0c;如果仍然使用Luma来计算&#xff0c;容易造…...

Linux iptables使用详解

一、Linux系统下使用iptables 在Linux中&#xff0c;常用的防火墙工具是iptables。以下是一些基本的iptables命令&#xff0c;用于配置防火墙规则。 查看现有的iptables规则&#xff1a; sudo iptables -L 清除所有现有的规则&#xff08;慎用&#xff0c;可能导致服务不可用…...

算法02 递归算法及其相关问题

递归 在编程中&#xff0c;我们把函数直接或者间接调用自身的过程叫做递归。 递归处理问题的过程是&#xff1a;通常把一个大型的复杂问题&#xff0c;转变成一个与原问题类似的&#xff0c;规模更小的问题来进行求解。 递归的三大要素 函数的参数。在用递归解决问题时&…...

手游刚开服就被攻击怎么办?如何防御DDoS?

开服初期是手游最脆弱的阶段&#xff0c;极易成为DDoS攻击的目标。一旦遭遇攻击&#xff0c;可能导致服务器瘫痪、玩家流失&#xff0c;甚至造成巨大经济损失。本文为开发者提供一套简洁有效的应急与防御方案&#xff0c;帮助快速应对并构建长期防护体系。 一、遭遇攻击的紧急应…...

Nuxt.js 中的路由配置详解

Nuxt.js 通过其内置的路由系统简化了应用的路由配置&#xff0c;使得开发者可以轻松地管理页面导航和 URL 结构。路由配置主要涉及页面组件的组织、动态路由的设置以及路由元信息的配置。 自动路由生成 Nuxt.js 会根据 pages 目录下的文件结构自动生成路由配置。每个文件都会对…...

VTK如何让部分单位不可见

最近遇到一个需求&#xff0c;需要让一个vtkDataSet中的部分单元不可见&#xff0c;查阅了一些资料大概有以下几种方式 1.通过颜色映射表来进行&#xff0c;是最正规的做法 vtkNew<vtkLookupTable> lut; //值为0不显示&#xff0c;主要是最后一个参数&#xff0c;透明度…...

rnn判断string中第一次出现a的下标

# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...

Ubuntu Cursor升级成v1.0

0. 当前版本低 使用当前 Cursor v0.50时 GitHub Copilot Chat 打不开&#xff0c;快捷键也不好用&#xff0c;当看到 Cursor 升级后&#xff0c;还是蛮高兴的 1. 下载 Cursor 下载地址&#xff1a;https://www.cursor.com/cn/downloads 点击下载 Linux (x64) &#xff0c;…...

掌握 HTTP 请求:理解 cURL GET 语法

cURL 是一个强大的命令行工具&#xff0c;用于发送 HTTP 请求和与 Web 服务器交互。在 Web 开发和测试中&#xff0c;cURL 经常用于发送 GET 请求来获取服务器资源。本文将详细介绍 cURL GET 请求的语法和使用方法。 一、cURL 基本概念 cURL 是 "Client URL" 的缩写…...

Spring Security 认证流程——补充

一、认证流程概述 Spring Security 的认证流程基于 过滤器链&#xff08;Filter Chain&#xff09;&#xff0c;核心组件包括 UsernamePasswordAuthenticationFilter、AuthenticationManager、UserDetailsService 等。整个流程可分为以下步骤&#xff1a; 用户提交登录请求拦…...

WEB3全栈开发——面试专业技能点P4数据库

一、mysql2 原生驱动及其连接机制 概念介绍 mysql2 是 Node.js 环境中广泛使用的 MySQL 客户端库&#xff0c;基于 mysql 库改进而来&#xff0c;具有更好的性能、Promise 支持、流式查询、二进制数据处理能力等。 主要特点&#xff1a; 支持 Promise / async-await&#xf…...

Windows 下端口占用排查与释放全攻略

Windows 下端口占用排查与释放全攻略​ 在开发和运维过程中&#xff0c;经常会遇到端口被占用的问题&#xff08;如 8080、3306 等常用端口&#xff09;。本文将详细介绍如何通过命令行和图形化界面快速定位并释放被占用的端口&#xff0c;帮助你高效解决此类问题。​ 一、准…...

深度解析:etcd 在 Milvus 向量数据库中的关键作用

目录 &#x1f680; 深度解析&#xff1a;etcd 在 Milvus 向量数据库中的关键作用 &#x1f4a1; 什么是 etcd&#xff1f; &#x1f9e0; Milvus 架构简介 &#x1f4e6; etcd 在 Milvus 中的核心作用 &#x1f527; 实际工作流程示意 ⚠️ 如果 etcd 出现问题会怎样&am…...