Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 2f9f332

Browse files
IanChildsfacebook-github-bot
authored andcommitted
Allow named outputs in Android Keystore
Summary: This gives the ability to access each of the saved paths in the `Keystore` without needing to resort to flavors. This is better because it is consistent with the way that we want Buck V2 to work. Reviewed By: mykola-semko fbshipit-source-id: 4befae359413d96dab8c71e3c557568a9693f5e2
1 parent 94fef34 commit 2f9f332

3 files changed

Lines changed: 60 additions & 7 deletions

File tree

src/com/facebook/buck/jvm/java/Keystore.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,23 @@
1919
import com.facebook.buck.core.build.buildable.context.BuildableContext;
2020
import com.facebook.buck.core.build.context.BuildContext;
2121
import com.facebook.buck.core.model.BuildTarget;
22+
import com.facebook.buck.core.model.OutputLabel;
2223
import com.facebook.buck.core.rulekey.AddToRuleKey;
2324
import com.facebook.buck.core.rules.BuildRuleParams;
25+
import com.facebook.buck.core.rules.attr.HasMultipleOutputs;
2426
import com.facebook.buck.core.rules.impl.AbstractBuildRuleWithDeclaredAndExtraDeps;
2527
import com.facebook.buck.core.sourcepath.SourcePath;
2628
import com.facebook.buck.io.filesystem.ProjectFilesystem;
2729
import com.facebook.buck.step.Step;
2830
import com.google.common.collect.ImmutableList;
31+
import com.google.common.collect.ImmutableSet;
32+
import com.google.common.collect.ImmutableSortedSet;
2933
import javax.annotation.Nullable;
3034

31-
public class Keystore extends AbstractBuildRuleWithDeclaredAndExtraDeps {
35+
public class Keystore extends AbstractBuildRuleWithDeclaredAndExtraDeps
36+
implements HasMultipleOutputs {
37+
private static final OutputLabel KEYSTORE_LABEL = OutputLabel.of("keystore");
38+
private static final OutputLabel PROPERTIES_LABEL = OutputLabel.of("properties");
3239

3340
@AddToRuleKey private final SourcePath pathToStore;
3441
@AddToRuleKey private final SourcePath pathToProperties;
@@ -44,12 +51,29 @@ public Keystore(
4451
this.pathToProperties = properties;
4552
}
4653

54+
@Override
55+
public ImmutableSet<OutputLabel> getOutputLabels() {
56+
return ImmutableSet.of(KEYSTORE_LABEL, PROPERTIES_LABEL);
57+
}
58+
4759
@Nullable
4860
@Override
4961
public SourcePath getSourcePathToOutput() {
5062
return null;
5163
}
5264

65+
@Nullable
66+
@Override
67+
public ImmutableSortedSet<SourcePath> getSourcePathToOutput(OutputLabel outputLabel) {
68+
if (outputLabel.equals(KEYSTORE_LABEL)) {
69+
return ImmutableSortedSet.of(pathToStore);
70+
} else if (outputLabel.equals(PROPERTIES_LABEL)) {
71+
return ImmutableSortedSet.of(pathToProperties);
72+
} else {
73+
return ImmutableSortedSet.of();
74+
}
75+
}
76+
5377
public SourcePath getPathToStore() {
5478
return pathToStore;
5579
}

test/com/facebook/buck/android/AndroidKeystoreIntegrationTest.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,34 @@ public void setUp() throws IOException {
4141
}
4242

4343
@Test
44-
public void testKeystoreOutput() throws IOException {
45-
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore");
44+
public void testKeystoreOutputUsingFlavor() throws IOException {
45+
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_using_flavor");
4646
String copyOutput = workspace.getFileContents(output);
4747
String source = workspace.getFileContents("keystores/debug.keystore");
4848
assertEquals(source, copyOutput);
4949
}
5050

5151
@Test
52-
public void testKeystorePropertiesOutput() throws IOException {
53-
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_properties");
52+
public void testKeystorePropertiesOutputUsingFlavor() throws IOException {
53+
Path output =
54+
workspace.buildAndReturnOutput("//keystores:copy_keystore_properties_using_flavor");
55+
String copyOutput = workspace.getFileContents(output);
56+
String source = workspace.getFileContents("keystores/debug.keystore.properties");
57+
assertEquals(source, copyOutput);
58+
}
59+
60+
@Test
61+
public void testKeystoreOutputUsingNamedOutput() throws IOException {
62+
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_using_named_output");
63+
String copyOutput = workspace.getFileContents(output);
64+
String source = workspace.getFileContents("keystores/debug.keystore");
65+
assertEquals(source, copyOutput);
66+
}
67+
68+
@Test
69+
public void testKeystorePropertiesOutputUsingNamedOutput() throws IOException {
70+
Path output =
71+
workspace.buildAndReturnOutput("//keystores:copy_keystore_properties_using_named_output");
5472
String copyOutput = workspace.getFileContents(output);
5573
String source = workspace.getFileContents("keystores/debug.keystore.properties");
5674
assertEquals(source, copyOutput);

test/com/facebook/buck/android/testdata/android_project/keystores/BUCK.fixture

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ keystore(
66
)
77

88
genrule(
9-
name = "copy_keystore",
9+
name = "copy_keystore_using_flavor",
1010
out = "copy.keystore",
1111
cmd = "cp $(location :debug#keystore) $OUT",
1212
)
1313
genrule(
14-
name = "copy_keystore_properties",
14+
name = "copy_keystore_properties_using_flavor",
1515
out = "copy.properties",
1616
cmd = "cp $(location :debug#properties) $OUT",
1717
)
18+
19+
genrule(
20+
name = "copy_keystore_using_named_output",
21+
out = "copy.keystore",
22+
cmd = "cp $(location :debug[keystore]) $OUT",
23+
)
24+
genrule(
25+
name = "copy_keystore_properties_using_named_output",
26+
out = "copy.properties",
27+
cmd = "cp $(location :debug[properties]) $OUT",
28+
)

0 commit comments

Comments
 (0)