Search in sources :

Example 26 with HumanReadableException

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

the class MainIntegrationTest method testConfigRemoval.

@Test
public void testConfigRemoval() throws IOException, InterruptedException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "includes_removals", tmp);
    workspace.setUp();
    // It should produce exception as we want explicit ide setting.
    try {
        workspace.runBuckCommand("project", "--config", "project.ide=");
    } catch (HumanReadableException e) {
        assertThat(e.getHumanReadableErrorMessage(), Matchers.stringContainsInOrder("Please specify ide using --ide option " + "or set ide in .buckconfig"));
    } catch (Exception e) {
        // other exceptions are not expected
        throw e;
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) HumanReadableException(com.facebook.buck.util.HumanReadableException) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) Test(org.junit.Test)

Example 27 with HumanReadableException

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

the class AbstractPrebuiltCxxLibraryGroupDescription method getStaticLinkArgs.

/**
   * @return the link args formed from the user-provided static link line after resolving library
   *         macro references.
   */
private Iterable<Arg> getStaticLinkArgs(BuildTarget target, ImmutableList<SourcePath> libs, ImmutableList<String> args) {
    ImmutableList.Builder<Arg> builder = ImmutableList.builder();
    for (String arg : args) {
        Optional<Pair<String, String>> libRef = getLibRef(ImmutableSet.of(LIB_MACRO), arg);
        if (libRef.isPresent()) {
            int index;
            try {
                index = Integer.parseInt(libRef.get().getSecond());
            } catch (NumberFormatException e) {
                throw new HumanReadableException("%s: ", target);
            }
            if (index < 0 || index >= libs.size()) {
                throw new HumanReadableException("%s: ", target);
            }
            builder.add(SourcePathArg.of(libs.get(index)));
        } else {
            builder.add(StringArg.of(arg));
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) HumanReadableException(com.facebook.buck.util.HumanReadableException) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) Pair(com.facebook.buck.model.Pair)

Example 28 with HumanReadableException

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

the class TargetsCommand method getDependentNodes.

/**
   * @param graph A graph used to resolve dependencies between targets.
   * @param nodes A set of nodes.
   * @param detectTestChanges If true, tests are considered to be dependencies of the targets they
   *                          are testing.
   * @return A set of all nodes that transitively depend on {@code nodes}
   * (a superset of {@code nodes}).
   */
private static ImmutableSet<TargetNode<?, ?>> getDependentNodes(final TargetGraph graph, ImmutableSet<TargetNode<?, ?>> nodes, boolean detectTestChanges) {
    ImmutableMultimap.Builder<TargetNode<?, ?>, TargetNode<?, ?>> extraEdgesBuilder = ImmutableMultimap.builder();
    if (detectTestChanges) {
        for (TargetNode<?, ?> node : graph.getNodes()) {
            if (node.getConstructorArg() instanceof HasTests) {
                ImmutableSortedSet<BuildTarget> tests = ((HasTests) node.getConstructorArg()).getTests();
                for (BuildTarget testTarget : tests) {
                    Optional<TargetNode<?, ?>> testNode = graph.getOptional(testTarget);
                    if (!testNode.isPresent()) {
                        throw new HumanReadableException("'%s' (test of '%s') is not in the target graph.", testTarget, node);
                    }
                    extraEdgesBuilder.put(testNode.get(), node);
                }
            }
        }
    }
    final ImmutableMultimap<TargetNode<?, ?>, TargetNode<?, ?>> extraEdges = extraEdgesBuilder.build();
    final ImmutableSet.Builder<TargetNode<?, ?>> builder = ImmutableSet.builder();
    AbstractBreadthFirstTraversal<TargetNode<?, ?>> traversal = new AbstractBreadthFirstTraversal<TargetNode<?, ?>>(nodes) {

        @Override
        public ImmutableSet<TargetNode<?, ?>> visit(TargetNode<?, ?> targetNode) {
            builder.add(targetNode);
            return FluentIterable.from(graph.getIncomingNodesFor(targetNode)).append(extraEdges.get(targetNode)).toSet();
        }
    };
    traversal.start();
    return builder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) HasTests(com.facebook.buck.model.HasTests) AbstractBreadthFirstTraversal(com.facebook.buck.graph.AbstractBreadthFirstTraversal) ImmutableMultimap(com.google.common.collect.ImmutableMultimap)

Example 29 with HumanReadableException

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

the class HaskellBuckConfig method getCompiler.

@Override
public ToolProvider getCompiler() {
    Optional<ToolProvider> configuredCompiler = delegate.getToolProvider(SECTION, "compiler");
    if (configuredCompiler.isPresent()) {
        return configuredCompiler.get();
    }
    Optional<Path> systemCompiler = getSystemCompiler();
    if (systemCompiler.isPresent()) {
        return new ConstantToolProvider(new HashedFileTool(systemCompiler.get()));
    }
    throw new HumanReadableException("No Haskell compiler found in .buckconfig (%s.compiler) or on system", SECTION);
}
Also used : ToolProvider(com.facebook.buck.rules.ToolProvider) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) Path(java.nio.file.Path) ConstantToolProvider(com.facebook.buck.rules.ConstantToolProvider) HashedFileTool(com.facebook.buck.rules.HashedFileTool) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 30 with HumanReadableException

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

the class GoDescriptors method makeSymlinkTree.

private static SymlinkTree makeSymlinkTree(BuildRuleParams params, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, ImmutableSet<GoLinkable> linkables) {
    ImmutableMap.Builder<Path, SourcePath> treeMapBuilder = ImmutableMap.builder();
    for (GoLinkable linkable : linkables) {
        for (Map.Entry<Path, SourcePath> linkInput : linkable.getGoLinkInput().entrySet()) {
            treeMapBuilder.put(getPathInSymlinkTree(pathResolver, linkInput.getKey(), linkInput.getValue()), linkInput.getValue());
        }
    }
    ImmutableMap<Path, SourcePath> treeMap;
    try {
        treeMap = treeMapBuilder.build();
    } catch (IllegalArgumentException ex) {
        throw new HumanReadableException(ex, "Multiple go targets have the same package name when compiling %s", params.getBuildTarget().getFullyQualifiedName());
    }
    Path root = BuildTargets.getScratchPath(params.getProjectFilesystem(), params.getBuildTarget(), "__%s__tree");
    return new SymlinkTree(params.getBuildTarget(), params.getProjectFilesystem(), root, treeMap, ruleFinder);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) HumanReadableException(com.facebook.buck.util.HumanReadableException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap)

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