Java Code Examples for com.google.devtools.common.options.OptionsParser#getOptionDefinitions()
The following examples show how to use
com.google.devtools.common.options.OptionsParser#getOptionDefinitions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigCommand.java From bazel with Apache License 2.0 | 6 votes |
private static Map<String, Pair<Object, Object>> diffOptions( Class<? extends FragmentOptions> fragment, @Nullable FragmentOptions options1, @Nullable FragmentOptions options2) { Map<String, Pair<Object, Object>> diffs = new HashMap<>(); for (OptionDefinition option : OptionsParser.getOptionDefinitions(fragment)) { Object value1 = options1 == null ? null : options1.getValueFromDefinition(option); Object value2 = options2 == null ? null : options2.getValueFromDefinition(option); if (!Objects.equals(value1, value2)) { diffs.put(option.getOptionName(), Pair.of(value1, value2)); } } return diffs; }
Example 2
Source File: FunctionTransitionUtil.java From bazel with Apache License 2.0 | 6 votes |
/** For all the options in the BuildOptions, build a map from option name to its information. */ static ImmutableMap<String, OptionInfo> buildOptionInfo(BuildOptions buildOptions) { ImmutableMap.Builder<String, OptionInfo> builder = new ImmutableMap.Builder<>(); ImmutableSet<Class<? extends FragmentOptions>> optionClasses = buildOptions.getNativeOptions().stream() .map(FragmentOptions::getClass) .collect(ImmutableSet.toImmutableSet()); for (Class<? extends FragmentOptions> optionClass : optionClasses) { ImmutableList<OptionDefinition> optionDefinitions = OptionsParser.getOptionDefinitions(optionClass); for (OptionDefinition def : optionDefinitions) { String optionName = def.getOptionName(); builder.put(optionName, new OptionInfo(optionClass, def)); } } return builder.build(); }
Example 3
Source File: TransitiveOptionDetails.java From bazel with Apache License 2.0 | 5 votes |
/** Builds a {@code TransitiveOptionDetails} for the given set of native and Starlark options. */ static TransitiveOptionDetails forOptions( Iterable<? extends FragmentOptions> buildOptions, Map<Label, Object> starlarkOptions) { ImmutableMap.Builder<String, OptionDetails> map = ImmutableMap.builder(); try { for (FragmentOptions options : buildOptions) { ImmutableList<OptionDefinition> optionDefinitions = OptionsParser.getOptionDefinitions(options.getClass()); Map<OptionDefinition, SelectRestriction> selectRestrictions = options.getSelectRestrictions(); for (OptionDefinition optionDefinition : optionDefinitions) { if (ImmutableList.copyOf(optionDefinition.getOptionMetadataTags()) .contains(OptionMetadataTag.INTERNAL)) { // ignore internal options continue; } Object value = optionDefinition.getField().get(options); if (value == null && !optionDefinition.isSpecialNullDefault()) { // See {@link Option#defaultValue} for an explanation of default "null" strings. value = optionDefinition.getUnparsedDefaultValue(); } map.put( optionDefinition.getOptionName(), new OptionDetails( options.getClass(), value, optionDefinition.allowsMultiple(), selectRestrictions.get(optionDefinition))); } } } catch (IllegalAccessException e) { throw new IllegalStateException( "Unexpected illegal access trying to create this configuration's options map: ", e); } return new TransitiveOptionDetails(map.build(), ImmutableMap.copyOf(starlarkOptions)); }