Simplify tf_vendored repo rule.

PiperOrigin-RevId: 814099609
This commit is contained in:
Christian Sigg 2025-10-02 00:11:26 -07:00 committed by TensorFlower Gardener
parent 2a8dcaf97e
commit 239c89159c
4 changed files with 17 additions and 27 deletions

View File

@ -5,8 +5,8 @@ load("//third_party:repo.bzl", "tf_vendored")
load("//third_party/tf_runtime:workspace.bzl", tf_runtime = "repo")
def workspace():
tf_vendored(name = "local_xla", relpath = "third_party/xla")
tf_vendored(name = "local_tsl", relpath = "third_party/xla/third_party/tsl")
tf_vendored(name = "local_xla", path = "third_party/xla")
tf_vendored(name = "local_tsl", path = "third_party/xla/third_party/tsl")
http_archive(
name = "io_bazel_rules_closure",

19
third_party/repo.bzl vendored
View File

@ -140,21 +140,16 @@ def tf_http_archive(name, sha256, urls, **kwargs):
**kwargs
)
def _tf_vendored_impl(repository_ctx):
parent_path = repository_ctx.path(repository_ctx.attr.parent).dirname
# get_child doesn't allow slashes. Yes this is silly. bazel_skylib paths
# doesn't work with path objects.
relpath_parts = repository_ctx.attr.relpath.split("/")
vendored_path = parent_path
for part in relpath_parts:
vendored_path = vendored_path.get_child(part)
repository_ctx.symlink(vendored_path, ".")
def _tf_vendored_impl(ctx):
ctx.symlink(ctx.path(ctx.attr._root).dirname.get_child(ctx.attr.path), ".")
tf_vendored = repository_rule(
implementation = _tf_vendored_impl,
doc = "Similar to local_repository, but path is relative to the root of the " +
"repository, not the root of the workspace.",
attrs = {
"parent": attr.label(default = "//:WORKSPACE"),
"relpath": attr.string(),
"_root": attr.label(default = "//:unused"),
"path": attr.string(),
},
local = True,
)

View File

@ -138,21 +138,16 @@ def tf_http_archive(name, sha256, urls, **kwargs):
**kwargs
)
def _tf_vendored_impl(repository_ctx):
parent_path = repository_ctx.path(repository_ctx.attr.parent).dirname
# get_child doesn't allow slashes. Yes this is silly. bazel_skylib paths
# doesn't work with path objects.
relpath_parts = repository_ctx.attr.relpath.split("/")
vendored_path = parent_path
for part in relpath_parts:
vendored_path = vendored_path.get_child(part)
repository_ctx.symlink(vendored_path, ".")
def _tf_vendored_impl(ctx):
ctx.symlink(ctx.path(ctx.attr._root).dirname.get_child(ctx.attr.path), ".")
tf_vendored = repository_rule(
implementation = _tf_vendored_impl,
doc = "Similar to local_repository, but path is relative to the root of the " +
"repository, not the root of the workspace.",
attrs = {
"parent": attr.label(default = "//:WORKSPACE"),
"relpath": attr.string(),
"_root": attr.label(default = "//:unused"),
"path": attr.string(),
},
local = True,
)

View File

@ -6,7 +6,7 @@ load("//third_party:repo.bzl", "tf_vendored")
# buildifier: disable=unnamed-macro
def workspace():
# Declares @tsl
tf_vendored(name = "tsl", relpath = "third_party/tsl")
tf_vendored(name = "tsl", path = "third_party/tsl")
# Alias so it can be loaded without assigning to a different symbol to prevent
# shadowing previous loads and trigger a buildifier warning.