Search in sources :

Example 1 with NoAndroidSdkException

use of com.facebook.buck.android.NoAndroidSdkException 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)

Example 2 with NoAndroidSdkException

use of com.facebook.buck.android.NoAndroidSdkException in project buck by facebook.

the class Genrule method addEnvironmentVariables.

protected void addEnvironmentVariables(SourcePathResolver pathResolver, ExecutionContext context, ImmutableMap.Builder<String, String> environmentVariablesBuilder) {
    environmentVariablesBuilder.put("SRCS", Joiner.on(' ').join(FluentIterable.from(srcs).transform(pathResolver::getAbsolutePath).transform(Object::toString)));
    environmentVariablesBuilder.put("OUT", getAbsoluteOutputFilePath(pathResolver));
    environmentVariablesBuilder.put("GEN_DIR", getProjectFilesystem().resolve(getProjectFilesystem().getBuckPaths().getGenDir()).toString());
    environmentVariablesBuilder.put("SRCDIR", absolutePathToSrcDirectory.toString());
    environmentVariablesBuilder.put("TMP", absolutePathToTmpDirectory.toString());
    // TODO(bolinfest): This entire hack needs to be removed. The [tools] section of .buckconfig
    // should be generalized to specify local paths to tools that can be used in genrules.
    AndroidPlatformTarget android;
    try {
        android = context.getAndroidPlatformTarget();
    } catch (NoAndroidSdkException e) {
        android = null;
    }
    if (android != null) {
        Optional<Path> sdkDirectory = android.getSdkDirectory();
        if (sdkDirectory.isPresent()) {
            environmentVariablesBuilder.put("ANDROID_HOME", sdkDirectory.get().toString());
        }
        Optional<Path> ndkDirectory = android.getNdkDirectory();
        if (ndkDirectory.isPresent()) {
            environmentVariablesBuilder.put("NDK_HOME", ndkDirectory.get().toString());
        }
        environmentVariablesBuilder.put("DX", android.getDxExecutable().toString());
        environmentVariablesBuilder.put("ZIPALIGN", android.getZipalignExecutable().toString());
    }
    // TODO(t5302074): This shouldn't be necessary. Speculatively disabling.
    environmentVariablesBuilder.put("NO_BUCKD", "1");
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) NoAndroidSdkException(com.facebook.buck.android.NoAndroidSdkException) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget)

Aggregations

AndroidPlatformTarget (com.facebook.buck.android.AndroidPlatformTarget)2 NoAndroidSdkException (com.facebook.buck.android.NoAndroidSdkException)2 Path (java.nio.file.Path)2 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Supplier (com.google.common.base.Supplier)1 ClassPath (com.google.common.reflect.ClassPath)1