Skip to content

Commit

Permalink
Clarify documentation for repository_ctx.symlink() and rename paramet…
Browse files Browse the repository at this point in the history
…ers to match `ln`.

RELNOTES: None.
PiperOrigin-RevId: 474033473
Change-Id: I125c14669e4c4ce234227b5e3211b1027d10e41f
  • Loading branch information
ahumesky authored and Copybara-Service committed Sep 13, 2022
1 parent 2a39af6 commit fdcaaf4
Showing 1 changed file with 19 additions and 14 deletions.
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit fdcaaf4

Please sign in to comment.