Search in sources :

Example 1 with InvocationPolicy

use of com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy 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)

Aggregations

InvocationPolicy (com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy)1 OptionsParser (com.google.devtools.common.options.OptionsParser)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1