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

Commit c9acd32

Browse files
IanChildsfacebook-github-bot
authored andcommitted
Remove flavors from Android Keystore
Summary: We can now used named outputs instead. Reviewed By: ndmitchell, mykola-semko fbshipit-source-id: a4ad919a4aeccd756905b50165d1bbb9ef926b1d
1 parent db3ef6b commit c9acd32

6 files changed

Lines changed: 7 additions & 124 deletions

File tree

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ public boolean useDependencyOrderClasspathForTests() {
388388
return delegate.getBoolean(SECTION, "use_dependency_order_classpath_for_tests").orElse(false);
389389
}
390390

391-
public boolean useFlavorsForKeystore() {
392-
return delegate.getBoolean(SECTION, "use_flavors_for_keystore").orElse(true);
393-
}
394-
395391
public enum SourceAbiVerificationMode {
396392
/** Don't verify ABI jars. */
397393
OFF,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ public Collection<Description<?>> getDescriptions(DescriptionCreationContext con
5959
new JavaTestRunnerDescription(
6060
toolchainProvider, javaConfig, javaCDBuckConfig, downwardApiConfig),
6161
new JavaTestDescription(toolchainProvider, javaConfig, javaCDBuckConfig, downwardApiConfig),
62-
new KeystoreDescription(javaConfig));
62+
new KeystoreDescription());
6363
}
6464
}

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

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,92 +19,30 @@
1919
import com.facebook.buck.core.description.arg.BuildRuleArg;
2020
import com.facebook.buck.core.description.arg.HasDeclaredDeps;
2121
import com.facebook.buck.core.model.BuildTarget;
22-
import com.facebook.buck.core.model.Flavor;
23-
import com.facebook.buck.core.model.FlavorSet;
24-
import com.facebook.buck.core.model.Flavored;
25-
import com.facebook.buck.core.model.InternalFlavor;
26-
import com.facebook.buck.core.model.TargetConfiguration;
2722
import com.facebook.buck.core.rules.BuildRule;
2823
import com.facebook.buck.core.rules.BuildRuleCreationContextWithTargetGraph;
2924
import com.facebook.buck.core.rules.BuildRuleParams;
3025
import com.facebook.buck.core.rules.DescriptionWithTargetGraph;
3126
import com.facebook.buck.core.sourcepath.SourcePath;
3227
import com.facebook.buck.core.util.immutables.RuleArg;
33-
import com.facebook.buck.shell.ExportFile;
34-
import com.facebook.buck.shell.ExportFileDescription;
35-
import com.facebook.buck.shell.ExportFileDirectoryAction;
36-
import com.google.common.collect.ImmutableSet;
3728

38-
public class KeystoreDescription
39-
implements DescriptionWithTargetGraph<KeystoreDescriptionArg>, Flavored {
40-
41-
static final Flavor PROPERTIES = InternalFlavor.of("properties");
42-
static final Flavor KEYSTORE = InternalFlavor.of("keystore");
43-
44-
private static final ImmutableSet<Flavor> FLAVORS = ImmutableSet.of(PROPERTIES, KEYSTORE);
45-
private final JavaBuckConfig javaBuckConfig;
46-
47-
public KeystoreDescription(JavaBuckConfig javaBuckConfig) {
48-
this.javaBuckConfig = javaBuckConfig;
49-
}
29+
public class KeystoreDescription implements DescriptionWithTargetGraph<KeystoreDescriptionArg> {
5030

5131
@Override
5232
public Class<KeystoreDescriptionArg> getConstructorArgType() {
5333
return KeystoreDescriptionArg.class;
5434
}
5535

56-
@Override
57-
public boolean hasFlavors(
58-
ImmutableSet<Flavor> flavors, TargetConfiguration toolchainTargetConfiguration) {
59-
if (!javaBuckConfig.useFlavorsForKeystore() && !flavors.isEmpty()) {
60-
throw new IllegalStateException("Flavors are not permitted for keystore, try named outputs!");
61-
}
62-
63-
for (Flavor flavor : flavors) {
64-
if (!FLAVORS.contains(flavor)) {
65-
return false;
66-
}
67-
}
68-
return true;
69-
}
70-
7136
@Override
7237
public BuildRule createBuildRule(
7338
BuildRuleCreationContextWithTargetGraph context,
7439
BuildTarget buildTarget,
7540
BuildRuleParams params,
7641
KeystoreDescriptionArg args) {
77-
78-
FlavorSet flavors = buildTarget.getFlavors();
79-
if (!javaBuckConfig.useFlavorsForKeystore() && !flavors.isEmpty()) {
80-
throw new IllegalStateException("Flavors are not permitted for keystore, try named outputs!");
81-
}
82-
83-
if (flavors.contains(PROPERTIES)) {
84-
return createExportFile(context, buildTarget, "keystore.properties", args.getProperties());
85-
} else if (flavors.contains(KEYSTORE)) {
86-
return createExportFile(context, buildTarget, "keystore.keystore", args.getStore());
87-
}
88-
8942
return new Keystore(
9043
buildTarget, context.getProjectFilesystem(), params, args.getStore(), args.getProperties());
9144
}
9245

93-
private ExportFile createExportFile(
94-
BuildRuleCreationContextWithTargetGraph context,
95-
BuildTarget buildTarget,
96-
String name,
97-
SourcePath source) {
98-
return new ExportFile(
99-
buildTarget,
100-
context.getProjectFilesystem(),
101-
context.getActionGraphBuilder(),
102-
name,
103-
ExportFileDescription.Mode.REFERENCE,
104-
source,
105-
ExportFileDirectoryAction.FAIL);
106-
}
107-
10846
@RuleArg
10947
interface AbstractKeystoreDescriptionArg extends BuildRuleArg, HasDeclaredDeps {
11048
SourcePath getStore();

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

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.facebook.buck.testutil.TemporaryPaths;
2222
import com.facebook.buck.testutil.integration.ProjectWorkspace;
2323
import com.facebook.buck.testutil.integration.TestDataHelper;
24-
import com.facebook.buck.util.ExitCode;
2524
import java.io.IOException;
2625
import java.nio.file.Path;
2726
import org.junit.Before;
@@ -41,57 +40,19 @@ public void setUp() throws IOException {
4140
workspace.setUp();
4241
}
4342

44-
@Test
45-
public void testKeystoreOutputUsingFlavor() throws IOException {
46-
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_using_flavor");
47-
String copyOutput = workspace.getFileContents(output);
48-
String source = workspace.getFileContents("keystores/debug.keystore");
49-
assertEquals(source, copyOutput);
50-
}
51-
52-
@Test
53-
public void testKeystorePropertiesOutputUsingFlavor() throws IOException {
54-
Path output =
55-
workspace.buildAndReturnOutput("//keystores:copy_keystore_properties_using_flavor");
56-
String copyOutput = workspace.getFileContents(output);
57-
String source = workspace.getFileContents("keystores/debug.keystore.properties");
58-
assertEquals(source, copyOutput);
59-
}
60-
6143
@Test
6244
public void testKeystoreOutputUsingNamedOutput() throws IOException {
63-
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_using_named_output");
45+
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore");
6446
String copyOutput = workspace.getFileContents(output);
6547
String source = workspace.getFileContents("keystores/debug.keystore");
6648
assertEquals(source, copyOutput);
6749
}
6850

6951
@Test
7052
public void testKeystorePropertiesOutputUsingNamedOutput() throws IOException {
71-
Path output =
72-
workspace.buildAndReturnOutput("//keystores:copy_keystore_properties_using_named_output");
53+
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_properties");
7354
String copyOutput = workspace.getFileContents(output);
7455
String source = workspace.getFileContents("keystores/debug.keystore.properties");
7556
assertEquals(source, copyOutput);
7657
}
77-
78-
@Test
79-
public void testKeystoreOutputUsingFlavorDisallowed() {
80-
workspace
81-
.runBuckBuild(
82-
"//keystores:copy_keystore_using_flavor", "-c", "java.use_flavors_for_keystore=false")
83-
.assertExitCode(
84-
"Flavors are not permitted for keystore, try named outputs!", ExitCode.FATAL_GENERIC);
85-
}
86-
87-
@Test
88-
public void testKeystorePropertiesOutputUsingFlavorDisallowed() {
89-
workspace
90-
.runBuckBuild(
91-
"//keystores:copy_keystore_properties_using_flavor",
92-
"-c",
93-
"java.use_flavors_for_keystore=false")
94-
.assertExitCode(
95-
"Flavors are not permitted for keystore, try named outputs!", ExitCode.FATAL_GENERIC);
96-
}
9758
}

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

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

88
genrule(
9-
name = "copy_keystore_using_flavor",
10-
out = "copy.keystore",
11-
cmd = "cp $(location :debug#keystore) $OUT",
12-
)
13-
genrule(
14-
name = "copy_keystore_properties_using_flavor",
15-
out = "copy.properties",
16-
cmd = "cp $(location :debug#properties) $OUT",
17-
)
18-
19-
genrule(
20-
name = "copy_keystore_using_named_output",
9+
name = "copy_keystore",
2110
out = "copy.keystore",
2211
cmd = "cp $(location :debug[keystore]) $OUT",
2312
)
2413
genrule(
25-
name = "copy_keystore_properties_using_named_output",
14+
name = "copy_keystore_properties",
2615
out = "copy.properties",
2716
cmd = "cp $(location :debug[properties]) $OUT",
2817
)

test/com/facebook/buck/jvm/java/KeystoreBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.facebook.buck.jvm.java;
1818

19-
import com.facebook.buck.core.config.FakeBuckConfig;
2019
import com.facebook.buck.core.model.BuildTarget;
2120
import com.facebook.buck.core.model.targetgraph.AbstractNodeBuilder;
2221
import com.facebook.buck.core.sourcepath.SourcePath;
@@ -26,7 +25,7 @@ public class KeystoreBuilder
2625
KeystoreDescriptionArg.Builder, KeystoreDescriptionArg, KeystoreDescription, Keystore> {
2726

2827
private KeystoreBuilder(BuildTarget target) {
29-
super(new KeystoreDescription(JavaBuckConfig.of(FakeBuckConfig.empty())), target);
28+
super(new KeystoreDescription(), target);
3029
}
3130

3231
public static KeystoreBuilder createBuilder(BuildTarget target) {

0 commit comments

Comments
 (0)