use of com.facebook.buck.android.AndroidPlatformTarget in project buck by facebook.
the class ReDexStepTest method constructorArgsAreUsedToCreateShellCommand.
@Test
public void constructorArgsAreUsedToCreateShellCommand() {
Path workingDirectory = Paths.get("/where/the/code/is");
List<String> redexBinaryArgs = ImmutableList.of("/usr/bin/redex");
Map<String, String> redexEnvironmentVariables = ImmutableMap.of("REDEX_DEBUG", "1");
Path inputApkPath = Paths.get("buck-out/gen/app.apk.zipalign");
Path outputApkPath = Paths.get("buck-out/gen/app.apk");
Path keystorePath = Paths.get("keystores/debug.keystore");
KeystoreProperties keystoreProperties = new KeystoreProperties(keystorePath, "storepass", "keypass", "alias");
Supplier<KeystoreProperties> keystorePropertiesSupplier = Suppliers.ofInstance(keystoreProperties);
Path redexConfigPath = Paths.get("redex/redex-config.json");
Optional<Path> redexConfig = Optional.of(redexConfigPath);
ImmutableList<Arg> redexExtraArgs = ImmutableList.of(StringArg.of("foo"), StringArg.of("bar"));
Path proguardMap = Paths.get("buck-out/gen/app/__proguard__/mapping.txt");
Path proguardConfig = Paths.get("app.proguard.config");
Path seeds = Paths.get("buck-out/gen/app/__proguard__/seeds.txt");
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ReDexStep redex = new ReDexStep(workingDirectory, redexBinaryArgs, redexEnvironmentVariables, inputApkPath, outputApkPath, keystorePropertiesSupplier, redexConfig, redexExtraArgs, proguardMap, proguardConfig, seeds, pathResolver);
assertEquals("redex", redex.getShortName());
AndroidPlatformTarget androidPlatform = EasyMock.createMock(AndroidPlatformTarget.class);
Path sdkDirectory = Paths.get("/Users/user/android-sdk-macosx");
EasyMock.expect(androidPlatform.getSdkDirectory()).andReturn(Optional.of(sdkDirectory));
EasyMock.replay(androidPlatform);
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatform)).build();
assertEquals(ImmutableMap.of("ANDROID_SDK", sdkDirectory.toString(), "REDEX_DEBUG", "1"), redex.getEnvironmentVariables(context));
EasyMock.verify(androidPlatform);
assertEquals(ImmutableList.of("/usr/bin/redex", "--config", redexConfigPath.toString(), "--sign", "--keystore", keystorePath.toString(), "--keyalias", "alias", "--keypass", "keypass", "--proguard-map", proguardMap.toString(), "-P", proguardConfig.toString(), "--keep", seeds.toString(), "--out", outputApkPath.toString(), "foo", "bar", inputApkPath.toString()), redex.getShellCommandInternal(context));
}
use of com.facebook.buck.android.AndroidPlatformTarget in project buck by facebook.
the class CleanCommandTest method createCommandRunnerParams.
private CommandRunnerParams createCommandRunnerParams() throws InterruptedException, IOException {
projectFilesystem = new FakeProjectFilesystem();
Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
Supplier<AndroidPlatformTarget> androidPlatformTargetSupplier = AndroidPlatformTarget.EXPLODING_ANDROID_PLATFORM_TARGET_SUPPLIER;
return CommandRunnerParams.builder().setConsole(new TestConsole()).setStdIn(new ByteArrayInputStream("".getBytes("UTF-8"))).setCell(cell).setAndroidPlatformTargetSupplier(androidPlatformTargetSupplier).setArtifactCacheFactory(new SingletonArtifactCacheFactory(new NoopArtifactCache())).setBuckEventBus(BuckEventBusFactory.newInstance()).setParser(createMock(Parser.class)).setPlatform(Platform.detect()).setEnvironment(ImmutableMap.copyOf(System.getenv())).setJavaPackageFinder(new FakeJavaPackageFinder()).setObjectMapper(ObjectMappers.newDefaultInstance()).setClock(new DefaultClock()).setProcessManager(Optional.empty()).setWebServer(Optional.empty()).setBuckConfig(FakeBuckConfig.builder().build()).setFileHashCache(new StackedFileHashCache(ImmutableList.of())).setExecutors(ImmutableMap.of()).setBuildEnvironmentDescription(CommandRunnerParamsForTesting.BUILD_ENVIRONMENT_DESCRIPTION).setVersionedTargetGraphCache(new VersionedTargetGraphCache()).setActionGraphCache(new ActionGraphCache(new BroadcastEventListener())).setKnownBuildRuleTypesFactory(new KnownBuildRuleTypesFactory(new FakeProcessExecutor(), new FakeAndroidDirectoryResolver())).build();
}
use of com.facebook.buck.android.AndroidPlatformTarget in project buck by facebook.
the class ReDexStep method getEnvironmentVariables.
@Override
public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
AndroidPlatformTarget platformTarget = context.getAndroidPlatformTarget();
Optional<Path> sdkDirectory = platformTarget.getSdkDirectory();
if (!sdkDirectory.isPresent()) {
throw new RuntimeException("Could not find ANDROID_SDK directory for ReDexStep");
}
return ImmutableMap.<String, String>builder().put("ANDROID_SDK", sdkDirectory.get().toString()).putAll(redexEnvironmentVariables).build();
}
use of com.facebook.buck.android.AndroidPlatformTarget in project buck by facebook.
the class GenruleTest method testShouldIncludeAndroidSpecificEnvInEnvironmentIfPresent.
@Test
public void testShouldIncludeAndroidSpecificEnvInEnvironmentIfPresent() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
AndroidPlatformTarget android = EasyMock.createNiceMock(AndroidPlatformTarget.class);
Path sdkDir = Paths.get("/opt/users/android_sdk");
Path ndkDir = Paths.get("/opt/users/android_ndk");
EasyMock.expect(android.getSdkDirectory()).andStubReturn(Optional.of(sdkDir));
EasyMock.expect(android.getNdkDirectory()).andStubReturn(Optional.of(ndkDir));
EasyMock.expect(android.getDxExecutable()).andStubReturn(Paths.get("."));
EasyMock.expect(android.getZipalignExecutable()).andStubReturn(Paths.get("zipalign"));
EasyMock.replay(android);
BuildTarget target = BuildTargetFactory.newInstance("//example:genrule");
Genrule genrule = GenruleBuilder.newGenruleBuilder(target).setBash("echo something > $OUT").setOut("file").build(resolver);
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(android)).build();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
genrule.addEnvironmentVariables(pathResolver, context, builder);
ImmutableMap<String, String> env = builder.build();
assertEquals(Paths.get(".").toString(), env.get("DX"));
assertEquals(Paths.get("zipalign").toString(), env.get("ZIPALIGN"));
assertEquals(sdkDir.toString(), env.get("ANDROID_HOME"));
assertEquals(ndkDir.toString(), env.get("NDK_HOME"));
EasyMock.verify(android);
}
use of com.facebook.buck.android.AndroidPlatformTarget in project buck by facebook.
the class Main method createAndroidPlatformTargetSupplier.
@VisibleForTesting
static Supplier<AndroidPlatformTarget> createAndroidPlatformTargetSupplier(final AndroidDirectoryResolver androidDirectoryResolver, final AndroidBuckConfig androidBuckConfig, final BuckEventBus eventBus) {
// of its getCacheName() method in its RuleKey.
return new Supplier<AndroidPlatformTarget>() {
@Nullable
private AndroidPlatformTarget androidPlatformTarget;
@Nullable
private NoAndroidSdkException exception;
@Override
public AndroidPlatformTarget get() {
if (androidPlatformTarget != null) {
return androidPlatformTarget;
} else if (exception != null) {
throw exception;
}
Optional<Path> androidSdkDirOption = androidDirectoryResolver.getSdkOrAbsent();
if (!androidSdkDirOption.isPresent()) {
exception = new NoAndroidSdkException();
throw exception;
}
String androidPlatformTargetId;
Optional<String> target = androidBuckConfig.getAndroidTarget();
if (target.isPresent()) {
androidPlatformTargetId = target.get();
} else {
androidPlatformTargetId = AndroidPlatformTarget.DEFAULT_ANDROID_PLATFORM_TARGET;
eventBus.post(ConsoleEvent.warning("No Android platform target specified. Using default: %s", androidPlatformTargetId));
}
Optional<AndroidPlatformTarget> androidPlatformTargetOptional = AndroidPlatformTarget.getTargetForId(androidPlatformTargetId, androidDirectoryResolver, androidBuckConfig.getAaptOverride());
if (androidPlatformTargetOptional.isPresent()) {
androidPlatformTarget = androidPlatformTargetOptional.get();
return androidPlatformTarget;
} else {
exception = NoAndroidSdkException.createExceptionForPlatformThatCannotBeFound(androidPlatformTargetId);
throw exception;
}
}
};
}
Aggregations