Skip to content

Commit

Permalink
target pattern file: allow comments
Browse files Browse the repository at this point in the history
`--target_pattern_file` could be a great tool assisting migration of a
code base from one Bazel config to another.  User could define a list of
targets that can be built with the new configs and incrementally expand
that list with each change that was introduced.  Multiple users / teams
could collaborate on such migration by adding / removing their targets
into / from the pattern file.

Having the ability to provide comments to annotate the targets in the
pattern file with extra information during the migration process added a
great value and context for build maintainers to track migration
progress.

Add support for Bash-style comments to the target-pattern file.
  • Loading branch information
sluongng committed Jul 18, 2022
1 parent 8a19544 commit 27f6487
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.google.devtools.common.options.OptionsParsingResult;
import java.io.IOException;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/** Provides support for reading target patterns from a file or the command-line. */
final class TargetPatternsHelper {
Expand All @@ -54,7 +56,12 @@ public static List<String> readFrom(CommandEnvironment env, OptionsParsingResult
Path residuePath =
env.getWorkingDirectory().getRelative(buildRequestOptions.targetPatternFile);
try {
targets = FileSystemUtils.readLines(residuePath, UTF_8);
targets = FileSystemUtils.readLines(residuePath, UTF_8)
.stream()
.map(s -> s.split("#")[0])
.map(String::trim)
.filter(Predicate.not(String::isEmpty))
.collect(Collectors.toList());
} catch (IOException e) {
throw new TargetPatternsHelperException(
"I/O error reading from " + residuePath.getPathString() + ": " + e.getMessage(),
Expand Down
3 changes: 2 additions & 1 deletion src/test/shell/integration/target_pattern_file_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ sh_test(name = "y", srcs = ["x.out"])
EOF

cat >build.params <<'EOF'
//:x
# Test comment
//:x # Trailing comment
//:y
EOF
}
Expand Down

0 comments on commit 27f6487

Please sign in to comment.