com.google.devtools.build.lib.syntax.Printer Java Examples

The following examples show how to use com.google.devtools.build.lib.syntax.Printer. 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: ConstraintCollection.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("<");
  if (parent() != null) {
    printer.append("parent: ");
    parent().repr(printer);
    printer.append(", ");
  }
  printer.append("[");
  printer.append(
      constraints().values().stream()
          .map(ConstraintValueInfo::label)
          .map(Functions.toStringFunction())
          .collect(joining(", ")));
  printer.append("]");
  printer.append(">");
}
 
Example #2
Source File: FunctionUtil.java    From bazel with Apache License 2.0 6 votes vote down vote up
/** Constructor to be used for normal parameters. */
public static FunctionParamInfo forParam(
    String name, String docString, @Nullable Object defaultValue) {
  FunctionParamInfo.Builder paramBuilder =
      FunctionParamInfo.newBuilder().setName(name).setDocString(docString);
  if (defaultValue == null) {
    paramBuilder.setMandatory(true);
  } else {
    BasePrinter printer = Printer.getSimplifiedPrinter();
    printer.repr(defaultValue);
    String defaultValueString = printer.toString();

    if (defaultValueString.isEmpty()) {
      defaultValueString = "{unknown object}";
    }
    paramBuilder.setDefaultValue(defaultValueString).setMandatory(false);
  }
  return paramBuilder.build();
}
 
Example #3
Source File: LibraryToLink.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void debugPrint(Printer printer) {
  printer.append("<LibraryToLink(");
  printer.append(
      Joiner.on(", ")
          .skipNulls()
          .join(
              mapEntry("object", getObjectFiles()),
              mapEntry("pic_objects", getPicObjectFiles()),
              mapEntry("static_library", getStaticLibrary()),
              mapEntry("pic_static_library", getPicStaticLibrary()),
              mapEntry("dynamic_library", getDynamicLibrary()),
              mapEntry("resolved_symlink_dynamic_library", getResolvedSymlinkDynamicLibrary()),
              mapEntry("interface_library", getInterfaceLibrary()),
              mapEntry(
                  "resolved_symlink_interface_library", getResolvedSymlinkInterfaceLibrary()),
              mapEntry("alwayslink", getAlwayslink())));
  printer.append(")>");
}
 
Example #4
Source File: RuleConfiguredTarget.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public void debugPrint(Printer printer) {
  // Show the names of the provider keys that this target propagates.
  // Provider key names might potentially be *private* information, and thus a comprehensive
  // list of provider keys should not be exposed in any way other than for debug information.
  printer.append("<target " + getLabel() + ", keys:[");
  ImmutableList.Builder<String> starlarkProviderKeyStrings = ImmutableList.builder();
  for (int providerIndex = 0; providerIndex < providers.getProviderCount(); providerIndex++) {
    Object providerKey = providers.getProviderKeyAt(providerIndex);
    if (providerKey instanceof Provider.Key) {
      starlarkProviderKeyStrings.add(providerKey.toString());
    }
  }
  printer.append(Joiner.on(", ").join(starlarkProviderKeyStrings.build()));
  printer.append("]>");
}
 
Example #5
Source File: Depset.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("depset(");
  printer.printList(set.toList(), "[", ", ", "]", null);
  Order order = getOrder();
  if (order != Order.STABLE_ORDER) {
    printer.append(", order = ");
    printer.repr(order.getStarlarkName());
  }
  printer.append(")");
}
 
Example #6
Source File: BuildType.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  // Convert to a lib.syntax.SelectorList to guarantee consistency with callers that serialize
  // directly on that type.
  List<SelectorValue> selectorValueList = new ArrayList<>();
  for (Selector<T> element : elements) {
    selectorValueList.add(new SelectorValue(element.getEntries(), element.getNoMatchError()));
  }
  try {
    printer.repr(com.google.devtools.build.lib.packages.SelectorList.of(selectorValueList));
  } catch (EvalException e) {
    throw new IllegalStateException("this list should have been validated on creation");
  }
}
 
Example #7
Source File: Type.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static String message(Type<?> type, Object value, @Nullable Object what) {
  Printer.BasePrinter printer = Printer.getPrinter();
  printer.append("expected value of type '").append(type.toString()).append("'");
  if (what != null) {
    printer.append(" for ").append(what.toString());
  }
  printer.append(", but got ");
  printer.repr(value);
  printer.append(" (").append(Starlark.type(value)).append(")");
  return printer.toString();
}
 
Example #8
Source File: ResolvedToolchainContext.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("<toolchain_context.resolved_labels: ");
  printer.append(
      toolchains().keySet().stream()
          .map(ToolchainTypeInfo::typeLabel)
          .map(Label::toString)
          .collect(joining(", ")));
  printer.append(">");
}
 
Example #9
Source File: RepositoryResolvedEvent.java    From bazel with Apache License 2.0 5 votes vote down vote up
static String representModifications(Map<String, Object> changes) {
  StringBuilder representation = new StringBuilder();
  boolean isFirst = true;
  for (Map.Entry<String, Object> entry : changes.entrySet()) {
    if (!isFirst) {
      representation.append(", ");
    }
    representation
        .append(entry.getKey())
        .append(" = ")
        .append(Printer.getPrinter().repr(entry.getValue()));
    isFirst = false;
  }
  return representation.toString();
}
 
Example #10
Source File: StarlarkRuleImplementationFunctionsTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrintArgs() throws Exception {
  setRuleContext(createRuleContext("//foo:foo"));
  ev.exec("args = ruleContext.actions.args()", "args.add_all(['--foo', '--bar'])");
  Args args = (Args) ev.eval("args");
  assertThat(Printer.getPrinter().debugPrint(args).toString()).isEqualTo("--foo --bar");
}
 
Example #11
Source File: CcLinkingContext.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void debugPrint(Printer printer) {
  printer.append("<CcLinkingContext([");
  for (LinkerInput linkerInput : linkerInputs.toList()) {
    linkerInput.debugPrint(printer);
    printer.append(", ");
  }
  printer.append("])>");
}
 
Example #12
Source File: Args.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void debugPrint(Printer printer) {
  try {
    printer.append(Joiner.on(" ").join(build().arguments()));
  } catch (CommandLineExpansionException e) {
    printer.append("Cannot expand command line: " + e.getMessage());
  }
}
 
Example #13
Source File: Runfiles.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("SymlinkEntry(path = ");
  printer.repr(getPathString());
  printer.append(", target_file = ");
  getArtifact().repr(printer);
  printer.append(")");
}
 
Example #14
Source File: StarlarkRepositoryModule.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  if (exportedName == null) {
    printer.append("<anonymous starlark repository rule>");
  } else {
    printer.append("<starlark repository rule " + extensionLabel + "%" + exportedName + ">");
  }
}
 
Example #15
Source File: ConstraintSettingInfo.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.format("ConstraintSettingInfo(%s", label.toString());
  if (defaultConstraintValueLabel != null) {
    printer.format(", default_constraint_value=%s", defaultConstraintValueLabel.toString());
  }
  printer.append(")");
}
 
Example #16
Source File: SyncCommand.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static ResolvedEvent resolveBind(Rule rule) {
  String name = rule.getName();
  Label actual = (Label) rule.getAttributeContainer().getAttr("actual");
  String nativeCommand =
      "bind(name = "
          + Printer.getPrinter().repr(name)
          + ", actual = "
          + Printer.getPrinter().repr(actual.getCanonicalForm())
          + ")";

  return new ResolvedEvent() {
    @Override
    public String getName() {
      return name;
    }

    @Override
    public Object getResolvedInformation() {
      return ImmutableMap.<String, Object>builder()
          .put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, "bind")
          .put(
              ResolvedHashesFunction.ORIGINAL_ATTRIBUTES,
              ImmutableMap.<String, Object>of("name", name, "actual", actual))
          .put(ResolvedHashesFunction.NATIVE, nativeCommand)
          .build();
    }
  };
}
 
Example #17
Source File: SkylarkDependencyTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void repr() {
  SkylarkDependency dep =
      new SkylarkDependency(
          BuildTargetFactory.newInstance("//foo:bar"),
          ProviderInfoCollectionImpl.builder()
              .build(new ImmutableDefaultInfo(SkylarkDict.empty(), ImmutableList.of())));

  assertEquals("<dependency //foo:bar>", Printer.repr(dep));
}
 
Example #18
Source File: ConfigApiFakes.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #19
Source File: GoogleLegacyStubs.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("<unknown object>");
}
 
Example #20
Source File: FakeLateBoundDefaultApi.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #21
Source File: RepositoryResolvedEvent.java    From bazel with Apache License 2.0 4 votes vote down vote up
public RepositoryResolvedEvent(Rule rule, StructImpl attrs, Path outputDirectory, Object result) {
  this.outputDirectory = outputDirectory;

  String originalClass =
      rule.getRuleClassObject().getRuleDefinitionEnvironmentLabel() + "%" + rule.getRuleClass();
  resolvedInformationBuilder.put(ORIGINAL_RULE_CLASS, originalClass);
  resolvedInformationBuilder.put(DEFINITION_INFORMATION, getRuleDefinitionInformation(rule));

  ImmutableMap.Builder<String, Object> origAttrBuilder = ImmutableMap.builder();
  ImmutableMap.Builder<String, Object> defaults = ImmutableMap.builder();

  for (Attribute attr : rule.getAttributes()) {
    String name = attr.getPublicName();
    try {
      Object value = attrs.getValue(name, Object.class);
      if (value != null) {
        if (rule.isAttributeValueExplicitlySpecified(attr)) {
          origAttrBuilder.put(name, value);
        } else {
          defaults.put(name, value);
        }
      }
    } catch (EvalException e) {
      // Do nothing, just ignore the value.
    }
  }
  ImmutableMap<String, Object> origAttr = origAttrBuilder.build();
  resolvedInformationBuilder.put(ORIGINAL_ATTRIBUTES, origAttr);

  repositoryBuilder.put(RULE_CLASS, originalClass);

  if (result == Starlark.NONE) {
    // Rule claims to be already reproducible, so wants to be called as is.
    repositoryBuilder.put(ATTRIBUTES, origAttr);
    this.informationReturned = false;
    this.message = "Repository rule '" + rule.getName() + "' finished.";
  } else if (result instanceof Map) {
    // Rule claims that the returned (probably changed) arguments are a reproducible
    // version of itself.
    repositoryBuilder.put(ATTRIBUTES, result);
    Pair<Map<String, Object>, List<String>> diff =
        compare(origAttr, defaults.build(), (Map<?, ?>) result);
    if (diff.getFirst().isEmpty() && diff.getSecond().isEmpty()) {
      this.informationReturned = false;
      this.message = "Repository rule '" + rule.getName() + "' finished.";
    } else {
      this.informationReturned = true;
      if (diff.getFirst().isEmpty()) {
        this.message =
            "Rule '"
                + rule.getName()
                + "' indicated that a canonical reproducible form can be obtained by"
                + " dropping arguments "
                + Printer.getPrinter().repr(diff.getSecond());
      } else if (diff.getSecond().isEmpty()) {
        this.message =
            "Rule '"
                + rule.getName()
                + "' indicated that a canonical reproducible form can be obtained by"
                + " modifying arguments "
                + representModifications(diff.getFirst());
      } else {
        this.message =
            "Rule '"
                + rule.getName()
                + "' indicated that a canonical reproducible form can be obtained by"
                + " modifying arguments "
                + representModifications(diff.getFirst())
                + " and dropping "
                + Printer.getPrinter().repr(diff.getSecond());
      }
    }
  } else {
    // TODO(aehlig): handle strings specially to allow encodings of the former
    // values to be accepted as well.
    resolvedInformationBuilder.put(REPOSITORIES, result);
    repositoryBuilder = null; // We already added the REPOSITORIES entry
    this.informationReturned = true;
    this.message = "Repository rule '" + rule.getName() + "' returned: " + result;
  }

  this.name = rule.getName();
}
 
Example #22
Source File: FakePyInfo.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #23
Source File: FakeCoverageCommon.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #24
Source File: StarlarkAttributesCollection.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("<rule collection for " + starlarkRuleContext.getRuleLabelCanonicalName() + ">");
}
 
Example #25
Source File: FakeObjcProvider.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #26
Source File: FakeAppleDynamicFrameworkInfo.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #27
Source File: FakeConfigurationTransition.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #28
Source File: FakeAppleStaticLibraryInfo.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {}
 
Example #29
Source File: StarlarkConfig.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("<config>");
}
 
Example #30
Source File: AbstractConfiguredTarget.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void repr(Printer printer) {
  printer.append("<unknown target " + getLabel() + ">");
}