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

Update sorting out of starlark flags to also identify external repo starlark flags #11510

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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 @@ -228,7 +228,7 @@ public static Pair<ImmutableList<String>, ImmutableList<String>> removeStarlarkO
ImmutableList.Builder<String> keep = ImmutableList.builder();
ImmutableList.Builder<String> remove = ImmutableList.builder();
for (String name : list) {
((name.startsWith("--//") || name.startsWith("--no//")) ? remove : keep).add(name);
(name.matches("--(no)?(@.*)?//.*") ? remove : keep).add(name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex-based parsing is going to fall into difficulties. Can this just strip off the -- and the no (if present), and call LabelValidator.validateAbsoluteLabel, and check for exceptions being thrown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much better. Done.

}
return Pair.of(remove.build(), keep.build());
}
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/google/devtools/build/lib/skylark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:test_runner",
],
deps = [
"//src/main/java/com/google/devtools/build/lib:runtime",
"//src/main/java/com/google/devtools/build/lib:syntax",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/analysis:actions/parameter_file_write_action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.skylark.util.StarlarkOptionsTestCase;
import com.google.devtools.build.lib.runtime.StarlarkOptionsParser;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.common.options.OptionsParsingException;
import com.google.devtools.common.options.OptionsParsingResult;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Unit test for the {@code StarlarkOptionsParser}. */
/**
* Unit test for the {@code StarlarkOptionsParser}.
*/
@RunWith(JUnit4.class)
public class StarlarkOptionsParsingTest extends StarlarkOptionsTestCase {

Expand Down Expand Up @@ -314,4 +319,16 @@ public void testOptionsAreParsedWithBuildTestsOnly() throws Exception {

assertThat(result.getStarlarkOptions().get("//test:my_int_setting")).isEqualTo(15);
}

@Test
public void testRemoveStarlarkOptionsWorks() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test for the --@//external/starlark/option main repo case please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! added

Pair<ImmutableList<String>, ImmutableList<String>> residueAndStarlarkOptions = StarlarkOptionsParser
.removeStarlarkOptions(ImmutableList
.of("--//local/starlark/option", "--@some_repo//external/starlark/option",
"some-random-residue", "--mangled//external/starlark/option"));
assertThat(residueAndStarlarkOptions.getFirst())
.containsExactly("--//local/starlark/option", "--@some_repo//external/starlark/option");
assertThat(residueAndStarlarkOptions.getSecond())
.containsExactly("some-random-residue", "--mangled//external/starlark/option");
}
}