Skip to content

Commit

Permalink
Check OS X version to decide if sandbox is supported.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=132570504
  • Loading branch information
hermione521 authored and damienmg committed Sep 9, 2016
1 parent bfa369f commit 934d42d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.devtools.build.lib.shell.CommandException;
import com.google.devtools.build.lib.shell.KillableObserver;
import com.google.devtools.build.lib.shell.TimeoutKillableObserver;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.Path;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -58,6 +59,24 @@ final class DarwinSandboxRunner extends SandboxRunner {
}

static boolean isSupported() {
// Check osx version, only >=10.11 is supported.
// And we should check if sandbox still work when it gets 11.x
String osxVersion = OS.getVersion();
String[] parts = osxVersion.split("\\.");
if (parts.length != 3) {
// Currently the format is 10.11.x
return false;
}
try {
int v0 = Integer.parseInt(parts[0]);
int v1 = Integer.parseInt(parts[1]);
if (v0 != 10 || v1 < 11) {
return false;
}
} catch (NumberFormatException e) {
return false;
}

List<String> args = new ArrayList<>();
args.add(SANDBOX_EXEC);
args.add("-p");
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/google/devtools/build/lib/util/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public String getCanonicalName() {
return canonicalName;
}

public static String getVersion() {
return System.getProperty("os.version");
}

@Override
public String toString() {
return getCanonicalName();
Expand All @@ -55,7 +59,7 @@ private static OS determineCurrentOs() {
osName = System.getProperty("os.name");
}

if (osName == null) {
if (osName == null) {
return OS.UNKNOWN;
}

Expand Down

0 comments on commit 934d42d

Please sign in to comment.