|
| 1 | +From ef519afd270781a41a54b485e5b54462790e2eb5 Mon Sep 17 00:00:00 2001 |
| 2 | +From: John Firebaugh <john.firebaugh@gmail.com> |
| 3 | +Date: Fri, 23 Dec 2022 20:06:00 -0800 |
| 4 | +Subject: [PATCH] Add support for WORKSPACE.bazel Fixes #97 |
| 5 | + |
| 6 | +--- |
| 7 | + .../private/bazel_integration_test.bzl | 25 +++++++++++++++++-- |
| 8 | + tools/find_child_workspace_packages.sh | 5 +--- |
| 9 | + tools/shared_fns.sh | 2 +- |
| 10 | + tools/update_deleted_packages.sh | 9 +------ |
| 11 | + 4 files changed, 26 insertions(+), 15 deletions(-) |
| 12 | + |
| 13 | +diff --git a/bazel_integration_test/private/bazel_integration_test.bzl b/bazel_integration_test/private/bazel_integration_test.bzl |
| 14 | +index fa1ceb3..5207bd7 100644 |
| 15 | +--- a/bazel_integration_test/private/bazel_integration_test.bzl |
| 16 | ++++ b/bazel_integration_test/private/bazel_integration_test.bzl |
| 17 | +@@ -15,6 +15,27 @@ load(":integration_test_utils.bzl", "integration_test_utils") |
| 18 | + # CC: if Bazel use specific C-compiler it should be inherited by default |
| 19 | + _DEFAULT_ENV_INHERIT = ["SUDO_ASKPASS", "HOME", "CC"] |
| 20 | + |
| 21 | ++def _select_workspace_file_impl(ctx): |
| 22 | ++ workspace_file = paths.join(ctx.attr.workspace_path, "WORKSPACE") |
| 23 | ++ workspace_bazel = paths.join(ctx.attr.workspace_path, "WORKSPACE.bazel") |
| 24 | ++ for file in ctx.attr.srcs.files.to_list(): |
| 25 | ++ if file.path.endswith(workspace_file) or file.path.endswith(workspace_bazel): |
| 26 | ++ return [DefaultInfo(files = depset([file]))] |
| 27 | ++ fail("Can't find WORKSPACE or WORKSPACE.bazel in %s" % ctx.attr.workspace_path) |
| 28 | ++ |
| 29 | ++select_workspace_file = rule( |
| 30 | ++ implementation = _select_workspace_file_impl, |
| 31 | ++ attrs = { |
| 32 | ++ "srcs": attr.label( |
| 33 | ++ allow_files = True, |
| 34 | ++ mandatory = True, |
| 35 | ++ ), |
| 36 | ++ "workspace_path": attr.string( |
| 37 | ++ mandatory = True, |
| 38 | ++ ), |
| 39 | ++ }, |
| 40 | ++) |
| 41 | ++ |
| 42 | + def bazel_integration_test( |
| 43 | + name, |
| 44 | + test_runner, |
| 45 | +@@ -115,10 +136,10 @@ def bazel_integration_test( |
| 46 | + # convey the actual workspace directory to the rule. The location of |
| 47 | + # the WORKSPACE file seems to be the best way to do this. |
| 48 | + bazel_wksp_file_name = name + "_bazel_workspace_file" |
| 49 | +- select_file( |
| 50 | ++ select_workspace_file( |
| 51 | + name = bazel_wksp_file_name, |
| 52 | + srcs = workspace_files_name, |
| 53 | +- subpath = paths.join(workspace_path, "WORKSPACE"), |
| 54 | ++ workspace_path = workspace_path, |
| 55 | + ) |
| 56 | + |
| 57 | + args.extend(["--workspace", "$(location :%s)" % (bazel_wksp_file_name)]) |
| 58 | +diff --git a/tools/find_child_workspace_packages.sh b/tools/find_child_workspace_packages.sh |
| 59 | +index 46a0325..13c6478 100755 |
| 60 | +--- a/tools/find_child_workspace_packages.sh |
| 61 | ++++ b/tools/find_child_workspace_packages.sh |
| 62 | +@@ -66,11 +66,8 @@ while (("$#")); do |
| 63 | + esac |
| 64 | + done |
| 65 | + |
| 66 | +-if [[ -z "${workspace_root:-}" ]] && [[ -n "${BUILD_WORKING_DIRECTORY:-}" ]]; then |
| 67 | +- workspace_root="${BUILD_WORKING_DIRECTORY:-}" |
| 68 | +-fi |
| 69 | + if [[ -z "${workspace_root:-}" ]]; then |
| 70 | +- workspace_root="$(dirname "$(upsearch WORKSPACE)")" |
| 71 | ++ workspace_root="${BUILD_WORKSPACE_DIRECTORY}" |
| 72 | + fi |
| 73 | + if [[ ! -d "${workspace_root:-}" ]]; then |
| 74 | + fail "The workspace root was not found. ${workspace_root:-}" |
| 75 | +diff --git a/tools/shared_fns.sh b/tools/shared_fns.sh |
| 76 | +index 7c92bdf..d831f04 100644 |
| 77 | +--- a/tools/shared_fns.sh |
| 78 | ++++ b/tools/shared_fns.sh |
| 79 | +@@ -4,5 +4,5 @@ find_workspace_dirs() { |
| 80 | + local path="${1}" |
| 81 | + # Make sure that the -print0 is the last primary for find. Otherwise, you |
| 82 | + # will get undesirable results. |
| 83 | +- find "${path}" -name "WORKSPACE" -print0 | xargs -0 -n 1 dirname |
| 84 | ++ find "${path}" -name "WORKSPACE" -o -name "WORKSPACE.bazel" -print0 | xargs -0 -n 1 dirname |
| 85 | + } |
| 86 | +diff --git a/tools/update_deleted_packages.sh b/tools/update_deleted_packages.sh |
| 87 | +index db73b1c..ec435c8 100755 |
| 88 | +--- a/tools/update_deleted_packages.sh |
| 89 | ++++ b/tools/update_deleted_packages.sh |
| 90 | +@@ -71,15 +71,8 @@ while (("$#")); do |
| 91 | + done |
| 92 | + |
| 93 | + |
| 94 | +-# Try to search for the workspace root |
| 95 | + if [[ -z "${workspace_root:-}" ]]; then |
| 96 | +- # If the BUILD_WORKING_DIRECTORY exists, it will be the directory from which the command was run |
| 97 | +- if [[ -n "${BUILD_WORKING_DIRECTORY:-}" ]]; then |
| 98 | +- search_start_dir="${BUILD_WORKING_DIRECTORY}" |
| 99 | +- else |
| 100 | +- search_start_dir="${PWD}" |
| 101 | +- fi |
| 102 | +- workspace_root="$(dirname "$(upsearch --start_dir "${search_start_dir}" WORKSPACE)")" |
| 103 | ++ workspace_root="${BUILD_WORKSPACE_DIRECTORY}" |
| 104 | + fi |
| 105 | + if [[ ! -d "${workspace_root:-}" ]]; then |
| 106 | + exit_with_msg "The workspace root was not found. ${workspace_root:-}" |
| 107 | +-- |
| 108 | +2.39.0 |
| 109 | + |
0 commit comments