Java Code Examples for com.google.devtools.build.lib.syntax.StarlarkSemantics#DEFAULT

The following examples show how to use com.google.devtools.build.lib.syntax.StarlarkSemantics#DEFAULT . 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: StarlarkDebugServerTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and starts a worker thread parsing, resolving, and executing the given Starlark file to
 * populate the specified module, or if none is given, in a fresh module with a default
 * environment.
 */
private static Thread execInWorkerThread(ParserInput input, @Nullable Module module) {
  Thread javaThread =
      new Thread(
          () -> {
            try (Mutability mu = Mutability.create("test")) {
              StarlarkThread thread = new StarlarkThread(mu, StarlarkSemantics.DEFAULT);
              EvalUtils.exec(
                  input, FileOptions.DEFAULT, module != null ? module : Module.create(), thread);
            } catch (SyntaxError.Exception | EvalException | InterruptedException ex) {
              throw new AssertionError(ex);
            }
          });
  javaThread.start();
  return javaThread;
}
 
Example 2
Source File: StarlarkProviderTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
/** Instantiates a {@link StarlarkInfo} with fields a=1, b=2, c=3 (and nothing else). */
private static StarlarkInfo instantiateWithA1B2C3(StarlarkProvider provider) throws Exception {
  try (Mutability mu = Mutability.create()) {
    StarlarkThread thread = new StarlarkThread(mu, StarlarkSemantics.DEFAULT);
    Object result =
        Starlark.call(
            thread,
            provider,
            /*args=*/ ImmutableList.of(),
            /*kwargs=*/ ImmutableMap.of("a", 1, "b", 2, "c", 3));
    assertThat(result).isInstanceOf(StarlarkInfo.class);
    return (StarlarkInfo) result;
  }
}
 
Example 3
Source File: StarlarkSemanticsConsistencyTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void checkDefaultsMatch() {
  StarlarkSemanticsOptions defaultOptions = Options.getDefaults(StarlarkSemanticsOptions.class);
  StarlarkSemantics defaultSemantics = StarlarkSemantics.DEFAULT;
  StarlarkSemantics semanticsFromOptions = defaultOptions.toStarlarkSemantics();
  assertThat(semanticsFromOptions).isEqualTo(defaultSemantics);
}
 
Example 4
Source File: StarlarkSemanticsConsistencyTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void canGetBuilderFromInstance() {
  StarlarkSemantics original = StarlarkSemantics.DEFAULT;
  assertThat(original.internalStarlarkFlagTestCanary()).isFalse();
  StarlarkSemantics modified = original.toBuilder().internalStarlarkFlagTestCanary(true).build();
  assertThat(modified.internalStarlarkFlagTestCanary()).isTrue();
}
 
Example 5
Source File: SelectTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static Object eval(String expr)
    throws SyntaxError.Exception, EvalException, InterruptedException {
  ParserInput input = ParserInput.fromLines(expr);
  Module module =
      Module.withPredeclared(StarlarkSemantics.DEFAULT, /*predeclared=*/ StarlarkLibrary.COMMON);
  try (Mutability mu = Mutability.create()) {
    StarlarkThread thread = new StarlarkThread(mu, StarlarkSemantics.DEFAULT);
    return EvalUtils.eval(input, FileOptions.DEFAULT, module, thread);
  }
}
 
Example 6
Source File: WorkspaceFactoryTestHelper.java    From bazel with Apache License 2.0 5 votes vote down vote up
WorkspaceFactoryTestHelper(boolean allowOverride, Root root) {
  this.root = root;
  this.exception = null;
  this.events = null;
  this.allowOverride = allowOverride;
  this.starlarkSemantics = StarlarkSemantics.DEFAULT;
}
 
Example 7
Source File: AllocationTrackerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private void exec(String... lines)
    throws SyntaxError.Exception, EvalException, InterruptedException {
  ParserInput input = ParserInput.create(Joiner.on("\n").join(lines), "a.star");
  Module module =
      Module.withPredeclared(
          StarlarkSemantics.DEFAULT,
          ImmutableMap.of(
              "sample", new SamplerValue(),
              "myrule", new MyRuleFunction()));
  try (Mutability mu = Mutability.create("test")) {
    StarlarkThread thread = new StarlarkThread(mu, StarlarkSemantics.DEFAULT);
    EvalUtils.exec(input, FileOptions.DEFAULT, module, thread);
  }
}
 
Example 8
Source File: AbstractPackageLoader.java    From bazel with Apache License 2.0 4 votes vote down vote up
public Builder useDefaultStarlarkSemantics() {
  this.starlarkSemantics = StarlarkSemantics.DEFAULT;
  return this;
}
 
Example 9
Source File: ObjcProviderTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
private static ObjcProvider.StarlarkBuilder objcProviderBuilder() {
  return new ObjcProvider.StarlarkBuilder(StarlarkSemantics.DEFAULT);
}