Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0.0] Rename stripPrefix= to strip_prefix= #24035

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
<code>build_file</code>, 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 <code>build_file</code>, this field can
be used to strip it from extracted files.

<p>For compatibility, this parameter may also be used under the deprecated name
<code>stripPrefix</code>.
"""),
@Param(
name = "allow_fail",
Expand Down Expand Up @@ -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,
Expand All @@ -986,8 +994,10 @@ public StructImpl downloadAndExtract(
Dict<?, ?> headersUnchecked, // <String, List<String> | String> expected
String integrity,
Dict<?, ?> renameFiles, // <String, String> expected
String oldStripPrefix,
StarlarkThread thread)
throws RepositoryFunctionException, InterruptedException, EvalException {
stripPrefix = renamedStripPrefix("download_and_extract", stripPrefix, oldStripPrefix);
ImmutableMap<URI, Map<String, List<String>>> authHeaders =
getAuthHeaders(getAuthContents(authUnchecked, "auth"));

Expand All @@ -996,8 +1006,9 @@ public StructImpl downloadAndExtract(
ImmutableList<URL> urls =
getUrls(
url,
/*ensureNonEmpty=*/ !allowFail,
/*checksumGiven=*/ !Strings.isNullOrEmpty(sha256) || !Strings.isNullOrEmpty(integrity));
/* ensureNonEmpty= */ !allowFail,
/* checksumGiven= */ !Strings.isNullOrEmpty(sha256)
|| !Strings.isNullOrEmpty(integrity));
Optional<Checksum> checksum;
RepositoryFunctionException checksumValidation = null;
try {
Expand Down Expand Up @@ -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"
+ " <code>build_file</code>, 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 <code>build_file</code>, this field can be
used to strip it from extracted files.

<p>For compatibility, this parameter may also be used under the deprecated name
<code>stripPrefix</code>.
"""),
@Param(
name = "rename_files",
defaultValue = "{}",
Expand All @@ -1173,15 +1188,23 @@ 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 <code>watch()</code> docs for more "
+ "information."),
@Param(
name = "stripPrefix",
documented = false,
positional = false,
named = true,
defaultValue = "''"),
})
public void extract(
Object archive,
Object output,
String stripPrefix,
Dict<?, ?> renameFiles, // <String, String> expected
String watchArchive,
String oldStripPrefix,
StarlarkThread thread)
throws RepositoryFunctionException, InterruptedException, EvalException {
stripPrefix = renamedStripPrefix("extract", stripPrefix, oldStripPrefix);
StarlarkPath archivePath = getPath(archive);

if (!archivePath.exists()) {
Expand Down Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Loading