Search in sources :

Example 1 with MutableList

use of com.google.devtools.build.lib.syntax.SkylarkList.MutableList in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testResolveCommandInputs.

@Test
public void testResolveCommandInputs() throws Exception {
    evalRuleContextCode(createRuleContext("//foo:resolve_me"), "inputs, argv, input_manifests = ruleContext.resolve_command(", "   tools=ruleContext.attr.tools)");
    @SuppressWarnings("unchecked") List<Artifact> inputs = (List<Artifact>) (List<?>) (MutableList) lookup("inputs");
    assertArtifactFilenames(inputs, "mytool.sh", "mytool", "foo_Smytool-runfiles", "t.exe");
    @SuppressWarnings("unchecked") CompositeRunfilesSupplier runfilesSupplier = new CompositeRunfilesSupplier((List<RunfilesSupplier>) lookup("input_manifests"));
    assertThat(runfilesSupplier.getMappings()).hasSize(1);
}
Also used : CompositeRunfilesSupplier(com.google.devtools.build.lib.actions.CompositeRunfilesSupplier) MutableList(com.google.devtools.build.lib.syntax.SkylarkList.MutableList) MutableList(com.google.devtools.build.lib.syntax.SkylarkList.MutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Artifact(com.google.devtools.build.lib.actions.Artifact) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) CompositeRunfilesSupplier(com.google.devtools.build.lib.actions.CompositeRunfilesSupplier) Test(org.junit.Test)

Example 2 with MutableList

use of com.google.devtools.build.lib.syntax.SkylarkList.MutableList in project bazel by bazelbuild.

the class BinaryOperatorExpression method plus.

/** Implements Operator.PLUS. */
private static Object plus(Object lval, Object rval, Environment env, Location location) throws EvalException {
    // int + int
    if (lval instanceof Integer && rval instanceof Integer) {
        return ((Integer) lval).intValue() + ((Integer) rval).intValue();
    }
    // string + string
    if (lval instanceof String && rval instanceof String) {
        return (String) lval + (String) rval;
    }
    if (lval instanceof SelectorValue || rval instanceof SelectorValue || lval instanceof SelectorList || rval instanceof SelectorList) {
        return SelectorList.concat(location, lval, rval);
    }
    if ((lval instanceof Tuple) && (rval instanceof Tuple)) {
        return Tuple.copyOf(Iterables.concat((Tuple) lval, (Tuple) rval));
    }
    if ((lval instanceof MutableList) && (rval instanceof MutableList)) {
        return MutableList.concat((MutableList) lval, (MutableList) rval, env);
    }
    if (lval instanceof SkylarkDict && rval instanceof SkylarkDict) {
        return SkylarkDict.plus((SkylarkDict<?, ?>) lval, (SkylarkDict<?, ?>) rval, env);
    }
    if (lval instanceof Concatable && rval instanceof Concatable) {
        Concatable lobj = (Concatable) lval;
        Concatable robj = (Concatable) rval;
        Concatter concatter = lobj.getConcatter();
        if (concatter != null && concatter.equals(robj.getConcatter())) {
            return concatter.concat(lobj, robj, location);
        } else {
            throw typeException(lval, rval, Operator.PLUS, location);
        }
    }
    // TODO(bazel-team): Remove this case. Union of sets should use '|' instead of '+'.
    if (lval instanceof SkylarkNestedSet) {
        return new SkylarkNestedSet((SkylarkNestedSet) lval, rval, location);
    }
    throw typeException(lval, rval, Operator.PLUS, location);
}
Also used : MutableList(com.google.devtools.build.lib.syntax.SkylarkList.MutableList) Concatter(com.google.devtools.build.lib.syntax.Concatable.Concatter) Tuple(com.google.devtools.build.lib.syntax.SkylarkList.Tuple)

Aggregations

MutableList (com.google.devtools.build.lib.syntax.SkylarkList.MutableList)2 ImmutableList (com.google.common.collect.ImmutableList)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 CompositeRunfilesSupplier (com.google.devtools.build.lib.actions.CompositeRunfilesSupplier)1 RunfilesSupplier (com.google.devtools.build.lib.actions.RunfilesSupplier)1 Concatter (com.google.devtools.build.lib.syntax.Concatable.Concatter)1 Tuple (com.google.devtools.build.lib.syntax.SkylarkList.Tuple)1 List (java.util.List)1 Test (org.junit.Test)1