From 96202b17df83f61c5c0ddf39dc42c1db177f9162 Mon Sep 17 00:00:00 2001 From: Lukacs Berki Date: Thu, 11 Feb 2016 13:45:56 +0000 Subject: Make local_repository and new_local_repository work on Windows. This makes it possible to compile //third_party/ijar with a bootstrapped Bazel on Windows in dslomov's tree. -- MOS_MIGRATED_REVID=114428109 --- .../lib/rules/repository/LocalRepositoryFunction.java | 13 ++----------- .../build/lib/rules/repository/RepositoryFunction.java | 11 +++-------- .../com/google/devtools/build/lib/vfs/FileSystemUtils.java | 14 +++++--------- .../google/devtools/build/lib/vfs/WindowsFileSystem.java | 5 +++++ 4 files changed, 15 insertions(+), 28 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java index d37204379e..eb527befc9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java @@ -19,8 +19,6 @@ import com.google.devtools.build.lib.packages.AggregatingAttributeMapper; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.skyframe.FileValue; import com.google.devtools.build.lib.syntax.Type; -import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyFunction.Environment; @@ -45,18 +43,11 @@ public class LocalRepositoryFunction extends RepositoryFunction { AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule); PathFragment pathFragment = new PathFragment(mapper.get("path", Type.STRING)); try { - FileSystem fs = outputDirectory.getFileSystem(); - if (fs.supportsSymbolicLinksNatively()) { - outputDirectory.createSymbolicLink(pathFragment); - } else { - FileSystemUtils.createDirectoryAndParents(outputDirectory); - FileSystemUtils.copyTreesBelow( - fs.getPath(getTargetPath(rule, getWorkspace())), outputDirectory); - } + outputDirectory.createSymbolicLink(pathFragment); } catch (IOException e) { throw new RepositoryFunctionException( new IOException("Could not create symlink to repository " + pathFragment + ": " - + e.getMessage()), Transience.TRANSIENT); + + e.getMessage(), e), Transience.TRANSIENT); } FileValue repositoryValue = getRepositoryDirectory(outputDirectory, env); if (repositoryValue == null) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java index 7f230a7ef6..ee93a82227 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java @@ -339,14 +339,9 @@ public abstract class RepositoryFunction { throws RepositoryFunctionException { try { FileSystemUtils.createDirectoryAndParents(repositoryDirectory); - if (repositoryDirectory.getFileSystem().supportsSymbolicLinksNatively()) { - for (Path target : targetDirectory.getDirectoryEntries()) { - Path symlinkPath = - repositoryDirectory.getRelative(target.getBaseName()); - createSymbolicLink(symlinkPath, target); - } - } else { - FileSystemUtils.copyTreesBelow(targetDirectory, repositoryDirectory); + for (Path target : targetDirectory.getDirectoryEntries()) { + Path symlinkPath = repositoryDirectory.getRelative(target.getBaseName()); + createSymbolicLink(symlinkPath, target); } } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java index 55dd402411..900f6dbae2 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystemUtils.java @@ -583,8 +583,7 @@ public class FileSystemUtils { /** * Copies all dir trees under a given 'from' dir to location 'to', while overwriting - * all files in the potentially existing 'to'. Does not follow any symbolic links, - * but copies them instead. + * all files in the potentially existing 'to'. Resolves symbolic links. * *

The source and the destination must be non-overlapping, otherwise an * IllegalArgumentException will be thrown. This method cannot be used to copy @@ -602,16 +601,13 @@ public class FileSystemUtils { Collection entries = from.getDirectoryEntries(); for (Path entry : entries) { - if (entry.isDirectory(Symlinks.NOFOLLOW)) { + if (entry.isFile()) { + Path newEntry = to.getChild(entry.getBaseName()); + copyFile(entry, newEntry); + } else { Path subDir = to.getChild(entry.getBaseName()); subDir.createDirectory(); copyTreesBelow(entry, subDir); - } else if (entry.isSymbolicLink()) { - Path newLink = to.getChild(entry.getBaseName()); - newLink.createSymbolicLink(entry.readSymbolicLinkUnchecked()); - } else { - Path newEntry = to.getChild(entry.getBaseName()); - copyFile(entry, newEntry); } } } diff --git a/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java index 80bb9dca9b..d15d7c68c2 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java @@ -53,6 +53,11 @@ public class WindowsFileSystem extends JavaIoFileSystem { } } + @Override + public boolean supportsSymbolicLinksNatively() { + return false; + } + private void createDirectoryJunction(File sourceDirectory, File targetPath) throws IOException { StringBuilder cl = new StringBuilder("cmd.exe /c "); cl.append("mklink /J "); -- cgit v1.2.3