Skip to content

Commit f686677

Browse files
kchodorowlberki
authored andcommitted
Preserve repositories' rooted paths
This was taking the "right" rooted path, converting it to a path, and then making the rooted path [/path/to/external/repo/BUILD]/[] (where it should have been [/path/to/external/repo]/[BUILD]). -- MOS_MIGRATED_REVID=107726114
1 parent 8533b7a commit f686677

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ protected RepositoryValue writeBuildFile(FileValue directoryValue, String conten
135135
protected RepositoryValue symlinkBuildFile(
136136
Rule rule, Path workspaceDirectory, FileValue directoryValue, Environment env)
137137
throws RepositoryFunctionException {
138+
Preconditions.checkState(
139+
directoryValue.realRootedPath().getRelativePath().equals(PathFragment.EMPTY_FRAGMENT));
140+
138141
AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
139142
PathFragment buildFile = new PathFragment(mapper.get("build_file", Type.STRING));
140143
Path buildFileTarget = workspaceDirectory.getRelative(buildFile);
@@ -167,7 +170,8 @@ protected RepositoryValue symlinkBuildFile(
167170
Transience.TRANSIENT);
168171
}
169172

170-
Path buildFilePath = directoryValue.realRootedPath().asPath().getRelative("BUILD");
173+
RootedPath buildFilePath = RootedPath.toRootedPath(
174+
directoryValue.realRootedPath().getRoot(), new PathFragment("BUILD"));
171175
if (createSymbolicLink(buildFilePath, buildFileTarget, env) == null) {
172176
return null;
173177
}
@@ -207,8 +211,8 @@ public static boolean symlinkLocalRepositoryContents(
207211
throws RepositoryFunctionException {
208212
try {
209213
for (Path target : targetDirectory.getDirectoryEntries()) {
210-
Path symlinkPath =
211-
repositoryDirectory.getRelative(target.getBaseName());
214+
RootedPath symlinkPath = RootedPath.toRootedPath(
215+
repositoryDirectory, new PathFragment(target.getBaseName()));
212216
if (createSymbolicLink(symlinkPath, target, env) == null) {
213217
return false;
214218
}
@@ -220,24 +224,23 @@ public static boolean symlinkLocalRepositoryContents(
220224
return true;
221225
}
222226

223-
private static FileValue createSymbolicLink(Path from, Path to, Environment env)
227+
private static FileValue createSymbolicLink(RootedPath from, Path to, Environment env)
224228
throws RepositoryFunctionException {
229+
Path fromPath = from.asPath();
225230
try {
226231
// Remove not-symlinks that are already there.
227-
if (from.exists()) {
228-
from.delete();
232+
if (fromPath.exists()) {
233+
fromPath.delete();
229234
}
230-
FileSystemUtils.ensureSymbolicLink(from, to);
235+
FileSystemUtils.ensureSymbolicLink(fromPath, to);
231236
} catch (IOException e) {
232237
throw new RepositoryFunctionException(
233238
new IOException(String.format("Error creating symbolic link from %s to %s: %s",
234239
from, to, e.getMessage())), Transience.TRANSIENT);
235240
}
236241

237-
SkyKey outputDirectoryKey = FileValue.key(RootedPath.toRootedPath(
238-
from, PathFragment.EMPTY_FRAGMENT));
239242
try {
240-
return (FileValue) env.getValueOrThrow(outputDirectoryKey, IOException.class,
243+
return (FileValue) env.getValueOrThrow(FileValue.key(from), IOException.class,
241244
FileSymlinkException.class, InconsistentFilesystemException.class);
242245
} catch (IOException | FileSymlinkException | InconsistentFilesystemException e) {
243246
throw new RepositoryFunctionException(

0 commit comments

Comments
 (0)