use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.
the class ExampleWorker method main.
public static void main(String[] args) throws Exception {
if (ImmutableSet.copyOf(args).contains("--persistent_worker")) {
OptionsParser parser = OptionsParser.newOptionsParser(ExampleWorkerOptions.class);
parser.setAllowResidue(false);
parser.parse(args);
ExampleWorkerOptions workerOptions = parser.getOptions(ExampleWorkerOptions.class);
Preconditions.checkState(workerOptions.persistentWorker);
runPersistentWorker(workerOptions);
} else {
// This is a single invocation of the example that exits after it processed the request.
processRequest(ImmutableList.copyOf(args));
}
}
use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.
the class BuildEncyclopediaGenerator method main.
public static void main(String[] args) {
OptionsParser parser = OptionsParser.newOptionsParser(BuildEncyclopediaOptions.class);
parser.setAllowResidue(false);
parser.parseAndExitUponError(args);
BuildEncyclopediaOptions options = parser.getOptions(BuildEncyclopediaOptions.class);
if (options.help) {
printUsage(parser);
Runtime.getRuntime().exit(0);
}
if (options.inputDirs.size() == 0 || options.provider.isEmpty()) {
printUsage(parser);
Runtime.getRuntime().exit(1);
}
try {
BuildEncyclopediaProcessor processor = null;
if (options.singlePage) {
processor = new SinglePageBuildEncyclopediaProcessor(createRuleClassProvider(options.provider));
} else {
processor = new MultiPageBuildEncyclopediaProcessor(createRuleClassProvider(options.provider));
}
processor.generateDocumentation(options.inputDirs, options.outputDir, options.blacklist);
} catch (BuildEncyclopediaDocException e) {
fail(e, false);
} catch (Throwable e) {
fail(e, true);
}
}
use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.
the class DexBuilder method processRequest.
private static void processRequest(ExecutorService executor, Cache<DexingKey, byte[]> dexCache, List<String> args) throws OptionsParsingException, IOException, InterruptedException, ExecutionException {
OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class, DexingOptions.class);
optionsParser.setAllowResidue(false);
optionsParser.parse(args);
Options options = optionsParser.getOptions(Options.class);
try (ZipFile in = new ZipFile(options.inputJar.toFile());
ZipOutputStream out = createZipOutputStream(options.outputZip)) {
produceDexArchive(in, out, executor, /*convertOnReaderThread*/
false, optionsParser.getOptions(DexingOptions.class), dexCache);
}
// Use input's timestamp for output file so the output file is stable.
Files.setLastModifiedTime(options.outputZip, Files.getLastModifiedTime(options.inputJar));
}
use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.
the class DexReducer method parseArguments.
private void parseArguments(String[] args) {
OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
optionsParser.parseAndExitUponError(args);
Options options = optionsParser.getOptions(Options.class);
paths = options.inputZips;
outFile = options.outputZip;
}
use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.
the class RemoteWorker method main.
public static void main(String[] args) throws Exception {
OptionsParser parser = OptionsParser.newOptionsParser(RemoteOptions.class, RemoteWorkerOptions.class);
parser.parseAndExitUponError(args);
RemoteOptions remoteOptions = parser.getOptions(RemoteOptions.class);
RemoteWorkerOptions remoteWorkerOptions = parser.getOptions(RemoteWorkerOptions.class);
if (remoteWorkerOptions.workPath == null) {
printUsage(parser);
return;
}
System.out.println("*** Initializing in-memory cache server.");
ConcurrentMap<String, byte[]> cache = ConcurrentMapFactory.isRemoteCacheOptions(remoteOptions) ? ConcurrentMapFactory.create(remoteOptions) : new ConcurrentHashMap<String, byte[]>();
System.out.println("*** Starting grpc server on all locally bound IPs on port " + remoteWorkerOptions.listenPort + ".");
Path workPath = getFileSystem().getPath(remoteWorkerOptions.workPath);
FileSystemUtils.createDirectoryAndParents(workPath);
RemoteWorker worker = new RemoteWorker(workPath, remoteWorkerOptions, new ConcurrentMapActionCache(cache));
final Server server = ServerBuilder.forPort(remoteWorkerOptions.listenPort).addService(worker.getCasServer()).addService(worker.getExecutionServer()).addService(worker.getExecCacheServer()).build();
server.start();
final Path pidFile;
if (remoteWorkerOptions.pidFile != null) {
pidFile = getFileSystem().getPath(remoteWorkerOptions.pidFile);
PrintWriter writer = new PrintWriter(pidFile.getOutputStream());
writer.append(Integer.toString(ProcessUtils.getpid()));
writer.append("\n");
writer.close();
} else {
pidFile = null;
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.err.println("*** Shutting down grpc server.");
server.shutdown();
if (pidFile != null) {
try {
pidFile.delete();
} catch (IOException e) {
System.err.println("Cannot remove pid file: " + pidFile.toString());
}
}
System.err.println("*** Server shut down.");
}
});
server.awaitTermination();
}
Aggregations