Skip to content

Remove the dependency on the internal rules_webtesting util #6771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions third_party/platform_http_file.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Downloads files based on local platform."""

load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external")
load("//third_party:fonts.bzl", "tensorboard_fonts_workspace")
load("//third_party:python.bzl", "tensorboard_python_workspace")
load("//third_party:js.bzl", "tensorboard_js_workspace")
load("//third_party:rust.bzl", "tensorboard_rust_workspace")

def _impl(repository_ctx):
if repository_ctx.os.name.lower().startswith("mac os"):
urls = repository_ctx.attr.macos_urls
sha256 = repository_ctx.attr.macos_sha256
elif repository_ctx.os.name.lower().startswith("windows"):
urls = repository_ctx.attr.windows_urls
sha256 = repository_ctx.attr.windows_sha256
else:
urls = repository_ctx.attr.amd64_urls
sha256 = repository_ctx.attr.amd64_sha256
basename = urls[0][urls[0].rindex("/") + 1:]

# sanitize the basename (for filenames with %20 in them)
basename = basename.replace("%20", "-")
repository_ctx.download(urls, basename, sha256)

# if archive is a dmg then convert it to a zip
if basename.endswith(".dmg"):
zipfile = basename.replace(".dmg", ".zip")
repository_ctx.execute([repository_ctx.path(Label("//web/internal:convert_dmg.sh")), basename, zipfile])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script something that needs to be copied to our repo as well? (and this path updated, perhaps?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, we will try alternative approaches.

basename = zipfile
repository_ctx.symlink(basename, "file/" + basename)
repository_ctx.file(
"file/BUILD",
"\n".join([
("# DO NOT EDIT: automatically generated BUILD file for " +
"platform_http_file rule " + repository_ctx.name),
"licenses(%s)" % repr(repository_ctx.attr.licenses),
"filegroup(",
" name = 'file',",
" srcs = ['%s']," % basename,
" visibility = ['//visibility:public'],",
")",
]),
)

platform_http_file = repository_rule(
attrs = {
"licenses": attr.string_list(mandatory = True, allow_empty = False),
"amd64_urls": attr.string_list(),
"amd64_sha256": attr.string(),
"macos_urls": attr.string_list(),
"macos_sha256": attr.string(),
"windows_urls": attr.string_list(),
"windows_sha256": attr.string(),
},
implementation = _impl,
)
2 changes: 1 addition & 1 deletion third_party/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ TensorBoard external dependencies that can be loaded in WORKSPACE files.
"""

load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external")
load("@io_bazel_rules_webtesting//web/internal:platform_http_file.bzl", "platform_http_file") # buildifier: disable=bzl-visibility
load("//third_party:fonts.bzl", "tensorboard_fonts_workspace")
load("//third_party:platform_http_file.bzl", "platform_http_file")
load("//third_party:python.bzl", "tensorboard_python_workspace")
load("//third_party:js.bzl", "tensorboard_js_workspace")
load("//third_party:rust.bzl", "tensorboard_rust_workspace")
Expand Down