Skip to content

Commit

Permalink
Revert: Support regex in attrfilter
Browse files Browse the repository at this point in the history
Summary: This reverts commit Support regex in attrfilter.

Test Plan: revert-hammer

fbshipit-source-id: 48d2fad
  • Loading branch information
plamenko authored and facebook-github-bot committed Mar 17, 2017
1 parent f49451b commit 1ef2f73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 41 deletions.
16 changes: 8 additions & 8 deletions docs/command/query.soy
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ expr ::= word
| expr except expr
| expr - expr
| allpaths(expr, expr)
| attrfilter(pattern, word, expr)
| attrfilter(word, word, expr)
| buildfile(expr)
| deps(expr)
| deps(expr, depth)
Expand Down Expand Up @@ -346,21 +346,21 @@ $ dot -Tpng result.dot -o image.png

<p><pre>
{literal}
expr ::= attrfilter(word, pattern, expr)
expr ::= attrfilter(word, word, expr)
{/literal}
</pre></p>

<p>
The <code>attrfilter(attribute, pattern, expression)</code> operator evaluates
The <code>attrfilter(attribute, value, expression)</code> operator evaluates
the given <code>expression</code> and filters the resulting build targets
whose <code>attribute</code> match the given <code>pattern</code>.
whose <code>attribute</code> contain the given <code>value</code>.
</p>

<p>
If the attribute is just a value, say <code>name</code>, it is compared to the
given <code>pattern</code>. If it's a list, the target is filtered if the
given <code>pattern</code> is contained in the list. If it's a dictionary,
the <code>pattern</code> is searched both in the keys and values of the
given <code>value</code>. If it's a list, the target is filtered if the
given <code>value</code> is contained in the list. If it's a dictionary,
the <code>value</code> is searched both in the keys and values of the
dictionary.
</p>

Expand Down Expand Up @@ -446,7 +446,7 @@ equivalent to <code>deps(//foo:bar, 1)</code>.

<p><pre>
{literal}
expr ::= filter(pattern, expr)
expr ::= filter(word, expr)
{/literal}
</pre></p>

Expand Down
19 changes: 4 additions & 15 deletions src/com/facebook/buck/query/AttrFilterFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListeningExecutorService;

import java.util.regex.Pattern;

/**
* A attrfilter(attribute, value, argument) filter expression, which computes the subset
* of nodes in 'argument' whose 'attribute' contains the given value.
Expand Down Expand Up @@ -62,20 +60,11 @@ public ImmutableSet<QueryTarget> eval(
ImmutableList<Argument> args,
ListeningExecutorService executor)
throws QueryException, InterruptedException {
final String attrValue = args.get(1).getWord();
Pattern compiledPattern;
try {
compiledPattern = Pattern.compile(attrValue);
} catch (IllegalArgumentException e) {
throw new QueryException(
String.format("Illegal pattern regexp '%s': %s", attrValue, e.getMessage()));
}
QueryExpression argument = args.get(args.size() - 1).getExpression();
String attr = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, args.get(0).getWord());

final Predicate<Object> predicate = input -> compiledPattern.matcher(input.toString()).find();

final QueryExpression argument = args.get(args.size() - 1).getExpression();
final String attr = CaseFormat.LOWER_UNDERSCORE.to(
CaseFormat.LOWER_CAMEL, args.get(0).getWord());
final String attrValue = args.get(1).getWord();
final Predicate<Object> predicate = input -> attrValue.equals(input.toString());

ImmutableSet.Builder<QueryTarget> result = new ImmutableSet.Builder<>();
for (QueryTarget target : argument.eval(env, executor)) {
Expand Down
18 changes: 0 additions & 18 deletions test/com/facebook/buck/cli/QueryCommandIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,24 +646,6 @@ public void testFilterAttrTests() throws IOException {
assertThat(
result.getStdout(),
is(equalToIgnoringPlatformNewlines("//example:four\n")));

result = workspace.runBuckCommand(
"query",
"attrfilter(tests, '.*-tests', '//example/...')");
result.assertSuccess();
assertThat(
result.getStdout(),
is(equalToIgnoringPlatformNewlines(
"//example/app:seven\n//example:four\n//example:one\n//example:six\n")));

result = workspace.runBuckCommand(
"query",
"attrfilter(tests, '(three|four)-tests', '//example/...')");
result.assertSuccess();
assertThat(
result.getStdout(),
is(equalToIgnoringPlatformNewlines("//example:four\n")));

}

@Test
Expand Down

0 comments on commit 1ef2f73

Please sign in to comment.