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);
}
}
}
use of com.google.devtools.common.options.OptionsParser in project bazel by bazelbuild.
the class AndroidResourceMergingAction method main.
public static void main(String[] args) throws Exception {
final Stopwatch timer = Stopwatch.createStarted();
OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class, AaptConfigOptions.class);
optionsParser.enableParamsFileSupport(FileSystems.getDefault());
optionsParser.parseAndExitUponError(args);
AaptConfigOptions aaptConfigOptions = optionsParser.getOptions(AaptConfigOptions.class);
Options options = optionsParser.getOptions(Options.class);
Preconditions.checkNotNull(options.primaryData);
Preconditions.checkNotNull(options.primaryManifest);
Preconditions.checkNotNull(options.classJarOutput);
try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resource_merge_tmp")) {
Path tmp = scopedTmp.getPath();
Path mergedAssets = tmp.resolve("merged_assets");
Path mergedResources = tmp.resolve("merged_resources");
Path generatedSources = tmp.resolve("generated_resources");
Path processedManifest = tmp.resolve("manifest-processed/AndroidManifest.xml");
logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
VariantType packageType = VariantType.LIBRARY;
AndroidResourceClassWriter resourceClassWriter = AndroidResourceClassWriter.createWith(aaptConfigOptions.androidJar, generatedSources, Strings.nullToEmpty(options.packageForR));
resourceClassWriter.setIncludeClassFile(true);
resourceClassWriter.setIncludeJavaFile(false);
final MergedAndroidData mergedData = AndroidResourceMerger.mergeData(options.primaryData, options.primaryManifest, options.directData, options.transitiveData, mergedResources, mergedAssets, new StubPngCruncher(), packageType, options.symbolsBinOut, resourceClassWriter);
logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
// the manifests compatible with the old manifest merger.
if (options.manifestOutput != null) {
MergedAndroidData processedData = AndroidManifestProcessor.with(stdLogger).processManifest(packageType, options.packageForR, null, /* applicationId */
-1, /* versionCode */
null, /* versionName */
mergedData, processedManifest);
AndroidResourceOutputs.copyManifestToOutput(processedData, options.manifestOutput);
}
AndroidResourceOutputs.createClassJar(generatedSources, options.classJarOutput);
logger.fine(String.format("Create classJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
if (options.resourcesOutput != null) {
Path resourcesDir = AndroidResourceProcessor.processDataBindings(mergedData.getResourceDir(), options.dataBindingInfoOut, packageType, options.packageForR, options.primaryManifest);
// For now, try compressing the library resources that we pass to the validator. This takes
// extra CPU resources to pack and unpack (~2x), but can reduce the zip size (~4x).
AndroidResourceOutputs.createResourcesZip(resourcesDir, mergedData.getAssetDir(), options.resourcesOutput, true);
logger.fine(String.format("Create resources.zip finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
} catch (MergingException e) {
logger.log(Level.SEVERE, "Error during merging resources", e);
throw e;
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected", e);
throw e;
}
logger.fine(String.format("Resources merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
Aggregations