From fdcaaf4af3296bf544589810ad46b438bfe5e1fb Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 13 Sep 2022 09:05:14 -0700 Subject: [PATCH] Clarify documentation for repository_ctx.symlink() and rename parameters to match `ln`. RELNOTES: None. PiperOrigin-RevId: 474033473 Change-Id: I125c14669e4c4ce234227b5e3211b1027d10e41f --- .../starlark/StarlarkRepositoryContext.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryContext.java index 6852a96fa09241..3f3d271153d801 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryContext.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryContext.java @@ -182,46 +182,51 @@ private StarlarkPath externalPath(String method, Object pathObject) useStarlarkThread = true, parameters = { @Param( - name = "from", + name = "target", allowedTypes = { @ParamType(type = String.class), @ParamType(type = Label.class), @ParamType(type = StarlarkPath.class) }, - doc = "path to which the created symlink should point to."), + doc = "The path that the symlink should point to."), @Param( - name = "to", + name = "link_name", allowedTypes = { @ParamType(type = String.class), @ParamType(type = Label.class), @ParamType(type = StarlarkPath.class) }, - doc = "path of the symlink to create, relative to the repository directory."), + doc = "The path of the symlink to create, relative to the repository directory."), }) - public void symlink(Object from, Object to, StarlarkThread thread) + public void symlink(Object target, Object linkName, StarlarkThread thread) throws RepositoryFunctionException, EvalException, InterruptedException { - StarlarkPath fromPath = getPath("symlink()", from); - StarlarkPath toPath = getPath("symlink()", to); + StarlarkPath targetPath = getPath("symlink()", target); + StarlarkPath linkPath = getPath("symlink()", linkName); WorkspaceRuleEvent w = WorkspaceRuleEvent.newSymlinkEvent( - fromPath.toString(), - toPath.toString(), + targetPath.toString(), + linkPath.toString(), getIdentifyingStringForLogging(), thread.getCallerLocation()); env.getListener().post(w); try { - checkInOutputDirectory("write", toPath); - makeDirectories(toPath.getPath()); - toPath.getPath().createSymbolicLink(fromPath.getPath()); + checkInOutputDirectory("write", linkPath); + makeDirectories(linkPath.getPath()); + linkPath.getPath().createSymbolicLink(targetPath.getPath()); } catch (IOException e) { throw new RepositoryFunctionException( new IOException( - "Could not create symlink from " + fromPath + " to " + toPath + ": " + e.getMessage(), + "Could not create symlink from " + + targetPath + + " to " + + linkPath + + ": " + + e.getMessage(), e), Transience.TRANSIENT); } catch (InvalidPathException e) { throw new RepositoryFunctionException( - Starlark.errorf("Could not create %s: %s", toPath, e.getMessage()), + Starlark.errorf("Could not create %s: %s", linkPath, e.getMessage()), Transience.PERSISTENT); } }