add support for filtering out Bazel targets from common structure (#76173)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76173

We need this facility temporarily to sequence some changes without
breakage. This is generally not a good idea since the main purpose of
this effort is to replicate builds in OSS Bazel.
ghstack-source-id: 155215491

Test Plan: Manual test and rely on CI.

Reviewed By: dreiss

Differential Revision: D35815290

fbshipit-source-id: 89bacda373e7ba03d6a3fcbcaa5af42ae5eac154
(cherry picked from commit 1b808bbc94c939da1fd410d81b22d43bdfe1cda0)
This commit is contained in:
mikey dagitses
2022-05-03 05:05:03 -07:00
committed by PyTorch MergeBot
parent 9bcb4de168
commit 596c54c699

View File

@ -3,6 +3,10 @@ load("@rules_cuda//cuda:defs.bzl", "requires_cuda_enabled")
load("//c10/macros:cmake_configure_file.bzl", "cmake_configure_file")
load("//tools/config:defs.bzl", "if_cuda")
def _genrule(**kwds):
if _enabled(**kwds):
native.genrule(**kwds)
def _py_library(name, **kwds):
deps = [dep for dep in kwds.pop("deps", []) if dep != None]
native.py_library(name = name, deps = deps, **kwds)
@ -19,7 +23,7 @@ rules = struct(
cc_test = cc_test,
cmake_configure_file = cmake_configure_file,
filegroup = native.filegroup,
genrule = native.genrule,
genrule = _genrule,
glob = native.glob,
if_cuda = if_cuda,
py_binary = native.py_binary,
@ -29,3 +33,7 @@ rules = struct(
select = select,
test_suite = native.test_suite,
)
def _enabled(tags = [], **_kwds):
"""Determines if the target is enabled."""
return "-bazel" not in tags