Skip to content

Commit

Permalink
[7.4.0] Repo context cherry-picks (#23389)
Browse files Browse the repository at this point in the history
Cherry-picks the following commits:
* Clarify /rules/lib/builtins/repository_ctx description of default
working_directory for execute()
(fa2fbcd)
* Normalize repository starlark API docs
(8f16990)
* Document source of truth for `rctx.download*` cache key
(d4b416f)
* Make `get_default_canonical_id` public
(6052ad6)
* No longer eagerly fetch labels in repo rule
(6fabb1f)

Closes #23372

---------

Co-authored-by: David Sanderson <32687193+dws@users.noreply.github.com>
Co-authored-by: Jordan Mele <SiliconSoldier@outlook.com.au>
Co-authored-by: Jordan Mele <jordan.mele@outlook.com.au>
  • Loading branch information
4 people authored Aug 24, 2024
1 parent 069dd38 commit f1a1f2d
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 584 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
name = "exec_result",
category = DocCategory.BUILTIN,
doc =
"A structure storing result of repository_ctx.execute() method. It contains the standard"
+ " output stream content, the standard error stream content and the execution return"
+ " code.")
"""
A structure storing result of repository_ctx.execute() method. It contains the standard \
output stream content, the standard error stream content and the execution return \
code.
""")
final class StarlarkExecutionResult implements StarlarkValue {
private final int returnCode;
private final String stdout;
Expand All @@ -73,9 +75,11 @@ public boolean isImmutable() {
name = "return_code",
structField = true,
doc =
"The return code returned after the execution of the program. 256 if the process was"
+ " terminated by a time out; values larger than 128 indicate termination by a"
+ " signal.")
"""
The return code returned after the execution of the program. 256 if the process was \
terminated by a time out; values larger than 128 indicate termination by a \
signal.
""")
public int getReturnCode() {
return returnCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public boolean isImmutable() {
name = "environ",
structField = true,
doc =
"The dictionary of environment variables."
+ "<p><b>NOTE</b>: Retrieving an environment variable from this dictionary does not "
+ "establish a dependency from a repository rule or module extension to the "
+ "environment variable. To establish a dependency when looking up an "
+ "environment variable, use either <code>repository_ctx.getenv</code> or "
+ "<code>module_ctx.getenv</code> instead.")
"""
The dictionary of environment variables. \
<p><b>NOTE</b>: Retrieving an environment variable from this dictionary does not \
establish a dependency from a repository rule or module extension to the \
environment variable. To establish a dependency when looking up an \
environment variable, use either <code>repository_ctx.getenv</code> or \
<code>module_ctx.getenv</code> instead.
""")
public ImmutableMap<String, String> getEnvironmentVariables() {
return environ;
}
Expand All @@ -60,8 +62,10 @@ public ImmutableMap<String, String> getEnvironmentVariables() {
name = "name",
structField = true,
doc =
"A string identifying the operating system Bazel is running on (the value of the"
+ " \"os.name\" Java property converted to lower case).")
"""
A string identifying the operating system Bazel is running on (the value of the \
<code>"os.name"</code> Java property converted to lower case).
""")
public String getName() {
return System.getProperty("os.name").toLowerCase(Locale.ROOT);
}
Expand All @@ -70,8 +74,10 @@ public String getName() {
name = "arch",
structField = true,
doc =
"A string identifying the architecture Bazel is running on (the value of the \"os.arch\""
+ " Java property converted to lower case).")
"""
A string identifying the architecture Bazel is running on (the value of the \
<code>"os.arch"</code> Java property converted to lower case).
""")
public String getArch() {
return System.getProperty("os.arch").toLowerCase(Locale.ROOT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,27 @@ public String getBasename() {
@StarlarkMethod(
name = "readdir",
doc =
"Returns the list of entries in the directory denoted by this path. Each entry is a "
+ "<code>path</code> object itself.",
"""
Returns the list of entries in the directory denoted by this path. Each entry is a \
<code>path</code> object itself.
""",
parameters = {
@Param(
name = "watch",
defaultValue = "'auto'",
positional = false,
named = true,
doc =
"whether Bazel should watch the list of entries in this directory and refetch the "
+ "repository or re-evaluate the module extension next time when any changes "
+ "are detected. Changes to detect include entry creation, deletion, and "
+ "renaming. Note that this doesn't watch the <em>contents</em> of any entries "
+ "in the directory.<p>Can be the string 'yes', 'no', or 'auto'. If set to "
+ "'auto', Bazel will only watch this directory when it is legal to do so (see "
+ "<a "
+ "href=\"repository_ctx.html#watch\"><code>repository_ctx.watch()</code></a> "
+ "docs for more information)."),
"""
whether Bazel should watch the list of entries in this directory and refetch the \
repository or re-evaluate the module extension next time when any changes \
are detected. Changes to detect include entry creation, deletion, and \
renaming. Note that this doesn't watch the <em>contents</em> of any entries \
in the directory.<p>Can be the string 'yes', 'no', or 'auto'. If set to \
'auto', Bazel will only watch this directory when it is legal to do so (see \
<a href="repository_ctx.html#watch"><code>repository_ctx.watch()</code></a> \
docs for more information).
"""),
})
public ImmutableList<StarlarkPath> readdir(String watch)
throws EvalException, RepositoryFunctionException, InterruptedException {
Expand Down Expand Up @@ -138,8 +141,10 @@ public StarlarkPath getDirname() {
@Param(
name = "relative_paths",
doc =
"Zero or more relative path strings to append to this path with path separators"
+ "added as needed."))
"""
Zero or more relative path strings to append to this path with path separators \
added as needed.
"""))
public StarlarkPath getChild(Tuple relativePaths) throws EvalException {
return new StarlarkPath(
ctx,
Expand All @@ -153,10 +158,12 @@ public StarlarkPath getChild(Tuple relativePaths) throws EvalException {
name = "exists",
structField = true,
doc =
"Returns true if the file or directory denoted by this path exists.<p>Note that "
+ "accessing this field does <em>not</em> cause the path to be watched. If you'd "
+ "like the repo rule or module extension to be sensitive to the path's existence, "
+ "use the <code>watch()</code> method on the context object.")
"""
Returns true if the file or directory denoted by this path exists.<p>Note that \
accessing this field does <em>not</em> cause the path to be watched. If you'd \
like the repo rule or module extension to be sensitive to the path's existence, \
use the <code>watch()</code> method on the context object.
""")
public boolean exists() {
return path.exists();
}
Expand All @@ -165,10 +172,12 @@ public boolean exists() {
name = "is_dir",
structField = true,
doc =
"Returns true if this path points to a directory.<p>Note that accessing this field does "
+ "<em>not</em> cause the path to be watched. If you'd like the repo rule or module "
+ "extension to be sensitive to whether the path is a directory or a file, use the "
+ "<code>watch()</code> method on the context object.")
"""
Returns true if this path points to a directory.<p>Note that accessing this field does \
<em>not</em> cause the path to be watched. If you'd like the repo rule or module \
extension to be sensitive to whether the path is a directory or a file, use the \
<code>watch()</code> method on the context object.
""")
public boolean isDir() {
return path.isDirectory();
}
Expand All @@ -177,8 +186,10 @@ public boolean isDir() {
name = "realpath",
structField = true,
doc =
"Returns the canonical path for this path by repeatedly replacing all symbolic links "
+ "with their referents.")
"""
Returns the canonical path for this path by repeatedly replacing all symbolic links \
with their referents.
""")
public StarlarkPath realpath() throws IOException {
return new StarlarkPath(ctx, path.resolveSymbolicLinks());
}
Expand Down
Loading

0 comments on commit f1a1f2d

Please sign in to comment.