From 8fd0bc28be11246a04f4b553772f72b810798856 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 6 Jan 2020 14:21:53 -0800 Subject: [PATCH] refactor(builtin): vendor in runfiles.bash helper --- BUILD.bazel | 2 + .../bazel_integration_test.bzl | 2 +- internal/common/test/BUILD.bazel | 2 +- internal/common/test/copy_to_bin_tests.sh | 2 +- internal/linker/test/integration/BUILD.bazel | 2 +- .../linker/test/integration/run_program.sh | 2 +- internal/node/launcher.sh | 2 +- internal/node/node.bzl | 4 +- internal/npm_install/test/BUILD.bazel | 2 +- internal/npm_install/test/bazel_bin_test.sh | 2 +- packages/jasmine/src/jasmine_node_test.bzl | 2 +- packages/karma/src/karma_web_test.bzl | 2 +- packages/karma/test/stack_trace/BUILD.bazel | 2 +- .../protractor/src/protractor_web_test.bzl | 2 +- .../internal/devserver/launcher_template.sh | 2 +- .../src/internal/devserver/ts_devserver.bzl | 2 +- .../test/devmode_consumer/BUILD.bazel | 2 +- .../devmode_consumer/devmode_consumer_test.sh | 2 +- .../typescript/test/es6_consumer/BUILD.bazel | 2 +- .../test/es6_consumer/es6_output_test.sh | 2 +- .../typescript/test/some_module/BUILD.bazel | 2 +- .../test/some_module/module_load_test.sh | 2 +- .../github.com/bazelbuild/bazel/BUILD.bazel | 7 + .../github.com/bazelbuild/bazel/LICENSE | 202 ++++++++++++++++++ .../bazel/tools/bash/runfiles/BUILD.bazel | 11 + .../bazel/tools/bash/runfiles/runfiles.bash | 181 ++++++++++++++++ 26 files changed, 425 insertions(+), 22 deletions(-) create mode 100644 third_party/github.com/bazelbuild/bazel/BUILD.bazel create mode 100644 third_party/github.com/bazelbuild/bazel/LICENSE create mode 100644 third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/BUILD.bazel create mode 100644 third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash diff --git a/BUILD.bazel b/BUILD.bazel index 3dd206a4fe..1edf7099e2 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -87,7 +87,9 @@ pkg_npm( "//internal/pkg_npm:package_contents", "//internal/pkg_web:package_contents", "//internal/providers:package_contents", + "//third_party/github.com/bazelbuild/bazel:package_contents", "//third_party/github.com/bazelbuild/bazel-skylib:package_contents", + "//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles:package_contents", "//third_party/github.com/buffer-from:package_contents", "//third_party/github.com/gjtorikian/isBinaryFile:package_contents", "//third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths:package_contents", diff --git a/internal/bazel_integration_test/bazel_integration_test.bzl b/internal/bazel_integration_test/bazel_integration_test.bzl index e171969c02..d4de34e43e 100644 --- a/internal/bazel_integration_test/bazel_integration_test.bzl +++ b/internal/bazel_integration_test/bazel_integration_test.bzl @@ -89,7 +89,7 @@ call :rlocation {TMPL_args} ARGS launcher_content = """#!/usr/bin/env bash # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${{RUNFILES_DIR:-/dev/null}}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${{RUNFILES_MANIFEST_FILE:-/dev/null}}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/internal/common/test/BUILD.bazel b/internal/common/test/BUILD.bazel index 4185ca8551..c3d6f4244b 100644 --- a/internal/common/test/BUILD.bazel +++ b/internal/common/test/BUILD.bazel @@ -14,7 +14,7 @@ sh_test( ":a", "//third_party/github.com/bazelbuild/bazel-skylib:tests/unittest.bash", ], - deps = ["@bazel_tools//tools/bash/runfiles"], + deps = ["@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles"], ) copy_to_bin( diff --git a/internal/common/test/copy_to_bin_tests.sh b/internal/common/test/copy_to_bin_tests.sh index a07b95d4aa..d807267853 100755 --- a/internal/common/test/copy_to_bin_tests.sh +++ b/internal/common/test/copy_to_bin_tests.sh @@ -14,7 +14,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/internal/linker/test/integration/BUILD.bazel b/internal/linker/test/integration/BUILD.bazel index cb14043bdc..503ca8e57c 100644 --- a/internal/linker/test/integration/BUILD.bazel +++ b/internal/linker/test/integration/BUILD.bazel @@ -41,7 +41,7 @@ sh_binary( "//internal/linker:index.js", "//internal/linker/test/integration/static_linked_pkg", "//internal/linker/test/integration/static_linked_scoped_pkg", - "@bazel_tools//tools/bash/runfiles", + "@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", "@build_bazel_rules_nodejs//toolchains/node:node_bin", ], ) diff --git a/internal/linker/test/integration/run_program.sh b/internal/linker/test/integration/run_program.sh index 2fb0c77ea5..ee653c8562 100755 --- a/internal/linker/test/integration/run_program.sh +++ b/internal/linker/test/integration/run_program.sh @@ -21,7 +21,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/internal/node/launcher.sh b/internal/node/launcher.sh index 0b5f404de4..6ad3e28fed 100644 --- a/internal/node/launcher.sh +++ b/internal/node/launcher.sh @@ -15,7 +15,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 8a716cdc6b..45462c2b00 100644 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -238,7 +238,7 @@ def _nodejs_binary_impl(ctx): runfiles = [] runfiles.extend(node_tool_files) - runfiles.extend(ctx.files._bash_runfile_helpers) + runfiles.extend(ctx.files._bash_runfile_helper) runfiles.append(ctx.outputs.loader_script) runfiles.append(ctx.outputs.require_patch_script) runfiles.append(ctx.file._repository_args) @@ -444,7 +444,7 @@ jasmine_node_test( `--node_options=--preserve-symlinks` """, ), - "_bash_runfile_helpers": attr.label(default = Label("@bazel_tools//tools/bash/runfiles")), + "_bash_runfile_helper": attr.label(default = Label("@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles")), "_launcher_template": attr.label( default = Label("//internal/node:launcher.sh"), allow_single_file = True, diff --git a/internal/npm_install/test/BUILD.bazel b/internal/npm_install/test/BUILD.bazel index f7e9583afa..4310039ca9 100644 --- a/internal/npm_install/test/BUILD.bazel +++ b/internal/npm_install/test/BUILD.bazel @@ -87,7 +87,7 @@ sh_test( name = "bazel_bin_test", srcs = ["bazel_bin_test.sh"], data = [ - "@bazel_tools//tools/bash/runfiles", + "@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", "@npm//testy/bin:testy", ], ) diff --git a/internal/npm_install/test/bazel_bin_test.sh b/internal/npm_install/test/bazel_bin_test.sh index 77d3f20bbc..8c442fafe0 100755 --- a/internal/npm_install/test/bazel_bin_test.sh +++ b/internal/npm_install/test/bazel_bin_test.sh @@ -2,7 +2,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/packages/jasmine/src/jasmine_node_test.bzl b/packages/jasmine/src/jasmine_node_test.bzl index bae78bbf74..f19a8e8764 100644 --- a/packages/jasmine/src/jasmine_node_test.bzl +++ b/packages/jasmine/src/jasmine_node_test.bzl @@ -72,7 +72,7 @@ def jasmine_node_test( all_data = data + srcs + deps + [Label(jasmine)] all_data += [":%s_devmode_srcs.MF" % name] - all_data += [Label("@bazel_tools//tools/bash/runfiles")] + all_data += [Label("@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles")] # jasmine_runner.js consumes the first 3 args. # The remaining target templated_args will be passed through to jasmine or diff --git a/packages/karma/src/karma_web_test.bzl b/packages/karma/src/karma_web_test.bzl index 261d9037aa..6ad4c3fbf7 100644 --- a/packages/karma/src/karma_web_test.bzl +++ b/packages/karma/src/karma_web_test.bzl @@ -238,7 +238,7 @@ def _karma_web_test_impl(ctx): content = """#!/usr/bin/env bash # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${{RUNFILES_DIR:-/dev/null}}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${{RUNFILES_MANIFEST_FILE:-/dev/null}}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/packages/karma/test/stack_trace/BUILD.bazel b/packages/karma/test/stack_trace/BUILD.bazel index e8e9858938..f535aa5dc0 100644 --- a/packages/karma/test/stack_trace/BUILD.bazel +++ b/packages/karma/test/stack_trace/BUILD.bazel @@ -48,7 +48,7 @@ sh_test( srcs = ["test_sourcemap.sh"], data = [ ":karma_test_chromium-local", - "@bazel_tools//tools/bash/runfiles", + "@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", ], tags = [ "browser:chromium-local", diff --git a/packages/protractor/src/protractor_web_test.bzl b/packages/protractor/src/protractor_web_test.bzl index 71b7694fe5..83911078a7 100644 --- a/packages/protractor/src/protractor_web_test.bzl +++ b/packages/protractor/src/protractor_web_test.bzl @@ -108,7 +108,7 @@ def _protractor_web_test_impl(ctx): content = """#!/usr/bin/env bash # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${{RUNFILES_DIR:-/dev/null}}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${{RUNFILES_MANIFEST_FILE:-/dev/null}}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/packages/typescript/src/internal/devserver/launcher_template.sh b/packages/typescript/src/internal/devserver/launcher_template.sh index 7553783af4..9738d48e40 100644 --- a/packages/typescript/src/internal/devserver/launcher_template.sh +++ b/packages/typescript/src/internal/devserver/launcher_template.sh @@ -16,7 +16,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/packages/typescript/src/internal/devserver/ts_devserver.bzl b/packages/typescript/src/internal/devserver/ts_devserver.bzl index f0f682ff51..9e42ce6ce5 100644 --- a/packages/typescript/src/internal/devserver/ts_devserver.bzl +++ b/packages/typescript/src/internal/devserver/ts_devserver.bzl @@ -188,7 +188,7 @@ ts_devserver = rule( allow_files = True, aspects = [node_modules_aspect], ), - "_bash_runfile_helpers": attr.label(default = Label("@bazel_tools//tools/bash/runfiles")), + "_bash_runfile_helpers": attr.label(default = Label("@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles")), "_launcher_template": attr.label(allow_single_file = True, default = Label("//internal/devserver:launcher_template.sh")), "_requirejs_script": attr.label(allow_single_file = True, default = Label("//third_party/npm/requirejs:require.js")), }, diff --git a/packages/typescript/test/devmode_consumer/BUILD.bazel b/packages/typescript/test/devmode_consumer/BUILD.bazel index 197d28684e..2a22497be8 100644 --- a/packages/typescript/test/devmode_consumer/BUILD.bazel +++ b/packages/typescript/test/devmode_consumer/BUILD.bazel @@ -10,6 +10,6 @@ sh_test( srcs = ["devmode_consumer_test.sh"], data = [ ":devmode_consumer", - "@bazel_tools//tools/bash/runfiles", + "@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", ], ) diff --git a/packages/typescript/test/devmode_consumer/devmode_consumer_test.sh b/packages/typescript/test/devmode_consumer/devmode_consumer_test.sh index 3c06cc8fe4..f760ef1eb9 100755 --- a/packages/typescript/test/devmode_consumer/devmode_consumer_test.sh +++ b/packages/typescript/test/devmode_consumer/devmode_consumer_test.sh @@ -2,7 +2,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/packages/typescript/test/es6_consumer/BUILD.bazel b/packages/typescript/test/es6_consumer/BUILD.bazel index 68f9883de8..a8be845adf 100644 --- a/packages/typescript/test/es6_consumer/BUILD.bazel +++ b/packages/typescript/test/es6_consumer/BUILD.bazel @@ -24,6 +24,6 @@ sh_test( srcs = ["es6_output_test.sh"], data = [ ":es6_output", - "@bazel_tools//tools/bash/runfiles", + "@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", ], ) diff --git a/packages/typescript/test/es6_consumer/es6_output_test.sh b/packages/typescript/test/es6_consumer/es6_output_test.sh index cfbebdaaaf..0d07236f4d 100755 --- a/packages/typescript/test/es6_consumer/es6_output_test.sh +++ b/packages/typescript/test/es6_consumer/es6_output_test.sh @@ -2,7 +2,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/packages/typescript/test/some_module/BUILD.bazel b/packages/typescript/test/some_module/BUILD.bazel index 44777e9398..ae774f7db2 100644 --- a/packages/typescript/test/some_module/BUILD.bazel +++ b/packages/typescript/test/some_module/BUILD.bazel @@ -31,6 +31,6 @@ sh_test( srcs = ["module_load_test.sh"], data = [ ":bin", - "@bazel_tools//tools/bash/runfiles", + "@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", ], ) diff --git a/packages/typescript/test/some_module/module_load_test.sh b/packages/typescript/test/some_module/module_load_test.sh index 927c35461a..81f8307aa2 100755 --- a/packages/typescript/test/some_module/module_load_test.sh +++ b/packages/typescript/test/some_module/module_load_test.sh @@ -2,7 +2,7 @@ # --- begin runfiles.bash initialization v2 --- # Copy-pasted from the Bazel Bash runfiles library v2. -set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ source "$0.runfiles/$f" 2>/dev/null || \ diff --git a/third_party/github.com/bazelbuild/bazel/BUILD.bazel b/third_party/github.com/bazelbuild/bazel/BUILD.bazel new file mode 100644 index 0000000000..354ad75cde --- /dev/null +++ b/third_party/github.com/bazelbuild/bazel/BUILD.bazel @@ -0,0 +1,7 @@ +licenses(["notice"]) + +filegroup( + name = "package_contents", + srcs = glob(["**"]), + visibility = ["//:__pkg__"], +) diff --git a/third_party/github.com/bazelbuild/bazel/LICENSE b/third_party/github.com/bazelbuild/bazel/LICENSE new file mode 100644 index 0000000000..7a4a3ea242 --- /dev/null +++ b/third_party/github.com/bazelbuild/bazel/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. \ No newline at end of file diff --git a/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/BUILD.bazel b/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/BUILD.bazel new file mode 100644 index 0000000000..c09b2e8986 --- /dev/null +++ b/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/BUILD.bazel @@ -0,0 +1,11 @@ +filegroup( + name = "package_contents", + srcs = glob(["**"]), + visibility = ["//:__pkg__"], +) + +sh_library( + name = "runfiles", + srcs = ["runfiles.bash"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash b/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash new file mode 100644 index 0000000000..4c8c0ee812 --- /dev/null +++ b/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash @@ -0,0 +1,181 @@ +# Copyright 2018 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. + +# Runfiles lookup library for Bazel-built Bash binaries and tests, version 2. +# +# VERSION HISTORY: +# - version 2: Shorter init code. +# Features: +# - "set -euo pipefail" only at end of init code. +# "set -e" breaks the source || source || ... scheme on +# macOS, because it terminates if path1 does not exist. +# - Not exporting any environment variables in init code. +# This is now done in runfiles.bash itself. +# Compatibility: +# - The v1 init code can load the v2 library, i.e. if you have older source +# code (still using v1 init) then you can build it with newer Bazel (which +# contains the v2 library). +# - The reverse is not true: the v2 init code CANNOT load the v1 library, +# i.e. if your project (or any of its external dependencies) use v2 init +# code, then you need a newer Bazel version (which contains the v2 +# library). +# - version 1: Original Bash runfiles library. +# +# ENVIRONMENT: +# - If RUNFILES_LIB_DEBUG=1 is set, the script will print diagnostic messages to +# stderr. +# +# USAGE: +# 1. Depend on this runfiles library from your build rule: +# +# sh_binary( +# name = "my_binary", +# ... +# deps = ["@bazel_tools//tools/bash/runfiles"], +# ) +# +# 2. Source the runfiles library. +# +# The runfiles library itself defines rlocation which you would need to look +# up the library's runtime location, thus we have a chicken-and-egg problem. +# Insert the following code snippet to the top of your main script: +# +# # --- begin runfiles.bash initialization v2 --- +# # Copy-pasted from the Bazel Bash runfiles library v2. +# set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash +# source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ +# source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ +# source "$0.runfiles/$f" 2>/dev/null || \ +# source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ +# source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ +# { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e +# # --- end runfiles.bash initialization v2 --- +# +# +# 3. Use rlocation to look up runfile paths. +# +# cat "$(rlocation my_workspace/path/to/my/data.txt)" +# + +if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ -f "$0.runfiles_manifest" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" + elif [[ -f "$0.runfiles/MANIFEST" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" + elif [[ -f "$0.runfiles/build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash" ]]; then + export RUNFILES_DIR="$0.runfiles" + fi +fi + +case "$(uname -s | tr [:upper:] [:lower:])" in +msys*|mingw*|cygwin*) + # matches an absolute Windows path + export _RLOCATION_ISABS_PATTERN="^[a-zA-Z]:[/\\]" + ;; +*) + # matches an absolute Unix path + export _RLOCATION_ISABS_PATTERN="^/[^/].*" + ;; +esac + +# Prints to stdout the runtime location of a data-dependency. +function rlocation() { + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): start" + fi + if [[ "$1" =~ $_RLOCATION_ISABS_PATTERN ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): absolute path, return" + fi + # If the path is absolute, print it as-is. + echo "$1" + elif [[ "$1" == ../* || "$1" == */.. || "$1" == ./* || "$1" == */./* || "$1" == "*/." || "$1" == *//* ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "ERROR[runfiles.bash]: rlocation($1): path is not normalized" + fi + return 1 + elif [[ "$1" == \\* ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "ERROR[runfiles.bash]: rlocation($1): absolute path without" \ + "drive name" + fi + return 1 + else + if [[ -e "${RUNFILES_DIR:-/dev/null}/$1" ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): found under RUNFILES_DIR ($RUNFILES_DIR), return" + fi + echo "${RUNFILES_DIR}/$1" + elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): looking in RUNFILES_MANIFEST_FILE ($RUNFILES_MANIFEST_FILE)" + fi + local -r result=$(grep -m1 "^$1 " "${RUNFILES_MANIFEST_FILE}" | cut -d ' ' -f 2-) + if [[ -e "${result:-/dev/null}" ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): found in manifest as ($result)" + fi + echo "$result" + else + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): not found in manifest" + fi + echo "" + fi + else + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "ERROR[runfiles.bash]: cannot look up runfile \"$1\" " \ + "(RUNFILES_DIR=\"${RUNFILES_DIR:-}\"," \ + "RUNFILES_MANIFEST_FILE=\"${RUNFILES_MANIFEST_FILE:-}\")" + fi + return 1 + fi + fi +} +export -f rlocation + +# Exports the environment variables that subprocesses need in order to use +# runfiles. +# If a subprocess is a Bazel-built binary rule that also uses the runfiles +# libraries under @bazel_tools//tools//runfiles, then that binary needs +# these envvars in order to initialize its own runfiles library. +function runfiles_export_envvars() { + if [[ ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" \ + && ! -d "${RUNFILES_DIR:-/dev/null}" ]]; then + return 1 + fi + + if [[ ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ -f "$RUNFILES_DIR/MANIFEST" ]]; then + export RUNFILES_MANIFEST_FILE="$RUNFILES_DIR/MANIFEST" + elif [[ -f "${RUNFILES_DIR}_manifest" ]]; then + export RUNFILES_MANIFEST_FILE="${RUNFILES_DIR}_manifest" + else + export RUNFILES_MANIFEST_FILE= + fi + elif [[ ! -d "${RUNFILES_DIR:-/dev/null}" ]]; then + if [[ "$RUNFILES_MANIFEST_FILE" == */MANIFEST \ + && -d "${RUNFILES_MANIFEST_FILE%/MANIFEST}" ]]; then + export RUNFILES_DIR="${RUNFILES_MANIFEST_FILE%/MANIFEST}" + export JAVA_RUNFILES="$RUNFILES_DIR" + elif [[ "$RUNFILES_MANIFEST_FILE" == *_manifest \ + && -d "${RUNFILES_MANIFEST_FILE%_manifest}" ]]; then + export RUNFILES_DIR="${RUNFILES_MANIFEST_FILE%_manifest}" + export JAVA_RUNFILES="$RUNFILES_DIR" + else + export RUNFILES_DIR= + fi + fi +} +export -f runfiles_export_envvars \ No newline at end of file