Search in sources :

Example 51 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class RustTestDescription method findDepsForTargetFromConstructorArgs.

@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, RustTestDescription.Arg constructorArg) {
    ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
    ToolProvider compiler = rustBuckConfig.getRustCompiler();
    deps.addAll(compiler.getParseTimeDeps());
    deps.addAll(CxxPlatforms.getParseTimeDeps(cxxPlatforms.getValues()));
    return deps.build();
}
Also used : ToolProvider(com.facebook.buck.rules.ToolProvider) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 52 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class ExportFileDescription method createBuildRule.

@Override
public <A extends Arg> ExportFile createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {
    BuildTarget target = params.getBuildTarget();
    Mode mode = args.mode.orElse(Mode.COPY);
    String name;
    if (args.out.isPresent()) {
        if (mode == ExportFileDescription.Mode.REFERENCE) {
            throw new HumanReadableException("%s: must not set `out` for `export_file` when using `REFERENCE` mode", params.getBuildTarget());
        }
        name = args.out.get();
    } else {
        name = target.getShortNameAndFlavorPostfix();
    }
    SourcePath src;
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    if (args.src.isPresent()) {
        if (mode == ExportFileDescription.Mode.REFERENCE && !pathResolver.getFilesystem(args.src.get()).equals(params.getProjectFilesystem())) {
            throw new HumanReadableException("%s: must use `COPY` mode for `export_file` when source (%s) uses a different cell", target, args.src.get());
        }
        src = args.src.get();
    } else {
        src = new PathSourcePath(params.getProjectFilesystem(), target.getBasePath().resolve(target.getShortNameAndFlavorPostfix()));
    }
    return new ExportFile(params, ruleFinder, pathResolver, name, mode, src);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 53 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class GraphEnhancementQueryEnvironment method getNode.

private TargetNode<?, ?> getNode(QueryTarget target) {
    Preconditions.checkState(target instanceof QueryBuildTarget);
    Preconditions.checkArgument(targetGraph.isPresent());
    BuildTarget buildTarget = ((QueryBuildTarget) target).getBuildTarget();
    return targetGraph.get().getOptional(buildTarget).orElse(null);
}
Also used : QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) QueryBuildTarget(com.facebook.buck.query.QueryBuildTarget)

Example 54 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class RustCompileUtils method requireBuild.

public static RustCompileRule requireBuild(BuildRuleParams params, BuildRuleResolver resolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, RustBuckConfig rustConfig, ImmutableList<String> extraFlags, ImmutableList<String> extraLinkerFlags, Iterable<Arg> linkerInputs, String crateName, CrateType crateType, Linker.LinkableDepType depType, ImmutableSortedSet<SourcePath> sources, SourcePath rootModule) throws NoSuchBuildTargetException {
    BuildTarget target = getCompileBuildTarget(params.getBuildTarget(), cxxPlatform, crateType);
    // If this rule has already been generated, return it.
    Optional<RustCompileRule> existing = resolver.getRuleOptionalWithType(target, RustCompileRule.class);
    if (existing.isPresent()) {
        return existing.get();
    }
    return createBuild(target, crateName, params, resolver, pathResolver, ruleFinder, cxxPlatform, rustConfig, extraFlags, extraLinkerFlags, linkerInputs, crateType, depType, true, sources, rootModule);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget)

Example 55 with BuildTarget

use of com.facebook.buck.model.BuildTarget in project buck by facebook.

the class NeededCoverageSpecTypeCoercer method coerce.

@Override
public NeededCoverageSpec coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
    if (object instanceof NeededCoverageSpec) {
        return (NeededCoverageSpec) object;
    }
    if (object instanceof Collection<?>) {
        Collection<?> collection = (Collection<?>) object;
        if (collection.size() == 2 || collection.size() == 3) {
            Iterator<?> iter = collection.iterator();
            Float neededRatio = floatTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next());
            if (neededRatio < 0 || neededRatio > 1) {
                throw CoerceFailedException.simple(object, getOutputClass(), "the needed coverage ratio should be in range [0; 1]");
            }
            BuildTarget buildTarget = buildTargetTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next());
            Optional<String> pathName = Optional.empty();
            if (iter.hasNext()) {
                pathName = Optional.of(pathNameTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next()));
            }
            return NeededCoverageSpec.of(neededRatio, buildTarget, pathName);
        }
    }
    throw CoerceFailedException.simple(object, getOutputClass(), "input should be a tuple of needed coverage ratio, a build target, and optionally a path");
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Collection(java.util.Collection) NeededCoverageSpec(com.facebook.buck.python.NeededCoverageSpec)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1045 Test (org.junit.Test)758 Path (java.nio.file.Path)323 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)289 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)254 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)248 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)226 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)216 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)209 BuildRule (com.facebook.buck.rules.BuildRule)196 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)178 SourcePath (com.facebook.buck.rules.SourcePath)163 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)161 TargetGraph (com.facebook.buck.rules.TargetGraph)156 PathSourcePath (com.facebook.buck.rules.PathSourcePath)116 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)108 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)91 ImmutableSet (com.google.common.collect.ImmutableSet)90 ImmutableMap (com.google.common.collect.ImmutableMap)78 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)75