diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java index 25b155e00fca63..8902fe24254db4 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkBaseExternalContext.java @@ -904,16 +904,18 @@ public Object download( ".tzst", "tar.bz2", ".tbz", ".ar", or ".deb" here. """), @Param( - name = "stripPrefix", + name = "strip_prefix", defaultValue = "''", named = true, doc = """ - A directory prefix to strip from the extracted files. - Many archives contain a top-level directory that contains all files in the \ - archive. Instead of needing to specify this prefix over and over in the \ - build_file, this field can be used to strip it from extracted \ - files. + A directory prefix to strip from the extracted files. Many archives contain a + top-level directory that contains all files in the archive. Instead of needing to + specify this prefix over and over in the build_file, this field can + be used to strip it from extracted files. + +

For compatibility, this parameter may also be used under the deprecated name + stripPrefix. """), @Param( name = "allow_fail", @@ -973,6 +975,12 @@ public Object download( contain non-Unicode filenames, or which have files that would extract to \ the same path on case-insensitive filesystems. """), + @Param( + name = "stripPrefix", + documented = false, + positional = false, + named = true, + defaultValue = "''"), }) public StructImpl downloadAndExtract( Object url, @@ -986,8 +994,10 @@ public StructImpl downloadAndExtract( Dict headersUnchecked, // | String> expected String integrity, Dict renameFiles, // expected + String oldStripPrefix, StarlarkThread thread) throws RepositoryFunctionException, InterruptedException, EvalException { + stripPrefix = renamedStripPrefix("download_and_extract", stripPrefix, oldStripPrefix); ImmutableMap>> authHeaders = getAuthHeaders(getAuthContents(authUnchecked, "auth")); @@ -996,8 +1006,9 @@ public StructImpl downloadAndExtract( ImmutableList urls = getUrls( url, - /*ensureNonEmpty=*/ !allowFail, - /*checksumGiven=*/ !Strings.isNullOrEmpty(sha256) || !Strings.isNullOrEmpty(integrity)); + /* ensureNonEmpty= */ !allowFail, + /* checksumGiven= */ !Strings.isNullOrEmpty(sha256) + || !Strings.isNullOrEmpty(integrity)); Optional checksum; RepositoryFunctionException checksumValidation = null; try { @@ -1141,15 +1152,19 @@ public StructImpl downloadAndExtract( "path to the directory where the archive will be unpacked," + " relative to the repository directory."), @Param( - name = "stripPrefix", + name = "strip_prefix", defaultValue = "''", named = true, doc = - "a directory prefix to strip from the extracted files." - + "\nMany archives contain a top-level directory that contains all files in the" - + " archive. Instead of needing to specify this prefix over and over in the" - + " build_file, this field can be used to strip it from extracted" - + " files."), + """ + a directory prefix to strip from the extracted files. Many archives contain a + top-level directory that contains all files in the archive. Instead of needing to + specify this prefix over and over in the build_file, this field can be + used to strip it from extracted files. + +

For compatibility, this parameter may also be used under the deprecated name + stripPrefix. + """), @Param( name = "rename_files", defaultValue = "{}", @@ -1173,6 +1188,12 @@ public StructImpl downloadAndExtract( + "not attempt to watch the file; passing 'auto' will only attempt to watch " + "the file when it is legal to do so (see watch() docs for more " + "information."), + @Param( + name = "stripPrefix", + documented = false, + positional = false, + named = true, + defaultValue = "''"), }) public void extract( Object archive, @@ -1180,8 +1201,10 @@ public void extract( String stripPrefix, Dict renameFiles, // expected String watchArchive, + String oldStripPrefix, StarlarkThread thread) throws RepositoryFunctionException, InterruptedException, EvalException { + stripPrefix = renamedStripPrefix("extract", stripPrefix, oldStripPrefix); StarlarkPath archivePath = getPath(archive); if (!archivePath.exists()) { @@ -1258,6 +1281,20 @@ public boolean isFinished() { } } + private static String renamedStripPrefix(String method, String stripPrefix, String oldStripPrefix) + throws EvalException { + if (oldStripPrefix.isEmpty()) { + return stripPrefix; + } + if (stripPrefix.isEmpty()) { + return oldStripPrefix; + } + throw Starlark.errorf( + "%s() got multiple values for parameter 'strip_prefix' (via compatibility alias" + + " 'stripPrefix')", + method); + } + @StarlarkMethod( name = "file", doc = "Generates a file in the repository directory with the provided content.", diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index 54c02154e8930d..527b61399e21b9 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -1922,7 +1922,7 @@ def _rule_impl(ctx): result = ctx.download_and_extract( url = [], type = "zip", - stripPrefix="ext", + strip_prefix="ext", sha256 = ctx.attr.sha256, allow_fail = True, )