aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2016-01-26 08:46:08 +0000
committerGravatar Lukacs Berki <lberki@google.com>2016-01-26 13:06:07 +0000
commit546c265ba453008d302a6c73acefc22dbcd6d6e1 (patch)
tree4f9987ba711ebaadeff9997dda941e39f04972c7 /src/main/java/com/google/devtools/build
parentc66373c21630cf467a46d96e2dd1f0f8daf0f42e (diff)
Add a (working) windows compatibility mode that makes Bazel create hardlinks for links to writable files.
Curiously enough, the native Unix JNI wrapper already had a function for link(), but it wasn't on the Java interface. build-runfiles is also updated accordingly. -- MOS_MIGRATED_REVID=113029168
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java9
3 files changed, 27 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java
index b557a6a08a..9534f5c591 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java
@@ -27,8 +27,11 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.shell.CommandException;
import com.google.devtools.build.lib.util.CommandBuilder;
import com.google.devtools.build.lib.util.OsUtils;
+import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.UnixFileSystem;
+import com.google.devtools.build.lib.vfs.UnixFileSystem.SymlinkStrategy;
import java.util.List;
@@ -130,6 +133,12 @@ public final class SymlinkTreeHelper {
args.add("--use_metadata");
}
+ FileSystem fs = execRoot.getFileSystem();
+ if (fs instanceof UnixFileSystem
+ && ((UnixFileSystem) fs).getSymlinkStrategy() == SymlinkStrategy.WINDOWS_COMPATIBLE) {
+ args.add("--windows_compatible");
+ }
+
args.add(inputManifest.getPathString());
args.add(symlinkTreeRoot.getPathString());
diff --git a/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java b/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java
index 2e062a72bb..eab24a525d 100644
--- a/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/unix/FilesystemUtils.java
@@ -167,6 +167,16 @@ public final class FilesystemUtils {
throws IOException;
/**
+ * Native wrapper around POSIX link(2) syscall.
+ *
+ * @param oldpath the file to link to
+ * @param newpath the new path for the link
+ * @throws IOException iff the link() syscall failed.
+ */
+ public static native void link(String oldpath, String newpath)
+ throws IOException;
+
+ /**
* Native wrapper around POSIX stat(2) syscall.
*
* @param path the file to stat.
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java
index c0d41bd9c1..ee6af3fb39 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/UnixFileSystem.java
@@ -374,7 +374,10 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
throws IOException {
SymlinkImplementation strategy = computeSymlinkImplementation(linkPath, targetFragment);
switch (strategy) {
- case HARDLINK: // TBD, fallthrough for now
+ case HARDLINK:
+ FilesystemUtils.link(targetFragment.toString(), linkPath.toString());
+ break;
+
case JUNCTION: // Junctions are emulated on Linux with symlinks, fall through
case SYMLINK:
synchronized (linkPath) {
@@ -492,6 +495,10 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
"Target is a non-writable file", linkPath, targetFragment);
}
+ public SymlinkStrategy getSymlinkStrategy() {
+ return symlinkStrategy;
+ }
+
@Override
protected PathFragment readSymbolicLink(Path path) throws IOException {
// Note that the default implementation of readSymbolicLinkUnchecked calls this method and thus