Search in sources :

Example 16 with OptionsParsingException

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

the class BlazeRuntime method serverMain.

/**
   * A main method that does not send email. The return value indicates the desired exit status of
   * the program.
   */
private static int serverMain(Iterable<BlazeModule> modules, OutErr outErr, String[] args) {
    InterruptSignalHandler sigintHandler = null;
    try {
        final RPCServer blazeServer = createBlazeRPCServer(modules, Arrays.asList(args));
        // Register the signal handler.
        sigintHandler = new InterruptSignalHandler() {

            @Override
            public void run() {
                LOG.severe("User interrupt");
                blazeServer.interrupt();
            }
        };
        blazeServer.serve();
        return ExitCode.SUCCESS.getNumericExitCode();
    } catch (OptionsParsingException e) {
        outErr.printErr(e.getMessage());
        return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode();
    } catch (IOException e) {
        outErr.printErr("I/O Error: " + e.getMessage());
        return ExitCode.BUILD_FAILURE.getNumericExitCode();
    } catch (AbruptExitException e) {
        outErr.printErr(e.getMessage());
        return e.getExitCode().getNumericExitCode();
    } finally {
        if (sigintHandler != null) {
            sigintHandler.uninstall();
        }
    }
}
Also used : InterruptSignalHandler(com.google.devtools.build.lib.server.signal.InterruptSignalHandler) RPCServer(com.google.devtools.build.lib.server.RPCServer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) IOException(java.io.IOException) AbruptExitException(com.google.devtools.build.lib.util.AbruptExitException)

Example 17 with OptionsParsingException

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

the class DateFilterConverter method convert.

@Override
public DateFilter convert(String input) throws OptionsParsingException {
    if (input.isEmpty()) {
        return null;
    }
    String[] parts = input.split("\\.\\.");
    if (parts.length != 2) {
        throw new OptionsParsingException("Error parsing time_between option: no '..' found.");
    }
    if (parts[0].isEmpty()) {
        throw new OptionsParsingException("Error parsing time_between option: start date not found");
    }
    if (parts[1].isEmpty()) {
        throw new OptionsParsingException("Error parsing time_between option: end date not found");
    }
    // TODO(yueg): support more date formats
    try {
        Date from = DateFilter.DATE_FORMAT.parse(parts[0]);
        Date to = DateFilter.DATE_FORMAT.parse(parts[1]);
        return new DateFilter(from, to);
    } catch (ParseException e) {
        throw new OptionsParsingException("Error parsing datetime, format should be: yyyy-MM-ddTHH:mm:ss");
    }
}
Also used : OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) ParseException(java.text.ParseException) Date(java.util.Date)

Example 18 with OptionsParsingException

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

the class InvocationPolicyEnforcerTest method testAllowValuesDisallowsFlagDefaultButNoPolicyDefault.

@Test
public void testAllowValuesDisallowsFlagDefaultButNoPolicyDefault() throws Exception {
    InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
    invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getAllowValuesBuilder().addAllowedValues("foo").addAllowedValues("bar");
    InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
    // Option should be its default
    TestOptions testOptions = getTestOptions();
    assertEquals(STRING_FLAG_DEFAULT, testOptions.testString);
    try {
        enforcer.enforce(parser, "build");
        fail();
    } catch (OptionsParsingException e) {
    // expected.
    }
}
Also used : InvocationPolicy(com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) Test(org.junit.Test)

Example 19 with OptionsParsingException

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

the class InvocationPolicyEnforcerTest method testAllowValuesDisallowsMultipleValues.

@Test
public void testAllowValuesDisallowsMultipleValues() throws Exception {
    InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
    invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_multiple_string").getAllowValuesBuilder().addAllowedValues("foo").addAllowedValues("bar");
    InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
    parser.parse("--test_multiple_string=baz", "--test_multiple_string=bar");
    // Option should be "baz" and "bar" as specified by the user.
    TestOptions testOptions = getTestOptions();
    assertThat(testOptions.testMultipleString).containsExactly("baz", "bar").inOrder();
    try {
        enforcer.enforce(parser, "build");
        fail();
    } catch (OptionsParsingException e) {
    // expected, since baz is not allowed.
    }
}
Also used : InvocationPolicy(com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) Test(org.junit.Test)

Example 20 with OptionsParsingException

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

the class InvocationPolicyEnforcerTest method testDisallowValuesRaisesErrorIfDefaultIsDisallowedAndSetsUseDefault.

@Test
public void testDisallowValuesRaisesErrorIfDefaultIsDisallowedAndSetsUseDefault() throws Exception {
    InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
    invocationPolicyBuilder.addFlagPoliciesBuilder().setFlagName("test_string").getDisallowValuesBuilder().addDisallowedValues(STRING_FLAG_DEFAULT).getUseDefaultBuilder();
    InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder);
    try {
        enforcer.enforce(parser, "build");
        fail();
    } catch (OptionsParsingException e) {
        assertThat(e.getMessage()).contains("but also specifies to use the default value");
    }
}
Also used : InvocationPolicy(com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy) InvocationPolicyEnforcer(com.google.devtools.build.lib.flags.InvocationPolicyEnforcer) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException) Test(org.junit.Test)

Aggregations

OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)26 InvocationPolicyEnforcer (com.google.devtools.build.lib.flags.InvocationPolicyEnforcer)15 InvocationPolicy (com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy)11 Test (org.junit.Test)11 OptionsParser (com.google.devtools.common.options.OptionsParser)6 Path (com.google.devtools.build.lib.vfs.Path)3 PackageCacheOptions (com.google.devtools.build.lib.pkgcache.PackageCacheOptions)2 BlazeRuntime (com.google.devtools.build.lib.runtime.BlazeRuntime)2 AbruptExitException (com.google.devtools.build.lib.util.AbruptExitException)2 OptionsBase (com.google.devtools.common.options.OptionsBase)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Artifact (com.google.devtools.build.lib.actions.Artifact)1 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)1 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)1 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)1 BuildOptions (com.google.devtools.build.lib.analysis.config.BuildOptions)1 FragmentOptions (com.google.devtools.build.lib.analysis.config.FragmentOptions)1 Label (com.google.devtools.build.lib.cmdline.Label)1