Skip to content

Commit

Permalink
Make tests more resilient to alternative values for TOOLS_REPOSITORY
Browse files Browse the repository at this point in the history
This has no effect on public Bazel, but helps some Google-internal tests pass, since the tools repo is not under "@bazel_tools".

PiperOrigin-RevId: 227033450
  • Loading branch information
brandjon authored and Copybara-Service committed Dec 27, 2018
1 parent df4ceb4 commit f4ddd6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -245,30 +246,32 @@ protected static Set<Artifact> getNonToolInputs(Action action) {

protected void checkDebugKey(String debugKeyFile, boolean hasDebugKeyTarget) throws Exception {
ConfiguredTarget binary = getConfiguredTarget("//java/com/google/android/hello:b");
String defaultKeyStoreFile =
ruleClassProvider.getToolsRepository() + "//tools/android:debug_keystore";
Label defaultKeyStoreFile =
Label.parseAbsoluteUnchecked(
ruleClassProvider.getToolsRepository() + "//tools/android:debug_keystore");
Label debugKeyFileLabel = Label.parseAbsolute(debugKeyFile, ImmutableMap.of());

if (hasDebugKeyTarget) {
assertWithMessage("Debug key file target missing.")
.that(checkKeyPresence(binary, debugKeyFile, defaultKeyStoreFile))
.that(checkKeyPresence(binary, debugKeyFileLabel, defaultKeyStoreFile))
.isTrue();
} else {
assertWithMessage("Debug key file is default, although different target specified.")
.that(checkKeyPresence(binary, defaultKeyStoreFile, debugKeyFile))
.that(checkKeyPresence(binary, defaultKeyStoreFile, debugKeyFileLabel))
.isTrue();
}
}

private boolean checkKeyPresence(
ConfiguredTarget binary, String shouldHaveKey, String shouldNotHaveKey) throws Exception {
ConfiguredTarget binary, Label shouldHaveKey, Label shouldNotHaveKey) throws Exception {
boolean hasKey = false;
boolean doesNotHaveKey = false;

for (ConfiguredTarget debugKeyTarget : getDirectPrerequisites(binary)) {
if (debugKeyTarget.getLabel().toString().equals(shouldHaveKey)) {
if (debugKeyTarget.getLabel().equals(shouldHaveKey)) {
hasKey = true;
}
if (debugKeyTarget.getLabel().toString().equals(shouldNotHaveKey)) {
if (debugKeyTarget.getLabel().equals(shouldNotHaveKey)) {
doesNotHaveKey = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.devtools.build.lib.analysis.util.DefaultsPackageUtil;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.common.options.OptionsParsingException;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -32,8 +32,14 @@ public class CppOptionsTest {
@Test
public void testGetDefaultsPackage() throws Exception {
String content = DefaultsPackageUtil.getDefaultsPackageForOptions(CppOptions.class);
assertThat(content).contains("filegroup(name = 'crosstool',\n"
+ " srcs = ['" + TestConstants.TOOLS_REPOSITORY + "//tools/cpp:toolchain'])");
Label toolchainLabel =
Label.parseAbsoluteUnchecked(TestConstants.TOOLS_REPOSITORY + "//tools/cpp:toolchain");
assertThat(content)
.contains(
String.format(
// Indentation matched literally.
"filegroup(name = 'crosstool',\n srcs = ['%s'])",
toolchainLabel.getDefaultCanonicalForm()));
}

@Test
Expand Down

0 comments on commit f4ddd6b

Please sign in to comment.