Java Code Examples for com.google.devtools.common.options.OptionsParser#setStarlarkOptions()

The following examples show how to use com.google.devtools.common.options.OptionsParser#setStarlarkOptions() . 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: BuildOptionsTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void parsingResultTransform() throws Exception {
  BuildOptions original = BuildOptions.of(BUILD_CONFIG_OPTIONS, "--cpu=foo", "--stamp");

  OptionsParser parser = OptionsParser.builder().optionsClasses(BUILD_CONFIG_OPTIONS).build();
  parser.parse("--cpu=bar", "--nostamp");
  parser.setStarlarkOptions(ImmutableMap.of("//custom:flag", "hello"));

  BuildOptions modified = original.applyParsingResult(parser);

  assertThat(original.get(CoreOptions.class).cpu)
      .isNotEqualTo(modified.get(CoreOptions.class).cpu);
  assertThat(modified.get(CoreOptions.class).cpu).isEqualTo("bar");
  assertThat(modified.get(CoreOptions.class).stampBinaries).isFalse();
  assertThat(modified.getStarlarkOptions().get(Label.parseAbsoluteUnchecked("//custom:flag")))
      .isEqualTo("hello");
}
 
Example 2
Source File: BuildOptionsTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void parsingResultMatchStarlark() throws Exception {
  BuildOptions original =
      BuildOptions.builder()
          .addStarlarkOption(Label.parseAbsoluteUnchecked("//custom:flag"), "hello")
          .build();

  OptionsParser matchingParser =
      OptionsParser.builder().optionsClasses(BUILD_CONFIG_OPTIONS).build();
  matchingParser.setStarlarkOptions(ImmutableMap.of("//custom:flag", "hello"));

  OptionsParser notMatchingParser =
      OptionsParser.builder().optionsClasses(BUILD_CONFIG_OPTIONS).build();
  notMatchingParser.setStarlarkOptions(ImmutableMap.of("//custom:flag", "foo"));

  assertThat(original.matches(matchingParser)).isTrue();
  assertThat(original.matches(notMatchingParser)).isFalse();
}
 
Example 3
Source File: BuildOptionsTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void parsingResultMatchEmptyNativeMatchWithStarlark() throws Exception {
  BuildOptions original =
      BuildOptions.builder()
          .addStarlarkOption(Label.parseAbsoluteUnchecked("//custom:flag"), "hello")
          .build();

  ImmutableList<Class<? extends FragmentOptions>> fragmentClasses =
      ImmutableList.<Class<? extends FragmentOptions>>builder()
          .add(CoreOptions.class)
          .add(CppOptions.class)
          .build();

  OptionsParser parser = OptionsParser.builder().optionsClasses(fragmentClasses).build();
  parser.parse("--cxxopt=bar");
  parser.setStarlarkOptions(ImmutableMap.of("//custom:flag", "hello"));

  assertThat(original.matches(parser)).isTrue();
}
 
Example 4
Source File: ConfigurationTestCase.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Variation of {@link #createCollection(String...)} that also supports Starlark-defined options.
 *
 * @param starlarkOptions map of Starlark-defined options where the keys are option names (in the
 *     form of label-like strings) and the values are option values
 * @param args native option name/pair descriptions in command line form (e.g. "--cpu=k8")
 */
protected BuildConfigurationCollection createCollection(
    ImmutableMap<String, Object> starlarkOptions, String... args) throws Exception {
  OptionsParser parser =
      OptionsParser.builder()
          .optionsClasses(
              ImmutableList.<Class<? extends OptionsBase>>builder()
                  .addAll(buildOptionClasses)
                  .add(TestOptions.class)
                  .build())
          .build();
  parser.setStarlarkOptions(starlarkOptions);
  parser.parse(TestConstants.PRODUCT_SPECIFIC_FLAGS);
  parser.parse(args);

  ImmutableSortedSet<String> multiCpu = ImmutableSortedSet.copyOf(
      parser.getOptions(TestOptions.class).multiCpus);

  skyframeExecutor.handleDiffsForTesting(reporter);
  BuildConfigurationCollection collection = skyframeExecutor.createConfigurations(
      reporter, BuildOptions.of(buildOptionClasses, parser), multiCpu, false);
  return collection;
}
 
Example 5
Source File: BuildOptionsTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void parsingResultTransformIllegalStarlarkLabel() throws Exception {
  BuildOptions original = BuildOptions.of(BUILD_CONFIG_OPTIONS);

  OptionsParser parser = OptionsParser.builder().optionsClasses(BUILD_CONFIG_OPTIONS).build();
  parser.setStarlarkOptions(ImmutableMap.of("@@@", "hello"));

  assertThrows(IllegalArgumentException.class, () -> original.applyParsingResult(parser));
}
 
Example 6
Source File: BuildOptionsTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void parsingResultMatchStarlarkOptionMissing() throws Exception {
  BuildOptions original =
      BuildOptions.builder()
          .addStarlarkOption(Label.parseAbsoluteUnchecked("//custom:flag1"), "hello")
          .build();

  OptionsParser parser = OptionsParser.builder().optionsClasses(BUILD_CONFIG_OPTIONS).build();
  parser.setStarlarkOptions(ImmutableMap.of("//custom:flag2", "foo"));

  assertThat(original.matches(parser)).isFalse();
}