use of com.google.devtools.build.lib.shell.CommandException in project bazel by bazelbuild.
the class CleanCommand method exec.
@Override
public ExitCode exec(CommandEnvironment env, OptionsProvider options) throws ShutdownBlazeServerException {
Options cleanOptions = options.getOptions(Options.class);
cleanOptions.expunge_async = cleanOptions.cleanStyle.equals("expunge_async");
cleanOptions.expunge = cleanOptions.cleanStyle.equals("expunge");
cleanOptions.async = cleanOptions.cleanStyle.equals("async");
env.getEventBus().post(new NoBuildEvent());
if (!cleanOptions.expunge && !cleanOptions.expunge_async && !cleanOptions.async && !cleanOptions.cleanStyle.isEmpty()) {
env.getReporter().handle(Event.error(null, "Invalid clean_style value '" + cleanOptions.cleanStyle + "'"));
return ExitCode.COMMAND_LINE_ERROR;
}
String asyncName = (cleanOptions.expunge || cleanOptions.expunge_async) ? "--expunge_async" : "--async";
// for non-Linux platforms (https://github.com/bazelbuild/bazel/issues/1906).
if ((cleanOptions.expunge_async || cleanOptions.async) && OS.getCurrent() != OS.LINUX) {
boolean expunge = cleanOptions.expunge_async;
String fallbackName = expunge ? "--expunge" : "synchronous clean";
env.getReporter().handle(Event.info(null, /*location*/
asyncName + " cannot be used on non-Linux platforms, falling back to " + fallbackName));
cleanOptions.expunge_async = false;
cleanOptions.expunge = expunge;
cleanOptions.async = false;
cleanOptions.cleanStyle = expunge ? "expunge" : "";
}
String cleanBanner = (cleanOptions.expunge_async || cleanOptions.async) ? "Starting clean." : "Starting clean (this may take a while). " + "Consider using " + asyncName + " if the clean takes more than several minutes.";
env.getReporter().handle(Event.info(null, /*location*/
cleanBanner));
try {
String symlinkPrefix = options.getOptions(BuildRequest.BuildRequestOptions.class).getSymlinkPrefix(env.getRuntime().getProductName());
actuallyClean(env, env.getOutputBase(), cleanOptions, symlinkPrefix);
return ExitCode.SUCCESS;
} catch (IOException e) {
env.getReporter().handle(Event.error(e.getMessage()));
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
} catch (CommandException | ExecException e) {
env.getReporter().handle(Event.error(e.getMessage()));
return ExitCode.RUN_FAILURE;
} catch (InterruptedException e) {
env.getReporter().handle(Event.error("clean interrupted"));
return ExitCode.INTERRUPTED;
}
}
use of com.google.devtools.build.lib.shell.CommandException in project bazel by bazelbuild.
the class DarwinSandboxRunner method isSupported.
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");
args.add("(version 1) (allow default)");
args.add("/usr/bin/true");
ImmutableMap<String, String> env = ImmutableMap.of();
File cwd = new File("/usr/bin");
Command cmd = new Command(args.toArray(new String[0]), env, cwd);
try {
cmd.execute(/* stdin */
new byte[] {}, Command.NO_OBSERVER, ByteStreams.nullOutputStream(), ByteStreams.nullOutputStream(), /* killSubprocessOnInterrupt */
true);
} catch (CommandException e) {
return false;
}
return true;
}
use of com.google.devtools.build.lib.shell.CommandException in project bazel by bazelbuild.
the class DarwinSandboxedStrategy method getConfStr.
/**
* Returns the value of a POSIX or X/Open system configuration variable.
*/
private static String getConfStr(String confVar) throws IOException {
String[] commandArr = new String[2];
commandArr[0] = "getconf";
commandArr[1] = confVar;
Command cmd = new Command(commandArr);
CommandResult res;
try {
res = cmd.execute();
} catch (CommandException e) {
throw new IOException("getconf failed", e);
}
return new String(res.getStdout(), UTF_8).trim();
}
Aggregations