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

[Cherrypick 4.2.1] Revert 80c59de in 4.2 branch #13893

Merged
Merged
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 @@ -109,8 +109,6 @@ public void parse(ExtendedEventHandler eventHandler) throws OptionsParsingExcept
ImmutableMap.Builder<String, Object> parsedOptions = new ImmutableMap.Builder<>();
for (Map.Entry<String, Pair<String, Target>> option : unparsedOptions.entrySet()) {
String loadedFlag = option.getKey();
// String loadedFlag =
// Label.parseAbsoluteUnchecked(option.getKey()).getDefaultCanonicalForm();
String unparsedValue = option.getValue().first;
Target buildSettingTarget = option.getValue().second;
BuildSetting buildSetting =
Expand Down Expand Up @@ -157,11 +155,7 @@ private void parseArg(
if (value != null) {
// --flag=value or -flag=value form
Target buildSettingTarget = loadBuildSetting(name, nativeOptionsParser, eventHandler);
// Use the unambiguous canonical form to ensure we don't have
// duplicate options getting into the starlark options map.
unparsedOptions.put(
buildSettingTarget.getLabel().getDefaultCanonicalForm(),
new Pair<>(value, buildSettingTarget));
unparsedOptions.put(name, new Pair<>(value, buildSettingTarget));
} else {
boolean booleanValue = true;
// check --noflag form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,40 +45,18 @@ public void testFlagEqualsValueForm() throws Exception {
assertThat(result.getResidue()).isEmpty();
}

// test --@main_workspace//flag=value parses out to //flag=value
// test --@other_workspace//flag=value parses out to @other_workspace//flag=value
// test --@workspace//flag=value
@Test
public void testFlagNameWithWorkspace() throws Exception {
writeBasicIntFlag();
scratch.file("test/repo2/WORKSPACE");
scratch.file(
"test/repo2/defs.bzl",
"def _impl(ctx):",
" pass",
"my_flag = rule(",
" implementation = _impl,",
" build_setting = config.int(flag = True),",
")");
scratch.file(
"test/repo2/BUILD",
"load(':defs.bzl', 'my_flag')",
"my_flag(name = 'flag2', build_setting_default=2)");

rewriteWorkspace(
"workspace(name = 'starlark_options_test')",
"local_repository(",
" name = 'repo2',",
" path = 'test/repo2',",
")");
rewriteWorkspace("workspace(name = 'starlark_options_test')");

OptionsParsingResult result =
parseStarlarkOptions(
"--@starlark_options_test//test:my_int_setting=666 --@repo2//:flag2=222");
parseStarlarkOptions("--@starlark_options_test//test:my_int_setting=666");

assertThat(result.getStarlarkOptions()).hasSize(2);
assertThat(result.getStarlarkOptions().get("//test:my_int_setting"))
assertThat(result.getStarlarkOptions()).hasSize(1);
assertThat(result.getStarlarkOptions().get("@starlark_options_test//test:my_int_setting"))
.isEqualTo(StarlarkInt.of(666));
assertThat(result.getStarlarkOptions().get("@repo2//:flag2")).isEqualTo(StarlarkInt.of(222));
assertThat(result.getResidue()).isEmpty();
}

Expand Down