-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7024] Allow chaining of the same function type in aquery.
For example: inputs('a', inputs('b', expr)) would now filter all actions which results from evaluating expr and whose inputs matches both patterns 'a' and 'b'. RELNOTES: [#7024] Allow chaining of the same function type in aquery. PiperOrigin-RevId: 228322146
- Loading branch information
Showing
13 changed files
with
365 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/com/google/devtools/build/lib/query2/AqueryActionFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2019 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.devtools.build.lib.query2; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
|
||
/** Encapsulate the action filters parsed from aquery command. */ | ||
public class AqueryActionFilter { | ||
// TODO(leba): Use Enum for list of filters. | ||
private final ImmutableMap<String, List<Pattern>> filterMap; | ||
|
||
private AqueryActionFilter(Builder builder) { | ||
filterMap = ImmutableMap.copyOf(builder.filterMap); | ||
} | ||
|
||
public static AqueryActionFilter emptyInstance() { | ||
return builder().build(); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public boolean hasFilterForFunction(String function) { | ||
return filterMap.containsKey(function); | ||
} | ||
|
||
/** | ||
* Returns whether the input string matches ALL the filter patterns of a specific type parsed from | ||
* aquery command. | ||
* | ||
* @param function the name of the aquery function (inputs, outputs, mnemonic) | ||
* @param input the string to be matched against | ||
*/ | ||
public boolean matchesAllPatternsForFunction(String function, String input) { | ||
if (!hasFilterForFunction(function)) { | ||
return false; | ||
} | ||
|
||
return filterMap.get(function).stream() | ||
.map(pattern -> pattern.matcher(input).matches()) | ||
.reduce(true, Boolean::logicalAnd); | ||
} | ||
|
||
/** Builder class for {@code AqueryActionFilter} */ | ||
public static class Builder { | ||
private final Map<String, List<Pattern>> filterMap; | ||
|
||
public Builder() { | ||
filterMap = new HashMap<>(); | ||
} | ||
|
||
public Builder put(String key, Pattern value) { | ||
filterMap.putIfAbsent(key, new ArrayList<>()); | ||
filterMap.get(key).add(value); | ||
|
||
return this; | ||
} | ||
|
||
public AqueryActionFilter build() { | ||
return new AqueryActionFilter(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.