Search in sources :

Example 46 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class TestResultAnalyzerTest method createMocks.

@Before
public final void createMocks() throws Exception {
    Path mockPath = mock(Path.class);
    OptionsParser testSpecificOptions = OptionsParser.newOptionsParser(TestSummaryOptions.class, ExecutionOptions.class);
    EventBus mockBus = mock(EventBus.class);
    underTest = new TestResultAnalyzer(mockPath, testSpecificOptions.getOptions(TestSummaryOptions.class), testSpecificOptions.getOptions(ExecutionOptions.class), mockBus);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) EventBus(com.google.common.eventbus.EventBus) OptionsParser(com.google.devtools.common.options.OptionsParser) Before(org.junit.Before)

Example 47 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class InvocationPolicyEnforcerTest method createOptionsPolicyEnforcer.

private static InvocationPolicyEnforcer createOptionsPolicyEnforcer(InvocationPolicy.Builder invocationPolicyBuilder) throws Exception {
    InvocationPolicy policyProto = invocationPolicyBuilder.build();
    // An OptionsPolicyEnforcer could be constructed in the test directly from the InvocationPolicy
    // proto, however Blaze will actually take the policy as another flag with a Base64 encoded
    // binary proto and parse that, so exercise that code path in the test.
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    policyProto.writeTo(out);
    String policyBase64 = BaseEncoding.base64().encode(out.toByteArray());
    OptionsParser startupOptionsParser = OptionsParser.newOptionsParser(BlazeServerStartupOptions.class);
    String policyOption = "--invocation_policy=" + policyBase64;
    startupOptionsParser.parse(policyOption);
    return InvocationPolicyEnforcer.create(startupOptionsParser.getOptions(BlazeServerStartupOptions.class).invocationPolicy);
}
Also used : InvocationPolicy(com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 48 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class ConfigurationTestCase method createCollection.

protected BuildConfigurationCollection createCollection(String... args) throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(ImmutableList.<Class<? extends OptionsBase>>builder().addAll(buildOptionClasses).add(TestOptions.class).build());
    parser.parse(args);
    InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
    optionsPolicyEnforcer.enforce(parser);
    ImmutableSortedSet<String> multiCpu = ImmutableSortedSet.copyOf(parser.getOptions(TestOptions.class).multiCpus);
    BuildOptions buildOptions = BuildOptions.applyStaticConfigOverride(BuildOptions.of(buildOptionClasses, parser));
    skyframeExecutor.handleDiffs(reporter);
    BuildConfigurationCollection collection = skyframeExecutor.createConfigurations(reporter, configurationFactory, buildOptions, multiCpu, false);
    return collection;
}
Also used : OptionsBase(com.google.devtools.common.options.OptionsBase) BuildOptions(com.google.devtools.build.lib.analysis.config.BuildOptions) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParser(com.google.devtools.common.options.OptionsParser) BuildConfigurationCollection(com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection)

Example 49 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class PackageCacheTest method parsePackageCacheOptions.

private PackageCacheOptions parsePackageCacheOptions(String... options) throws Exception {
    OptionsParser parser = OptionsParser.newOptionsParser(PackageCacheOptions.class);
    parser.parse(new String[] { "--default_visibility=public" });
    parser.parse(options);
    InvocationPolicyEnforcer optionsPolicyEnforcer = analysisMock.getInvocationPolicyEnforcer();
    try {
        optionsPolicyEnforcer.enforce(parser);
    } catch (OptionsParsingException e) {
        throw new IllegalStateException(e);
    }
    return parser.getOptions(PackageCacheOptions.class);
}
Also used : InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) OptionsParser(com.google.devtools.common.options.OptionsParser)

Example 50 with OptionsParser

use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.

the class ExampleWorker method processRequest.

private static void processRequest(List<String> args) throws Exception {
    ImmutableList.Builder<String> expandedArgs = ImmutableList.builder();
    for (String arg : args) {
        Matcher flagFileMatcher = FLAG_FILE_PATTERN.matcher(arg);
        if (flagFileMatcher.matches()) {
            expandedArgs.addAll(Files.readAllLines(Paths.get(flagFileMatcher.group(1)), UTF_8));
        } else {
            expandedArgs.add(arg);
        }
    }
    OptionsParser parser = OptionsParser.newOptionsParser(ExampleWorkOptions.class);
    parser.setAllowResidue(true);
    parser.parse(expandedArgs.build());
    ExampleWorkOptions options = parser.getOptions(ExampleWorkOptions.class);
    List<String> outputs = new ArrayList<>();
    if (options.writeUUID) {
        outputs.add("UUID " + workerUuid.toString());
    }
    if (options.writeCounter) {
        outputs.add("COUNTER " + workUnitCounter++);
    }
    String residueStr = Joiner.on(' ').join(parser.getResidue());
    if (options.uppercase) {
        residueStr = residueStr.toUpperCase();
    }
    outputs.add(residueStr);
    if (options.printInputs) {
        for (Entry<String, String> input : inputs.entrySet()) {
            outputs.add("INPUT " + input.getKey() + " " + input.getValue());
        }
    }
    if (options.printEnv) {
        for (Entry<String, String> entry : System.getenv().entrySet()) {
            outputs.add(entry.getKey() + "=" + entry.getValue());
        }
    }
    String outputStr = Joiner.on('\n').join(outputs);
    if (options.outputFile.isEmpty()) {
        System.out.println(outputStr);
    } else {
        try (PrintStream outputFile = new PrintStream(options.outputFile)) {
            outputFile.println(outputStr);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) Matcher(java.util.regex.Matcher) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) OptionsParser(com.google.devtools.common.options.OptionsParser) ExampleWorkOptions(com.google.devtools.build.lib.worker.ExampleWorkerOptions.ExampleWorkOptions)

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