Search in sources :

Example 31 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class HalideLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget target = params.getBuildTarget();
    ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(target.getFlavors());
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
    if (flavors.contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR)) {
        ImmutableMap.Builder<Path, SourcePath> headersBuilder = ImmutableMap.builder();
        BuildTarget compileTarget = resolver.requireRule(target.withFlavors(HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor())).getBuildTarget();
        Path outputPath = HalideCompile.headerOutputPath(compileTarget, params.getProjectFilesystem(), args.functionName);
        headersBuilder.put(outputPath.getFileName(), new ExplicitBuildTargetSourcePath(compileTarget, outputPath));
        return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, cxxPlatform, headersBuilder.build(), HeaderVisibility.PUBLIC, true);
    } else if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
        CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
        return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, hostCxxPlatform, params);
    } else if (flavors.contains(HALIDE_COMPILER_FLAVOR)) {
        // We always want to build the halide "compiler" for the host platform, so
        // we use the host flavor here, regardless of the flavors on the build
        // target.
        CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
        final ImmutableSortedSet<BuildTarget> compilerDeps = args.compilerDeps;
        return createHalideCompiler(params.withAppendedFlavor(HALIDE_COMPILER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(resolver.getAllRules(compilerDeps)), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, pathResolver, ruleFinder, hostCxxPlatform, args.srcs, args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, args.linkerFlags, args.platformLinkerFlags, args.includeDirs);
    } else if (flavors.contains(CxxDescriptionEnhancer.STATIC_FLAVOR) || flavors.contains(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR)) {
        // See: https://github.com/halide/Halide/blob/e3c301f3/src/LLVM_Output.cpp#L152
        return createHalideStaticLibrary(params, resolver, ruleFinder, cxxPlatform, args);
    } else if (flavors.contains(CxxDescriptionEnhancer.SHARED_FLAVOR)) {
        throw new HumanReadableException("halide_library '%s' does not support shared libraries as output", params.getBuildTarget());
    } else if (flavors.contains(HALIDE_COMPILE_FLAVOR)) {
        return createHalideCompile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, cxxPlatform, Optional.of(args.compilerInvocationFlags), args.functionName);
    }
    return new HalideLibrary(params, resolver, args.supportedPlatformsRegex);
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 32 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class DownloadStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    BuckEventBus eventBus = context.getBuckEventBus();
    try {
        Path resolved = filesystem.resolve(output);
        boolean success = downloader.fetch(eventBus, url, resolved);
        if (!success) {
            return StepExecutionResult.of(reportFailedDownload(eventBus));
        }
        HashCode readHash = Files.asByteSource(resolved.toFile()).hash(Hashing.sha1());
        if (!sha1.equals(readHash)) {
            eventBus.post(ConsoleEvent.severe("Unable to download %s (hashes do not match. Expected %s, saw %s)", url, sha1, readHash));
            return StepExecutionResult.of(-1);
        }
    } catch (IOException e) {
        return StepExecutionResult.of(reportFailedDownload(eventBus));
    } catch (HumanReadableException e) {
        eventBus.post(ConsoleEvent.severe(e.getHumanReadableErrorMessage(), e));
        return StepExecutionResult.of(-1);
    }
    return StepExecutionResult.SUCCESS;
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) HumanReadableException(com.facebook.buck.util.HumanReadableException) IOException(java.io.IOException)

Example 33 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class MavenUrlDecoder method toHttpUrl.

public static URI toHttpUrl(Optional<String> mavenRepo, URI uri) {
    Preconditions.checkArgument("mvn".equals(uri.getScheme()), "URI must start with mvn: " + uri);
    Preconditions.checkArgument(mavenRepo.isPresent(), "You must specify the maven repo in the \"download->maven_repo\" section of your " + ".buckconfig");
    String repo = mavenRepo.get();
    if (!repo.endsWith("/")) {
        repo += "/";
    }
    Matcher matcher = URL_PATTERN.matcher(uri.getSchemeSpecificPart());
    if (!matcher.matches()) {
        throw new HumanReadableException("Unable to parse: " + uri);
    }
    String host = matcher.group("host");
    if (Strings.isNullOrEmpty(host)) {
        host = repo;
    }
    String group = matcher.group("group").replace('.', '/');
    String artifactId = matcher.group("id");
    String type = matcher.group("type");
    String version = matcher.group("version");
    Optional<String> classifier = Optional.ofNullable(matcher.group("classifier"));
    if (!host.endsWith("/")) {
        host += "/";
    }
    try {
        String plainUri = String.format("%s%s/%s/%s/%s", host, group, artifactId, version, fileNameFor(artifactId, version, type, classifier));
        URI generated = new URI(plainUri);
        if ("https".equals(generated.getScheme()) || "http".equals(generated.getScheme())) {
            return generated;
        }
        throw new HumanReadableException("Can only download maven artifacts over HTTP or HTTPS: %s", generated);
    } catch (URISyntaxException e) {
        throw new HumanReadableException("Unable to parse URL: " + uri);
    }
}
Also used : Matcher(java.util.regex.Matcher) HumanReadableException(com.facebook.buck.util.HumanReadableException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 34 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class RemoteFileDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
    HashCode sha1;
    try {
        sha1 = HashCode.fromString(args.sha1);
    } catch (IllegalArgumentException e) {
        throw new HumanReadableException(e, "%s when parsing sha1 of %s", e.getMessage(), params.getBuildTarget().getUnflavoredBuildTarget().getFullyQualifiedName());
    }
    String out = args.out.orElse(params.getBuildTarget().getShortNameAndFlavorPostfix());
    RemoteFile.Type type = args.type.orElse(RemoteFile.Type.DATA);
    if (type == RemoteFile.Type.EXECUTABLE) {
        return new RemoteFileBinary(params, downloader, args.url, sha1, out, type);
    }
    return new RemoteFile(params, downloader, args.url, sha1, out, type);
}
Also used : HashCode(com.google.common.hash.HashCode) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 35 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class DotnetFramework method resolveFramework.

// TODO(t8390117): Use official Win32 APIs to find the framework
@VisibleForTesting
static DotnetFramework resolveFramework(FileSystem osFilesystem, ImmutableMap<String, String> env, FrameworkVersion version) {
    Path programFiles = findProgramFiles(osFilesystem, env);
    Path baseDir = programFiles.resolve("Reference Assemblies").resolve("Microsoft").resolve("Framework");
    Path frameworkDir;
    switch(version) {
        case NET35:
            frameworkDir = baseDir.resolve("v3.5");
            break;
        case NET40:
        // fall through
        case NET45:
        // fall through
        case NET46:
            frameworkDir = baseDir.resolve(".NETFramework").resolve(version.getDirName());
            break;
        // Which we should never reach
        default:
            throw new HumanReadableException("Unknown .net framework version: %s", version);
    }
    if (!Files.exists(frameworkDir)) {
        throw new HumanReadableException("Resolved framework dir for %s does not exist: %s", version, frameworkDir);
    }
    if (!Files.isDirectory(frameworkDir)) {
        throw new HumanReadableException("Resolved framework directory is not a directory: %s", frameworkDir);
    }
    return new DotnetFramework(version, frameworkDir);
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15