diff --git a/test/current_toolchain_tools/BUILD.bazel b/test/current_toolchain_tools/BUILD.bazel index 4559a90e66..e1979a9538 100644 --- a/test/current_toolchain_tools/BUILD.bazel +++ b/test/current_toolchain_tools/BUILD.bazel @@ -1,32 +1,14 @@ -# Test that all toolchain tools are executable targets -[ - sh_test( - name = tool + "_test", - srcs = ["current_exec_files_test.sh"], - args = [ - "$(rootpath //rust/toolchain:current_exec_{}_files)".format(tool), - "--executable", - # The final arg is expected to match a similar pattern: - # cargo 1.53.0 (4369396ce 2021-04-27) - r"^" + tool + r" [0-9\.]\+ ([0-9a-z]\{9\} [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\})", - ], - data = [ - "//rust/toolchain:current_exec_{}_files".format(tool), - ], - ) - for tool in [ - "cargo", - "clippy", - "rustc", - "rustdoc", - "rustfmt", - ] -] - -# Note, rustc_srcs is too big for this test +# Executable targets will output a pattern similar to the following +# cargo 1.53.0 (4369396ce 2021-04-27) +# Also Note, rustc_srcs is too big for this test _FILES = { - "rust_stdlib": r"\.rlib", - "rustc_lib": r"libstd", + "cargo": ("--executable", r"^cargo [0-9\.]\+ ([0-9a-z]\{9\} [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\})"), + "clippy": ("--executable", r"^clippy [0-9\.]\+ ([0-9a-z]\{8\} [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\})"), + "rust_stdlib": ("--files", r"\.rlib"), + "rustc": ("--executable", r"^rustc [0-9\.]\+ ([0-9a-z]\{9\} [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\})"), + "rustc_lib": ("--files", r"rustc_driver"), + "rustdoc": ("--executable", r"^rustdoc [0-9\.]\+ ([0-9a-z]\{9\} [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\})"), + "rustfmt": ("--executable", r"^rustfmt [0-9\.]\+\-stable ([0-9a-z]\{8\} [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\})"), } # Generate a list manifest for all files in the filegroup @@ -37,22 +19,25 @@ _FILES = { outs = ["{}_manifest".format(files)], cmd = "for file in $(rootpaths //rust/toolchain:current_exec_{}_files); do echo $$file >> $@; done".format(files), ) - for files in _FILES.keys() + for files in _FILES + if "--files" in _FILES[files] ] -# Check to see that a particular file patter exists in the manifest +# Test that all toolchain tools are executable targets [ sh_test( - name = "{}_test".format(files), + name = tool + "_test", srcs = ["current_exec_files_test.sh"], args = [ - "$(rootpath :{}_manifest)".format(files), - "--files", - pattern, + "$(rootpath //rust/toolchain:current_exec_{}_files)".format(tool) if "--executable" == arg else "$(rootpath {}_manifest)".format(tool), + arg, + "'{}'".format(pattern), ], data = [ - ":{}_manifest".format(files), - ], + "//rust/toolchain:current_exec_{}_files".format(tool), + ] + ( + ["{}_manifest".format(tool)] if "--files" == arg else [] + ), ) - for files, pattern in _FILES.items() + for tool, (arg, pattern) in _FILES.items() ] diff --git a/test/current_toolchain_tools/current_exec_files_test.sh b/test/current_toolchain_tools/current_exec_files_test.sh index 77838e494a..aa55c4b25b 100755 --- a/test/current_toolchain_tools/current_exec_files_test.sh +++ b/test/current_toolchain_tools/current_exec_files_test.sh @@ -4,17 +4,22 @@ set -xeuo pipefail TARGET="$1" OPTION="$2" -PATTERN="$3" + +# To parse this argument on windows it must be wrapped in quotes but +# these quotes should not be passed to grep. Remove them here. +PATTERN="$(echo -n "$3" | sed "s/'//g")" if [[ "${OPTION}" == "--executable" ]]; then # Clippy requires this environment variable is set export SYSROOT="" + "${TARGET}" --version "${TARGET}" --version | grep "${PATTERN}" exit 0 fi if [[ "${OPTION}" == "--files" ]]; then + cat "${TARGET}" grep "${PATTERN}" "${TARGET}" exit 0 fi