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);
}
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);
}
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;
}
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);
}
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);
}
}
}
Aggregations