Skip to content

Commit

Permalink
Revert "fix main repo starlark options parsing.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#13890.

This reverts commit 80c59de.
  • Loading branch information
katre committed Aug 23, 2021
1 parent a04cb1b commit ba86780
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
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

0 comments on commit ba86780

Please sign in to comment.