Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target pattern file: allow comments #15903

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.devtools.build.lib.runtime.commands;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.base.Preconditions;
Expand All @@ -29,6 +30,7 @@
import com.google.devtools.common.options.OptionsParsingResult;
import java.io.IOException;
import java.util.List;
import java.util.function.Predicate;

/** Provides support for reading target patterns from a file or the command-line. */
final class TargetPatternsHelper {
Expand All @@ -54,7 +56,11 @@ 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(toImmutableList());
} 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