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

Commit

Permalink
Remove flavors from Android Keystore
Browse files Browse the repository at this point in the history
Summary: We can now used named outputs instead.

Reviewed By: ndmitchell, mykola-semko

fbshipit-source-id: a4ad919a4aeccd756905b50165d1bbb9ef926b1d
  • Loading branch information
IanChilds authored and facebook-github-bot committed Sep 16, 2021
1 parent db3ef6b commit c9acd32
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 124 deletions.
4 changes: 0 additions & 4 deletions src/com/facebook/buck/jvm/java/JavaBuckConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ public boolean useDependencyOrderClasspathForTests() {
return delegate.getBoolean(SECTION, "use_dependency_order_classpath_for_tests").orElse(false);
}

public boolean useFlavorsForKeystore() {
return delegate.getBoolean(SECTION, "use_flavors_for_keystore").orElse(true);
}

public enum SourceAbiVerificationMode {
/** Don't verify ABI jars. */
OFF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public Collection<Description<?>> getDescriptions(DescriptionCreationContext con
new JavaTestRunnerDescription(
toolchainProvider, javaConfig, javaCDBuckConfig, downwardApiConfig),
new JavaTestDescription(toolchainProvider, javaConfig, javaCDBuckConfig, downwardApiConfig),
new KeystoreDescription(javaConfig));
new KeystoreDescription());
}
}
64 changes: 1 addition & 63 deletions src/com/facebook/buck/jvm/java/KeystoreDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,92 +19,30 @@
import com.facebook.buck.core.description.arg.BuildRuleArg;
import com.facebook.buck.core.description.arg.HasDeclaredDeps;
import com.facebook.buck.core.model.BuildTarget;
import com.facebook.buck.core.model.Flavor;
import com.facebook.buck.core.model.FlavorSet;
import com.facebook.buck.core.model.Flavored;
import com.facebook.buck.core.model.InternalFlavor;
import com.facebook.buck.core.model.TargetConfiguration;
import com.facebook.buck.core.rules.BuildRule;
import com.facebook.buck.core.rules.BuildRuleCreationContextWithTargetGraph;
import com.facebook.buck.core.rules.BuildRuleParams;
import com.facebook.buck.core.rules.DescriptionWithTargetGraph;
import com.facebook.buck.core.sourcepath.SourcePath;
import com.facebook.buck.core.util.immutables.RuleArg;
import com.facebook.buck.shell.ExportFile;
import com.facebook.buck.shell.ExportFileDescription;
import com.facebook.buck.shell.ExportFileDirectoryAction;
import com.google.common.collect.ImmutableSet;

public class KeystoreDescription
implements DescriptionWithTargetGraph<KeystoreDescriptionArg>, Flavored {

static final Flavor PROPERTIES = InternalFlavor.of("properties");
static final Flavor KEYSTORE = InternalFlavor.of("keystore");

private static final ImmutableSet<Flavor> FLAVORS = ImmutableSet.of(PROPERTIES, KEYSTORE);
private final JavaBuckConfig javaBuckConfig;

public KeystoreDescription(JavaBuckConfig javaBuckConfig) {
this.javaBuckConfig = javaBuckConfig;
}
public class KeystoreDescription implements DescriptionWithTargetGraph<KeystoreDescriptionArg> {

@Override
public Class<KeystoreDescriptionArg> getConstructorArgType() {
return KeystoreDescriptionArg.class;
}

@Override
public boolean hasFlavors(
ImmutableSet<Flavor> flavors, TargetConfiguration toolchainTargetConfiguration) {
if (!javaBuckConfig.useFlavorsForKeystore() && !flavors.isEmpty()) {
throw new IllegalStateException("Flavors are not permitted for keystore, try named outputs!");
}

for (Flavor flavor : flavors) {
if (!FLAVORS.contains(flavor)) {
return false;
}
}
return true;
}

@Override
public BuildRule createBuildRule(
BuildRuleCreationContextWithTargetGraph context,
BuildTarget buildTarget,
BuildRuleParams params,
KeystoreDescriptionArg args) {

FlavorSet flavors = buildTarget.getFlavors();
if (!javaBuckConfig.useFlavorsForKeystore() && !flavors.isEmpty()) {
throw new IllegalStateException("Flavors are not permitted for keystore, try named outputs!");
}

if (flavors.contains(PROPERTIES)) {
return createExportFile(context, buildTarget, "keystore.properties", args.getProperties());
} else if (flavors.contains(KEYSTORE)) {
return createExportFile(context, buildTarget, "keystore.keystore", args.getStore());
}

return new Keystore(
buildTarget, context.getProjectFilesystem(), params, args.getStore(), args.getProperties());
}

private ExportFile createExportFile(
BuildRuleCreationContextWithTargetGraph context,
BuildTarget buildTarget,
String name,
SourcePath source) {
return new ExportFile(
buildTarget,
context.getProjectFilesystem(),
context.getActionGraphBuilder(),
name,
ExportFileDescription.Mode.REFERENCE,
source,
ExportFileDirectoryAction.FAIL);
}

@RuleArg
interface AbstractKeystoreDescriptionArg extends BuildRuleArg, HasDeclaredDeps {
SourcePath getStore();
Expand Down
43 changes: 2 additions & 41 deletions test/com/facebook/buck/android/AndroidKeystoreIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.facebook.buck.testutil.TemporaryPaths;
import com.facebook.buck.testutil.integration.ProjectWorkspace;
import com.facebook.buck.testutil.integration.TestDataHelper;
import com.facebook.buck.util.ExitCode;
import java.io.IOException;
import java.nio.file.Path;
import org.junit.Before;
Expand All @@ -41,57 +40,19 @@ public void setUp() throws IOException {
workspace.setUp();
}

@Test
public void testKeystoreOutputUsingFlavor() throws IOException {
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_using_flavor");
String copyOutput = workspace.getFileContents(output);
String source = workspace.getFileContents("keystores/debug.keystore");
assertEquals(source, copyOutput);
}

@Test
public void testKeystorePropertiesOutputUsingFlavor() throws IOException {
Path output =
workspace.buildAndReturnOutput("//keystores:copy_keystore_properties_using_flavor");
String copyOutput = workspace.getFileContents(output);
String source = workspace.getFileContents("keystores/debug.keystore.properties");
assertEquals(source, copyOutput);
}

@Test
public void testKeystoreOutputUsingNamedOutput() throws IOException {
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_using_named_output");
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore");
String copyOutput = workspace.getFileContents(output);
String source = workspace.getFileContents("keystores/debug.keystore");
assertEquals(source, copyOutput);
}

@Test
public void testKeystorePropertiesOutputUsingNamedOutput() throws IOException {
Path output =
workspace.buildAndReturnOutput("//keystores:copy_keystore_properties_using_named_output");
Path output = workspace.buildAndReturnOutput("//keystores:copy_keystore_properties");
String copyOutput = workspace.getFileContents(output);
String source = workspace.getFileContents("keystores/debug.keystore.properties");
assertEquals(source, copyOutput);
}

@Test
public void testKeystoreOutputUsingFlavorDisallowed() {
workspace
.runBuckBuild(
"//keystores:copy_keystore_using_flavor", "-c", "java.use_flavors_for_keystore=false")
.assertExitCode(
"Flavors are not permitted for keystore, try named outputs!", ExitCode.FATAL_GENERIC);
}

@Test
public void testKeystorePropertiesOutputUsingFlavorDisallowed() {
workspace
.runBuckBuild(
"//keystores:copy_keystore_properties_using_flavor",
"-c",
"java.use_flavors_for_keystore=false")
.assertExitCode(
"Flavors are not permitted for keystore, try named outputs!", ExitCode.FATAL_GENERIC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@ keystore(
)

genrule(
name = "copy_keystore_using_flavor",
out = "copy.keystore",
cmd = "cp $(location :debug#keystore) $OUT",
)
genrule(
name = "copy_keystore_properties_using_flavor",
out = "copy.properties",
cmd = "cp $(location :debug#properties) $OUT",
)

genrule(
name = "copy_keystore_using_named_output",
name = "copy_keystore",
out = "copy.keystore",
cmd = "cp $(location :debug[keystore]) $OUT",
)
genrule(
name = "copy_keystore_properties_using_named_output",
name = "copy_keystore_properties",
out = "copy.properties",
cmd = "cp $(location :debug[properties]) $OUT",
)
3 changes: 1 addition & 2 deletions test/com/facebook/buck/jvm/java/KeystoreBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.facebook.buck.jvm.java;

import com.facebook.buck.core.config.FakeBuckConfig;
import com.facebook.buck.core.model.BuildTarget;
import com.facebook.buck.core.model.targetgraph.AbstractNodeBuilder;
import com.facebook.buck.core.sourcepath.SourcePath;
Expand All @@ -26,7 +25,7 @@ public class KeystoreBuilder
KeystoreDescriptionArg.Builder, KeystoreDescriptionArg, KeystoreDescription, Keystore> {

private KeystoreBuilder(BuildTarget target) {
super(new KeystoreDescription(JavaBuckConfig.of(FakeBuckConfig.empty())), target);
super(new KeystoreDescription(), target);
}

public static KeystoreBuilder createBuilder(BuildTarget target) {
Expand Down

0 comments on commit c9acd32

Please sign in to comment.