From ea4bca1101b725c208168a9553aa8b446a8f6ff2 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Sat, 15 Jan 2022 12:58:10 -0800 Subject: [PATCH] refactor: remove vendored write_file.bzl We didn't have local modifications so we can just depend directly on upstream --- internal/generated_file_test/BUILD.bazel | 2 +- internal/node/test/BUILD.bazel | 2 +- internal/pkg_npm/test/BUILD.bazel | 2 +- .../generated_tsconfig/gen_src/BUILD.bazel | 2 +- .../test/ts_project/rootdir/BUILD.bazel | 2 +- .../rules/private/write_file_private.bzl | 114 ------------------ .../bazel-skylib/rules/write_file.bzl | 30 ----- .../bazel_workspaces_consistent/BUILD.bazel | 2 +- 8 files changed, 6 insertions(+), 150 deletions(-) delete mode 100644 third_party/github.com/bazelbuild/bazel-skylib/rules/private/write_file_private.bzl delete mode 100644 third_party/github.com/bazelbuild/bazel-skylib/rules/write_file.bzl diff --git a/internal/generated_file_test/BUILD.bazel b/internal/generated_file_test/BUILD.bazel index c18b4479ee..59a2f7484f 100644 --- a/internal/generated_file_test/BUILD.bazel +++ b/internal/generated_file_test/BUILD.bazel @@ -1,6 +1,6 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("//packages/rollup:index.bzl", "rollup_bundle") -load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") +load("@bazel_skylib//rules:write_file.bzl", "write_file") package(default_visibility = ["//visibility:public"]) diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel index 70088d121b..f8b8cedb36 100644 --- a/internal/node/test/BUILD.bazel +++ b/internal/node/test/BUILD.bazel @@ -3,7 +3,7 @@ load("@npm//typescript:index.bzl", "tsc") load("//:index.bzl", "js_library") load("//packages/jasmine:index.bzl", "jasmine_node_test") load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file") -load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") +load("@bazel_skylib//rules:write_file.bzl", "write_file") # You can have a nodejs_binary with no node_modules attribute # and no fine grained deps diff --git a/internal/pkg_npm/test/BUILD.bazel b/internal/pkg_npm/test/BUILD.bazel index bc0fde5351..688e59e3c3 100644 --- a/internal/pkg_npm/test/BUILD.bazel +++ b/internal/pkg_npm/test/BUILD.bazel @@ -2,7 +2,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") load("//packages/jasmine:index.bzl", "jasmine_node_test") load("//packages/rollup:index.bzl", "rollup_bundle") load("//packages/concatjs:index.bzl", "ts_library") -load("//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") +load("@bazel_skylib//rules:write_file.bzl", "write_file") write_file( name = "produces_files", diff --git a/packages/typescript/test/ts_project/generated_tsconfig/gen_src/BUILD.bazel b/packages/typescript/test/ts_project/generated_tsconfig/gen_src/BUILD.bazel index 02219d9eb0..63893dc303 100644 --- a/packages/typescript/test/ts_project/generated_tsconfig/gen_src/BUILD.bazel +++ b/packages/typescript/test/ts_project/generated_tsconfig/gen_src/BUILD.bazel @@ -1,5 +1,5 @@ load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test") -load("@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") +load("@bazel_skylib//rules:write_file.bzl", "write_file") load("//packages/typescript:index.bzl", "ts_project") write_file( diff --git a/packages/typescript/test/ts_project/rootdir/BUILD.bazel b/packages/typescript/test/ts_project/rootdir/BUILD.bazel index fb564ef0e5..99857344cb 100644 --- a/packages/typescript/test/ts_project/rootdir/BUILD.bazel +++ b/packages/typescript/test/ts_project/rootdir/BUILD.bazel @@ -1,4 +1,4 @@ -load("@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") +load("@bazel_skylib//rules:write_file.bzl", "write_file") load("//packages/typescript:index.bzl", "ts_project") write_file( diff --git a/third_party/github.com/bazelbuild/bazel-skylib/rules/private/write_file_private.bzl b/third_party/github.com/bazelbuild/bazel-skylib/rules/private/write_file_private.bzl deleted file mode 100644 index a5a69ae72d..0000000000 --- a/third_party/github.com/bazelbuild/bazel-skylib/rules/private/write_file_private.bzl +++ /dev/null @@ -1,114 +0,0 @@ -# Copyright 2019 The Bazel 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. - -"""Implementation of write_file macro and underlying rules. - -These rules write a UTF-8 encoded text file, using Bazel's FileWriteAction. -'_write_xfile' marks the resulting file executable, '_write_file' does not. -""" - -def _common_impl(ctx, is_windows, is_executable): - if ctx.attr.newline == "auto": - newline = "\r\n" if is_windows else "\n" - elif ctx.attr.newline == "windows": - newline = "\r\n" - else: - newline = "\n" - - # ctx.actions.write creates a FileWriteAction which uses UTF-8 encoding. - ctx.actions.write( - output = ctx.outputs.out, - content = newline.join(ctx.attr.content) if ctx.attr.content else "", - is_executable = is_executable, - ) - files = depset(direct = [ctx.outputs.out]) - runfiles = ctx.runfiles(files = [ctx.outputs.out]) - if is_executable: - return [DefaultInfo(files = files, runfiles = runfiles, executable = ctx.outputs.out)] - else: - return [DefaultInfo(files = files, runfiles = runfiles)] - -def _impl(ctx): - return _common_impl(ctx, ctx.attr.is_windows, False) - -def _ximpl(ctx): - return _common_impl(ctx, ctx.attr.is_windows, True) - -# @unsorted-dict-items -_ATTRS = { - "out": attr.output(mandatory = True), - "content": attr.string_list(mandatory = False, allow_empty = True), - "newline": attr.string(values = ["unix", "windows", "auto"], default = "auto"), - "is_windows": attr.bool(mandatory = True), -} - -_write_file = rule( - implementation = _impl, - provides = [DefaultInfo], - attrs = _ATTRS, -) - -_write_xfile = rule( - implementation = _ximpl, - executable = True, - provides = [DefaultInfo], - attrs = _ATTRS, -) - -def write_file( - name, - out, - content = [], - is_executable = False, - newline = "auto", - **kwargs): - """Creates a UTF-8 encoded text file. - - Args: - name: Name of the rule. - out: Path of the output file, relative to this package. - content: A list of strings. Lines of text, the contents of the file. - Newlines are added automatically after every line except the last one. - is_executable: A boolean. Whether to make the output file executable. - When True, the rule's output can be executed using `bazel run` and can - be in the srcs of binary and test rules that require executable - sources. - newline: one of ["auto", "unix", "windows"]: line endings to use. "auto" - for platform-determined, "unix" for LF, and "windows" for CRLF. - **kwargs: further keyword arguments, e.g. visibility - """ - if is_executable: - _write_xfile( - name = name, - content = content, - out = out, - newline = newline or "auto", - is_windows = select({ - "@bazel_tools//src/conditions:host_windows": True, - "//conditions:default": False, - }), - **kwargs - ) - else: - _write_file( - name = name, - content = content, - out = out, - newline = newline or "auto", - is_windows = select({ - "@bazel_tools//src/conditions:host_windows": True, - "//conditions:default": False, - }), - **kwargs - ) diff --git a/third_party/github.com/bazelbuild/bazel-skylib/rules/write_file.bzl b/third_party/github.com/bazelbuild/bazel-skylib/rules/write_file.bzl deleted file mode 100644 index 602f78d2f6..0000000000 --- a/third_party/github.com/bazelbuild/bazel-skylib/rules/write_file.bzl +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2019 The Bazel 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. - -"""A rule that writes a UTF-8 encoded text file from user-specified contents. - -native.genrule() is sometimes used to create a text file. The 'write_file' and -macro does this with a simpler interface than genrule. - -The rules generated by the macro do not use Bash or any other shell to write the -file. Instead they use Starlark's built-in file writing action -(ctx.actions.write). -""" - -load( - "//third_party/github.com/bazelbuild/bazel-skylib:rules/private/write_file_private.bzl", - _write_file = "write_file", -) - -write_file = _write_file diff --git a/tools/npm_packages/bazel_workspaces_consistent/BUILD.bazel b/tools/npm_packages/bazel_workspaces_consistent/BUILD.bazel index 5764dd849e..d84bacda88 100644 --- a/tools/npm_packages/bazel_workspaces_consistent/BUILD.bazel +++ b/tools/npm_packages/bazel_workspaces_consistent/BUILD.bazel @@ -1,4 +1,4 @@ -load("@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") +load("@bazel_skylib//rules:write_file.bzl", "write_file") load(":index.bzl", "some_rule") # Just a dumb target to make sure we can use it from code that installs this npm package