Search in sources :

Example 1 with AndroidPlatformTarget

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));
}
Also used : Path(java.nio.file.Path) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) KeystoreProperties(com.facebook.buck.android.KeystoreProperties) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 2 with AndroidPlatformTarget

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();
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) KnownBuildRuleTypesFactory(com.facebook.buck.rules.KnownBuildRuleTypesFactory) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) VersionedTargetGraphCache(com.facebook.buck.versions.VersionedTargetGraphCache) SingletonArtifactCacheFactory(com.facebook.buck.artifact_cache.SingletonArtifactCacheFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) ByteArrayInputStream(java.io.ByteArrayInputStream) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) DefaultClock(com.facebook.buck.timing.DefaultClock) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell)

Example 3 with AndroidPlatformTarget

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();
}
Also used : Path(java.nio.file.Path) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget)

Example 4 with AndroidPlatformTarget

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);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 5 with AndroidPlatformTarget

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;
            }
        }
    };
}
Also used : ClassPath(com.google.common.reflect.ClassPath) Path(java.nio.file.Path) NoAndroidSdkException(com.facebook.buck.android.NoAndroidSdkException) Supplier(com.google.common.base.Supplier) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

AndroidPlatformTarget (com.facebook.buck.android.AndroidPlatformTarget)8 Path (java.nio.file.Path)7 NoAndroidSdkException (com.facebook.buck.android.NoAndroidSdkException)3 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 SourcePath (com.facebook.buck.rules.SourcePath)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 ExecutionContext (com.facebook.buck.step.ExecutionContext)2 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Supplier (com.google.common.base.Supplier)2 ClassPath (com.google.common.reflect.ClassPath)2 Test (org.junit.Test)2 AndroidBuckConfig (com.facebook.buck.android.AndroidBuckConfig)1 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)1 DefaultAndroidDirectoryResolver (com.facebook.buck.android.DefaultAndroidDirectoryResolver)1 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)1 KeystoreProperties (com.facebook.buck.android.KeystoreProperties)1