Search in sources :

Example 1 with OptionsParser

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));
    }
}
Also used : OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 2 with OptionsParser

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);
    }
}
Also used : OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 3 with OptionsParser

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));
}
Also used : DexingOptions(com.google.devtools.build.android.dexer.Dexing.DexingOptions) ZipFile(java.util.zip.ZipFile) DexingOptions(com.google.devtools.build.android.dexer.Dexing.DexingOptions) ZipOutputStream(java.util.zip.ZipOutputStream) OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 4 with OptionsParser

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;
}
Also used : OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 5 with OptionsParser

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();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) Server(io.grpc.Server) ConcurrentMapActionCache(com.google.devtools.build.lib.remote.ConcurrentMapActionCache) RemoteOptions(com.google.devtools.build.lib.remote.RemoteOptions) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) OptionsParser(com.google.devtools.common.options.OptionsParser) PrintWriter(java.io.PrintWriter)

Aggregations

OptionsParser (com.google.devtools.common.options.OptionsParser)50 Path (java.nio.file.Path)11 IOException (java.io.IOException)10 Stopwatch (com.google.common.base.Stopwatch)8 Test (org.junit.Test)7 InvocationPolicyEnforcer (com.google.devtools.build.lib.flags.InvocationPolicyEnforcer)6 OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)6 AaptConfigOptions (com.google.devtools.build.android.AndroidResourceProcessor.AaptConfigOptions)5 OptionsBase (com.google.devtools.common.options.OptionsBase)5 MergingException (com.android.ide.common.res2.MergingException)4 Path (com.google.devtools.build.lib.vfs.Path)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 EventBus (com.google.common.eventbus.EventBus)3 FlagAaptOptions (com.google.devtools.build.android.AndroidResourceProcessor.FlagAaptOptions)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 VariantType (com.android.builder.core.VariantType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 DexingOptions (com.google.devtools.build.android.dexer.Dexing.DexingOptions)2 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)2